summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2022-10-21 07:18:06 -0400
committerAlexei Podtelezhnikov <apodtele@gmail.com>2022-10-21 12:14:52 +0000
commit1bfaca0635d5c90fa6088dc01d99899a947b7d29 (patch)
treec8fe8d130357f28b76ef348f104a18ae275d8791
parent0ec85f71a8ceee6292becf8dafc42c171f71665e (diff)
downloadfreetype2-1bfaca0635d5c90fa6088dc01d99899a947b7d29.tar.gz
[cff, truetype] Simplify SVG metrics scaling.
Use pre-calculated scaling factors. Also, the advance widths used to be rounded, which was incorrect. * src/cff/cffgload.c (cff_slot_load): Use `x_scale` and `y_scale`. * src/truetype/ttgload.c (TT_Load_Glyph): Ditto.
-rw-r--r--src/cff/cffgload.c30
-rw-r--r--src/truetype/ttgload.c28
2 files changed, 23 insertions, 35 deletions
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index d8fc31857..23318d9ab 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -356,18 +356,14 @@
#ifdef FT_CONFIG_OPTION_SVG
/* check for OT-SVG */
- if ( ( load_flags & FT_LOAD_COLOR ) &&
- ( (TT_Face)glyph->root.face )->svg )
+ if ( ( load_flags & FT_LOAD_COLOR ) && face->svg )
{
/*
* We load the SVG document and try to grab the advances from the
* table. For the bearings we rely on the presetting hook to do that.
*/
- FT_Short dummy;
- FT_UShort advanceX;
- FT_UShort advanceY;
- SFNT_Service sfnt;
+ SFNT_Service sfnt = (SFNT_Service)face->sfnt;
if ( size && (size->root.metrics.x_ppem < 1 ||
@@ -379,10 +375,17 @@
FT_TRACE3(( "Trying to load SVG glyph\n" ));
- sfnt = (SFNT_Service)((TT_Face)glyph->root.face)->sfnt;
error = sfnt->load_svg_doc( (FT_GlyphSlot)glyph, glyph_index );
if ( !error )
{
+ FT_Fixed x_scale = size->root.metrics.x_scale;
+ FT_Fixed y_scale = size->root.metrics.y_scale;
+
+ FT_Short dummy;
+ FT_UShort advanceX;
+ FT_UShort advanceY;
+
+
FT_TRACE3(( "Successfully loaded SVG glyph\n" ));
glyph->root.format = FT_GLYPH_FORMAT_SVG;
@@ -407,17 +410,8 @@
glyph->root.linearHoriAdvance = advanceX;
glyph->root.linearVertAdvance = advanceY;
- advanceX =
- (FT_UShort)FT_MulDiv( advanceX,
- glyph->root.face->size->metrics.x_ppem,
- glyph->root.face->units_per_EM );
- advanceY =
- (FT_UShort)FT_MulDiv( advanceY,
- glyph->root.face->size->metrics.y_ppem,
- glyph->root.face->units_per_EM );
-
- glyph->root.metrics.horiAdvance = advanceX << 6;
- glyph->root.metrics.vertAdvance = advanceY << 6;
+ glyph->root.metrics.horiAdvance = FT_MulFix( advanceX, x_scale );
+ glyph->root.metrics.vertAdvance = FT_MulFix( advanceY, y_scale );
return error;
}
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 68698df14..a92b4c17a 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -2871,21 +2871,22 @@
/* check for OT-SVG */
if ( ( load_flags & FT_LOAD_COLOR ) && ( (TT_Face)glyph->face )->svg )
{
- SFNT_Service sfnt;
-
- FT_Short leftBearing;
- FT_Short topBearing;
- FT_UShort advanceX;
- FT_UShort advanceY;
+ TT_Face face = (TT_Face)glyph->face;
+ SFNT_Service sfnt = (SFNT_Service)face->sfnt;
FT_TRACE3(( "Trying to load SVG glyph\n" ));
- sfnt = (SFNT_Service)( (TT_Face)glyph->face )->sfnt;
error = sfnt->load_svg_doc( glyph, glyph_index );
if ( !error )
{
- TT_Face face = (TT_Face)glyph->face;
+ FT_Fixed x_scale = size->root.metrics.x_scale;
+ FT_Fixed y_scale = size->root.metrics.y_scale;
+
+ FT_Short leftBearing;
+ FT_Short topBearing;
+ FT_UShort advanceX;
+ FT_UShort advanceY;
FT_TRACE3(( "Successfully loaded SVG glyph\n" ));
@@ -2906,15 +2907,8 @@
glyph->linearHoriAdvance = advanceX;
glyph->linearVertAdvance = advanceY;
- advanceX = (FT_UShort)FT_MulDiv( advanceX,
- glyph->face->size->metrics.x_ppem,
- glyph->face->units_per_EM );
- advanceY = (FT_UShort)FT_MulDiv( advanceY,
- glyph->face->size->metrics.y_ppem,
- glyph->face->units_per_EM );
-
- glyph->metrics.horiAdvance = advanceX << 6;
- glyph->metrics.vertAdvance = advanceY << 6;
+ glyph->metrics.horiAdvance = FT_MulFix( advanceX, x_scale );
+ glyph->metrics.vertAdvance = FT_MulFix( advanceY, y_scale );
return error;
}