Skip to content

Commit

Permalink
fix font scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
GorgonMeducer committed Dec 24, 2024
1 parent b5ad0ce commit 200538c
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 61 deletions.
2 changes: 1 addition & 1 deletion ARM.Arm-2D.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
</RTE_Components_h>
</component>

<component Cclass="Acceleration" Cgroup="Arm-2D Extras" Csub="LCD ASCII Printf" Cversion="2.6.5" condition="Arm-2D-Printf">
<component Cclass="Acceleration" Cgroup="Arm-2D Extras" Csub="LCD ASCII Printf" Cversion="2.8.0" condition="Arm-2D-Printf">
<description>A helper service for fonts and LCD printf.</description>
<files>
<file category="header" name="Helper/Include/arm_2d_helper_font.h" />
Expand Down
8 changes: 4 additions & 4 deletions Helper/Include/arm_2d_helper_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* Title: #include "arm_2d_helper_font.h"
* Description: the font helper service header file
*
* $Date: 03. Dec 2024
* $Revision: V.2.7.6
* $Date: 24. Dec 2024
* $Revision: V.2.8.0
*
* Target Processor: Cortex-M cores
* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -158,7 +158,7 @@ extern "C" {
arm_2d_tile_t *ptileChar, \
COLOUR_INT tForeColour, \
uint_fast8_t chOpacity, \
float fScale)
q16_t q16Scale)

#define IMPL_FONT_GET_CHAR_DESCRIPTOR(__NAME) \
arm_2d_char_descriptor_t *__NAME( \
Expand Down Expand Up @@ -191,7 +191,7 @@ typedef arm_fsm_rt_t arm_2d_font_draw_char_handler_t(
arm_2d_tile_t *ptileChar,
COLOUR_INT tForeColour,
uint_fast8_t chOpacity,
float fScale);
q16_t q16Scale);

/* Font definitions */
struct arm_2d_font_t {
Expand Down
111 changes: 74 additions & 37 deletions Helper/Source/arm_2d_helper_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* Title: #include "arm_2d_helper_font.c"
* Description: the font helper service source code
*
* $Date: 03. Dec 2024
* $Revision: V.2.7.6
* $Date: 24. Dec 2024
* $Revision: V.2.8.0
*
* Target Processor: Cortex-M cores
* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -93,7 +93,8 @@ static struct {

arm_2d_tile_t *ptTargetFB;
uint32_t wMode;
float fScale;
//float fScale;
q16_t q16Scale;

uint32_t bForceAllCharUseSameWidth : 1;
uint32_t : 31;
Expand Down Expand Up @@ -319,12 +320,14 @@ static void __arm_lcd_text_update_char_buffer(void)

void arm_lcd_text_set_scale(float fScale)
{
if ((fScale != 0.0f) && ABS(fScale - 1.0f) > 0.01f) {
s_tLCDTextControl.fScale = ABS(fScale);
q16_t q16Scale = abs_q16(reinterpret_q16_f32(fScale));

if ((q16Scale != 0) && abs_q16(q16Scale - reinterpret_q16_s16(1)) > reinterpret_q16_f32(0.01f)) {
s_tLCDTextControl.q16Scale = q16Scale;

__arm_lcd_text_update_char_buffer();
} else {
s_tLCDTextControl.fScale = 0.0f;
s_tLCDTextControl.q16Scale = 0;
}
}

Expand Down Expand Up @@ -453,8 +456,8 @@ int16_t __arm_lcd_get_char_advance(const arm_2d_font_t *ptFont, arm_2d_char_desc
iAdvance = ptDescriptor->iAdvance;
} while(0);

if (s_tLCDTextControl.fScale > 0.0f) {
iAdvance = (int16_t)((float)iAdvance * s_tLCDTextControl.fScale);
if (s_tLCDTextControl.q16Scale > 0) {
iAdvance = reinterpret_s16_q16( mul_n_q16 ( s_tLCDTextControl.q16Scale, iAdvance));
/* NOTE: No need to adjust bearings in the following way. */
//ptDescriptor->iBearingX = (int16_t)((float)ptDescriptor->iBearingX * s_tLCDTextControl.fScale);
//ptDescriptor->iBearingY = (int16_t)((float)ptDescriptor->iBearingY * s_tLCDTextControl.fScale);
Expand Down Expand Up @@ -523,9 +526,9 @@ int16_t lcd_draw_char(int16_t iX, int16_t iY, uint8_t **ppchCharCode, uint_fast8
&tCharDescriptor.tileChar,
s_tLCDTextControl.tColour.tForeground,
chOpacity,
s_tLCDTextControl.fScale);
s_tLCDTextControl.q16Scale);

if (s_tLCDTextControl.fScale > 0.0f) {
if (s_tLCDTextControl.q16Scale > 0) {
ARM_2D_IMPL(arm_2d_op_fill_cl_msk_opa_trans_t, NULL);

arm_2d_region_get_minimal_enclosure(&s_tLCDTextControl.tTextRegion,
Expand All @@ -543,8 +546,9 @@ int16_t lcd_draw_char(int16_t iX, int16_t iY, uint8_t **ppchCharCode, uint_fast8
IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a8_font_draw_char)
{
ARM_2D_UNUSED(ptFont);
ARM_2D_UNUSED(q16Scale);

if (fScale == 0.0f) {
if (q16Scale == 0) {
return arm_2d_fill_colour_with_mask_and_opacity(
ptTile,
ptRegion,
Expand All @@ -568,7 +572,7 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a8_font_draw_char)
NULL,
c_tCentre,
0.0f,
fScale,
reinterpret_f32_q16(q16Scale),
tForeColour,
chOpacity,
&tTargetCenter);
Expand All @@ -577,8 +581,11 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a8_font_draw_char)

IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a1_font_draw_char)
{
ARM_2D_UNUSED(ptFont);
ARM_2D_UNUSED(q16Scale);

#if __ARM_2D_CFG_SUPPORT_TRANSFORM_FOR_NON_A8_FONTS__
if (fScale != 0.0f) {
if (q16Scale != 0) {

arm_2d_tile_t tTempA8CharTile = {
.tRegion = {
Expand Down Expand Up @@ -637,7 +644,7 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a1_font_draw_char)
&tTempCharTile,
tForeColour,
chOpacity,
fScale);
q16Scale);

} else
#endif
Expand All @@ -654,8 +661,11 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a1_font_draw_char)

IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a2_font_draw_char)
{
ARM_2D_UNUSED(ptFont);
ARM_2D_UNUSED(q16Scale);

#if __ARM_2D_CFG_SUPPORT_TRANSFORM_FOR_NON_A8_FONTS__
if (fScale != 0.0f) {
if (q16Scale != 0) {

arm_2d_tile_t tTempA8CharTile = {
.tRegion = {
Expand Down Expand Up @@ -714,7 +724,7 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a2_font_draw_char)
&tTempCharTile,
tForeColour,
chOpacity,
fScale);
q16Scale);

} else
#endif
Expand All @@ -732,7 +742,7 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a2_font_draw_char)
IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a4_font_draw_char)
{
#if __ARM_2D_CFG_SUPPORT_TRANSFORM_FOR_NON_A8_FONTS__
if (fScale != 0.0f) {
if (q16Scale != 0) {

arm_2d_tile_t tTempA8CharTile = {
.tRegion = {
Expand Down Expand Up @@ -791,7 +801,7 @@ IMPL_FONT_DRAW_CHAR(__arm_2d_lcd_text_default_a4_font_draw_char)
&tTempCharTile,
tForeColour,
chOpacity,
fScale);
q16Scale);

} else
#endif
Expand Down Expand Up @@ -827,9 +837,13 @@ arm_2d_size_t __arm_lcd_get_string_line_box(const char *str, const arm_2d_font_t
}
arm_2d_size_t tCharSize = ptFont->tCharSize;

if (s_tLCDTextControl.fScale > 0.0f) {
tCharSize.iHeight = (float)tCharSize.iHeight * s_tLCDTextControl.fScale + 2;
tCharSize.iWidth = (float)tCharSize.iWidth * s_tLCDTextControl.fScale + 2;
if (s_tLCDTextControl.q16Scale > 0) {
tCharSize.iHeight = reinterpret_s16_q16(
mul_n_q16(s_tLCDTextControl.q16Scale, tCharSize.iHeight))
+ 2;
tCharSize.iWidth = reinterpret_s16_q16(
mul_n_q16(s_tLCDTextControl.q16Scale, tCharSize.iWidth))
+ 2;
}

arm_2d_region_t tDrawBox = {
Expand Down Expand Up @@ -892,17 +906,29 @@ arm_2d_size_t __arm_lcd_get_string_line_box(const char *str, const arm_2d_font_t
void arm_lcd_putchar(const char *str)
{

if (!arm_2d_helper_pfb_is_region_active(s_tLCDTextControl.ptTargetFB, &s_tLCDTextControl.tRegion, true)) {
return ;
}

arm_2d_size_t tCharSize = s_tLCDTextControl.ptFont->tCharSize;

if (s_tLCDTextControl.fScale > 0.0f) {
tCharSize.iHeight = (float)tCharSize.iHeight * s_tLCDTextControl.fScale + 2;
tCharSize.iWidth = (float)tCharSize.iWidth * s_tLCDTextControl.fScale + 2;
if (s_tLCDTextControl.q16Scale > 0) {
tCharSize.iHeight = reinterpret_s16_q16(
mul_n_q16(s_tLCDTextControl.q16Scale, tCharSize.iHeight))
+ 2;
tCharSize.iWidth = reinterpret_s16_q16(
mul_n_q16(s_tLCDTextControl.q16Scale, tCharSize.iWidth))
+ 2;
}

do {
arm_2d_region_t tCharDrawRegion = s_tLCDTextControl.tRegion;
tCharDrawRegion.tSize.iWidth += tCharSize.iWidth;
tCharDrawRegion.tSize.iHeight += tCharSize.iHeight;
tCharDrawRegion.tLocation.iX -= tCharSize.iWidth >> 1;
tCharDrawRegion.tLocation.iY -= tCharSize.iHeight >> 1;

if (!arm_2d_helper_pfb_is_region_active(s_tLCDTextControl.ptTargetFB, &tCharDrawRegion, false)) {
return ;
}
} while(0);

arm_2d_size_t tDrawRegionSize = s_tLCDTextControl.tRegion.tSize;

if (*str) {
Expand Down Expand Up @@ -941,18 +967,29 @@ void arm_lcd_putchar(const char *str)

void arm_lcd_puts(const char *str)
{

if (!arm_2d_helper_pfb_is_region_active(s_tLCDTextControl.ptTargetFB, &s_tLCDTextControl.tRegion, true)) {
return ;
}

arm_2d_size_t tCharSize = s_tLCDTextControl.ptFont->tCharSize;

if (s_tLCDTextControl.fScale > 0.0f) {
tCharSize.iHeight = (float)tCharSize.iHeight * s_tLCDTextControl.fScale + 2;
tCharSize.iWidth = (float)tCharSize.iWidth * s_tLCDTextControl.fScale + 2;
if (s_tLCDTextControl.q16Scale > 0) {
tCharSize.iHeight = reinterpret_s16_q16(
mul_n_q16(s_tLCDTextControl.q16Scale, tCharSize.iHeight))
+ 2;
tCharSize.iWidth = reinterpret_s16_q16(
mul_n_q16(s_tLCDTextControl.q16Scale, tCharSize.iWidth))
+ 2;
}

do {
arm_2d_region_t tCharDrawRegion = s_tLCDTextControl.tRegion;
tCharDrawRegion.tSize.iWidth += tCharSize.iWidth;
tCharDrawRegion.tSize.iHeight += tCharSize.iHeight;
tCharDrawRegion.tLocation.iX -= tCharSize.iWidth >> 1;
tCharDrawRegion.tLocation.iY -= tCharSize.iHeight >> 1;

if (!arm_2d_helper_pfb_is_region_active(s_tLCDTextControl.ptTargetFB, &tCharDrawRegion, false)) {
return ;
}
} while(0);

arm_2d_size_t tDrawRegionSize = s_tLCDTextControl.tRegion.tSize;

while(*str) {
Expand Down Expand Up @@ -1036,7 +1073,7 @@ typedef enum {
#endif

ARM_NONNULL(1)
void arm_lcd_puts_label( const char *pchString,
void arm_lcd_puts_label(const char *pchString,
arm_2d_align_t tAlignment)
{
assert(NULL != pchString);
Expand Down
Loading

0 comments on commit 200538c

Please sign in to comment.