Commit faa3c88254fa13e780b813f69c05fa20d90af9eb

Werner Lemberg 2017-02-06T13:13:02

[truetype] Implement `VVAR' table support. * src/truetype/ttgxvar.h (GX_HVarTable): Renamed to... (GX_HVVarTable): ...This. (GX_Blend): Add fields for `VVAR' table handling. Other minor updates. * src/truetype/ttgxvar.c (ft_var_load_hvar): Renamed to... (ft_var_load_hvvar): ...This. Handle VVAR loading also (controlled by an additional parameter). (tt_hadvance_adjust): Renamed to... (tt_hvadvance_adjust): ...This. Handle application of advance height also (controlled by an additional parameter). (tt_hadvance_adjust, tt_vadvance_adjust): Wrappers for `tt_hvadvance_adjust'. * src/truetype/ttdriver.c (tt_service_metrics_variations): 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
diff --git a/ChangeLog b/ChangeLog
index a102c61..455b5cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2017-02-06  Werner Lemberg  <wl@gnu.org>
+
+	[truetype] Implement `VVAR' table support.
+
+	* src/truetype/ttgxvar.h (GX_HVarTable): Renamed to...
+	(GX_HVVarTable): ...This.
+	(GX_Blend): Add fields for `VVAR' table handling.
+	Other minor updates.
+
+	* src/truetype/ttgxvar.c (ft_var_load_hvar): Renamed to...
+	(ft_var_load_hvvar): ...This.
+	Handle VVAR loading also (controlled by an additional parameter).
+	(tt_hadvance_adjust): Renamed to...
+	(tt_hvadvance_adjust): ...This.
+	Handle application of advance height also (controlled by an
+	additional parameter).
+	(tt_hadvance_adjust, tt_vadvance_adjust): Wrappers for
+	`tt_hvadvance_adjust'.
+
+	* src/truetype/ttdriver.c (tt_service_metrics_variations): Updated.
+
 2017-02-05  Werner Lemberg  <wl@gnu.org>
 
 	[autofit] Use better blue zone characters for lowercase latin.
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index 19f7858..6f9b746 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -502,7 +502,7 @@
     (FT_LSB_Adjust_Func)     NULL,                   /* lsb_adjust      */
     (FT_RSB_Adjust_Func)     NULL,                   /* rsb_adjust      */
 
-    (FT_VAdvance_Adjust_Func)NULL,                   /* vadvance_adjust */
+    (FT_VAdvance_Adjust_Func)tt_vadvance_adjust,     /* vadvance_adjust */
     (FT_TSB_Adjust_Func)     NULL,                   /* tsb_adjust      */
     (FT_BSB_Adjust_Func)     NULL,                   /* bsb_adjust      */
     (FT_VOrg_Adjust_Func)    NULL,                   /* vorg_adjust     */
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 0e34a2a..0168120 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -701,12 +701,16 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    ft_var_load_hvar                                                   */
+  /*    ft_var_load_hvvar                                                  */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Parse the `HVAR' table and set `blend->hvar_loaded' to TRUE.       */
+  /*    If `vertical' is zero, parse the `HVAR' table and set              */
+  /*    `blend->hvar_loaded' to TRUE.  On success, `blend->hvar_checked'   */
+  /*    is set to TRUE.                                                    */
   /*                                                                       */
-  /*    On success, `blend->hvar_checked' is set to TRUE.                  */
+  /*    If `vertical' is not zero, parse the `VVAR' table and set          */
+  /*    `blend->vvar_loaded' to TRUE.  On success, `blend->vvar_checked'   */
+  /*    is set to TRUE.                                                    */
   /*                                                                       */
   /*    Some memory may remain allocated on error; it is always freed in   */
   /*    `tt_done_blend', however.                                          */
@@ -718,13 +722,16 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   static FT_Error
-  ft_var_load_hvar( TT_Face  face )
+  ft_var_load_hvvar( TT_Face  face,
+                     FT_Bool  vertical )
   {
     FT_Stream  stream = FT_FACE_STREAM( face );
     FT_Memory  memory = stream->memory;
 
     GX_Blend  blend = face->blend;
 
+    GX_HVVarTable  table;
+
     FT_Error   error;
     FT_UShort  majorVersion;
     FT_ULong   table_len;
@@ -733,11 +740,23 @@
     FT_ULong   widthMap_offset;
 
 
-    blend->hvar_loaded = TRUE;
+    if ( vertical )
+    {
+      blend->vvar_loaded = TRUE;
+
+      FT_TRACE2(( "VVAR " ));
+
+      error = face->goto_table( face, TTAG_VVAR, stream, &table_len );
+    }
+    else
+    {
+      blend->hvar_loaded = TRUE;
+
+      FT_TRACE2(( "HVAR " ));
 
-    FT_TRACE2(( "HVAR " ));
+      error = face->goto_table( face, TTAG_HVAR, stream, &table_len );
+    }
 
-    error = face->goto_table( face, TTAG_HVAR, stream, &table_len );
     if ( error )
     {
       FT_TRACE2(( "is missing\n" ));
@@ -762,13 +781,23 @@
          FT_READ_ULONG( widthMap_offset ) )
       goto Exit;
 
-    if ( FT_NEW( blend->hvar_table ) )
-      goto Exit;
+    if ( vertical )
+    {
+      if ( FT_NEW( blend->vvar_table ) )
+        goto Exit;
+      table = blend->vvar_table;
+    }
+    else
+    {
+      if ( FT_NEW( blend->hvar_table ) )
+        goto Exit;
+      table = blend->hvar_table;
+    }
 
     error = ft_var_load_item_variation_store(
               face,
               table_offset + store_offset,
-              &blend->hvar_table->itemStore );
+              &table->itemStore );
     if ( error )
       goto Exit;
 
@@ -777,8 +806,8 @@
       error = ft_var_load_delta_set_index_mapping(
                 face,
                 table_offset + widthMap_offset,
-                &blend->hvar_table->widthMap,
-                &blend->hvar_table->itemStore );
+                &table->widthMap,
+                &table->itemStore );
       if ( error )
         goto Exit;
     }
@@ -789,13 +818,26 @@
   Exit:
     if ( !error )
     {
-      blend->hvar_checked = TRUE;
+      if ( vertical )
+      {
+        blend->vvar_checked = TRUE;
+
+        /* FreeType doesn't provide functions to quickly retrieve    */
+        /* TSB, BSB, or VORG values; we thus don't have to implement */
+        /* support for those three item variation stores.            */
+
+        face->variation_support |= TT_FACE_FLAG_VAR_VADVANCE;
+      }
+      else
+      {
+        blend->hvar_checked = TRUE;
 
-      /* FreeType doesn't provide functions to quickly retrieve */
-      /* LSB or RSB values; we thus don't have to implement     */
-      /* support for those two item variation stores.           */
+        /* FreeType doesn't provide functions to quickly retrieve */
+        /* LSB or RSB values; we thus don't have to implement     */
+        /* support for those two item variation stores.           */
 
-      face->variation_support |= TT_FACE_FLAG_VAR_HADVANCE;
+        face->variation_support |= TT_FACE_FLAG_VAR_HADVANCE;
+      }
     }
 
     return error;
@@ -894,50 +936,77 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    tt_hadvance_adjust                                                 */
+  /*    tt_hvadvance_adjust                                                */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Apply HVAR advance width adjustment of a given glyph.              */
+  /*    Apply `HVAR' advance width or `VVAR' advance height adjustment of  */
+  /*    a given glyph.                                                     */
   /*                                                                       */
   /* <Input>                                                               */
-  /*    gindex :: The glyph index.                                         */
+  /*    gindex   :: The glyph index.                                       */
+  /*                                                                       */
+  /*    vertical :: If set, handle `VVAR' table.                           */
   /*                                                                       */
   /* <InOut>                                                               */
-  /*    face   :: The font face.                                           */
+  /*    face     :: The font face.                                         */
   /*                                                                       */
-  /*    adelta :: Points to width value that gets modified.                */
+  /*    adelta   :: Points to width or height value that gets modified.    */
   /*                                                                       */
-  FT_LOCAL_DEF( FT_Error )
-  tt_hadvance_adjust( TT_Face  face,
-                      FT_UInt  gindex,
-                      FT_Int  *avalue )
+  static FT_Error
+  tt_hvadvance_adjust( TT_Face  face,
+                       FT_UInt  gindex,
+                       FT_Int  *avalue,
+                       FT_Bool  vertical )
   {
     FT_Error  error = FT_Err_Ok;
     FT_UInt   innerIndex, outerIndex;
     FT_Int    delta;
 
+    GX_HVVarTable  table;
+
 
     if ( !face->doblend || !face->blend )
       goto Exit;
 
-    if ( !face->blend->hvar_loaded )
+    if ( vertical )
     {
-      /* initialize hvar table */
-      face->blend->hvar_error = ft_var_load_hvar( face );
-    }
+      if ( !face->blend->vvar_loaded )
+      {
+        /* initialize vvar table */
+        face->blend->vvar_error = ft_var_load_hvvar( face, 1 );
+      }
+
+      if ( !face->blend->vvar_checked )
+      {
+        error = face->blend->vvar_error;
+        goto Exit;
+      }
 
-    if ( !face->blend->hvar_checked )
+      table = face->blend->vvar_table;
+    }
+    else
     {
-      error = face->blend->hvar_error;
-      goto Exit;
+      if ( !face->blend->hvar_loaded )
+      {
+        /* initialize hvar table */
+        face->blend->hvar_error = ft_var_load_hvvar( face, 0 );
+      }
+
+      if ( !face->blend->hvar_checked )
+      {
+        error = face->blend->hvar_error;
+        goto Exit;
+      }
+
+      table = face->blend->hvar_table;
     }
 
-    /* advance width adjustments are always present in an `HVAR' table, */
-    /* no need to test for this capability                              */
+    /* advance width or height adjustments are always present in an */
+    /* `HVAR' or `VVAR' table; no need to test for this capability  */
 
-    if ( face->blend->hvar_table->widthMap.innerIndex )
+    if ( table->widthMap.innerIndex )
     {
-      if ( gindex >= face->blend->hvar_table->widthMap.mapCount )
+      if ( gindex >= table->widthMap.mapCount )
       {
         FT_TRACE2(( "gindex %d out of range\n", gindex ));
         error = FT_THROW( Invalid_Argument );
@@ -945,8 +1014,8 @@
       }
 
       /* trust that HVAR parser has checked indices */
-      outerIndex = face->blend->hvar_table->widthMap.outerIndex[gindex];
-      innerIndex = face->blend->hvar_table->widthMap.innerIndex[gindex];
+      outerIndex = table->widthMap.outerIndex[gindex];
+      innerIndex = table->widthMap.innerIndex[gindex];
     }
     else
     {
@@ -957,7 +1026,7 @@
       outerIndex = 0;
       innerIndex = gindex;
 
-      varData = &face->blend->hvar_table->itemStore.varData[outerIndex];
+      varData = &table->itemStore.varData[outerIndex];
       if ( gindex >= varData->itemCount )
       {
         FT_TRACE2(( "gindex %d out of range\n", gindex ));
@@ -967,13 +1036,15 @@
     }
 
     delta = ft_var_get_item_delta( face,
-                                   &face->blend->hvar_table->itemStore,
+                                   &table->itemStore,
                                    outerIndex,
                                    innerIndex );
 
-    FT_TRACE5(( "horizontal width %d adjusted by %d units (HVAR)\n",
+    FT_TRACE5(( "%s value %d adjusted by %d units (%s)\n",
+                vertical ? "vertical height" : "horizontal width",
                 *avalue,
-                delta ));
+                delta,
+                vertical ? "VVAR" : "HVAR" ));
 
     *avalue += delta;
 
@@ -982,6 +1053,24 @@
   }
 
 
+  FT_LOCAL_DEF( FT_Error )
+  tt_hadvance_adjust( TT_Face  face,
+                      FT_UInt  gindex,
+                      FT_Int  *avalue )
+  {
+    return tt_hvadvance_adjust( face, gindex, avalue, 0 );
+  }
+
+
+  FT_LOCAL_DEF( FT_Error )
+  tt_vadvance_adjust( TT_Face  face,
+                      FT_UInt  gindex,
+                      FT_Int  *avalue )
+  {
+    return tt_hvadvance_adjust( face, gindex, avalue, 1 );
+  }
+
+
 #define GX_VALUE_SIZE  8
 
   /* all values are FT_Short or FT_UShort entities; */
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index 1d908cd..e431983 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -115,21 +115,26 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*                                                                       */
   /* <Struct>                                                              */
-  /*    GX_HVarTableRec                                                    */
+  /*    GX_HVVarTableRec                                                   */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Data from the `HVAR' table.                                        */
+  /*    Data from either the `HVAR' or `VVAR' table.                       */
   /*                                                                       */
-  typedef struct  GX_HVarTableRec_
+  typedef struct  GX_HVVarTableRec_
   {
     GX_ItemVarStoreRec    itemStore;        /* Item Variation Store  */
     GX_DeltaSetIdxMapRec  widthMap;         /* Advance Width Mapping */
+
 #if 0
     GX_DeltaSetIdxMapRec  lsbMap;           /* not implemented */
     GX_DeltaSetIdxMapRec  rsbMap;           /* not implemented */
+
+    GX_DeltaSetIdxMapRec  tsbMap;           /* not implemented */
+    GX_DeltaSetIdxMapRec  bsbMap;           /* not implemented */
+    GX_DeltaSetIdxMapRec  vorgMap;          /* not implemented */
 #endif
 
-  } GX_HVarTableRec, *GX_HVarTable;
+  } GX_HVVarTableRec, *GX_HVVarTable;
 
 
 #define MVAR_TAG_GASP_0  FT_MAKE_TAG( 'g', 's', 'p', '0' )
@@ -233,7 +238,12 @@ FT_BEGIN_HEADER
     FT_Bool         hvar_loaded;
     FT_Bool         hvar_checked;
     FT_Error        hvar_error;
-    GX_HVarTable    hvar_table;
+    GX_HVVarTable   hvar_table;
+
+    FT_Bool         vvar_loaded;
+    FT_Bool         vvar_checked;
+    FT_Error        vvar_error;
+    GX_HVVarTable   vvar_table;
 
     GX_MVarTable    mvar_table;
 
@@ -331,6 +341,11 @@ FT_BEGIN_HEADER
                       FT_UInt  gindex,
                       FT_Int  *adelta );
 
+  FT_LOCAL( FT_Error )
+  tt_vadvance_adjust( TT_Face  face,
+                      FT_UInt  gindex,
+                      FT_Int  *adelta );
+
   FT_LOCAL( void )
   tt_apply_mvar( TT_Face  face );