Commit 43c015823f7c8a708205b3501a862b8f50809363

Ewald Hew 2017-09-24T23:00:36

Objects for new interpreter (part 2). Make the new objects copy over values. They are essentially wrapper types for the different decoders/builders. * include/freetype/internal/psaux.h: Update declarations. (PS_Builder): Add `is_t1' flag. (PS_Decoder_{Get,Free}_Glyph_Callback): Renamed to... (CFF_Decoder_{Get,Free}_Glyph_Callback: ... this. (PS_Decoder): Updated. Add `t1_parse_callback' member. (PSAux_ServiceRec): Add `ps_decoder_init' member. * src/psaux/psdecode.h, src/psaux/psobjs.h: Update declarations. * src/psaux/psdecode.c, src/psaux/psobjs.c: Implement copy with two modes. * src/psaux/psauxmod.c: Add builder and decoder functions to `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
diff --git a/ChangeLog b/ChangeLog
index e8ba1e1..4de920b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2017-09-24  Ewald Hew  <ewaldhew@gmail.com>
 
+	[psaux] Objects for new interpreter (part 2).
+
+	Make the new objects copy over values.  They are essentially wrapper
+	types for the different decoders/builders.
+
+	* include/freetype/internal/psaux.h: Update declarations.
+	(PS_Builder): Add `is_t1' flag.
+	(PS_Decoder_{Get,Free}_Glyph_Callback): Renamed to...
+	(CFF_Decoder_{Get,Free}_Glyph_Callback: ... this.
+	(PS_Decoder): Updated.
+	Add `t1_parse_callback' member.
+	(PSAux_ServiceRec): Add `ps_decoder_init' member.
+
+	* src/psaux/psdecode.h, src/psaux/psobjs.h: Update declarations.
+
+	* src/psaux/psdecode.c, src/psaux/psobjs.c: Implement copy with two
+	modes.
+
+	* src/psaux/psauxmod.c: Add builder and decoder functions to `PSAux'
+	service.
+
+2017-09-24  Ewald Hew  <ewaldhew@gmail.com>
+
 	[psaux] Add objects for new interpreter.
 
 	Introduce `PS_Decoder' and `PS_Builder' which include all fields
diff --git a/include/freetype/internal/psaux.h b/include/freetype/internal/psaux.h
index 43ea776..3361b97 100644
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -457,14 +457,12 @@ FT_BEGIN_HEADER
   typedef struct  PS_Builder_FuncsRec_
   {
     void
-    (*init)( PS_Builder    builder,
-             FT_Face       face,
-             FT_Size       size,
-             FT_GlyphSlot  slot,
-             FT_Bool       hinting );
+    (*init)( void*        builder,
+             FT_Bool      is_t1,
+             PS_Builder*  ps_builder );
 
     void
-    (*done)( PS_Builder   builder );
+    (*done)( PS_Builder*   builder );
 
   } PS_Builder_FuncsRec;
 
@@ -521,13 +519,13 @@ FT_BEGIN_HEADER
     FT_Outline*     base;
     FT_Outline*     current;
 
-    FT_Pos          pos_x;
-    FT_Pos          pos_y;
+    FT_Pos*         pos_x;
+    FT_Pos*         pos_y;
 
-    FT_Vector       left_bearing;
-    FT_Vector       advance;
+    FT_Vector*      left_bearing;
+    FT_Vector*      advance;
 
-    FT_BBox         bbox;          /* bounding box */
+    FT_BBox*        bbox;          /* bounding box */
     FT_Bool         path_begun;
     FT_Bool         load_points;
     FT_Bool         no_recurse;
@@ -537,6 +535,8 @@ FT_BEGIN_HEADER
     void*           hints_funcs;    /* hinter-specific */
     void*           hints_globals;  /* hinter-specific */
 
+    FT_Bool         is_t1;
+
     PS_Builder_FuncsRec  funcs;
 
   };
@@ -570,15 +570,16 @@ FT_BEGIN_HEADER
 
 
   typedef FT_Error
-  (*PS_Decoder_Get_Glyph_Callback)( TT_Face    face,
-                                    FT_UInt    glyph_index,
-                                    FT_Byte**  pointer,
-                                    FT_ULong*  length );
+  (*CFF_Decoder_Get_Glyph_Callback)( TT_Face    face,
+                                     FT_UInt    glyph_index,
+                                     FT_Byte**  pointer,
+                                     FT_ULong*  length );
 
   typedef void
-  (*PS_Decoder_Free_Glyph_Callback)( TT_Face    face,
-                                     FT_Byte**  pointer,
-                                     FT_ULong   length );
+  (*CFF_Decoder_Free_Glyph_Callback)( TT_Face    face,
+                                      FT_Byte**  pointer,
+                                      FT_ULong   length );
+
 
   typedef struct  PS_Decoder_
   {
@@ -620,8 +621,8 @@ FT_BEGIN_HEADER
 
     FT_Bool            seac;
 
-    PS_Decoder_Get_Glyph_Callback   get_glyph_callback;
-    PS_Decoder_Free_Glyph_Callback  free_glyph_callback;
+    CFF_Decoder_Get_Glyph_Callback   get_glyph_callback;
+    CFF_Decoder_Free_Glyph_Callback  free_glyph_callback;
     
     /* Type 1 stuff */
     FT_Service_PsCMaps   psnames;      /* for seac */
@@ -638,6 +639,8 @@ FT_BEGIN_HEADER
     FT_Long*             buildchar;
     FT_UInt              len_buildchar;
 
+    void*                t1_parse_callback;
+
   } PS_Decoder;
 
 
@@ -1069,18 +1072,6 @@ FT_BEGIN_HEADER
   } CFF_Decoder_Zone;
 
 
-  typedef FT_Error
-  (*CFF_Decoder_Get_Glyph_Callback)( TT_Face    face,
-                                     FT_UInt    glyph_index,
-                                     FT_Byte**  pointer,
-                                     FT_ULong*  length );
-
-  typedef void
-  (*CFF_Decoder_Free_Glyph_Callback)( TT_Face    face,
-                                      FT_Byte**  pointer,
-                                      FT_ULong   length );
-
-
   typedef struct  CFF_Decoder_
   {
     CFF_Builder        builder;
@@ -1268,6 +1259,11 @@ FT_BEGIN_HEADER
     FT_UInt32
     (*cff_random)( FT_UInt32  r );
 
+    void
+    (*ps_decoder_init)( void*        decoder,
+                        FT_Bool      is_t1,
+                        PS_Decoder*  ps_decoder );
+
 
     T1_CMap_Classes  t1_cmap_classes;
 
diff --git a/src/psaux/psauxmod.c b/src/psaux/psauxmod.c
index eb94d54..d7223e2 100644
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -23,6 +23,7 @@
 #include "t1cmap.h"
 #include "psft.h"
 #include "cffdecode.h"
+#include "psdecode.h"
 
 #ifndef T1_CONFIG_OPTION_NO_AFM
 #include "afmparse.h"
@@ -62,6 +63,14 @@
 
 
   FT_CALLBACK_TABLE_DEF
+  const PS_Builder_FuncsRec  ps_builder_funcs =
+  {
+    ps_builder_init,          /* init */
+    ps_builder_done           /* done */
+  };
+
+
+  FT_CALLBACK_TABLE_DEF
   const T1_Builder_FuncsRec  t1_builder_funcs =
   {
     t1_builder_init,          /* init */
@@ -144,6 +153,7 @@
     &t1_decoder_funcs,
     t1_decrypt,
     cff_random,
+    ps_decoder_init,
 
     (const T1_CMap_ClassesRec*) &t1_cmap_classes,
 
diff --git a/src/psaux/psdecode.c b/src/psaux/psdecode.c
index 7003425..86b4286 100644
--- a/src/psaux/psdecode.c
+++ b/src/psaux/psdecode.c
@@ -2,7 +2,6 @@
 
 #include <ft2build.h>
 #include FT_INTERNAL_SERVICE_H
-#include FT_SERVICE_CFF_TABLE_LOAD_H
 
 #include "psdecode.h"
 #include "psobjs.h"
@@ -16,42 +15,76 @@
   /*    ps_decoder_init                                                    */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Initializes a given glyph decoder.                                 */
+  /*    Creates a decoder for the combined Type 1 / CFF interpreter.       */
   /*                                                                       */
   /* <InOut>                                                               */
   /*    decoder :: A pointer to the glyph builder to initialize.           */
   /*                                                                       */
   /* <Input>                                                               */
-  /*    face      :: The current face object.                              */
   /*                                                                       */
-  /*    size      :: The current size object.                              */
   /*                                                                       */
-  /*    slot      :: The current glyph object.                             */
   /*                                                                       */
-  /*    hinting   :: Whether hinting is active.                            */
   /*                                                                       */
-  /*    hint_mode :: The hinting mode.                                     */
   /*                                                                       */
   FT_LOCAL_DEF( void )
-  ps_decoder_init( PS_Decoder*     decoder,
-                   TT_Face         face,
-                   FT_Size         size,
-                   CFF_GlyphSlot   slot,
-                   FT_Byte**       glyph_names,
-                   PS_Blend        blend,
-                   FT_Bool         hinting,
-                   FT_Render_Mode  hint_mode,
-                   PS_Decoder_Get_Glyph_Callback   get_callback,
-                   PS_Decoder_Free_Glyph_Callback  free_callback )
+  ps_decoder_init( void*        decoder,
+                   FT_Bool      is_t1,
+                   PS_Decoder*  ps_decoder )
   {
-  }
+    FT_ZERO( ps_decoder );
 
+    if ( is_t1 )
+    {
+      T1_Decoder  t1_decoder = (T1_Decoder)decoder;
 
-  /* this function is used to select the subfont */
-  /* and the locals subrs array                  */
-  FT_LOCAL_DEF( FT_Error )
-  ps_decoder_prepare( PS_Decoder*  decoder,
-                      FT_Size      size,
-                      FT_UInt      glyph_index )
-  {
+      ps_builder_init( &t1_decoder->builder,
+                       is_t1,
+                       &ps_decoder->builder );
+
+      ps_decoder->psnames            =  t1_decoder->psnames;
+
+      ps_decoder->num_glyphs         =  t1_decoder->num_glyphs;
+      ps_decoder->glyph_names        =  t1_decoder->glyph_names;
+      ps_decoder->hint_mode          =  t1_decoder->hint_mode;
+      ps_decoder->blend              =  t1_decoder->blend;
+      /* ps_decoder->t1_parse_callback  =  t1_decoder->parse_callback; */
+
+      ps_decoder->num_locals         =  t1_decoder->num_subrs;
+      ps_decoder->locals             =  t1_decoder->subrs;
+      ps_decoder->locals_len         =  t1_decoder->subrs_len;
+      ps_decoder->locals_hash        =  t1_decoder->subrs_hash;
+
+      ps_decoder->buildchar          =  t1_decoder->buildchar;
+      ps_decoder->len_buildchar      =  t1_decoder->len_buildchar;
+
+      ps_decoder->lenIV              =  t1_decoder->lenIV;
+    }
+    else
+    {
+      CFF_Decoder*  cff_decoder = (CFF_Decoder*)decoder;
+
+      ps_builder_init( &cff_decoder->builder,
+                       is_t1,
+                       &ps_decoder->builder );
+
+      ps_decoder->cff                 =  cff_decoder->cff;
+      ps_decoder->current_subfont     =  cff_decoder->current_subfont;
+
+      ps_decoder->num_globals         =  cff_decoder->num_globals;
+      ps_decoder->globals             =  cff_decoder->globals;
+      ps_decoder->globals_bias        =  cff_decoder->globals_bias;
+      ps_decoder->num_locals          =  cff_decoder->num_locals;
+      ps_decoder->locals              =  cff_decoder->locals;
+      ps_decoder->locals_bias         =  cff_decoder->locals_bias;
+
+      ps_decoder->glyph_width         =  cff_decoder->glyph_width;
+      ps_decoder->nominal_width       =  cff_decoder->nominal_width;
+      ps_decoder->width_only          =  cff_decoder->width_only;
+
+      ps_decoder->hint_mode           =  cff_decoder->hint_mode;
+
+      ps_decoder->get_glyph_callback  =  cff_decoder->get_glyph_callback;
+      ps_decoder->free_glyph_callback =  cff_decoder->free_glyph_callback;
+    }
   }
+
diff --git a/src/psaux/psdecode.h b/src/psaux/psdecode.h
index 2a53065..dd7e6f2 100644
--- a/src/psaux/psdecode.h
+++ b/src/psaux/psdecode.h
@@ -5,9 +5,16 @@
 #include <ft2build.h>
 #include FT_INTERNAL_POSTSCRIPT_AUX_H
 
-#include "cffdecode.h"
-#include "t1decode.h"
 
+FT_BEGIN_HEADER
 
+  FT_LOCAL( void )
+  ps_decoder_init( void*        decoder,
+                   FT_Bool      is_t1,
+                   PS_Decoder*  ps_decoder );
+
+
+FT_END_HEADER
 
 #endif
+
diff --git a/src/psaux/psobjs.c b/src/psaux/psobjs.c
index 815bca3..a4dd448 100644
--- a/src/psaux/psobjs.c
+++ b/src/psaux/psobjs.c
@@ -2052,12 +2052,63 @@
   /*    hinting :: Whether hinting should be applied.                      */
   /*                                                                       */
   FT_LOCAL_DEF( void )
-  ps_builder_init( PS_Builder*    builder,
-                   TT_Face        face,
-                   FT_Size        size,
-                   CFF_GlyphSlot  glyph,
-                   FT_Bool        hinting )
+  ps_builder_init( void*        builder,
+                   FT_Bool      is_t1,
+                   PS_Builder*  ps_builder )
   {
+    FT_ZERO( ps_builder );
+
+    if ( is_t1 )
+    {
+      T1_Builder  t1builder = (T1_Builder)builder;
+
+      ps_builder->face           = (TT_Face)t1builder->face;
+      ps_builder->glyph          = t1builder->glyph;
+      ps_builder->memory         =  t1builder->memory;
+      ps_builder->loader         =  t1builder->loader;
+      ps_builder->base           =  t1builder->base;
+      ps_builder->current        =  t1builder->current;
+
+      ps_builder->pos_x          = &t1builder->pos_x;
+      ps_builder->pos_y          = &t1builder->pos_y;
+
+      ps_builder->left_bearing   = &t1builder->left_bearing;
+      ps_builder->advance        = &t1builder->advance;
+
+      ps_builder->bbox           = &t1builder->bbox;
+      ps_builder->path_begun     =  0;
+      ps_builder->load_points    =  t1builder->load_points;
+      ps_builder->no_recurse     =  t1builder->no_recurse;
+
+      ps_builder->metrics_only   =  t1builder->metrics_only;
+    }
+    else
+    {
+      CFF_Builder*  cffbuilder = (CFF_Builder*)builder;
+
+      ps_builder->face           = cffbuilder->face;
+      ps_builder->memory         =  cffbuilder->memory;
+      ps_builder->glyph          =  cffbuilder->glyph;
+      ps_builder->loader         =  cffbuilder->loader;
+      ps_builder->base           =  cffbuilder->base;
+      ps_builder->current        =  cffbuilder->current;
+
+      ps_builder->pos_x          = &cffbuilder->pos_x;
+      ps_builder->pos_y          = &cffbuilder->pos_y;
+
+      ps_builder->left_bearing   = &cffbuilder->left_bearing;
+      ps_builder->advance        = &cffbuilder->advance;
+
+      ps_builder->bbox           = &cffbuilder->bbox;
+      ps_builder->path_begun     =  cffbuilder->path_begun;
+      ps_builder->load_points    =  cffbuilder->load_points;
+      ps_builder->no_recurse     =  cffbuilder->no_recurse;
+
+      ps_builder->metrics_only   =  cffbuilder->metrics_only;
+    }
+
+    ps_builder->is_t1            = is_t1;
+    ps_builder->funcs            = ps_builder_funcs;
   }
 
 
diff --git a/src/psaux/psobjs.h b/src/psaux/psobjs.h
index 64e85c5..1f68419 100644
--- a/src/psaux/psobjs.h
+++ b/src/psaux/psobjs.h
@@ -242,11 +242,9 @@ FT_BEGIN_HEADER
   /*************************************************************************/
 
   FT_LOCAL( void )
-  ps_builder_init( PS_Builder*    builder,
-                   TT_Face        face,
-                   FT_Size        size,
-                   CFF_GlyphSlot  glyph,
-                   FT_Bool        hinting );
+  ps_builder_init( void*        builder,
+                   FT_Bool      is_t1,
+                   PS_Builder*  ps_builder );
 
   FT_LOCAL( void )
   ps_builder_done( PS_Builder*  builder );