The incremental interface now passes the old metrics when asking for replacement metrics so that they can be modified, not just replaced. For example, CFF fonts need this.
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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
diff --git a/include/freetype/ftincrem.h b/include/freetype/ftincrem.h
index 08ce7a9..c9e8b56 100644
--- a/include/freetype/ftincrem.h
+++ b/include/freetype/ftincrem.h
@@ -174,21 +174,22 @@ FT_BEGIN_HEADER
* vertical ::
* If true, return vertical metrics.
*
- * @output:
* ametrics ::
- * The glyph metrics in font units.
+ * This parameter is used for both input and output.
+ * The original glyph metrics, if any, in font units. If metrics are
+ * not available all the values must be set to zero.
*
- * afound ::
- * True if there are metrics at all.
+ * @output:
+ * ametrics ::
+ * The replacement glyph metrics in font units.
*
*/
typedef FT_Error
(*FT_Incremental_GetGlyphMetricsFunc)
- ( FT_Incremental incremental,
- FT_UInt glyph_index,
- FT_Bool vertical,
- FT_Incremental_MetricsRec *ametrics,
- FT_Bool *afound );
+ ( FT_Incremental incremental,
+ FT_UInt glyph_index,
+ FT_Bool vertical,
+ FT_Incremental_MetricsRec *ametrics );
/**************************************************************************
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 69277ae..0432aa0 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -2363,6 +2363,29 @@
cff_builder_done( &decoder.builder );
}
+ #ifdef FT_CONFIG_OPTION_INCREMENTAL
+
+ /* Incremental fonts can optionally override the metrics. */
+ if ( !error &&
+ face->root.internal->incremental_interface &&
+ face->root.internal->incremental_interface->funcs->get_glyph_metrics )
+ {
+ FT_Incremental_MetricsRec metrics;
+
+ metrics.bearing_x = decoder.builder.left_bearing.x;
+ metrics.bearing_y = decoder.builder.left_bearing.y;
+ metrics.advance = decoder.builder.advance.x;
+ error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
+ face->root.internal->incremental_interface->object,
+ glyph_index, FALSE, &metrics );
+ decoder.builder.left_bearing.x = metrics.bearing_x;
+ decoder.builder.left_bearing.y = metrics.bearing_y;
+ decoder.builder.advance.x = metrics.advance;
+ decoder.builder.advance.y = 0;
+ }
+
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
+
font_matrix = cff->top_font.font_dict.font_matrix;
font_offset = cff->top_font.font_dict.font_offset;
diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c
index 9e60674..15231f8 100644
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -89,7 +89,7 @@
else
-#endif
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* For ordinary fonts read the CID font dictionary index */
/* and charstring offset from the CIDMap. */
@@ -162,23 +162,21 @@
face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
- FT_Bool found = FALSE;
FT_Incremental_MetricsRec metrics;
-
+ metrics.bearing_x = decoder->builder.left_bearing.x;
+ metrics.bearing_y = decoder->builder.left_bearing.y;
+ metrics.advance = decoder->builder.advance.x;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
- glyph_index, FALSE, &metrics, &found );
- if ( found )
- {
- decoder->builder.left_bearing.x = metrics.bearing_x;
- decoder->builder.left_bearing.y = metrics.bearing_y;
- decoder->builder.advance.x = metrics.advance;
- decoder->builder.advance.y = 0;
- }
+ glyph_index, FALSE, &metrics );
+ decoder->builder.left_bearing.x = metrics.bearing_x;
+ decoder->builder.left_bearing.y = metrics.bearing_y;
+ decoder->builder.advance.x = metrics.advance;
+ decoder->builder.advance.y = 0;
}
-#endif
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
Exit:
return error;
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 7f4e8f5..42cf13a 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -808,42 +808,33 @@
FT_Short left_bearing = 0;
FT_UShort advance_width = 0;
-#ifdef FT_CONFIG_OPTION_INCREMENTAL
- FT_Bool metrics_found = FALSE;
+ Get_HMetrics( face, glyph_index,
+ (FT_Bool)!( loader->load_flags &
+ FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ),
+ &left_bearing,
+ &advance_width );
+#ifdef FT_CONFIG_OPTION_INCREMENTAL
/* If this is an incrementally loaded font see if there are */
/* overriding metrics for this glyph. */
if ( face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
- FT_Incremental_MetricsRec m;
-
+ FT_Incremental_MetricsRec metrics;
+ metrics.bearing_x = left_bearing;
+ metrics.bearing_y = 0;
+ metrics.advance = advance_width;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
- glyph_index, FALSE, &m, &metrics_found );
+ glyph_index, FALSE, &metrics );
if ( error )
goto Exit;
- left_bearing = (FT_Short)m.bearing_x;
- advance_width = (FT_UShort)m.advance;
+ left_bearing = (FT_Short)metrics.bearing_x;
+ advance_width = (FT_UShort)metrics.advance;
}
- if ( !metrics_found )
- Get_HMetrics( face, glyph_index,
- (FT_Bool)!( loader->load_flags &
- FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ),
- &left_bearing,
- &advance_width );
-
-#else
-
- Get_HMetrics( face, glyph_index,
- (FT_Bool)!( loader->load_flags &
- FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ),
- &left_bearing,
- &advance_width );
-
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
loader->left_bearing = left_bearing;
@@ -1326,7 +1317,6 @@
exec->is_composite = TRUE;
exec->pedantic_hinting =
(FT_Bool)( loader->load_flags & FT_LOAD_PEDANTIC );
-
error = TT_Run_Context( exec, ((TT_Size)loader->size)->debug );
if ( error && exec->pedantic_hinting )
goto Fail;
@@ -1449,33 +1439,9 @@
FT_Pos left; /* scaled vertical left side bearing */
FT_Pos top; /* scaled vertical top side bearing */
FT_Pos advance; /* scaled vertical advance height */
- FT_Bool metrics_found = FALSE;
-
-#ifdef FT_CONFIG_OPTION_INCREMENTAL
-
- /* If this is an incrementally loaded font see if there are */
- /* overriding metrics for this glyph. */
- if ( face->root.internal->incremental_interface &&
- face->root.internal->incremental_interface->funcs->get_glyph_metrics )
- {
- FT_Incremental_MetricsRec m;
- FT_Error error =
- face->root.internal->incremental_interface->funcs->get_glyph_metrics(
- face->root.internal->incremental_interface->object,
- glyph_index, TRUE, &m, &metrics_found );
-
-
- if ( error )
- return error;
-
- top_bearing = (FT_Short)m.bearing_y;
- advance_height = (FT_UShort)m.advance;
- }
-
-#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* Get the unscaled top bearing and advance height. */
- if ( !metrics_found && face->vertical_info &&
+ if ( face->vertical_info &&
face->vertical.number_Of_VMetrics > 0 )
{
/* Don't assume that both the vertical header and vertical */
@@ -1516,8 +1482,35 @@
}
}
+#ifdef FT_CONFIG_OPTION_INCREMENTAL
+
+ /* If this is an incrementally loaded font see if there are */
+ /* overriding metrics for this glyph. */
+ if ( face->root.internal->incremental_interface &&
+ face->root.internal->incremental_interface->funcs->get_glyph_metrics )
+ {
+ FT_Incremental_MetricsRec metrics;
+ FT_Error error = 0;
+
+ metrics.bearing_x = 0;
+ metrics.bearing_y = top_bearing;
+ metrics.advance = advance_height;
+ error =
+ face->root.internal->incremental_interface->funcs->get_glyph_metrics(
+ face->root.internal->incremental_interface->object,
+ glyph_index, TRUE, &metrics );
+
+ if ( error )
+ return error;
+
+ top_bearing = (FT_Short)metrics.bearing_y;
+ advance_height = (FT_UShort)metrics.advance;
+ }
+
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
+
/* We must adjust the top_bearing value from the bounding box given */
- /* in the glyph header to te bounding box calculated with */
+ /* in the glyph header to the bounding box calculated with */
/* FT_Get_Outline_CBox(). */
/* scale the metrics */
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index 0a3155d..6ebb872 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -76,7 +76,7 @@
glyph_index, char_string );
else
-#endif
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
/* For ordinary fonts get the character data stored in the face record. */
{
@@ -95,23 +95,21 @@
if ( !error && face->root.internal->incremental_interface &&
face->root.internal->incremental_interface->funcs->get_glyph_metrics )
{
- FT_Bool found = FALSE;
FT_Incremental_MetricsRec metrics;
-
+ metrics.bearing_x = decoder->builder.left_bearing.x;
+ metrics.bearing_y = decoder->builder.left_bearing.y;
+ metrics.advance = decoder->builder.advance.x;
error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
face->root.internal->incremental_interface->object,
- glyph_index, FALSE, &metrics, &found );
- if ( found )
- {
- decoder->builder.left_bearing.x = metrics.bearing_x;
- decoder->builder.left_bearing.y = metrics.bearing_y;
- decoder->builder.advance.x = metrics.advance;
- decoder->builder.advance.y = 0;
- }
+ glyph_index, FALSE, &metrics );
+ decoder->builder.left_bearing.x = metrics.bearing_x;
+ decoder->builder.left_bearing.y = metrics.bearing_y;
+ decoder->builder.advance.x = metrics.advance;
+ decoder->builder.advance.y = 0;
}
-#endif
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
return error;
}
@@ -137,7 +135,7 @@
face->root.internal->incremental_interface->object,
&glyph_data );
}
-#endif
+#endif /* FT_CONFIG_OPTION_INCREMENTAL */
return error;
}