Add vertical metrics support to OpenType CFF outlines. Based on a patch from Mike Moening <MikeM@RetekSolutions.com> * src/cff/cffgload.c (cff_face_get_vertical_metrics): New function. (cff_slot_load): Use cff_face_get_vertical_metrics. * docs/CHANGES: Updated.
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
diff --git a/ChangeLog b/ChangeLog
index b8186c5..c6ae94e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,17 +1,29 @@
+2005-11-17 Werner Lemberg <wl@gnu.org>
+
+ Add vertical metrics support to OpenType CFF outlines. Based on a
+ patch from Mike Moening <MikeM@RetekSolutions.com>
+
+ * src/cff/cffgload.c (cff_face_get_vertical_metrics): New function.
+ (cff_slot_load): Use cff_face_get_vertical_metrics.
+
+ * docs/CHANGES: Updated.
+
2005-11-17 Chia-I Wu <b90201047@ntu.edu.tw>
* src/base/ftcalc.c (FT_MulTo64): Commented out.
- * include/freetype/internal/ftcalc.h (FT_SqrtFixed), src/base/ftcalc.c
- (FT_SqrtFixed), include/freetype/internal/ftdebug.h
+ * include/freetype/internal/ftcalc.h (FT_SqrtFixed),
+ src/base/ftcalc.c (FT_SqrtFixed),
+ include/freetype/internal/ftdebug.h (FT_Trace_Get_Count,
+ FT_Trace_Get_Name, FT_Message, FT_Panic), src/base/ftdebug.c
(FT_Trace_Get_Count, FT_Trace_Get_Name, FT_Message, FT_Panic),
- src/base/ftdebug.c (FT_Trace_Get_Count, FT_Trace_Get_Name, FT_Message,
- FT_Panic), include/freetype/internal/ftobjs.h (FT_New_Memory,
- FT_Done_Memory), include/freetype/internal/ftstream.h
- (FT_Stream_Open), src/base/ftsystem.c (FT_New_Memory, FT_Done_Memory,
- FT_Stream_Open): s/FT_EXPORT/FT_BASE/.
+ include/freetype/internal/ftobjs.h (FT_New_Memory, FT_Done_Memory),
+ include/freetype/internal/ftstream.h (FT_Stream_Open),
+ src/base/ftsystem.c (FT_New_Memory, FT_Done_Memory, FT_Stream_Open):
+ s/FT_EXPORT/FT_BASE/.
- * builds/exports.mk: Manually add TT_New_Context to EXPORTS_LIST too.
+ * builds/exports.mk: Manually add TT_New_Context to EXPORTS_LIST
+ too.
2005-11-15 David Turner <david@freetype.org>
diff --git a/docs/CHANGES b/docs/CHANGES
index 0a9f352..6295ec2 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -6,6 +6,9 @@ LATEST CHANGES BETWEEN 2.2.0 and 2.1.10
- The FT_HAS_KERNING macro always returned 0.
+ - CFF OpenType fonts didn't return correct vertical metrics for
+ glyphs with outlines.
+
II. IMPORTANT CHANGES
- A new API `FT_TrueTypeGX_Validate' (in FT_GX_VALIDATE_H) has
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index f4e7753..d4ea07b 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -569,6 +569,117 @@
}
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* cff_face_get_vertical_metrics */
+ /* */
+ /* <Description> */
+ /* Return the vertical metrics in font units for a given glyph. The */
+ /* metrics are the top side bearing and advance height. */
+ /* */
+ /* <Input> */
+ /* header :: A pointer to the vertical metrics structure. */
+ /* */
+ /* idx :: The glyph index. */
+ /* */
+ /* <Output> */
+ /* bearing :: The top side bearing. */
+ /* */
+ /* advance :: The advance height. */
+ /* */
+ /* <Note> */
+ /* Horizontal metric values are directly computed from the CFF data, */
+ /* bypassing the `hmtx' table completely. */
+ /* */
+#ifdef FT_OPTIMIZE_MEMORY
+
+ static void
+ cff_face_get_vertical_metrics( TT_Face face,
+ FT_UInt idx,
+ FT_Short *abearing,
+ FT_UShort *aadvance )
+ {
+ TT_VertHeader* header;
+ FT_Byte* p;
+ FT_Byte* limit;
+ FT_UShort k;
+
+
+ header = &face->vertical;
+ p = face->vert_metrics;
+ limit = p + face->vert_metrics_size;
+
+ k = header->number_Of_VMetrics;
+
+ if ( k > 0 )
+ {
+ if ( idx < (FT_UInt)k )
+ {
+ p += 4 * idx;
+ if ( p + 4 > limit )
+ goto NoData;
+
+ *aadvance = FT_NEXT_USHORT( p );
+ *abearing = FT_NEXT_SHORT( p );
+ }
+ else
+ {
+ p += 4 * ( k - 1 );
+ if ( p + 4 > limit )
+ goto NoData;
+
+ *aadvance = FT_NEXT_USHORT( p );
+ p += 2 + 2 * ( idx - k );
+ if ( p + 2 > limit )
+ *abearing = 0;
+ else
+ *abearing = FT_PEEK_SHORT( p );
+ }
+ }
+ else
+ {
+ NoData:
+ *abearing = 0;
+ *aadvance = 0;
+ }
+ }
+
+#else /* !FT_OPTIMIZE_MEMORY */
+
+ static void
+ cff_face_get_vertical_metrics( TT_Face face,
+ FT_UInt idx,
+ FT_Short *abearing,
+ FT_UShort *aadvance )
+ {
+ TT_VertHeader* header = &face->vertical;
+ TT_LongMetrics longs_m;
+ FT_UShort k = header->number_Of_VMetrics;
+
+
+ if ( k == 0 )
+ {
+ *abearing = *aadvance = 0;
+ return;
+ }
+
+ if ( idx < (FT_UInt)k )
+ {
+ longs_m = (TT_LongMetrics)header->long_metrics + idx;
+ *abearing = longs_m->bearing;
+ *aadvance = longs_m->advance;
+ }
+ else
+ {
+ *abearing = ((TT_ShortMetrics*)header->short_metrics)[idx - k];
+ *aadvance = ((TT_LongMetrics)header->long_metrics)[k - 1].advance;
+ }
+ }
+
+#endif /* !FT_OPTIMIZE_MEMORY */
+
+
static FT_Error
cff_get_glyph_data( TT_Face face,
FT_UInt glyph_index,
@@ -1299,7 +1410,7 @@
goto Fail;
args = stack;
- while (args < decoder->top )
+ while ( args < decoder->top )
{
if ( phase )
x += args[0];
@@ -1425,7 +1536,7 @@
goto Fail;
args = stack;
- if (num_args < 4 || ( num_args % 4 ) > 1 )
+ if ( num_args < 4 || ( num_args % 4 ) > 1 )
goto Stack_Underflow;
if ( check_points( builder, ( num_args / 4 ) * 3 ) )
@@ -1772,7 +1883,8 @@
/* close hints recording session */
if ( hinter )
{
- if (hinter->close( hinter->hints, builder->current->n_points ) )
+ if ( hinter->close( hinter->hints,
+ builder->current->n_points ) )
goto Syntax_Error;
/* apply hints to the loaded glyph outline now */
@@ -2048,7 +2160,7 @@
case cff_op_ifelse:
{
- FT_Fixed cond = (args[2] <= args[3]);
+ FT_Fixed cond = ( args[2] <= args[3] );
FT_TRACE4(( " ifelse" ));
@@ -2268,22 +2380,6 @@
#endif /* 0 */
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /********** *********/
- /********** *********/
- /********** UNHINTED GLYPH LOADER *********/
- /********** *********/
- /********** The following code is in charge of loading a *********/
- /********** single outline. It completely ignores hinting *********/
- /********** and is used when FT_LOAD_NO_HINTING is set. *********/
- /********** *********/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
FT_LOCAL_DEF( FT_Error )
cff_slot_load( CFF_GlyphSlot glyph,
CFF_Size size,
@@ -2515,8 +2611,26 @@
/* make up vertical ones */
metrics->vertAdvance = 0;
+ metrics->vertBearingX = 0;
+ metrics->vertBearingY = 0;
+
glyph->root.linearVertAdvance = 0;
+ /* get the vertical metrics from the vtmx table if we have one */
+ if ( face->vertical_info &&
+ face->vertical.number_Of_VMetrics > 0 &&
+ face->vertical.long_metrics != 0 )
+ {
+ FT_Short vertBearingY = 0;
+ FT_UShort vertAdvance = 0;
+
+
+ cff_face_get_vertical_metrics( face, glyph_index,
+ &vertBearingY, &vertAdvance );
+ metrics->vertBearingY = vertBearingY;
+ metrics->vertAdvance = vertAdvance;
+ }
+
glyph->root.format = FT_GLYPH_FORMAT_OUTLINE;
glyph->root.outline.flags = 0;
@@ -2536,6 +2650,7 @@
advance.y = 0;
FT_Vector_Transform( &advance, &font_matrix );
metrics->horiAdvance = advance.x + font_offset.x;
+
advance.x = 0;
advance.y = metrics->vertAdvance;
FT_Vector_Transform( &advance, &font_matrix );
@@ -2560,8 +2675,8 @@
}
/* Then scale the metrics */
- metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
- metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
+ metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
+ metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
}
/* compute the other metrics */
@@ -2573,10 +2688,6 @@
metrics->horiBearingX = cbox.xMin;
metrics->horiBearingY = cbox.yMax;
- /* make up vertical ones */
- metrics->vertBearingX = 0;
- metrics->vertBearingY = 0;
-
if ( hinting )
ft_glyphslot_grid_fit_metrics( &glyph->root );
}