Commit 5eb0fd5e97c2af7aaeeb129571b2b820c5079604

Werner Lemberg 2017-03-12T20:46:56

[truetype] Store and use design coordinates also. * include/freetype/internal/services/svmm.h (FT_Get_Var_Blend_Func): Add `normalizedcoords' argument. * src/truetype/ttgxvar.h (GX_BlendRec): Add `coords' field to store the design coordinates of the current instance. Updated. * src/truetype/ttgxvar.c (TT_Set_MM_Blend): Move functionality to... (tt_set_mm_blend): ... New function. Convert data in `normalizedcoords' array to `coords' array on demand. (TT_Set_Var_Design): Store argument data in `coords' array. (TT_Get_Var_Design): Get data from `coords' array. (tt_get_var_blend): Updated. (tt_done_blend): Updated. * src/cff/cffload.c, src/cff/cffload.h (cff_get_var_blend): Updated. * src/cff/cf2ft.c (cf2_getNormalizedVector): Updated. * src/cff/cffobjs.c (cff_face_init): Updated.

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
diff --git a/ChangeLog b/ChangeLog
index 43ef3fb..6fb4fc9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,31 @@
 2017-03-12  Werner Lemberg  <wl@gnu.org>
 
+	[truetype] Store and use design coordinates also.
+
+	* include/freetype/internal/services/svmm.h (FT_Get_Var_Blend_Func):
+	Add `normalizedcoords' argument.
+
+	* src/truetype/ttgxvar.h (GX_BlendRec): Add `coords' field to store
+	the design coordinates of the current instance.
+	Updated.
+
+	* src/truetype/ttgxvar.c (TT_Set_MM_Blend): Move functionality to...
+	(tt_set_mm_blend): ... New function.
+	Convert data in `normalizedcoords' array to `coords' array on
+	demand.
+	(TT_Set_Var_Design): Store argument data in `coords' array.
+	(TT_Get_Var_Design): Get data from `coords' array.
+	(tt_get_var_blend): Updated.
+	(tt_done_blend): Updated.
+
+	* src/cff/cffload.c, src/cff/cffload.h (cff_get_var_blend): Updated.
+
+	* src/cff/cf2ft.c (cf2_getNormalizedVector): Updated.
+
+	* src/cff/cffobjs.c (cff_face_init): Updated.
+
+2017-03-12  Werner Lemberg  <wl@gnu.org>
+
 	src/truetype/ttgxvar.[ch]: s/avar_checked/avar_loaded/.
 
 2017-03-08  Werner Lemberg  <wl@gnu.org>
diff --git a/include/freetype/internal/services/svmm.h b/include/freetype/internal/services/svmm.h
index 97af1ac..1d51cd9 100644
--- a/include/freetype/internal/services/svmm.h
+++ b/include/freetype/internal/services/svmm.h
@@ -72,6 +72,7 @@ FT_BEGIN_HEADER
   (*FT_Get_Var_Blend_Func)( FT_Face      face,
                             FT_UInt     *num_coords,
                             FT_Fixed*   *coords,
+                            FT_Fixed*   *normalizedcoords,
                             FT_MM_Var*  *mm_var );
 
   typedef void
diff --git a/src/cff/cf2ft.c b/src/cff/cf2ft.c
index 5cca92a..eb8472f 100644
--- a/src/cff/cf2ft.c
+++ b/src/cff/cf2ft.c
@@ -457,7 +457,7 @@
     FT_ASSERT( decoder && decoder->builder.face );
     FT_ASSERT( vec && len );
 
-    return cff_get_var_blend( decoder->builder.face, len, vec, NULL );
+    return cff_get_var_blend( decoder->builder.face, len, NULL, vec, NULL );
   }
 #endif
 
diff --git a/src/cff/cffload.c b/src/cff/cffload.c
index 47626a7..d356ab3 100644
--- a/src/cff/cffload.c
+++ b/src/cff/cffload.c
@@ -1572,12 +1572,17 @@
   cff_get_var_blend( CFF_Face     face,
                      FT_UInt     *num_coords,
                      FT_Fixed*   *coords,
+                     FT_Fixed*   *normalizedcoords,
                      FT_MM_Var*  *mm_var )
   {
     FT_Service_MultiMasters  mm = (FT_Service_MultiMasters)face->mm;
 
 
-    return mm->get_var_blend( FT_FACE( face ), num_coords, coords, mm_var );
+    return mm->get_var_blend( FT_FACE( face ),
+                              num_coords,
+                              coords,
+                              normalizedcoords,
+                              mm_var );
   }
 
 
diff --git a/src/cff/cffload.h b/src/cff/cffload.h
index 1709a66..c745e81 100644
--- a/src/cff/cffload.h
+++ b/src/cff/cffload.h
@@ -112,6 +112,7 @@ FT_BEGIN_HEADER
   cff_get_var_blend( CFF_Face     face,
                      FT_UInt     *num_coords,
                      FT_Fixed*   *coords,
+                     FT_Fixed*   *normalizedcoords,
                      FT_MM_Var*  *mm_var );
 
   FT_LOCAL( void )
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index bcda2a9..8322761 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -703,7 +703,7 @@
           if ( error )
             goto Exit;
 
-          mm->get_var_blend( cffface, NULL, NULL, &mm_var );
+          mm->get_var_blend( cffface, NULL, NULL, NULL, &mm_var );
 
           if ( mm_var->namedstyle )
           {
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 641d07c..5abcd02 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -2259,35 +2259,11 @@
   }
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    TT_Set_MM_Blend                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Set the blend (normalized) coordinates for this instance of the    */
-  /*    font.  Check that the `gvar' table is reasonable and does some     */
-  /*    initial preparation.                                               */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    face       :: The font.                                            */
-  /*                  Initialize the blend structure with `gvar' data.     */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    num_coords :: The number of available coordinates.  If it is       */
-  /*                  larger than the number of axes, ignore the excess    */
-  /*                  values.  If it is smaller than the number of axes,   */
-  /*                  use the default value (0) for the remaining axes.    */
-  /*                                                                       */
-  /*    coords     :: An array of `num_coords', each between [-1,1].       */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  FT_LOCAL_DEF( FT_Error )
-  TT_Set_MM_Blend( TT_Face    face,
+  static FT_Error
+  tt_set_mm_blend( TT_Face    face,
                    FT_UInt    num_coords,
-                   FT_Fixed*  coords )
+                   FT_Fixed*  coords,
+                   FT_Bool    set_design_coords )
   {
     FT_Error    error = FT_Err_Ok;
     GX_Blend    blend;
@@ -2318,7 +2294,8 @@
 
     if ( num_coords > mmvar->num_axis )
     {
-      FT_TRACE2(( "TT_Set_MM_Blend: only using first %d of %d coordinates\n",
+      FT_TRACE2(( "TT_Set_MM_Blend:"
+                  " only using first %d of %d coordinates\n",
                   mmvar->num_axis, num_coords ));
       num_coords = mmvar->num_axis;
     }
@@ -2347,6 +2324,12 @@
       if ( FT_SET_ERROR( ft_var_load_gvar( face ) ) )
         goto Exit;
 
+    if ( !blend->coords )
+    {
+      if ( FT_NEW_ARRAY( blend->coords, mmvar->num_axis ) )
+        goto Exit;
+    }
+
     if ( !blend->normalizedcoords )
     {
       if ( FT_NEW_ARRAY( blend->normalizedcoords, mmvar->num_axis ) )
@@ -2391,6 +2374,12 @@
                  coords,
                  num_coords * sizeof ( FT_Fixed ) );
 
+    if ( set_design_coords )
+      ft_var_to_design( face,
+                        num_coords,
+                        blend->normalizedcoords,
+                        blend->coords );
+
     face->doblend = TRUE;
 
     if ( face->cvt )
@@ -2452,6 +2441,40 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    TT_Set_MM_Blend                                                    */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Set the blend (normalized) coordinates for this instance of the    */
+  /*    font.  Check that the `gvar' table is reasonable and does some     */
+  /*    initial preparation.                                               */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: The font.                                            */
+  /*                  Initialize the blend structure with `gvar' data.     */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    num_coords :: The number of available coordinates.  If it is       */
+  /*                  larger than the number of axes, ignore the excess    */
+  /*                  values.  If it is smaller than the number of axes,   */
+  /*                  use the default value (0) for the remaining axes.    */
+  /*                                                                       */
+  /*    coords     :: An array of `num_coords', each between [-1,1].       */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_LOCAL_DEF( FT_Error )
+  TT_Set_MM_Blend( TT_Face    face,
+                   FT_UInt    num_coords,
+                   FT_Fixed*  coords )
+  {
+    return tt_set_mm_blend( face, num_coords, coords, 1 );
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    TT_Get_MM_Blend                                                    */
   /*                                                                       */
   /* <Description>                                                         */
@@ -2493,7 +2516,8 @@
     nc = num_coords;
     if ( num_coords > blend->num_axis )
     {
-      FT_TRACE2(( "TT_Get_MM_Blend: only using first %d of %d coordinates\n",
+      FT_TRACE2(( "TT_Get_MM_Blend:"
+                  " only using first %d of %d coordinates\n",
                   blend->num_axis, num_coords ));
       nc = blend->num_axis;
     }
@@ -2546,11 +2570,16 @@
                      FT_UInt    num_coords,
                      FT_Fixed*  coords )
   {
-    FT_Error   error  = FT_Err_Ok;
-    FT_Memory  memory = face->root.memory;
+    FT_Error    error  = FT_Err_Ok;
+    GX_Blend    blend;
+    FT_MM_Var*  mmvar;
+    FT_UInt     i;
+    FT_Memory   memory = face->root.memory;
+
+    FT_Var_Axis*  a;
+    FT_Fixed*     c;
 
     FT_Fixed*  normalized = NULL;
-    FT_UInt    num_axes;
 
 
     if ( !face->blend )
@@ -2559,9 +2588,33 @@
         goto Exit;
     }
 
-    num_axes = face->blend->mmvar->num_axis;
+    blend = face->blend;
+    mmvar = blend->mmvar;
+
+    if ( num_coords > mmvar->num_axis )
+    {
+      FT_TRACE2(( "TT_Set_Var_Design:"
+                  " only using first %d of %d coordinates\n",
+                  mmvar->num_axis, num_coords ));
+      num_coords = mmvar->num_axis;
+    }
+
+    if ( !blend->coords )
+    {
+      if ( FT_NEW_ARRAY( blend->coords, mmvar->num_axis ) )
+        goto Exit;
+    }
+
+    FT_MEM_COPY( blend->coords,
+                 coords,
+                 num_coords * sizeof ( FT_Fixed ) );
+
+    a = mmvar->axis + num_coords;
+    c = coords + num_coords;
+    for ( i = num_coords; i < mmvar->num_axis; i++, a++, c++ )
+      *c = a->def;
 
-    if ( FT_NEW_ARRAY( normalized, num_axes ) )
+    if ( FT_NEW_ARRAY( normalized, mmvar->num_axis ) )
       goto Exit;
 
     if ( !face->blend->avar_loaded )
@@ -2569,7 +2622,7 @@
 
     ft_var_to_normalized( face, num_coords, coords, normalized );
 
-    error = TT_Set_MM_Blend( face, num_axes, normalized );
+    error = tt_set_mm_blend( face, mmvar->num_axis, normalized, 0 );
 
   Exit:
     FT_FREE( normalized );
@@ -2605,6 +2658,8 @@
                      FT_Fixed*  coords )
   {
     FT_Error  error = FT_Err_Ok;
+    GX_Blend  blend;
+    FT_UInt   i, nc;
 
 
     if ( !face->blend )
@@ -2613,13 +2668,30 @@
         return error;
     }
 
-    if ( !face->blend->avar_loaded )
-      ft_var_load_avar( face );
+    blend = face->blend;
 
-    ft_var_to_design( face,
-                      num_coords,
-                      face->blend->normalizedcoords,
-                      coords );
+    nc = num_coords;
+    if ( num_coords > blend->num_axis )
+    {
+      FT_TRACE2(( "TT_Get_Var_Design:"
+                  " only using first %d of %d coordinates\n",
+                  blend->num_axis, num_coords ));
+      nc = blend->num_axis;
+    }
+
+    if ( face->doblend )
+    {
+      for ( i = 0; i < nc; i++ )
+        coords[i] = blend->coords[i];
+    }
+    else
+    {
+      for ( i = 0; i < nc; i++ )
+        coords[i] = 0;
+    }
+
+    for ( ; i < num_coords; i++ )
+      coords[i] = 0;
 
     return FT_Err_Ok;
   }
@@ -3506,16 +3578,19 @@
   tt_get_var_blend( TT_Face      face,
                     FT_UInt     *num_coords,
                     FT_Fixed*   *coords,
+                    FT_Fixed*   *normalizedcoords,
                     FT_MM_Var*  *mm_var )
   {
     if ( face->blend )
     {
       if ( num_coords )
-        *num_coords = face->blend->num_axis;
+        *num_coords       = face->blend->num_axis;
       if ( coords )
-        *coords     = face->blend->normalizedcoords;
+        *coords           = face->blend->coords;
+      if ( normalizedcoords )
+        *normalizedcoords = face->blend->normalizedcoords;
       if ( mm_var )
-        *mm_var     = face->blend->mmvar;
+        *mm_var           = face->blend->mmvar;
     }
     else
     {
@@ -3583,6 +3658,7 @@
       /* blend->num_axis might not be set up yet */
       num_axes = blend->mmvar->num_axis;
 
+      FT_FREE( blend->coords );
       FT_FREE( blend->normalizedcoords );
       FT_FREE( blend->normalized_stylecoords );
       FT_FREE( blend->mmvar );
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index 804678c..7e81719 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -220,6 +220,11 @@ FT_BEGIN_HEADER
   /*    num_axis ::                                                        */
   /*      The number of axes along which interpolation may happen.         */
   /*                                                                       */
+  /*    coords ::                                                          */
+  /*      An array of design coordinates (in user space) indicating the    */
+  /*      contribution along each axis to the final interpolated font.     */
+  /*      `normalizedcoords' holds the same values.                        */
+  /*                                                                       */
   /*    normalizedcoords ::                                                */
   /*      An array of normalized values (between [-1,1]) indicating the    */
   /*      contribution along each axis to the final interpolated font.     */
@@ -294,6 +299,7 @@ FT_BEGIN_HEADER
   typedef struct  GX_BlendRec_
   {
     FT_UInt         num_axis;
+    FT_Fixed*       coords;
     FT_Fixed*       normalizedcoords;
 
     FT_MM_Var*      mmvar;
@@ -423,6 +429,7 @@ FT_BEGIN_HEADER
   tt_get_var_blend( TT_Face      face,
                     FT_UInt     *num_coords,
                     FT_Fixed*   *coords,
+                    FT_Fixed*   *normalizedcoords,
                     FT_MM_Var*  *mm_var );
 
   FT_LOCAL( void )