Hi,
This patch fixes some bugs in vertical metrics of truetype fonts. Some
of the bugs are subtle, so I list the reasons of the changes:
1. loader->pp3.y, loader->pp4.y are in 26.6, not in font units.
2. the advance height is fixed and the height of glyphs differs,
therefore glyphs should be vertically centered, instead of having fixed
top bearing,
3. as we use glyph's cbox to calculate the top bearing now (in contrast
to revision 1.2!), there's no need to adjust `top'.
The changelog entries are:
* src/sfnt/ttsbit.c (tt_face_load_sbit_image): Make up vertBearingY such
that glyphs are vertically centered.
* src/truetype/ttgload.c (compute_glyph_metrics): Make up vertBearingY
such that glyphs are vertically centered.
Fix some bugs in vertical metrics.
--
Regards,
olv
=== src/truetype/ttgload.c
==================================================================
--- src/truetype/ttgload.c (revision 975)
+++ src/truetype/ttgload.c (patch - level 1)
@@ -1765,42 +1765,41 @@
if ( face->vertical_info &&
face->vertical.number_Of_VMetrics > 0 )
{
- advance_height = (FT_UShort)( loader->pp4.y - loader->pp3.y );
- top_bearing = (FT_Short)( loader->pp3.y - bbox.yMax );
+ top_bearing = (FT_Short)FT_DivFix( loader->pp3.y - bbox.yMax,
y_scale );
+
+ if ( loader->pp3.y <= loader->pp4.y )
+ advance_height = 0;
+ else
+ advance_height = (FT_UShort)FT_DivFix( loader->pp3.y -
loader->pp4.y, y_scale );
}
else
{
- /* Make up the distances from the horizontal header. */
+ FT_Short max_height, height;
+
+ /* XXX Make up top side bearing and advance height in */
+ /* Get_VMetrics instead of here. */
+
/* NOTE: The OS/2 values are the only `portable' ones, */
/* which is why we use them, if there is an OS/2 */
/* table in the font. Otherwise, we use the */
/* values defined in the horizontal header. */
- /* */
- /* NOTE2: The sTypoDescender is negative, which is why */
- /* we compute the baseline-to-baseline distance */
- /* here with: */
- /* ascender - descender + linegap */
- /* */
- /* NOTE3: This is different from what MS's rasterizer */
- /* appears to do when getting default values */
- /* for the vertical phantom points. We leave */
- /* the old code untouched, but relying on */
- /* phantom points alone might be reasonable */
- /* (i.e., removing the `if' above). */
+
+ height = FT_DivFix( bbox.yMax - bbox.yMin, y_scale );
if ( face->os2.version != 0xFFFFU )
{
- top_bearing = (FT_Short)( face->os2.sTypoLineGap / 2 );
- advance_height = (FT_UShort)( face->os2.sTypoAscender -
- face->os2.sTypoDescender +
- face->os2.sTypoLineGap );
+ /* sTypoDescender is negative */
+ max_height = face->os2.sTypoAscender - face->os2.sTypoDescender;
+
+ top_bearing = (FT_Short)( ( max_height - height ) / 2 );
+ advance_height = (FT_UShort)( max_height + face->os2.sTypoLineGap );
}
else
{
- top_bearing = (FT_Short)( face->horizontal.Line_Gap / 2 );
- advance_height = (FT_UShort)( face->horizontal.Ascender +
- face->horizontal.Descender +
- face->horizontal.Line_Gap );
+ max_height = face->horizontal.Ascender + face->horizontal.Descender;
+
+ top_bearing = (FT_Short)( ( max_height - height ) / 2 );
+ advance_height = (FT_UShort)( max_height + face->horizontal.Line_Gap
);
}
}
@@ -1817,7 +1816,7 @@
metrics.bearing_x = 0;
metrics.bearing_y = top_bearing;
- metrics.advance = advance_height;
+ metrics.advance = advance_height;
error =
face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
@@ -1834,20 +1833,15 @@
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
- /* We must adjust the top_bearing value from the bounding box given */
- /* in the glyph header to the bounding box calculated with */
- /* FT_Get_Outline_CBox(). */
-
/* scale the metrics */
if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
{
- top = FT_MulFix( top_bearing + loader->bbox.yMax, y_scale )
- - bbox.yMax;
+ top = FT_MulFix( top_bearing, y_scale );
advance = FT_MulFix( advance_height, y_scale );
}
else
{
- top = top_bearing + loader->bbox.yMax - bbox.yMax;
+ top = top_bearing;
advance = advance_height;
}
@@ -1864,7 +1858,8 @@
if ( IS_HINTED( loader->load_flags ) )
{
left = FT_PIX_FLOOR( left );
- top = FT_PIX_CEIL( top );
+ /* top should be floor'ed */
+ top = FT_PIX_FLOOR( top );
advance = FT_PIX_ROUND( advance );
}
=== src/sfnt/ttsbit.c
==================================================================
--- src/sfnt/ttsbit.c (revision 975)
+++ src/sfnt/ttsbit.c (patch - level 1)
@@ -1501,7 +1501,7 @@
/* some heuristic values */
metrics->vertBearingX = (FT_Char)(-metrics->width / 2 );
- metrics->vertBearingY = (FT_Char)( advance / 10 );
+ metrics->vertBearingY = (FT_Char)( ( advance - metrics->height ) / 2 );
metrics->vertAdvance = (FT_Char)( advance * 12 / 10 );
}
_______________________________________________
Freetype-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/freetype-devel