From 0fb8795e2bc90edff6092d8184e3d7da210a2547 Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Thu, 28 Aug 2025 21:04:22 -0400 Subject: [PATCH] [base] Simplify autohinting conditions. After FreeType switched type1 and t1cid drivers to the Adobe engine a while ago, we could flag them as DRIVER_HINTS_LIGHTLY. We do it now explicitly in the driver_init and the property_set functions as a future reminder. This simplifies the conditions for autohinting. * src/base/ftobjs.c (FT_Load_Glyph): Rely only on !DRIVER_HINTS_LIGHTLY when selecting the autohinter for the LIGHT mode. * src/cff/cffdrivr.c (cff_driver_class): Move the flag from here... * src/cff/cffobjs.c (cff_driver_init): ... to here, explicitly. * src/cid/cidobjs.c (sid_driver_init): Set it explicitly. * src/type1/t1objs.c (T1_Driver_Init): Set it explicitly. * src/base/ftpsprop.c (ps_property_set): Sync the flags when switching. --- src/base/ftobjs.c | 41 ++++++++++++++--------------------------- src/base/ftpsprop.c | 6 ++++++ src/cff/cffdrivr.c | 7 +++---- src/cff/cffobjs.c | 3 ++- src/cid/cidobjs.c | 3 ++- src/cid/cidriver.c | 1 + src/type1/t1objs.c | 3 ++- 7 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index b689d93cb..12a103b0c 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -27,7 +27,6 @@ #include #include #include /* for SFNT_Load_Table_Func */ -#include /* for PS_Driver */ #include #include @@ -978,34 +977,22 @@ if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) || !FT_DRIVER_HAS_HINTER( driver ) ) autohint = TRUE; - else - { - FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags ); - FT_Bool is_light_type1; - TT_Face ttface = (TT_Face)face; + else if ( FT_LOAD_TARGET_MODE( load_flags ) == FT_RENDER_MODE_LIGHT && + !FT_DRIVER_HINTS_LIGHTLY( driver ) ) + autohint = TRUE; - /* only the new Adobe engine (for both CFF and Type 1) is `light'; */ - /* we use `strstr' to catch both `Type 1' and `CID Type 1' */ - is_light_type1 = - ft_strstr( FT_Get_Font_Format( face ), "Type 1" ) != NULL && - ((PS_Driver)driver)->hinting_engine == FT_HINTING_ADOBE; - - /* the check for `num_locations' assures that we actually */ - /* test for instructions in a TTF and not in a CFF-based OTF */ - /* */ - /* we check the size of the `fpgm' and `prep' tables, too -- */ - /* the assumption is that there don't exist real TTFs where */ - /* both `fpgm' and `prep' tables are missing */ - if ( ( mode == FT_RENDER_MODE_LIGHT && - ( !FT_DRIVER_HINTS_LIGHTLY( driver ) && - !is_light_type1 ) ) || - ( FT_IS_SFNT( face ) && - ttface->num_locations && - ttface->font_program_size == 0 && - ttface->cvt_program_size <= 7 ) ) - autohint = TRUE; - } + /* the check for `num_locations' assures that we actually */ + /* test for instructions in a TTF and not in a CFF-based OTF */ + /* */ + /* we check the size of the `fpgm' and `prep' tables, too -- */ + /* the assumption is that there don't exist real TTFs where */ + /* both `fpgm' and `prep' tables are missing */ + else if ( FT_IS_SFNT( face ) && + ((TT_Face)face)->num_locations && + ((TT_Face)face)->font_program_size == 0 && + ((TT_Face)face)->cvt_program_size <= 7 ) + autohint = TRUE; } if ( autohint ) diff --git a/src/base/ftpsprop.c b/src/base/ftpsprop.c index 37a6cee6c..083b243cf 100644 --- a/src/base/ftpsprop.c +++ b/src/base/ftpsprop.c @@ -166,6 +166,12 @@ error = FT_ERR( Unimplemented_Feature ); } + /* set the light hinting flags accordingly */ + if ( driver->hinting_engine == FT_HINTING_ADOBE ) + module->clazz->module_flags |= FT_MODULE_DRIVER_HINTS_LIGHTLY; + else if ( driver->hinting_engine == FT_HINTING_FREETYPE ) + module->clazz->module_flags &= ~FT_MODULE_DRIVER_HINTS_LIGHTLY; + return error; } diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c index f432c9e4a..0bb81e84f 100644 --- a/src/cff/cffdrivr.c +++ b/src/cff/cffdrivr.c @@ -1182,10 +1182,9 @@ FT_DEFINE_DRIVER( cff_driver_class, - FT_MODULE_FONT_DRIVER | - FT_MODULE_DRIVER_SCALABLE | - FT_MODULE_DRIVER_HAS_HINTER | - FT_MODULE_DRIVER_HINTS_LIGHTLY, + FT_MODULE_FONT_DRIVER | + FT_MODULE_DRIVER_SCALABLE | + FT_MODULE_DRIVER_HAS_HINTER, sizeof ( PS_DriverRec ), "cff", diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c index 78f1e1dcb..812002c18 100644 --- a/src/cff/cffobjs.c +++ b/src/cff/cffobjs.c @@ -1138,7 +1138,8 @@ /* set default property values, cf. `ftcffdrv.h' */ - driver->hinting_engine = FT_HINTING_ADOBE; + driver->hinting_engine = FT_HINTING_ADOBE; + module->clazz->module_flags |= FT_MODULE_DRIVER_HINTS_LIGHTLY; driver->no_stem_darkening = TRUE; diff --git a/src/cid/cidobjs.c b/src/cid/cidobjs.c index 8d337c411..7f2d76cfc 100644 --- a/src/cid/cidobjs.c +++ b/src/cid/cidobjs.c @@ -492,7 +492,8 @@ /* set default property values, cf. `ftt1drv.h' */ - driver->hinting_engine = FT_HINTING_ADOBE; + driver->hinting_engine = FT_HINTING_ADOBE; + module->clazz->module_flags |= FT_MODULE_DRIVER_HINTS_LIGHTLY; driver->no_stem_darkening = TRUE; diff --git a/src/cid/cidriver.c b/src/cid/cidriver.c index 4be8a5c00..c9a01fe19 100644 --- a/src/cid/cidriver.c +++ b/src/cid/cidriver.c @@ -236,6 +236,7 @@ FT_MODULE_FONT_DRIVER | FT_MODULE_DRIVER_SCALABLE | FT_MODULE_DRIVER_HAS_HINTER, + sizeof ( PS_DriverRec ), "t1cid", /* module name */ diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c index b1b27c31f..950e09015 100644 --- a/src/type1/t1objs.c +++ b/src/type1/t1objs.c @@ -604,7 +604,8 @@ /* set default property values, cf. `ftt1drv.h' */ - driver->hinting_engine = FT_HINTING_ADOBE; + driver->hinting_engine = FT_HINTING_ADOBE; + module->clazz->module_flags |= FT_MODULE_DRIVER_HINTS_LIGHTLY; driver->no_stem_darkening = TRUE;