[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master ba05f37: [ftgrid] Correctly handle MM data.
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master ba05f37: [ftgrid] Correctly handle MM data. |
Date: |
Wed, 4 Oct 2017 07:32:12 -0400 (EDT) |
branch: master
commit ba05f37b68e34c2a127aaca26a2878bdf1a0de56
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftgrid] Correctly handle MM data.
We have to reload the MM data after the cache gets reset.
* src/ftgrid.c (event_font_change): Move source code up in file.
(event_cff_hinting_engine_change,
event_tt_interpreter_version_change, event_warping_change,
event_lcd_mode_change, Process_Event <'h'>): Call
`event_font_change'.
---
ChangeLog | 12 +++
src/ftgrid.c | 312 ++++++++++++++++++++++++++++++-----------------------------
2 files changed, 171 insertions(+), 153 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bf209f0..2906c2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-10-04 Werner Lemberg <address@hidden>
+
+ [ftgrid] Correctly handle MM data.
+
+ We have to reload the MM data after the cache gets reset.
+
+ * src/ftgrid.c (event_font_change): Move source code up in file.
+ (event_cff_hinting_engine_change,
+ event_tt_interpreter_version_change, event_warping_change,
+ event_lcd_mode_change, Process_Event <'h'>): Call
+ `event_font_change'.
+
2017-10-03 Werner Lemberg <address@hidden>
[ftgrid] Fix crash.
diff --git a/src/ftgrid.c b/src/ftgrid.c
index 74b2d8d..0c9d8b7 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -1048,6 +1048,158 @@
static void
+ event_font_change( int delta )
+ {
+ FT_Error err;
+ FT_Size size;
+ FT_UInt n, num_names;
+ FT_Int instance_index;
+ FT_Multi_Master dummy;
+ int num_indices, is_GX;
+
+
+ if ( status.font_index + delta >= handle->num_fonts ||
+ status.font_index + delta < 0 )
+ return;
+
+ status.font_index += delta;
+
+ FTDemo_Set_Current_Font( handle, handle->fonts[status.font_index] );
+ FTDemo_Set_Current_Charsize( handle, status.ptsize, status.res );
+ FTDemo_Update_Current_Flags( handle );
+
+ num_indices = handle->current_font->num_indices;
+
+ if ( status.Num >= num_indices )
+ status.Num = num_indices - 1;
+
+ err = FTDemo_Get_Size( handle, &size );
+ if ( err )
+ return;
+
+ free( status.mm );
+ status.mm = NULL;
+
+ err = FT_Get_MM_Var( size->face, &status.mm );
+ if ( err )
+ return;
+
+ if ( status.mm->num_axis >= MAX_MM_AXES )
+ {
+ fprintf( stderr, "only handling first %d GX axes (of %d)\n",
+ MAX_MM_AXES, status.mm->num_axis );
+ status.used_num_axis = MAX_MM_AXES;
+ }
+ else
+ status.used_num_axis = status.mm->num_axis;
+
+ err = FT_Get_Multi_Master( size->face, &dummy );
+ is_GX = err ? 1 : 0;
+
+ num_names = FT_Get_Sfnt_Name_Count( size->face );
+
+ /* in `face_index', the instance index starts with value 1 */
+ instance_index = ( size->face->face_index >> 16 ) - 1;
+
+ for ( n = 0; n < MAX_MM_AXES; n++ )
+ {
+ free( status.axis_name[n] );
+ status.axis_name[n] = NULL;
+ }
+
+ for ( n = 0; n < status.used_num_axis; n++ )
+ {
+ if ( status.requested_cnt )
+ {
+ status.design_pos[n] = n < status.requested_cnt
+ ? status.requested_pos[n]
+ : status.mm->axis[n].def;
+ if ( status.design_pos[n] < status.mm->axis[n].minimum )
+ status.design_pos[n] = status.mm->axis[n].minimum;
+ else if ( status.design_pos[n] > status.mm->axis[n].maximum )
+ status.design_pos[n] = status.mm->axis[n].maximum;
+ }
+ else if ( FT_IS_NAMED_INSTANCE( size->face ) )
+ status.design_pos[n] = status.mm->namedstyle[instance_index].
+ coords[n];
+ else
+ status.design_pos[n] = status.mm->axis[n].def;
+
+ if ( is_GX )
+ {
+ FT_SfntName name;
+ FT_UInt strid, j;
+
+
+ name.string = NULL;
+ strid = status.mm->axis[n].strid;
+
+ /* iterate over all name entries */
+ /* to find an English entry for `strid' */
+
+ for ( j = 0; j < num_names; j++ )
+ {
+ error = FT_Get_Sfnt_Name( size->face, j, &name );
+ if ( error )
+ continue;
+
+ if ( name.name_id == strid )
+ {
+ /* XXX we don't have support for Apple's new `ltag' table yet, */
+ /* thus we ignore TT_PLATFORM_APPLE_UNICODE */
+ if ( ( name.platform_id == TT_PLATFORM_MACINTOSH &&
+ name.language_id == TT_MAC_LANGID_ENGLISH ) ||
+ ( name.platform_id == TT_PLATFORM_MICROSOFT &&
+ ( name.language_id & 0xFF )
+ == TT_MS_LANGID_ENGLISH_GENERAL ) )
+ break;
+ }
+ }
+
+ if ( name.string )
+ {
+ FT_UInt len;
+ char* s;
+
+
+ if ( name.platform_id == TT_PLATFORM_MACINTOSH )
+ {
+ len = put_ascii_string_size( name.string, name.string_len, 0 );
+ s = (char*)malloc( len );
+ if ( s )
+ {
+ put_ascii_string( s, name.string, name.string_len, 0 );
+ status.axis_name[n] = s;
+ }
+ }
+ else
+ {
+ len = put_unicode_be16_string_size( name.string,
+ name.string_len,
+ 0,
+ 0 );
+ s = (char*)malloc( len );
+ if ( s )
+ {
+ put_unicode_be16_string( s,
+ name.string,
+ name.string_len,
+ 0,
+ 0 );
+ status.axis_name[n] = s;
+ }
+ }
+ }
+ }
+ }
+
+ (void)FT_Set_Var_Design_Coordinates( size->face,
+ status.used_num_axis,
+ status.design_pos );
+ }
+
+
+ static void
event_cff_hinting_engine_change( int delta )
{
int new_cff_hinting_engine = 0;
@@ -1071,6 +1223,7 @@
/* are of type CFF, then unloading them explicitly. */
FTC_Manager_Reset( handle->cache_manager );
status.cff_hinting_engine = (FT_UInt)new_cff_hinting_engine;
+ event_font_change( 0 );
}
sprintf( status.header_buffer, "CFF engine changed to %s",
@@ -1099,6 +1252,7 @@
/* lazy to walk over all loaded fonts to check whether they */
/* are of type TTF, then unloading them explicitly. */
FTC_Manager_Reset( handle->cache_manager );
+ event_font_change( 0 );
}
sprintf( status.header_buffer,
@@ -1130,6 +1284,7 @@
/* are auto-hinted, then unloading them explicitly. */
FTC_Manager_Reset( handle->cache_manager );
status.warping = new_warping_state;
+ event_font_change( 0 );
}
status.header = status.warping ? "warping enabled"
@@ -1231,7 +1386,10 @@
}
if ( delta )
+ {
FTC_Manager_Reset( handle->cache_manager );
+ event_font_change( 0 );
+ }
sprintf( status.header_buffer, "rendering mode changed to %s",
lcd_mode );
@@ -1364,158 +1522,6 @@
}
- static void
- event_font_change( int delta )
- {
- FT_Error err;
- FT_Size size;
- FT_UInt n, num_names;
- FT_Int instance_index;
- FT_Multi_Master dummy;
- int num_indices, is_GX;
-
-
- if ( status.font_index + delta >= handle->num_fonts ||
- status.font_index + delta < 0 )
- return;
-
- status.font_index += delta;
-
- FTDemo_Set_Current_Font( handle, handle->fonts[status.font_index] );
- FTDemo_Set_Current_Charsize( handle, status.ptsize, status.res );
- FTDemo_Update_Current_Flags( handle );
-
- num_indices = handle->current_font->num_indices;
-
- if ( status.Num >= num_indices )
- status.Num = num_indices - 1;
-
- err = FTDemo_Get_Size( handle, &size );
- if ( err )
- return;
-
- free( status.mm );
- status.mm = NULL;
-
- err = FT_Get_MM_Var( size->face, &status.mm );
- if ( err )
- return;
-
- if ( status.mm->num_axis >= MAX_MM_AXES )
- {
- fprintf( stderr, "only handling first %d GX axes (of %d)\n",
- MAX_MM_AXES, status.mm->num_axis );
- status.used_num_axis = MAX_MM_AXES;
- }
- else
- status.used_num_axis = status.mm->num_axis;
-
- err = FT_Get_Multi_Master( size->face, &dummy );
- is_GX = err ? 1 : 0;
-
- num_names = FT_Get_Sfnt_Name_Count( size->face );
-
- /* in `face_index', the instance index starts with value 1 */
- instance_index = ( size->face->face_index >> 16 ) - 1;
-
- for ( n = 0; n < MAX_MM_AXES; n++ )
- {
- free( status.axis_name[n] );
- status.axis_name[n] = NULL;
- }
-
- for ( n = 0; n < status.used_num_axis; n++ )
- {
- if ( status.requested_cnt )
- {
- status.design_pos[n] = n < status.requested_cnt
- ? status.requested_pos[n]
- : status.mm->axis[n].def;
- if ( status.design_pos[n] < status.mm->axis[n].minimum )
- status.design_pos[n] = status.mm->axis[n].minimum;
- else if ( status.design_pos[n] > status.mm->axis[n].maximum )
- status.design_pos[n] = status.mm->axis[n].maximum;
- }
- else if ( FT_IS_NAMED_INSTANCE( size->face ) )
- status.design_pos[n] = status.mm->namedstyle[instance_index].
- coords[n];
- else
- status.design_pos[n] = status.mm->axis[n].def;
-
- if ( is_GX )
- {
- FT_SfntName name;
- FT_UInt strid, j;
-
-
- name.string = NULL;
- strid = status.mm->axis[n].strid;
-
- /* iterate over all name entries */
- /* to find an English entry for `strid' */
-
- for ( j = 0; j < num_names; j++ )
- {
- error = FT_Get_Sfnt_Name( size->face, j, &name );
- if ( error )
- continue;
-
- if ( name.name_id == strid )
- {
- /* XXX we don't have support for Apple's new `ltag' table yet, */
- /* thus we ignore TT_PLATFORM_APPLE_UNICODE */
- if ( ( name.platform_id == TT_PLATFORM_MACINTOSH &&
- name.language_id == TT_MAC_LANGID_ENGLISH ) ||
- ( name.platform_id == TT_PLATFORM_MICROSOFT &&
- ( name.language_id & 0xFF )
- == TT_MS_LANGID_ENGLISH_GENERAL ) )
- break;
- }
- }
-
- if ( name.string )
- {
- FT_UInt len;
- char* s;
-
-
- if ( name.platform_id == TT_PLATFORM_MACINTOSH )
- {
- len = put_ascii_string_size( name.string, name.string_len, 0 );
- s = (char*)malloc( len );
- if ( s )
- {
- put_ascii_string( s, name.string, name.string_len, 0 );
- status.axis_name[n] = s;
- }
- }
- else
- {
- len = put_unicode_be16_string_size( name.string,
- name.string_len,
- 0,
- 0 );
- s = (char*)malloc( len );
- if ( s )
- {
- put_unicode_be16_string( s,
- name.string,
- name.string_len,
- 0,
- 0 );
- status.axis_name[n] = s;
- }
- }
- }
- }
- }
-
- (void)FT_Set_Var_Design_Coordinates( size->face,
- status.used_num_axis,
- status.design_pos );
- }
-
-
static int
Process_Event( grEvent* event )
{
@@ -1615,7 +1621,7 @@
: "glyph hinting is now ignored";
FTC_Manager_Reset( handle->cache_manager );
- FTDemo_Update_Current_Flags( handle );
+ event_font_change( 0 );
break;
case grKEY( 'G' ):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master ba05f37: [ftgrid] Correctly handle MM data.,
Werner LEMBERG <=