[cff] Update advance width handling to OpenType 1.7. Problem reported by Behdad. * src/cff/cffdrivr.c (cff_get_advances): Handle SFNT case separately. * src/cff/cffgload.c (cff_slot_load): Use advance width and side bearing values from `hmtx' table if present.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
diff --git a/ChangeLog b/ChangeLog
index 985a889..ad0c031 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-04-10 Werner Lemberg <wl@gnu.org>
+
+ [cff] Update advance width handling to OpenType 1.7.
+
+ Problem reported by Behdad.
+
+ * src/cff/cffdrivr.c (cff_get_advances): Handle SFNT case
+ separately.
+
+ * src/cff/cffgload.c (cff_slot_load): Use advance width and side
+ bearing values from `hmtx' table if present.
+
2015-04-03 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/autofit/afhints.c (af_glyph_hints_reload): Use do-while loop.
diff --git a/include/internal/tttypes.h b/include/internal/tttypes.h
index 1d442f7..31dd0aa 100644
--- a/include/internal/tttypes.h
+++ b/include/internal/tttypes.h
@@ -1111,7 +1111,7 @@ FT_BEGIN_HEADER
/* This field also contains the associated */
/* vertical metrics table (`vmtx'), if found. */
/* IMPORTANT: The contents of this field is */
- /* undefined if the `verticalInfo' field is */
+ /* undefined if the `vertical_info' field is */
/* unset. */
/* */
/* num_names :: The number of name records within this */
diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c
index 35e23b9..f46a1c5 100644
--- a/src/cff/cffdrivr.c
+++ b/src/cff/cffdrivr.c
@@ -195,6 +195,68 @@
FT_GlyphSlot slot = face->glyph;
+ if ( FT_IS_SFNT( face ) )
+ {
+ /* OpenType 1.7 mandates that the data from `hmtx' table be used; */
+ /* it is no longer necessary that those values are identical to */
+ /* the values in the `CFF' table */
+
+ TT_Face ttface = (TT_Face)face;
+ FT_Short dummy;
+
+
+ if ( flags & FT_LOAD_VERTICAL_LAYOUT )
+ {
+ /* check whether we have data from the `vmtx' table at all; */
+ /* otherwise we extract the info from the CFF glyphstrings */
+ /* (instead of synthesizing a global value using the `OS/2' */
+ /* table) */
+ if ( !ttface->vertical_info )
+ goto Missing_Table;
+
+ for ( nn = 0; nn < count; nn++ )
+ {
+ FT_UShort ah;
+
+
+ ( (SFNT_Service)ttface->sfnt )->get_metrics( ttface,
+ 1,
+ start + nn,
+ &dummy,
+ &ah );
+
+ FT_TRACE5(( " idx %d: advance height %d font units\n",
+ start + nn, ah ));
+ advances[nn] = ah;
+ }
+ }
+ else
+ {
+ /* check whether we have data from the `hmtx' table at all */
+ if ( !ttface->horizontal.number_Of_HMetrics )
+ goto Missing_Table;
+
+ for ( nn = 0; nn < count; nn++ )
+ {
+ FT_UShort aw;
+
+
+ ( (SFNT_Service)ttface->sfnt )->get_metrics( ttface,
+ 0,
+ start + nn,
+ &dummy,
+ &aw );
+
+ FT_TRACE5(( " idx %d: advance width %d font units\n",
+ start + nn, aw ));
+ advances[nn] = aw;
+ }
+ }
+
+ return error;
+ }
+
+ Missing_Table:
flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
for ( nn = 0; nn < count; nn++ )
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index b5bc4a2..d731387 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -2725,7 +2725,7 @@
face->vertical_info &&
face->vertical.number_Of_VMetrics > 0 );
- /* get the vertical metrics from the vtmx table if we have one */
+ /* get the vertical metrics from the vmtx table if we have one */
if ( has_vertical_info )
{
(void)( (SFNT_Service)face->sfnt )->get_metrics( face, 1,
@@ -2953,25 +2953,43 @@
FT_Bool has_vertical_info;
- /* copy the _unscaled_ advance width */
- metrics->horiAdvance = decoder.glyph_width;
- glyph->root.linearHoriAdvance = decoder.glyph_width;
+ if ( face->horizontal.number_Of_HMetrics )
+ {
+ FT_Short horiBearingX = 0;
+ FT_UShort horiAdvance = 0;
+
+
+ ( (SFNT_Service)face->sfnt )->get_metrics( face, 0,
+ glyph_index,
+ &horiBearingX,
+ &horiAdvance );
+ metrics->horiAdvance = horiAdvance;
+ metrics->horiBearingX = horiBearingX;
+ glyph->root.linearHoriAdvance = horiAdvance;
+ }
+ else
+ {
+ /* copy the _unscaled_ advance width */
+ metrics->horiAdvance = decoder.glyph_width;
+ glyph->root.linearHoriAdvance = decoder.glyph_width;
+ }
+
glyph->root.internal->glyph_transformed = 0;
has_vertical_info = FT_BOOL( face->vertical_info &&
face->vertical.number_Of_VMetrics > 0 );
- /* get the vertical metrics from the vtmx table if we have one */
+ /* get the vertical metrics from the vmtx table if we have one */
if ( has_vertical_info )
{
FT_Short vertBearingY = 0;
FT_UShort vertAdvance = 0;
- (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 1,
- glyph_index,
- &vertBearingY,
- &vertAdvance );
+ ( (SFNT_Service)face->sfnt )->get_metrics( face, 1,
+ glyph_index,
+ &vertBearingY,
+ &vertAdvance );
metrics->vertBearingY = vertBearingY;
metrics->vertAdvance = vertAdvance;
}
@@ -3046,7 +3064,9 @@
metrics->width = cbox.xMax - cbox.xMin;
metrics->height = cbox.yMax - cbox.yMin;
- metrics->horiBearingX = cbox.xMin;
+ if ( !face->horizontal.number_Of_HMetrics )
+ metrics->horiBearingX = cbox.xMin;
+
metrics->horiBearingY = cbox.yMax;
if ( has_vertical_info )