Delay FT_GLYPH_FORMAT_OUTLINE assignmets.

This assignmets used to be done prematurely before errors were checked
and outlines were actually loaded. Delaying the assignment provides
certain protection against careless usage of malformed input that
should now remain FT_GLYPH_FORMAT_NONE.

* src/cff/cffgload.c (cff_slot_load): Ditto.
* src/cid/cidgload.c (cid_slot_load_glyph): Ditto.
* src/pfr/pfrobjs.c (pfr_slot_load): Ditto.
* src/truetype/ttgload.c (TT_Load_Glyph): Ditto.
* src/type1/t1gload.c (T1_Load_Glyph): Ditto.
This commit is contained in:
Alexei Podtelezhnikov 2025-01-03 21:26:10 -05:00
parent afc7000cac
commit 5245fd69fd
5 changed files with 35 additions and 50 deletions

View File

@ -461,7 +461,6 @@
glyph->hint = hinting;
glyph->scaled = scaled;
glyph->root.format = FT_GLYPH_FORMAT_OUTLINE; /* by default */
{
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
@ -596,10 +595,8 @@
{
/* Now, set the metrics -- this is rather simple, as */
/* the left side bearing is the xMin, and the top side */
/* bearing the yMax. */
/* For composite glyphs, return only left side bearing and */
/* advance width. */
/* bearing the yMax. For composite glyphs, return only */
/* left side bearing and advance width. */
if ( load_flags & FT_LOAD_NO_RECURSE )
{
FT_Slot_Internal internal = glyph->root.internal;
@ -618,6 +615,12 @@
FT_Bool has_vertical_info;
glyph->root.format = FT_GLYPH_FORMAT_OUTLINE;
glyph->root.outline.flags = FT_OUTLINE_REVERSE_FILL;
if ( size && size->root.metrics.y_ppem < 24 )
glyph->root.outline.flags |= FT_OUTLINE_HIGH_PRECISION;
if ( face->horizontal.number_Of_HMetrics )
{
FT_Short horiBearingX = 0;
@ -671,14 +674,6 @@
glyph->root.linearVertAdvance = metrics->vertAdvance;
glyph->root.format = FT_GLYPH_FORMAT_OUTLINE;
glyph->root.outline.flags = 0;
if ( size && size->root.metrics.y_ppem < 24 )
glyph->root.outline.flags |= FT_OUTLINE_HIGH_PRECISION;
glyph->root.outline.flags |= FT_OUTLINE_REVERSE_FILL;
/* apply the font matrix, if any */
if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L ||
font_matrix.xy != 0 || font_matrix.yx != 0 )

View File

@ -458,7 +458,6 @@
glyph->hint = hinting;
glyph->scaled = scaled;
cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
error = psaux->t1_decoder_funcs->init( &decoder,
cidglyph->face,
@ -498,12 +497,8 @@
/* now set the metrics -- this is rather simple, as */
/* the left side bearing is the xMin, and the top side */
/* bearing the yMax */
cidglyph->outline.flags &= FT_OUTLINE_OWNER;
cidglyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
/* for composite glyphs, return only left side bearing and */
/* advance width */
/* bearing the yMax; for composite glyphs, return only */
/* left side bearing and advance width */
if ( load_flags & FT_LOAD_NO_RECURSE )
{
FT_Slot_Internal internal = cidglyph->internal;
@ -524,6 +519,13 @@
FT_Glyph_Metrics* metrics = &cidglyph->metrics;
cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
cidglyph->outline.flags &= FT_OUTLINE_OWNER;
cidglyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
if ( cidsize->metrics.y_ppem < 24 )
cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
/* copy the _unscaled_ advance width */
metrics->horiAdvance =
FIXED_TO_INT( decoder.builder.advance.x );
@ -536,11 +538,6 @@
face->cid.font_bbox.yMin ) >> 16;
cidglyph->linearVertAdvance = metrics->vertAdvance;
cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
if ( cidsize->metrics.y_ppem < 24 )
cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
/* apply the font matrix, if any */
if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L ||
font_matrix.xy != 0 || font_matrix.yx != 0 )

View File

@ -355,9 +355,8 @@
goto Exit;
}
gchar = face->phy_font.chars + gindex;
pfrslot->format = FT_GLYPH_FORMAT_OUTLINE;
gps_offset = face->header.gps_section_offset;
gchar = face->phy_font.chars + gindex;
gps_offset = face->header.gps_section_offset;
/* load the glyph outline (FT_LOAD_NO_RECURSE isn't supported) */
error = pfr_glyph_load( &slot->glyph, face->root.stream,
@ -369,10 +368,9 @@
FT_Glyph_Metrics* metrics = &pfrslot->metrics;
FT_Pos advance;
FT_UInt em_metrics, em_outline;
FT_Bool scaling;
scaling = FT_BOOL( !( load_flags & FT_LOAD_NO_SCALE ) );
pfrslot->format = FT_GLYPH_FORMAT_OUTLINE;
/* copy outline data */
*outline = slot->glyph.loader->base.outline;
@ -427,7 +425,7 @@
#endif
/* scale when needed */
if ( scaling )
if ( !( load_flags & FT_LOAD_NO_SCALE ) )
{
FT_Int n;
FT_Fixed x_scale = pfrsize->metrics.x_scale;

View File

@ -2595,7 +2595,7 @@
glyph->metrics.horiAdvance = FT_MulFix( advanceX, x_scale );
glyph->metrics.vertAdvance = FT_MulFix( advanceY, y_scale );
return error;
goto Exit;
}
FT_TRACE3(( "Failed to load SVG glyph\n" ));
@ -2623,10 +2623,6 @@
goto Done;
}
glyph->format = FT_GLYPH_FORMAT_OUTLINE;
glyph->num_subglyphs = 0;
glyph->outline.flags = 0;
/* main loading loop */
error = load_truetype_glyph( &loader, glyph_index, 0, FALSE );
if ( !error )
@ -2638,6 +2634,8 @@
}
else
{
glyph->format = FT_GLYPH_FORMAT_OUTLINE;
glyph->outline = loader.gloader->base.outline;
glyph->outline.flags &= ~FT_OUTLINE_SINGLE_PASS;

View File

@ -404,7 +404,6 @@
glyph->hint = hinting;
glyph->scaled = scaled;
t1glyph->format = FT_GLYPH_FORMAT_OUTLINE;
error = decoder_funcs->init( &decoder,
t1glyph->face,
@ -449,16 +448,12 @@
must_finish_decoder = FALSE;
/* now, set the metrics -- this is rather simple, as */
/* the left side bearing is the xMin, and the top side */
/* bearing the yMax */
if ( !error )
{
t1glyph->outline.flags &= FT_OUTLINE_OWNER;
t1glyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
/* for composite glyphs, return only left side bearing and */
/* advance width */
/* now, set the metrics -- this is rather simple, as */
/* the left side bearing is the xMin, and the top side */
/* bearing the yMax; for composite glyphs, return only */
/* left side bearing and advance width */
if ( load_flags & FT_LOAD_NO_RECURSE )
{
FT_Slot_Internal internal = t1glyph->internal;
@ -479,6 +474,13 @@
FT_Glyph_Metrics* metrics = &t1glyph->metrics;
t1glyph->format = FT_GLYPH_FORMAT_OUTLINE;
t1glyph->outline.flags &= FT_OUTLINE_OWNER;
t1glyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
if ( t1size && t1size->metrics.y_ppem < 24 )
t1glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
/* copy the _unscaled_ advance width */
metrics->horiAdvance =
FIXED_TO_INT( decoder.builder.advance.x );
@ -501,11 +503,6 @@
FIXED_TO_INT( decoder.builder.advance.y );
}
t1glyph->format = FT_GLYPH_FORMAT_OUTLINE;
if ( t1size && t1size->metrics.y_ppem < 24 )
t1glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
#if 1
/* apply the font matrix, if any */
if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L ||