Commit 1487be586e86cf3b0102a82fd4761416d96cc083

Ewald Hew 2017-09-24T21:56:54

Create new `PSAux' service interface entries. NOTE: Does not compile! * include/freetype/internal/psaux.h: Include FT_INTERNAL_TRUETYPE_TYPES_H. (CFF_Builder_FuncsRec, CFF_Decocer_FuncsRec): New function tables. (CFF_Builder): Updated. Fix for forward declaration. (PSAux_ServiceRec): New field `cff_decoder_funcs'. * src/psaux/psauxmod.c (cff_builder_funcs, cff_decoder_funcs): New function tables. (PSAux_Interface): Updated. * include/freetype/internal/tttypes.h (TT_FaceRec): Add `psaux' service interface. * src/cff/cffgload.c, src/cff/cffobjs.c, src/cff/cffparse.c: Update function calls to use psaux service.

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
diff --git a/ChangeLog b/ChangeLog
index 5c4a821..02e0611 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2017-09-24  Ewald Hew  <ewaldhew@gmail.com>
 
+	[psaux, cff] Create new `PSAux' service interface entries.
+
+	NOTE: Does not compile!
+
+	* include/freetype/internal/psaux.h: Include
+	FT_INTERNAL_TRUETYPE_TYPES_H.
+	(CFF_Builder_FuncsRec, CFF_Decocer_FuncsRec): New function tables.
+	(CFF_Builder): Updated.
+	Fix for forward declaration.
+	(PSAux_ServiceRec): New field `cff_decoder_funcs'.
+
+	* src/psaux/psauxmod.c (cff_builder_funcs, cff_decoder_funcs): New
+	function tables.
+	(PSAux_Interface): Updated.
+
+	* include/freetype/internal/tttypes.h (TT_FaceRec): Add `psaux'
+	service interface.
+
+	* src/cff/cffgload.c, src/cff/cffobjs.c, src/cff/cffparse.c: Update
+	function calls to use psaux service.
+
+2017-09-24  Ewald Hew  <ewaldhew@gmail.com>
+
 	[psaux, cff] Move CFF builder components into `psaux' module.
 
 	NOTE: Does not compile!
diff --git a/include/freetype/internal/psaux.h b/include/freetype/internal/psaux.h
index 933d052..e29d452 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -25,6 +25,7 @@
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_TYPE1_TYPES_H
 #include FT_INTERNAL_HASH_H
+#include FT_INTERNAL_TRUETYPE_TYPES_H
 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
 
 
@@ -704,6 +705,67 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*************************************************************************/
+  /*****                                                               *****/
+  /*****                        CFF BUILDER                            *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  typedef struct  CFF_Builder_ CFF_Builder;
+
+
+  typedef FT_Error
+  (*CFF_Builder_Check_Points_Func)( CFF_Builder*  builder,
+                                    FT_Int        count );
+
+  typedef void
+  (*CFF_Builder_Add_Point_Func)( CFF_Builder*  builder,
+                                 FT_Pos        x,
+                                 FT_Pos        y,
+                                 FT_Byte       flag );
+  typedef FT_Error
+  (*CFF_Builder_Add_Point1_Func)( CFF_Builder*  builder,
+                                  FT_Pos        x,
+                                  FT_Pos        y );
+  typedef FT_Error
+  (*CFF_Builder_Start_Point_Func)( CFF_Builder*  builder,
+                                   FT_Pos        x,
+                                   FT_Pos        y );
+  typedef void
+  (*CFF_Builder_Close_Contour_Func)( CFF_Builder*  builder );
+
+  /* static */
+  typedef FT_Error
+  (*CFF_Builder_Add_Contour_Func)( CFF_Builder*  builder );
+
+  typedef const struct CFF_Builder_FuncsRec_*  CFF_Builder_Funcs;
+
+  typedef struct  CFF_Builder_FuncsRec_
+  {
+    /* static */
+    void
+    (*init)( CFF_Builder*   builder,
+             TT_Face        face,
+             CFF_Size       size,
+             CFF_GlyphSlot  glyph,
+             FT_Bool        hinting );
+
+    /* static */
+    void
+    (*done)( CFF_Builder*  builder );
+
+    CFF_Builder_Check_Points_Func   check_points;
+    CFF_Builder_Add_Point_Func      add_point;
+    CFF_Builder_Add_Point1_Func     add_point1;
+    CFF_Builder_Add_Contour_Func    add_contour;
+    CFF_Builder_Start_Point_Func    start_point;
+    CFF_Builder_Close_Contour_Func  close_contour;
+
+  } CFF_Builder_FuncsRec;
+
+
+  /*************************************************************************/
   /*                                                                       */
   /* <Structure>                                                           */
   /*    CFF_Builder                                                        */
@@ -748,7 +810,7 @@ FT_BEGIN_HEADER
   /*                                                                       */
   /*    hints_globals :: Auxiliary pointer for hinting.                    */
   /*                                                                       */
-  typedef struct  CFF_Builder_
+  struct  CFF_Builder_
   {
     FT_Memory       memory;
     TT_Face         face;
@@ -772,7 +834,10 @@ FT_BEGIN_HEADER
 
     void*           hints_funcs;    /* hinter-specific */
     void*           hints_globals;  /* hinter-specific */
-  } CFF_Builder;
+
+    CFF_Builder_FuncsRec  funcs;
+
+  };
 
 
   /*************************************************************************/
@@ -846,6 +911,34 @@ FT_BEGIN_HEADER
 
   } CFF_Decoder;
 
+  typedef const struct CFF_Decoder_FuncsRec_*  CFF_Decoder_Funcs;
+
+  typedef struct  CFF_Decoder_FuncsRec_
+  {
+    void
+    (*init)( CFF_Decoder*    decoder,
+             TT_Face         face,
+             CFF_Size        size,
+             CFF_GlyphSlot   slot,
+             FT_Bool         hinting,
+             FT_Render_Mode  hint_mode );
+
+    FT_Error
+    (*prepare)( CFF_Decoder*  decoder,
+                CFF_Size      size,
+                FT_UInt       glyph_index );
+
+    FT_Error
+    (*parse_charstrings)( CFF_Decoder*  decoder,
+                          FT_Byte*      charstring_base,
+                          FT_ULong      charstring_len
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+/*TODO(ewaldhew): seems hacky, is there a better way to do this?*/
+                         ,FT_Bool       in_dict
+#endif
+                          );
+
+  } CFF_Decoder_FuncsRec;
 
   /*************************************************************************/
   /*************************************************************************/
@@ -959,6 +1052,8 @@ FT_BEGIN_HEADER
     /* fields after this comment line were added after version 2.1.10 */
     const AFM_Parser_FuncsRec*  afm_parser_funcs;
 
+    const CFF_Decoder_FuncsRec*  cff_decoder_funcs;
+
   } PSAux_ServiceRec, *PSAux_Service;
 
   /* backward compatible type definition */
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index c0758e2..0fcc6b0 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -1445,6 +1445,9 @@ FT_BEGIN_HEADER
     void*                 var;
 #endif
 
+    /* a typeless pointer to the PostScript Aux service */
+    void*                 psaux;
+
 
     /***********************************************************************/
     /*                                                                     */
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 79a5d81..a5fde87 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -21,6 +21,7 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_SFNT_H
 #include FT_INTERNAL_CALC_H
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
 #include FT_OUTLINE_H
 #include FT_CFF_DRIVER_H
 
@@ -41,8 +42,6 @@
 #define FT_COMPONENT  trace_cffgload
 
 
-
-
   FT_LOCAL_DEF( FT_Error )
   cff_get_glyph_data( TT_Face    face,
                       FT_UInt    glyph_index,
@@ -144,11 +143,13 @@
     FT_Int       glyph_index;
     CFF_Font     cff = (CFF_Font)face->other;
 
+    PSAux_Service            psaux         = (PSAux_Service)face->psaux;
+    const CFF_Decoder_Funcs  decoder_funcs = psaux->cff_decoder_funcs;
 
     *max_advance = 0;
 
     /* Initialize load decoder */
-    cff_decoder_init( &decoder, face, 0, 0, 0, 0 );
+    decoder_funcs->init( &decoder, face, 0, 0, 0, 0 );
 
     decoder.builder.metrics_only = 1;
     decoder.builder.load_points  = 0;
@@ -167,12 +168,12 @@
                                   &charstring, &charstring_len );
       if ( !error )
       {
-        error = cff_decoder_prepare( &decoder, size, glyph_index );
+        error = decoder_funcs->prepare( &decoder, size, glyph_index );
         if ( !error )
-          error = cff_decoder_parse_charstrings( &decoder,
-                                                 charstring,
-                                                 charstring_len,
-                                                 0 );
+          error = decoder_funcs->parse_charstrings( &decoder,
+                                                    charstring,
+                                                    charstring_len,
+                                                    0 );
 
         cff_free_glyph_data( face, &charstring, &charstring_len );
       }
@@ -202,6 +203,9 @@
     FT_Bool      hinting, scaled, force_scaling;
     CFF_Font     cff  = (CFF_Font)face->extra.data;
 
+    PSAux_Service            psaux         = (PSAux_Service)face->psaux;
+    const CFF_Decoder_Funcs  decoder_funcs = psaux->cff_decoder_funcs;
+
     FT_Matrix    font_matrix;
     FT_Vector    font_offset;
 
@@ -399,8 +403,8 @@
       FT_ULong  charstring_len;
 
 
-      cff_decoder_init( &decoder, face, size, glyph, hinting,
-                        FT_LOAD_TARGET_MODE( load_flags ) );
+      decoder_funcs->init( &decoder, face, size, glyph, hinting,
+                           FT_LOAD_TARGET_MODE( load_flags ) );
 
       /* this is for pure CFFs */
       if ( load_flags & FT_LOAD_ADVANCE_ONLY )
@@ -415,23 +419,23 @@
       if ( error )
         goto Glyph_Build_Finished;
 
-      error = cff_decoder_prepare( &decoder, size, glyph_index );
+      error = decoder_funcs->prepare( &decoder, size, glyph_index );
       if ( error )
         goto Glyph_Build_Finished;
 
 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
       /* choose which CFF renderer to use */
       if ( driver->hinting_engine == FT_CFF_HINTING_FREETYPE )
-        error = cff_decoder_parse_charstrings( &decoder,
-                                               charstring,
-                                               charstring_len,
-                                               0 );
+        error = decoder_funcs->parse_charstrings( &decoder,
+                                                  charstring,
+                                                  charstring_len,
+                                                  0 );
       else
 #endif
       {
-        error = cf2_decoder_parse_charstrings( &decoder,
-                                               charstring,
-                                               charstring_len );
+        error = decoder_funcs->parse_charstrings( &decoder,
+                                                  charstring,
+                                                  charstring_len );
 
         /* Adobe's engine uses 16.16 numbers everywhere;              */
         /* as a consequence, glyphs larger than 2000ppem get rejected */
@@ -444,9 +448,9 @@
           force_scaling = TRUE;
           glyph->hint   = hinting;
 
-          error = cf2_decoder_parse_charstrings( &decoder,
-                                                 charstring,
-                                                 charstring_len );
+          error = decoder_funcs->parse_charstrings( &decoder,
+                                                    charstring,
+                                                    charstring_len );
         }
       }
 
@@ -484,7 +488,7 @@
   Glyph_Build_Finished:
       /* save new glyph tables, if no error */
       if ( !error )
-        cff_builder_done( &decoder.builder );
+        decoder.builder.funcs.done( &decoder.builder );
       /* XXX: anything to do for broken glyph entry? */
     }
 
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index 2899a4c..b0d275c 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -39,6 +39,8 @@
 
 #include "cfferrs.h"
 
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -493,6 +495,7 @@
     SFNT_Service        sfnt;
     FT_Service_PsCMaps  psnames;
     PSHinter_Service    pshinter;
+    PSAux_Service       psaux;
     FT_Bool             pure_cff    = 1;
     FT_Bool             cff2        = 0;
     FT_Bool             sfnt_format = 0;
@@ -513,6 +516,16 @@
     pshinter = (PSHinter_Service)FT_Get_Module_Interface(
                  library, "pshinter" );
 
+    psaux = (PSAux_Service)FT_Get_Module_Interface(
+              library, "psaux" );
+    if ( !psaux )
+    {
+      FT_ERROR(( "cff_face_init: cannot access `psaux' module\n" ));
+      error = FT_THROW( Missing_Module );
+      goto Exit;
+    }
+    face->psaux = psaux;
+
     FT_TRACE2(( "CFF driver\n" ));
 
     /* create input stream from resource */
diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c
index 9d7bf6d..63f20a1 100644
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -21,10 +21,10 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_CALC_H
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
 
 #include "cfferrs.h"
 #include "cffpic.h"
-#include "cffgload.h"
 #include "cffload.h"
 
 
@@ -1305,6 +1305,7 @@
     FT_UNUSED( library );
 
 
+
     parser->top    = parser->stack;
     parser->start  = start;
     parser->limit  = limit;
@@ -1388,10 +1389,19 @@
         cff_rec.top_font.font_dict.num_axes    = parser->num_axes;
         decoder.cff                            = &cff_rec;
 
-        error = cff_decoder_parse_charstrings( &decoder,
-                                               charstring_base,
-                                               charstring_len,
-                                               1 );
+        psaux = (PSAux_Service)FT_Get_Module_Interface(
+                  library, "psaux" );
+        if ( !psaux )
+        {
+          FT_ERROR(( "cff_parser_run: cannot access `psaux' module\n" ));
+          error = FT_THROW( Missing_Module );
+          goto Exit;
+        }
+        
+        error = psaux->cff_decoder_funcs->parse_charstrings( &decoder,
+                                                             charstring_base,
+                                                             charstring_len,
+                                                             1 );
 
         /* Now copy the stack data in the temporary decoder object,    */
         /* converting it back to charstring number representations     */
diff --git a/src/psaux/psauxmod.c b/src/psaux/psauxmod.c
index 1f589ce..cd9f525 100644
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -21,6 +21,8 @@
 #include "psobjs.h"
 #include "t1decode.h"
 #include "t1cmap.h"
+#include "cf2ft.h"
+#include "cffdecode.h"
 
 #ifndef T1_CONFIG_OPTION_NO_AFM
 #include "afmparse.h"
@@ -104,6 +106,35 @@
   };
 
 
+  FT_CALLBACK_TABLE_DEF
+  const CFF_Builder_FuncsRec  cff_builder_funcs =
+  {
+    cff_builder_init,          /* init */
+    cff_builder_done,          /* done */
+
+    cff_check_points,          /* check_points  */
+    cff_builder_add_point,     /* add_point     */
+    cff_builder_add_point1,    /* add_point1    */
+    cff_builder_add_contour,   /* add_contour   */
+    cff_builder_start_point,   /* start_point   */
+    cff_builder_close_contour  /* close_contour */
+  };
+
+
+  FT_CALLBACK_TABLE_DEF
+  const CFF_Decoder_FuncsRec  cff_decoder_funcs =
+  {
+    cff_decoder_init,              /* init              */
+    cff_decoder_prepare,           /* prepare           */
+
+#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
+    cff_decoder_parse_charstrings  /* parse_charstrings */
+#else
+    cf2_decoder_parse_charstrings
+#endif
+  };
+
+
   static
   const PSAux_Interface  psaux_interface =
   {
@@ -120,6 +151,8 @@
 #else
     0,
 #endif
+
+    &cff_decoder_funcs,
   };