[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.
This commit is contained in:
Alexei Podtelezhnikov 2025-08-28 21:04:22 -04:00
parent 48f91b5331
commit 0fb8795e2b
7 changed files with 30 additions and 34 deletions

View file

@ -27,7 +27,6 @@
#include <freetype/internal/ftrfork.h>
#include <freetype/internal/ftstream.h>
#include <freetype/internal/sfnt.h> /* for SFNT_Load_Table_Func */
#include <freetype/internal/psaux.h> /* for PS_Driver */
#include <freetype/internal/svginterface.h>
#include <freetype/tttables.h>
@ -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 )

View file

@ -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;
}

View file

@ -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",

View file

@ -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;

View file

@ -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;

View file

@ -236,6 +236,7 @@
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_SCALABLE |
FT_MODULE_DRIVER_HAS_HINTER,
sizeof ( PS_DriverRec ),
"t1cid", /* module name */

View file

@ -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;