[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master c7457bb: [ftstring] Load glyphs and advances ex
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master c7457bb: [ftstring] Load glyphs and advances explicitly. |
Date: |
Wed, 12 Sep 2018 23:04:35 -0400 (EDT) |
branch: master
commit c7457bbc2447c4e9afc20d0c8380d5af4c0bfbc2
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
[ftstring] Load glyphs and advances explicitly.
* src/ftcommon.h (FTDemo_Handle): Remove `string_reload' flag.
(TGlyph): Split `delta' into original `lsb_delta' and `rsb_delta'.
(FTDemo_String_Load): Declare new function.
* src/ftcommon.c (string_load, string_render_prepare): Merge into...
(FTDemo_String_Load): ... this function.
(FTDemo_String_Draw): Devoid of string loading.
* src/ftstring.c (main, Process_Event,Render_{Waterfall,KernCmp}):
Call `FTDemo_String_Load' explicitly.
---
ChangeLog | 14 ++++++
src/ftcommon.c | 151 +++++++++++++++------------------------------------------
src/ftcommon.h | 17 +++++--
src/ftstring.c | 82 ++++++++++++++++---------------
4 files changed, 109 insertions(+), 155 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index acd2235..82f35ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2018-09-12 Alexei Podtelezhnikov <address@hidden>
+
+ [ftstring] Load glyphs and advances explicitly.
+
+ * src/ftcommon.h (FTDemo_Handle): Remove `string_reload' flag.
+ (TGlyph): Split `delta' into original `lsb_delta' and `rsb_delta'.
+ (FTDemo_String_Load): Declare new function.
+ * src/ftcommon.c (string_load, string_render_prepare): Merge into...
+ (FTDemo_String_Load): ... this function.
+ (FTDemo_String_Draw): Devoid of string loading.
+
+ * src/ftstring.c (main, Process_Event,Render_{Waterfall,KernCmp}):
+ Call `FTDemo_String_Load' explicitly.
+
2018-09-11 Alexei Podtelezhnikov <address@hidden>
[ftstring] Keep all advances together.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index a3c699e..c0149bd 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -322,7 +322,6 @@
/* string_init */
memset( handle->string, 0, sizeof ( TGlyph ) * MAX_GLYPHS );
handle->string_length = 0;
- handle->string_reload = 1;
return handle;
}
@@ -567,8 +566,6 @@
default:
font->num_indices = 0x10000L;
}
-
- handle->string_reload = 1;
}
@@ -610,8 +607,6 @@
handle->scaler.pixel = 1; /* activate integer format */
handle->scaler.x_res = 0;
handle->scaler.y_res = 0;
-
- handle->string_reload = 1;
}
@@ -656,8 +651,6 @@
handle->scaler.pixel = 0; /* activate 26.6 format */
handle->scaler.x_res = (FT_UInt)resolution;
handle->scaler.y_res = (FT_UInt)resolution;
-
- handle->string_reload = 1;
}
@@ -726,7 +719,6 @@
}
handle->load_flags = flags;
- handle->string_reload = 1;
}
@@ -1320,18 +1312,19 @@
if ( handle->string_length >= MAX_GLYPHS )
break;
}
-
- handle->string_reload = 1;
}
- static FT_Error
- string_load( FTDemo_Handle* handle )
+ FT_Error
+ FTDemo_String_Load( FTDemo_Handle* handle,
+ FTDemo_String_Context* sc )
{
- int n;
FT_Size size;
FT_Face face;
- FT_Pos prev_rsb_delta = 0;
+ FT_Int i;
+ FT_Int length = handle->string_length;
+ PGlyph glyph, prev;
+ FT_Pos track_kern = 0;
error = FTDemo_Get_Size( handle, &size );
@@ -1340,11 +1333,8 @@
face = size->face;
- for ( n = 0; n < handle->string_length; n++ )
+ for ( glyph = handle->string, i = 0; i < length; glyph++, i++ )
{
- PGlyph glyph = handle->string + n;
-
-
/* clear existing image if there is one */
if ( glyph->image )
{
@@ -1368,87 +1358,56 @@
glyph->vadvance.x = 0;
glyph->vadvance.y = -metrics->vertAdvance;
+ glyph->lsb_delta = face->glyph->lsb_delta;
+ glyph->rsb_delta = face->glyph->rsb_delta;
+
glyph->hadvance.x = metrics->horiAdvance;
glyph->hadvance.y = 0;
-
- if ( handle->lcd_mode == LCD_MODE_LIGHT_SUBPIXEL )
- glyph->delta = face->glyph->lsb_delta - face->glyph->rsb_delta;
- else
- {
- if ( prev_rsb_delta - face->glyph->lsb_delta > 32 )
- glyph->delta = -1 * 64;
- else if ( prev_rsb_delta - face->glyph->lsb_delta < -31 )
- glyph->delta = 1 * 64;
- else
- glyph->delta = 0;
-
- prev_rsb_delta = face->glyph->rsb_delta;
- }
}
}
- return FT_Err_Ok;
- }
-
-
- static FT_Error
- string_render_prepare( FTDemo_Handle* handle,
- FTDemo_String_Context* sc )
- {
- FT_Face face;
- FT_Size size;
- PGlyph glyph = handle->string;
- PGlyph prev = handle->string + handle->string_length;
- FT_Pos track_kern = 0;
- FT_Int i;
-
-
- error = FTDemo_Get_Size( handle, &size );
- if ( error )
- return error;
-
- face = size->face;
-
- if ( !sc->vertical && sc->kerning_degree )
+ if ( sc->kerning_degree )
{
/* this function needs and returns points, not pixels */
- if ( FT_Get_Track_Kerning( face,
- (FT_Fixed)handle->scaler.width << 10,
- -sc->kerning_degree,
- &track_kern ) )
- track_kern = 0;
- else
+ if ( !FT_Get_Track_Kerning( face,
+ (FT_Fixed)handle->scaler.width << 10,
+ -sc->kerning_degree,
+ &track_kern ) )
track_kern = (FT_Pos)(
( track_kern / 1024.0 * handle->scaler.x_res ) /
72.0 );
}
- for ( i = 0; i < handle->string_length; i++ )
+ for ( prev = handle->string + length, glyph = handle->string, i = 0;
+ i < length;
+ prev = glyph, glyph++, i++ )
{
if ( !glyph->image )
continue;
- if ( !sc->vertical )
- {
- if ( handle->lcd_mode == LCD_MODE_LIGHT_SUBPIXEL )
- glyph->hadvance.x += glyph->delta;
+ if ( handle->lcd_mode == LCD_MODE_LIGHT_SUBPIXEL )
+ glyph->hadvance.x += glyph->lsb_delta - glyph->rsb_delta;
- prev->hadvance.x += track_kern;
+ prev->hadvance.x += track_kern;
- if ( sc->kerning_mode )
- {
- FT_Vector kern;
+ if ( sc->kerning_mode )
+ {
+ FT_Vector kern;
- FT_Get_Kerning( face, prev->glyph_index, glyph->glyph_index,
- FT_KERNING_UNFITTED, &kern );
+ FT_Get_Kerning( face, prev->glyph_index, glyph->glyph_index,
+ FT_KERNING_UNFITTED, &kern );
- prev->hadvance.x += kern.x;
- prev->hadvance.y += kern.y;
+ prev->hadvance.x += kern.x;
+ prev->hadvance.y += kern.y;
- if ( handle->lcd_mode != LCD_MODE_LIGHT_SUBPIXEL &&
- sc->kerning_mode > KERNING_MODE_NORMAL )
- prev->hadvance.x += glyph->delta;
+ if ( handle->lcd_mode != LCD_MODE_LIGHT_SUBPIXEL &&
+ sc->kerning_mode > KERNING_MODE_NORMAL )
+ {
+ if ( prev->rsb_delta - glyph->lsb_delta > 32 )
+ prev->hadvance.x -= 64;
+ else if ( prev->rsb_delta - glyph->lsb_delta < -31 )
+ prev->hadvance.x += 64;
}
}
@@ -1458,9 +1417,6 @@
prev->hadvance.x = ROUND( prev->hadvance.x );
prev->hadvance.y = ROUND( prev->hadvance.y );
}
-
- prev = glyph;
- glyph++;;
}
return FT_Err_Ok;
@@ -1477,8 +1433,6 @@
int n;
FT_Vector pen = { 0, 0};
FT_Vector advance;
- FT_Size size;
- FT_Face face;
if ( !sc ||
@@ -1488,25 +1442,6 @@
y > display->bitmap->rows )
return FT_Err_Invalid_Argument;
- error = FTDemo_Get_Size( handle, &size );
- if ( error )
- return error;
-
- face = size->face;
-
- if ( handle->string_reload )
- {
- error = string_load( handle );
- if ( error )
- return error;
-
- handle->string_reload = 0;
- }
-
- error = string_render_prepare( handle, sc );
- if ( error )
- return error;
-
/* change to Cartesian coordinates */
y = display->bitmap->rows - y;
@@ -1529,18 +1464,10 @@
/* XXX sbits */
/* get pen position */
- if ( sc->matrix && FT_IS_SCALABLE( face ) )
- {
- FT_Vector_Transform( &pen, sc->matrix );
+ FT_Vector_Transform( &pen, sc->matrix );
- pen.x = ( x << 6 ) - pen.x;
- pen.y = ( y << 6 ) - pen.y;
- }
- else
- {
- pen.x = ROUND( ( x << 6 ) - pen.x );
- pen.y = ROUND( ( y << 6 ) - pen.y );
- }
+ pen.x = ( x << 6 ) - pen.x;
+ pen.y = ( y << 6 ) - pen.y;
for ( n = 0; n < handle->string_length; n++ )
{
diff --git a/src/ftcommon.h b/src/ftcommon.h
index dbb0cdd..3a3b04c 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -116,10 +116,12 @@
FT_UInt glyph_index;
FT_Glyph image; /* the glyph image */
- FT_Pos delta; /* delta caused by hinting */
- FT_Vector hadvance; /* kerned horizontal advance */
- FT_Vector vvector; /* vert. origin => hori. origin */
- FT_Vector vadvance; /* vertical advance */
+ FT_Pos lsb_delta; /* delta caused by hinting */
+ FT_Pos rsb_delta; /* delta caused by hinting */
+ FT_Vector hadvance; /* kerned horizontal advance */
+
+ FT_Vector vvector; /* vert. origin => hori. origin */
+ FT_Vector vadvance; /* vertical advance */
} TGlyph, *PGlyph;
@@ -204,7 +206,6 @@
/* used for string rendering */
TGlyph string[MAX_GLYPHS];
int string_length;
- int string_reload;
unsigned long encoding;
FT_Stroker stroker;
@@ -337,6 +338,12 @@
const char* string );
+ /* load kerned advances with hinting compensation */
+ FT_Error
+ FTDemo_String_Load( FTDemo_Handle* handle,
+ FTDemo_String_Context* sc );
+
+
/* draw a string centered at (center_x, center_y) -- */
/* note that handle->use_sbits_cache is not supported */
FT_Error
diff --git a/src/ftstring.c b/src/ftstring.c
index c51a3cf..e509630 100644
--- a/src/ftstring.c
+++ b/src/ftstring.c
@@ -261,9 +261,6 @@
FTDemo_Set_Current_Font( handle, handle->fonts[status.font_index] );
FTDemo_Set_Current_Charsize( handle, status.ptsize, status.res );
- FTDemo_Update_Current_Flags( handle );
-
- FTDemo_String_Set( handle, status.text );
}
@@ -456,45 +453,37 @@
case grKeyEsc:
case grKEY( 'q' ):
ret = 1;
- break;
+ goto Exit;;
case grKeyF1:
case grKEY( '?' ):
event_help();
- break;
+ goto Exit;
case grKEY( 'b' ):
handle->use_sbits = !handle->use_sbits;
status.header = handle->use_sbits
? (char *)"embedded bitmaps are now used when
available"
: (char *)"embedded bitmaps are now ignored";
-
- FTDemo_Update_Current_Flags( handle );
- break;
+ goto Flags;
case grKEY( 'f' ):
handle->autohint = !handle->autohint;
status.header = handle->autohint
? (char *)"forced auto-hinting is now on"
: (char *)"forced auto-hinting is now off";
-
- FTDemo_Update_Current_Flags( handle );
- break;
+ goto Flags;
case grKEY( 'h' ):
handle->hinted = !handle->hinted;
status.header = handle->hinted
? (char *)"glyph hinting is now active"
: (char *)"glyph hinting is now ignored";
-
- FTDemo_Update_Current_Flags( handle );
- break;
+ goto Flags;
case grKEY( 'l' ):
event_lcdmode_change();
-
- FTDemo_Update_Current_Flags( handle );
- break;
+ goto Flags;
case grKEY( 'k' ):
sc->kerning_mode = ( sc->kerning_mode + 1 ) % N_KERNING_MODES;
@@ -504,7 +493,7 @@
: sc->kerning_mode == KERNING_MODE_NORMAL
? (char *)"pair kerning is now active"
: (char *)"pair kerning is now ignored";
- break;
+ goto String;
case grKEY( 't' ):
sc->kerning_degree = ( sc->kerning_degree + 1 ) % N_KERNING_DEGREES;
@@ -516,57 +505,66 @@
: sc->kerning_degree == KERNING_DEGREE_MEDIUM
? (char *)"medium track kerning active"
: (char *)"tight track kerning active";
- break;
+ goto String;
case grKeySpace:
event_color_change();
- break;
+ goto Exit;
case grKeyTab:
event_text_change();
FTDemo_String_Set( handle, status.text );
- break;
+ goto String;
case grKEY( 'V' ):
sc->vertical = !sc->vertical;
status.header = sc->vertical
? (char *)"using vertical layout"
: (char *)"using horizontal layout";
- break;
+ goto Exit;
case grKEY( 'g' ):
event_gamma_change( 0.1 );
- break;
+ goto Exit;
case grKEY( 'v' ):
event_gamma_change( -0.1 );
- break;
+ goto Exit;
case grKEY( 'n' ):
event_font_change( 1 );
- break;
+ FTDemo_String_Set( handle, status.text );
+ goto Flags;
case grKEY( 'p' ):
event_font_change( -1 );
- break;
+ FTDemo_String_Set( handle, status.text );
+ goto Flags;
- case grKeyUp: event_size_change( 64 ); break;
- case grKeyDown: event_size_change( -64 ); break;
- case grKeyPageUp: event_size_change( 640 ); break;
- case grKeyPageDown: event_size_change( -640 ); break;
+ case grKeyUp: event_size_change( 64 ); goto String;
+ case grKeyDown: event_size_change( -64 ); goto String;
+ case grKeyPageUp: event_size_change( 640 ); goto String;
+ case grKeyPageDown: event_size_change( -640 ); goto String;
- case grKeyLeft: event_center_change( 0x800 ); break;
- case grKeyRight: event_center_change( -0x800 ); break;
+ case grKeyLeft: event_center_change( 0x800 ); goto Exit;
+ case grKeyRight: event_center_change( -0x800 ); goto Exit;
- case grKeyF5: event_angle_change( -3 ); break;
- case grKeyF6: event_angle_change( 3 ); break;
- case grKeyF7: event_angle_change( -30 ); break;
- case grKeyF8: event_angle_change( 30 ); break;
+ case grKeyF5: event_angle_change( -3 ); goto Exit;
+ case grKeyF6: event_angle_change( 3 ); goto Exit;
+ case grKeyF7: event_angle_change( -30 ); goto Exit;
+ case grKeyF8: event_angle_change( 30 ); goto Exit;
default:
break;
}
+ Flags:
+ FTDemo_Update_Current_Flags( handle );
+
+ String:
+ FTDemo_String_Load( handle, &status.sc );
+
+ Exit:
return ret;
}
@@ -735,6 +733,7 @@
pt_size += step;
FTDemo_Set_Current_Charsize( handle, pt_size, status.res );
+ FTDemo_String_Load( handle, &status.sc );
error = FTDemo_Get_Size( handle, &size );
if ( error )
@@ -759,7 +758,7 @@
}
FTDemo_Set_Current_Charsize( handle, status.ptsize, status.res );
- FTDemo_Get_Size( handle, &size );
+ FTDemo_String_Load( handle, &status.sc );
return FT_Err_Ok;
}
@@ -782,6 +781,8 @@
height = CELLSTRING_HEIGHT;
/* First line: none */
+ FTDemo_String_Load( handle, &sc );
+
y = CELLSTRING_HEIGHT * 2 + display->bitmap->rows / 4 + height;
grWriteCellString( display->bitmap, 5,
y - ( height + CELLSTRING_HEIGHT ) / 2,
@@ -790,6 +791,7 @@
/* Second line: track kern only */
sc.kerning_degree = status.sc.kerning_degree;
+ FTDemo_String_Load( handle, &sc );
y += height;
grWriteCellString( display->bitmap, 5,
@@ -799,6 +801,7 @@
/* Third line: track kern + pair kern */
sc.kerning_mode = status.sc.kerning_mode;
+ FTDemo_String_Load( handle, &sc );
y += height;
grWriteCellString( display->bitmap, 5,
@@ -830,7 +833,6 @@
handle->encoding = status.encoding;
handle->use_sbits = 0;
- FTDemo_Update_Current_Flags( handle );
for ( ; argc > 0; argc--, argv++ )
{
@@ -864,7 +866,11 @@
event_color_change();
event_gamma_change( 0 );
+
event_font_change( 0 );
+ FTDemo_String_Set( handle, status.text );
+ FTDemo_Update_Current_Flags( handle );
+ FTDemo_String_Load( handle, &status.sc );
do
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master c7457bb: [ftstring] Load glyphs and advances explicitly.,
Alexei Podtelezhnikov <=