Commit 89fff9b9d193fdf97073d085cdb99bcb9823dda8

Wu, Chia-I (吳佳一) 2005-07-31T11:41:54

* src/truetype/ttobjs.h (tt_size_run_fpgm, tt_size_run_prep): New functions. * src/truetype/ttobjs.c (tt_size_run_fpgm, tt_size_run_prep): New functions. (tt_size_init): Add 4, instead of 2, (phantom) points to twilight zone. Move code that runs fpgm to tt_size_run_fpgm. (Reset_Outline_Size): Move code that runs prep to tt_size_run_prep. (tt_glyphzone_new): Allocate right size of arrays. Set max_points and max_contours properly.

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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
diff --git a/ChangeLog b/ChangeLog
index 8685464..a06acb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-07-31  Chia I Wu  <b90201047@ntu.edu.tw>
+
+	* src/truetype/ttobjs.h (tt_size_run_fpgm, tt_size_run_prep): New functions.
+
+	* src/truetype/ttobjs.c (tt_size_run_fpgm, tt_size_run_prep): New functions.
+	(tt_size_init): Add 4, instead of 2, (phantom) points to twilight zone.
+	Move code that runs fpgm to tt_size_run_fpgm.
+	(Reset_Outline_Size): Move code that runs prep to tt_size_run_prep.
+	(tt_glyphzone_new): Allocate right size of arrays.
+	Set max_points and max_contours properly.
+
 2005-07-26  Chia I Wu  <b90201047@ntu.edu.tw>
 
 	* src/truetype/ttdriver.c (Set_Char_Sizes): Avoid unnecessary
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index 05e673d..540b4e3 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -121,19 +121,21 @@
     FT_Error  error;
 
 
-    if ( maxPoints > 0 )
-      maxPoints += 2;
-
     FT_MEM_ZERO( zone, sizeof ( *zone ) );
     zone->memory = memory;
 
-    if ( FT_NEW_ARRAY( zone->org,      maxPoints * 2 ) ||
-         FT_NEW_ARRAY( zone->cur,      maxPoints * 2 ) ||
-         FT_NEW_ARRAY( zone->tags,     maxPoints     ) ||
-         FT_NEW_ARRAY( zone->contours, maxContours   ) )
+    if ( FT_NEW_ARRAY( zone->org,      maxPoints   ) ||
+         FT_NEW_ARRAY( zone->cur,      maxPoints   ) ||
+         FT_NEW_ARRAY( zone->tags,     maxPoints   ) ||
+         FT_NEW_ARRAY( zone->contours, maxContours ) )
     {
       tt_glyphzone_done( zone );
     }
+    else
+    {
+      zone->max_points = maxPoints;
+      zone->max_contours = maxContours;
+    }
 
     return error;
   }
@@ -318,6 +320,162 @@
   /*                                                                       */
   /*************************************************************************/
 
+#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    tt_size_run_fpgm                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Run the font program                                               */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    size :: A handle to the size object.                               */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  tt_size_run_fpgm( TT_Size  size )
+  {
+    TT_Face         face = (TT_Face)size->root.face;
+    TT_ExecContext  exec;
+    FT_Error        error;
+
+
+    /* debugging instances have their own context */
+    if ( size->debug )
+      exec = size->context;
+    else
+      exec = TT_New_Context( face );
+
+    if ( !exec )
+      return TT_Err_Could_Not_Find_Context;
+
+    TT_Load_Context( exec, face, size );
+
+    exec->callTop   = 0;
+    exec->top       = 0;
+
+    exec->period    = 64;
+    exec->phase     = 0;
+    exec->threshold = 0;
+
+    exec->instruction_trap = FALSE;
+    exec->F_dot_P = 0x10000L;
+
+    {
+      FT_Size_Metrics*  metrics    = &exec->metrics;
+      TT_Size_Metrics*  tt_metrics = &exec->tt_metrics;
+
+
+      metrics->x_ppem   = 0;
+      metrics->y_ppem   = 0;
+      metrics->x_scale  = 0;
+      metrics->y_scale  = 0;
+
+      tt_metrics->ppem  = 0;
+      tt_metrics->scale = 0;
+      tt_metrics->ratio = 0x10000L;
+    }
+
+    /* allow font program execution */
+    TT_Set_CodeRange( exec,
+                      tt_coderange_font,
+                      face->font_program,
+                      face->font_program_size );
+
+    /* disable CVT and glyph programs coderange */
+    TT_Clear_CodeRange( exec, tt_coderange_cvt );
+    TT_Clear_CodeRange( exec, tt_coderange_glyph );
+
+    if ( face->font_program_size > 0 )
+    {
+      error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
+
+      if ( !error )
+        error = face->interpreter( exec );
+    }
+    else
+      error = TT_Err_Ok;
+
+    if ( !error )
+      TT_Save_Context( exec, size );
+
+    if ( !size->debug )
+      TT_Done_Context( exec );
+
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    tt_size_run_prep                                                   */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Run the control value program                                      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    size :: A handle to the size object.                               */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  tt_size_run_prep( TT_Size  size )
+  {
+    TT_Face         face = (TT_Face)size->root.face;
+    TT_ExecContext  exec;
+    FT_Error        error;
+
+
+    /* debugging instances have their own context */
+    if ( size->debug )
+      exec = size->context;
+    else
+      exec = TT_New_Context( face );
+
+    if ( !exec )
+      return TT_Err_Could_Not_Find_Context;
+
+    TT_Load_Context( exec, face, size );
+
+    exec->callTop = 0;
+    exec->top     = 0;
+
+    exec->instruction_trap = FALSE;
+
+    TT_Set_CodeRange( exec,
+                      tt_coderange_cvt,
+                      face->cvt_program,
+                      face->cvt_program_size );
+
+    TT_Clear_CodeRange( exec, tt_coderange_glyph );
+
+    if ( face->cvt_program_size > 0 )
+    {
+      error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
+
+      if ( !error && !size->debug )
+        error = face->interpreter( exec );
+    }
+    else
+      error = TT_Err_Ok;
+
+    /* save as default graphics state */
+    size->GS = exec->GS;
+
+    TT_Save_Context( exec, size );
+
+    if ( !size->debug )
+      TT_Done_Context( exec );
+
+    return error;
+  }
+#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -338,15 +496,11 @@
   {
     TT_Size   size  = (TT_Size)ttsize;
     FT_Error  error = TT_Err_Ok;
-
-
 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
-
     TT_Face    face   = (TT_Face)size->root.face;
     FT_Memory  memory = face->root.memory;
     FT_Int     i;
 
-    TT_ExecContext  exec;
     FT_UShort       n_twilight;
     TT_MaxProfile*  maxp = &face->max_profile;
 
@@ -387,17 +541,30 @@
          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 );
 
-      goto Fail_Memory;
+      return error;
+    }
 
     /* reserve twilight zone */
     n_twilight = maxp->maxTwilightPoints;
+
+    /* there are 4 phantom points (do we need this?) */
+    n_twilight += 4;
+
     error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
     if ( error )
-      goto Fail_Memory;
+    {
+      tt_size_done( ttsize );
+
+      return error;
+    }
 
     size->twilight.n_points = n_twilight;
 
+    size->GS = tt_default_graphics_state;
+
     /* set `face->interpreter' according to the debug hook present */
     {
       FT_Library  library = face->root.driver->root.library;
@@ -409,95 +576,17 @@
         face->interpreter = (TT_Interpreter)TT_RunIns;
     }
 
-    /* Fine, now execute the font program! */
-    exec = size->context;
-    /* size objects used during debugging have their own context */
-    if ( !size->debug )
-      exec = TT_New_Context( face );
-
-    if ( !exec )
-    {
-      error = TT_Err_Could_Not_Find_Context;
-      goto Fail_Memory;
-    }
-
-    size->GS = tt_default_graphics_state;
-    TT_Load_Context( exec, face, size );
-
-    exec->callTop   = 0;
-    exec->top       = 0;
-
-    exec->period    = 64;
-    exec->phase     = 0;
-    exec->threshold = 0;
-
-    {
-      FT_Size_Metrics*  metrics    = &exec->metrics;
-      TT_Size_Metrics*  tt_metrics = &exec->tt_metrics;
-
-
-      metrics->x_ppem   = 0;
-      metrics->y_ppem   = 0;
-      metrics->x_scale  = 0;
-      metrics->y_scale  = 0;
-
-      tt_metrics->ppem  = 0;
-      tt_metrics->scale = 0;
-      tt_metrics->ratio = 0x10000L;
-    }
+    /* Fine, now run the font program! */
+    error = tt_size_run_fpgm( size );
 
-    exec->instruction_trap = FALSE;
-
-    exec->cvtSize = size->cvt_size;
-    exec->cvt     = size->cvt;
-
-    exec->F_dot_P = 0x10000L;
-
-    /* allow font program execution */
-    TT_Set_CodeRange( exec,
-                      tt_coderange_font,
-                      face->font_program,
-                      face->font_program_size );
-
-    /* disable CVT and glyph programs coderange */
-    TT_Clear_CodeRange( exec, tt_coderange_cvt );
-    TT_Clear_CodeRange( exec, tt_coderange_glyph );
-
-    if ( face->font_program_size > 0 )
-    {
-      error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
-      if ( !error )
-        error = face->interpreter( exec );
-
-      if ( error )
-        goto Fail_Exec;
-    }
-    else
-      error = TT_Err_Ok;
-
-    TT_Save_Context( exec, size );
-
-    if ( !size->debug )
-      TT_Done_Context( exec );
+    if ( error )
+      tt_size_done( ttsize );
 
 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
 
     size->ttmetrics.valid = FALSE;
-    return error;
-
-#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
-
-  Fail_Exec:
-    if ( !size->debug )
-      TT_Done_Context( exec );
-
-  Fail_Memory:
 
-    tt_size_done( ttsize );
     return error;
-
-#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
-
   }
 
 
@@ -516,9 +605,7 @@
   tt_size_done( FT_Size  ttsize )           /* TT_Size */
   {
     TT_Size    size = (TT_Size)ttsize;
-
 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
-
     FT_Memory  memory = size->root.face->memory;
 
 
@@ -625,10 +712,8 @@
 #endif
 
 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
-
     {
-      TT_ExecContext  exec;
-      FT_UInt         i, j;
+      FT_UInt  i;
 
 
       /* Scale the cvt values to the new ppem.          */
@@ -637,12 +722,12 @@
         size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
 
       /* All twilight points are originally zero */
-      for ( j = 0; j < (FT_UInt)size->twilight.n_points; j++ )
+      for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
       {
-        size->twilight.org[j].x = 0;
-        size->twilight.org[j].y = 0;
-        size->twilight.cur[j].x = 0;
-        size->twilight.cur[j].y = 0;
+        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 */
@@ -651,53 +736,8 @@
 
       size->GS = tt_default_graphics_state;
 
-      /* get execution context and run prep program */
-      if ( size->debug )
-        exec = size->context;
-      else
-        exec = TT_New_Context( face );
-      /* debugging instances have their own context */
-
-      if ( !exec )
-        return TT_Err_Could_Not_Find_Context;
-
-      TT_Load_Context( exec, face, size );
-
-      TT_Set_CodeRange( exec,
-                        tt_coderange_cvt,
-                        face->cvt_program,
-                        face->cvt_program_size );
-
-      TT_Clear_CodeRange( exec, tt_coderange_glyph );
-
-      exec->instruction_trap = FALSE;
-
-      exec->top     = 0;
-      exec->callTop = 0;
-
-      if ( face->cvt_program_size > 0 )
-      {
-        error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
-        if ( error )
-          goto End;
-
-        if ( !size->debug )
-          error = face->interpreter( exec );
-      }
-      else
-        error = TT_Err_Ok;
-
-      size->GS = exec->GS;
-      /* save default graphics state */
-
-    End:
-      TT_Save_Context( exec, size );
-
-      if ( !size->debug )
-        TT_Done_Context( exec );
-      /* debugging instances keep their context */
+      error = tt_size_run_prep( size );
     }
-
 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
 
     if ( !error )
diff --git a/src/truetype/ttobjs.h b/src/truetype/ttobjs.h
index d193b2d..b289d01 100644
--- a/src/truetype/ttobjs.h
+++ b/src/truetype/ttobjs.h
@@ -417,6 +417,14 @@ FT_BEGIN_HEADER
   FT_LOCAL( void )
   tt_size_done( FT_Size  ttsize );          /* TT_Size */
 
+#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+  FT_LOCAL( FT_Error )
+  tt_size_run_fpgm( TT_Size  size );
+
+  FT_LOCAL( FT_Error )
+  tt_size_run_prep( TT_Size  size );
+#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
+
   FT_LOCAL( FT_Error )
   tt_size_reset( TT_Size  size );