* src/truetype/ttobjs.h, src/truetype/ttobjs.c, src/truetype/ttgload.c: do not allocate interpreter-specific tables in memory if we're not going to load glyphs with it anyway.
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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
diff --git a/ChangeLog b/ChangeLog
index d0cd84a..2358cbd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2007-01-04 David Turner <david@freetype.org>
+ * src/truetype/ttobjs.h, src/truetype/ttobjs.c,
+ src/truetype/ttgload.c: do not allocate interpreter-specific
+ tables in memory if we're not going to load glyphs with it
+ anyway.
+
* src/sfnt/ttmtx.c, include/freetype/internal/tttypes.h:
don't extract the metrics table from the SFNT font file.
Instead, reparse it on each glyph load, since the runtime
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 8ddc692..a04f914 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1718,11 +1718,19 @@
#ifdef TT_USE_BYTECODE_INTERPRETER
/* load execution context */
+ if ( IS_HINTED( load_flags ) )
{
TT_ExecContext exec;
FT_Bool grayscale;
+ if ( !size->cvt_ready )
+ {
+ FT_Error error = tt_size_ready_bytecode( size );
+ if ( error )
+ return error;
+ }
+
/* query new execution context */
exec = size->debug ? size->context
: ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index b464fcd..908194e 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -519,29 +519,58 @@
#endif /* TT_USE_BYTECODE_INTERPRETER */
- /*************************************************************************/
- /* */
- /* <Function> */
- /* tt_size_init */
- /* */
- /* <Description> */
- /* Initialize a new TrueType size object. */
- /* */
- /* <InOut> */
- /* size :: A handle to the size object. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
- FT_LOCAL_DEF( FT_Error )
- tt_size_init( FT_Size ttsize ) /* TT_Size */
+#ifdef TT_USE_BYTECODE_INTERPRETER
+
+ static void
+ tt_size_done_bytecode( FT_Size ftsize )
{
- TT_Size size = (TT_Size)ttsize;
- FT_Error error = TT_Err_Ok;
+ TT_Size size = (TT_Size)ftsize;
+ TT_Face face = (TT_Face)ftsize->face;
+ FT_Memory memory = face->root.memory;
-#ifdef TT_USE_BYTECODE_INTERPRETER
+ if ( size->debug )
+ {
+ /* the debug context must be deleted by the debugger itself */
+ size->context = NULL;
+ size->debug = FALSE;
+ }
+
+ FT_FREE( size->cvt );
+ size->cvt_size = 0;
+
+ /* free storage area */
+ FT_FREE( size->storage );
+ size->storage_size = 0;
+
+ /* twilight zone */
+ tt_glyphzone_done( &size->twilight );
+
+ FT_FREE( size->function_defs );
+ FT_FREE( size->instruction_defs );
+
+ size->num_function_defs = 0;
+ size->max_function_defs = 0;
+ size->num_instruction_defs = 0;
+ size->max_instruction_defs = 0;
+
+ size->max_func = 0;
+ size->max_ins = 0;
- TT_Face face = (TT_Face)size->root.face;
+ size->bytecode_ready = 0;
+ size->cvt_ready = 0;
+ }
+
+
+ /* initialize bytecode-related fields in the size object,
+ * should only be needed when bytecode interpretation is
+ * really needed
+ */
+ static FT_Error
+ tt_size_init_bytecode( FT_Size ftsize )
+ {
+ FT_Error error;
+ TT_Size size = (TT_Size)ftsize;
+ TT_Face face = (TT_Face)ftsize->face;
FT_Memory memory = face->root.memory;
FT_Int i;
@@ -549,6 +578,9 @@
TT_MaxProfile* maxp = &face->max_profile;
+ size->bytecode_ready = 1;
+ size->cvt_ready = 0;
+
size->max_function_defs = maxp->maxFunctionDefs;
size->max_instruction_defs = maxp->maxInstructionDefs;
@@ -583,11 +615,7 @@
FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
FT_NEW_ARRAY( size->cvt, size->cvt_size ) ||
FT_NEW_ARRAY( size->storage, size->storage_size ) )
- {
- tt_size_done( ttsize );
-
- return error;
- }
+ goto Exit;
/* reserve twilight zone */
n_twilight = maxp->maxTwilightPoints;
@@ -597,11 +625,7 @@
error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
if ( error )
- {
- tt_size_done( ttsize );
-
- return error;
- }
+ goto Exit;
size->twilight.n_points = n_twilight;
@@ -621,10 +645,95 @@
/* Fine, now run the font program! */
error = tt_size_run_fpgm( size );
- if ( error )
- tt_size_done( ttsize );
+ Exit:
+ if (error)
+ tt_size_done_bytecode( ftsize );
+
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ tt_size_ready_bytecode( TT_Size size )
+ {
+ FT_Error error = 0;
+
+ if ( !size->bytecode_ready )
+ {
+ error = tt_size_init_bytecode( (FT_Size)size );
+ if ( error )
+ goto Exit;
+ }
+
+ /* rescale CVT when needed */
+ if ( !size->cvt_ready )
+ {
+ FT_UInt i;
+ TT_Face face = (TT_Face) size->root.face;
+
+
+ /* Scale the cvt values to the new ppem. */
+ /* We use by default the y ppem to scale the CVT. */
+ for ( i = 0; i < size->cvt_size; i++ )
+ size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
+
+ /* All twilight points are originally zero */
+ for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
+ {
+ size->twilight.org[i].x = 0;
+ size->twilight.org[i].y = 0;
+ size->twilight.cur[i].x = 0;
+ size->twilight.cur[i].y = 0;
+ }
+
+ /* clear storage area */
+ for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
+ size->storage[i] = 0;
+
+ size->GS = tt_default_graphics_state;
+
+ error = tt_size_run_prep( size );
+ }
+ Exit:
+ return error;
+ }
+
+#else /* !TT_USE_BYTECODE_INTERPRETER */
+
+ FT_LOCAL_DEF( FT_Error )
+ tt_size_ready_bytecode( TT_Size size )
+ {
+ FT_UNUSED(ftsize);
+ return 0;
+ }
-#endif /* TT_USE_BYTECODE_INTERPRETER */
+
+#endif /* !TT_USE_BYTECODE_INTERPRETER */
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* tt_size_init */
+ /* */
+ /* <Description> */
+ /* Initialize a new TrueType size object. */
+ /* */
+ /* <InOut> */
+ /* size :: A handle to the size object. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ FT_LOCAL_DEF( FT_Error )
+ tt_size_init( FT_Size ttsize ) /* TT_Size */
+ {
+ TT_Size size = (TT_Size)ttsize;
+ FT_Error error = TT_Err_Ok;
+
+#ifdef TT_USE_BYTECODE_INTERPRETER
+ size->bytecode_ready = 0;
+ size->cvt_ready = 0;
+#endif
size->ttmetrics.valid = FALSE;
size->strike_index = 0xFFFFFFFFUL;
@@ -650,38 +759,8 @@
TT_Size size = (TT_Size)ttsize;
#ifdef TT_USE_BYTECODE_INTERPRETER
-
- FT_Memory memory = size->root.face->memory;
-
-
- if ( size->debug )
- {
- /* the debug context must be deleted by the debugger itself */
- size->context = NULL;
- size->debug = FALSE;
- }
-
- FT_FREE( size->cvt );
- size->cvt_size = 0;
-
- /* free storage area */
- FT_FREE( size->storage );
- size->storage_size = 0;
-
- /* twilight zone */
- tt_glyphzone_done( &size->twilight );
-
- FT_FREE( size->function_defs );
- FT_FREE( size->instruction_defs );
-
- size->num_function_defs = 0;
- size->max_function_defs = 0;
- size->num_instruction_defs = 0;
- size->max_instruction_defs = 0;
-
- size->max_func = 0;
- size->max_ins = 0;
-
+ if ( size->bytecode_ready )
+ tt_size_done_bytecode( ttsize );
#endif
size->ttmetrics.valid = FALSE;
@@ -762,36 +841,8 @@
size->ttmetrics.y_ratio = 0x10000L;
}
-
#ifdef TT_USE_BYTECODE_INTERPRETER
-
- {
- FT_UInt i;
-
-
- /* Scale the cvt values to the new ppem. */
- /* We use by default the y ppem to scale the CVT. */
- for ( i = 0; i < size->cvt_size; i++ )
- size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
-
- /* All twilight points are originally zero */
- for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
- {
- size->twilight.org[i].x = 0;
- size->twilight.org[i].y = 0;
- size->twilight.cur[i].x = 0;
- size->twilight.cur[i].y = 0;
- }
-
- /* clear storage area */
- for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
- size->storage[i] = 0;
-
- size->GS = tt_default_graphics_state;
-
- error = tt_size_run_prep( size );
- }
-
+ size->cvt_ready = 0;
#endif /* TT_USE_BYTECODE_INTERPRETER */
if ( !error )
diff --git a/src/truetype/ttobjs.h b/src/truetype/ttobjs.h
index 5801af2..f81328f 100644
--- a/src/truetype/ttobjs.h
+++ b/src/truetype/ttobjs.h
@@ -358,6 +358,9 @@ FT_BEGIN_HEADER
FT_Bool debug;
TT_ExecContext context;
+ FT_Bool bytecode_ready;
+ FT_Bool cvt_ready;
+
#endif /* TT_USE_BYTECODE_INTERPRETER */
} TT_SizeRec;
@@ -425,6 +428,9 @@ FT_BEGIN_HEADER
FT_LOCAL( FT_Error )
tt_size_reset( TT_Size size );
+ FT_LOCAL( FT_Error )
+ tt_size_ready_bytecode( TT_Size size );
+
/*************************************************************************/
/* */