[truetype] Do linear scaling for FT_LOAD_NO_HINTING (#50470).

* src/truetype/ttobs.h (TT_SizeRec): Add field `hinted_metrics' to
hold hinted metrics.
Make `metrics' a pointer so that `tt_glyph_load' can easily switch
between metrics.

* src/truetype/ttdriver.c (tt_size_request): Updated.
(tt_glyph_load): Use top-level metrics if FT_LOAD_NO_HINTING is
used.

* src/truetype/ttgload.c (TT_Hint_Glyph, TT_Process_Simple_Glyph,
TT_Process_Composite_Component, load_truetype_glyph,
compute_glyph_metrics, TT_Load_Glyph): Updated.

* src/truetype/ttinterp.c (TT_Load_Context): Updated.

* src/truetype/ttobjs.c (tt_size_reset): Updated.

* src/truetype/ttsubpix.c (sph_set_tweaks): Updated.
This commit is contained in:
Werner Lemberg 2017-04-22 23:02:21 +02:00
parent 5aa6716a5e
commit 5f18d867c0
7 changed files with 55 additions and 23 deletions

View File

@ -1,3 +1,26 @@
2017-04-22 Werner Lemberg <wl@gnu.org>
[truetype] Do linear scaling for FT_LOAD_NO_HINTING (#50470).
* src/truetype/ttobs.h (TT_SizeRec): Add field `hinted_metrics' to
hold hinted metrics.
Make `metrics' a pointer so that `tt_glyph_load' can easily switch
between metrics.
* src/truetype/ttdriver.c (tt_size_request): Updated.
(tt_glyph_load): Use top-level metrics if FT_LOAD_NO_HINTING is
used.
* src/truetype/ttgload.c (TT_Hint_Glyph, TT_Process_Simple_Glyph,
TT_Process_Composite_Component, load_truetype_glyph,
compute_glyph_metrics, TT_Load_Glyph): Updated.
* src/truetype/ttinterp.c (TT_Load_Context): Updated.
* src/truetype/ttobjs.c (tt_size_reset): Updated.
* src/truetype/ttsubpix.c (sph_set_tweaks): Updated.
2017-04-22 Werner Lemberg <wl@gnu.org> 2017-04-22 Werner Lemberg <wl@gnu.org>
Add new `slight' auto-hinting mode. Add new `slight' auto-hinting mode.

View File

@ -361,9 +361,10 @@
#ifdef TT_USE_BYTECODE_INTERPRETER #ifdef TT_USE_BYTECODE_INTERPRETER
/* for the `MPS' bytecode instruction we need the point size */ /* for the `MPS' bytecode instruction we need the point size */
{ {
FT_UInt resolution = ttsize->metrics.x_ppem > ttsize->metrics.y_ppem FT_UInt resolution =
? req->horiResolution ttsize->metrics->x_ppem > ttsize->metrics->y_ppem
: req->vertResolution; ? req->horiResolution
: req->vertResolution;
/* if we don't have a resolution value, assume 72dpi */ /* if we don't have a resolution value, assume 72dpi */
@ -457,6 +458,11 @@
load_flags |= FT_LOAD_NO_HINTING; load_flags |= FT_LOAD_NO_HINTING;
} }
/* use hinted metrics only if we load a glyph with hinting */
size->metrics = ( load_flags & FT_LOAD_NO_HINTING )
? &ttsize->metrics
: &size->hinted_metrics;
/* now load the glyph outline if necessary */ /* now load the glyph outline if necessary */
error = TT_Load_Glyph( size, slot, glyph_index, load_flags ); error = TT_Load_Glyph( size, slot, glyph_index, load_flags );

View File

@ -778,8 +778,8 @@
} }
else else
{ {
loader->exec->metrics.x_scale = loader->size->metrics.x_scale; loader->exec->metrics.x_scale = loader->size->metrics->x_scale;
loader->exec->metrics.y_scale = loader->size->metrics.y_scale; loader->exec->metrics.y_scale = loader->size->metrics->y_scale;
} }
#endif #endif
@ -926,7 +926,7 @@
TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face );
FT_String* family = face->root.family_name; FT_String* family = face->root.family_name;
FT_UInt ppem = loader->size->metrics.x_ppem; FT_UInt ppem = loader->size->metrics->x_ppem;
FT_String* style = face->root.style_name; FT_String* style = face->root.style_name;
FT_UInt x_scale_factor = 1000; FT_UInt x_scale_factor = 1000;
#endif #endif
@ -955,9 +955,9 @@
if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 || if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ||
x_scale_factor != 1000 ) x_scale_factor != 1000 )
{ {
x_scale = FT_MulDiv( loader->size->metrics.x_scale, x_scale = FT_MulDiv( loader->size->metrics->x_scale,
(FT_Long)x_scale_factor, 1000 ); (FT_Long)x_scale_factor, 1000 );
y_scale = loader->size->metrics.y_scale; y_scale = loader->size->metrics->y_scale;
/* compensate for any scaling by de/emboldening; */ /* compensate for any scaling by de/emboldening; */
/* the amount was determined via experimentation */ /* the amount was determined via experimentation */
@ -977,8 +977,8 @@
/* scale the glyph */ /* scale the glyph */
if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
{ {
x_scale = loader->size->metrics.x_scale; x_scale = loader->size->metrics->x_scale;
y_scale = loader->size->metrics.y_scale; y_scale = loader->size->metrics->y_scale;
do_scale = TRUE; do_scale = TRUE;
} }
@ -1136,8 +1136,8 @@
if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
{ {
FT_Fixed x_scale = loader->size->metrics.x_scale; FT_Fixed x_scale = loader->size->metrics->x_scale;
FT_Fixed y_scale = loader->size->metrics.y_scale; FT_Fixed y_scale = loader->size->metrics->y_scale;
x = FT_MulFix( x, x_scale ); x = FT_MulFix( x, x_scale );
@ -1470,8 +1470,8 @@
if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
{ {
x_scale = loader->size->metrics.x_scale; x_scale = loader->size->metrics->x_scale;
y_scale = loader->size->metrics.y_scale; y_scale = loader->size->metrics->y_scale;
} }
else else
{ {
@ -2038,7 +2038,7 @@
y_scale = 0x10000L; y_scale = 0x10000L;
if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
y_scale = size->metrics.y_scale; y_scale = size->metrics->y_scale;
if ( glyph->format != FT_GLYPH_FORMAT_COMPOSITE ) if ( glyph->format != FT_GLYPH_FORMAT_COMPOSITE )
FT_Outline_Get_CBox( &glyph->outline, &bbox ); FT_Outline_Get_CBox( &glyph->outline, &bbox );
@ -2070,7 +2070,7 @@
widthp = tt_face_get_device_metrics( face, widthp = tt_face_get_device_metrics( face,
size->metrics.x_ppem, size->metrics->x_ppem,
glyph_index ); glyph_index );
#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY #ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY
@ -2637,11 +2637,11 @@
if ( !glyph->metrics.horiAdvance && glyph->linearHoriAdvance ) if ( !glyph->metrics.horiAdvance && glyph->linearHoriAdvance )
glyph->metrics.horiAdvance = glyph->metrics.horiAdvance =
FT_MulFix( glyph->linearHoriAdvance, FT_MulFix( glyph->linearHoriAdvance,
size->metrics.x_scale ); size->metrics->x_scale );
if ( !glyph->metrics.vertAdvance && glyph->linearVertAdvance ) if ( !glyph->metrics.vertAdvance && glyph->linearVertAdvance )
glyph->metrics.vertAdvance = glyph->metrics.vertAdvance =
FT_MulFix( glyph->linearVertAdvance, FT_MulFix( glyph->linearVertAdvance,
size->metrics.y_scale ); size->metrics->y_scale );
} }
return FT_Err_Ok; return FT_Err_Ok;
@ -2737,7 +2737,7 @@
/* TrueType glyphs at all sizes using the bytecode interpreter. */ /* TrueType glyphs at all sizes using the bytecode interpreter. */
/* */ /* */
if ( !( load_flags & FT_LOAD_NO_SCALE ) && if ( !( load_flags & FT_LOAD_NO_SCALE ) &&
size->metrics.y_ppem < 24 ) size->metrics->y_ppem < 24 )
glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
Exit: Exit:

View File

@ -402,7 +402,7 @@
exec->IDefs = size->instruction_defs; exec->IDefs = size->instruction_defs;
exec->pointSize = size->point_size; exec->pointSize = size->point_size;
exec->tt_metrics = size->ttmetrics; exec->tt_metrics = size->ttmetrics;
exec->metrics = size->metrics; exec->metrics = *size->metrics;
exec->maxFunc = size->max_func; exec->maxFunc = size->max_func;
exec->maxIns = size->max_ins; exec->maxIns = size->max_ins;

View File

@ -1220,7 +1220,7 @@
size->ttmetrics.valid = FALSE; size->ttmetrics.valid = FALSE;
size_metrics = &size->metrics; size_metrics = &size->hinted_metrics;
/* copy the result from base layer */ /* copy the result from base layer */
*size_metrics = size->root.metrics; *size_metrics = size->root.metrics;
@ -1280,6 +1280,8 @@
size->ttmetrics.y_ratio = 0x10000L; size->ttmetrics.y_ratio = 0x10000L;
} }
size->metrics = size_metrics;
#ifdef TT_USE_BYTECODE_INTERPRETER #ifdef TT_USE_BYTECODE_INTERPRETER
size->cvt_ready = -1; size->cvt_ready = -1;
#endif /* TT_USE_BYTECODE_INTERPRETER */ #endif /* TT_USE_BYTECODE_INTERPRETER */

View File

@ -278,7 +278,8 @@ FT_BEGIN_HEADER
/* we have our own copy of metrics so that we can modify */ /* we have our own copy of metrics so that we can modify */
/* it without affecting auto-hinting (when used) */ /* it without affecting auto-hinting (when used) */
FT_Size_Metrics metrics; FT_Size_Metrics* metrics; /* for the current rendering mode */
FT_Size_Metrics hinted_metrics; /* for the hinted rendering mode */
TT_Size_Metrics ttmetrics; TT_Size_Metrics ttmetrics;

View File

@ -906,7 +906,7 @@
{ {
TT_Face face = loader->face; TT_Face face = loader->face;
FT_String* family = face->root.family_name; FT_String* family = face->root.family_name;
FT_UInt ppem = loader->size->metrics.x_ppem; FT_UInt ppem = loader->size->metrics->x_ppem;
FT_String* style = face->root.style_name; FT_String* style = face->root.style_name;