w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

fvar.c
Go to the documentation of this file.
1 #include "fvar.h"
2 
3 #include "support/util.h"
4 
5 
6 // fvar instance tuple
7 // fvar instance
8 static INLINE void initFvarInstance(fvar_Instance *inst) {
9  memset(inst, 0, sizeof(*inst));
10  iVV.init(&inst->coordinates);
11 }
13  iVV.dispose(&inst->coordinates);
14 }
17 // table fvar
18 
20  sdsfree(m->name);
21  vq_deleteRegion(m->region);
22 }
23 
24 static INLINE void initFvar(table_fvar *fvar) {
25  memset(fvar, 0, sizeof(*fvar));
26  vf_iAxes.init(&fvar->axes);
27  fvar_iInstanceList.init(&fvar->instances);
28 }
29 static INLINE void disposeFvar(table_fvar *fvar) {
30  vf_iAxes.dispose(&fvar->axes);
31  fvar_iInstanceList.dispose(&fvar->instances);
32 
33  fvar_Master *current, *tmp;
34  HASH_ITER(hh, fvar->masters, current, tmp) {
35  HASH_DEL(fvar->masters, current);
37  FREE(current);
38  }
39 }
40 
42  fvar_Master *m = NULL;
43  HASH_FIND(hh, fvar->masters, region, VQ_REGION_SIZE(region->dimensions), m);
44  if (m) {
46  return m->region;
47  } else {
48  NEW_CLEAN_1(m);
49  sds sMasterID = sdsfromlonglong(1 + HASH_CNT(hh, fvar->masters));
50  m->name = sdscatsds(sdsnew("m"), sMasterID);
51  sdsfree(sMasterID);
52  m->region = region;
53  HASH_ADD_KEYPTR(hh, fvar->masters, m->region, VQ_REGION_SIZE(region->dimensions), m);
54  return m->region;
55  }
56 }
57 
58 static const fvar_Master *fvar_findMasterByRegion(const table_fvar *fvar, const vq_Region *region) {
59  fvar_Master *m = NULL;
60  HASH_FIND(hh, fvar->masters, region, VQ_REGION_SIZE(region->dimensions), m);
61  return m;
62 }
63 
66  .registerRegion = fvar_registerRegion,
67  .findMasterByRegion = fvar_findMasterByRegion};
68 
69 // Local typedefs for parsing axis record
70 #pragma pack(1)
71 struct FVARHeader {
80 };
81 
89 };
90 
95 };
96 #pragma pack()
97 
99  table_fvar *fvar = NULL;
100  FOR_TABLE(OTFCC_CHR('f','v','a','r'), table) {
102  if (table.length < sizeof(struct FVARHeader)) goto FAIL;
103 
104  struct FVARHeader *header = (struct FVARHeader *)data;
105  if (be16(header->majorVersion) != 1) goto FAIL;
106  if (be16(header->minorVersion) != 0) goto FAIL;
107  if (be16(header->axesArrayOffset) == 0) goto FAIL;
108  if (be16(header->axisCount) == 0) goto FAIL;
109  if (be16(header->axisSize) != sizeof(struct VariationAxisRecord)) goto FAIL;
110  uint16_t nAxes = be16(header->axisCount);
111  uint16_t instanceSizeWithoutPSNID = 4 + nAxes * sizeof(f16dot16);
112  uint16_t instanceSizeWithPSNID = 2 + instanceSizeWithoutPSNID;
113  if (be16(header->instanceSize) != instanceSizeWithoutPSNID &&
114  be16(header->instanceSize) != instanceSizeWithPSNID)
115  goto FAIL;
116  if (table.length < be16(header->axesArrayOffset) +
117  sizeof(struct VariationAxisRecord) * nAxes +
118  be16(header->instanceSize) * be16(header->instanceCount))
119  goto FAIL;
120 
121  fvar = table_iFvar.create();
122 
123  // parse axes
124  struct VariationAxisRecord *axisRecord =
125  (struct VariationAxisRecord *)(data + be16(header->axesArrayOffset));
126  for (uint16_t j = 0; j < nAxes; j++) {
127  vf_Axis axis = {.tag = be32(axisRecord->axisTag),
128  .minValue = otfcc_from_fixed(be32(axisRecord->minValue)),
129  .defaultValue = otfcc_from_fixed(be32(axisRecord->defaultValue)),
130  .maxValue = otfcc_from_fixed(be32(axisRecord->maxValue)),
131  .flags = be16(axisRecord->flags),
132  .axisNameID = be16(axisRecord->axisNameID)};
133  vf_iAxes.push(&fvar->axes, axis);
134  axisRecord++;
135  }
136 
137  // parse instances
138  uint16_t nInstances = be16(header->instanceCount);
139  bool hasPostscriptNameID = be16(header->instanceSize) == instanceSizeWithPSNID;
140  struct InstanceRecord *instance = (struct InstanceRecord *)axisRecord;
141  for (uint16_t j = 0; j < nInstances; j++) {
142  fvar_Instance inst;
143  fvar_iInstance.init(&inst);
144  inst.subfamilyNameID = be16(instance->subfamilyNameID);
145  inst.flags = be16(instance->flags);
146  for (uint16_t k = 0; k < nAxes; k++) {
147  iVV.push(&inst.coordinates, otfcc_from_fixed(be32(instance->coordinates[k])));
148  }
149  iVV.shrinkToFit(&inst.coordinates);
150  if (hasPostscriptNameID) {
151  inst.postScriptNameID =
152  be16(*(uint16_t *)(((font_file_pointer)instance) + instanceSizeWithoutPSNID));
153  }
154  fvar_iInstanceList.push(&fvar->instances, inst);
156  be16(header->instanceSize));
157  }
158  vf_iAxes.shrinkToFit(&fvar->axes);
159  fvar_iInstanceList.shrinkToFit(&fvar->instances);
160 
161  return fvar;
162 
163  FAIL:
164  logWarning("table 'fvar' corrupted.\n");
165  table_iFvar.free(fvar);
166  fvar = NULL;
167  }
168  return NULL;
169 }
170 
172  if (!table) return;
173  loggedStep("fvar") {
175  // dump axes
176  json_value *_axes = json_object_new(table->axes.length);
177  foreach (vf_Axis *axis, table->axes) {
178  json_value *_axis = json_object_new(5);
179  json_object_push(_axis, "minValue", json_double_new(axis->minValue));
180  json_object_push(_axis, "defaultValue", json_double_new(axis->defaultValue));
181  json_object_push(_axis, "maxValue", json_double_new(axis->maxValue));
182  json_object_push(_axis, "flags", json_integer_new(axis->flags));
183  json_object_push(_axis, "axisNameID", json_integer_new(axis->axisNameID));
184  json_object_push_tag(_axes, axis->tag, _axis);
185  }
186  json_object_push(t, "axes", _axes);
187  // dump instances
188  json_value *_instances = json_array_new(table->instances.length);
189  foreach (fvar_Instance *instance, table->instances) {
190  json_value *_instance = json_object_new(4);
191  json_object_push(_instance, "subfamilyNameID",
192  json_integer_new(instance->subfamilyNameID));
193  if (instance->postScriptNameID) {
194  json_object_push(_instance, "postScriptNameID",
195  json_integer_new(instance->postScriptNameID));
196  }
197  json_object_push(_instance, "flags", json_integer_new(instance->flags));
198  json_object_push(_instance, "coordinates", json_new_VVp(&instance->coordinates, table));
199  json_array_push(_instances, _instance);
200  }
201  json_object_push(t, "instances", _instances);
202  // dump masters
203  json_value *_masters = json_object_new(HASH_COUNT(table->masters));
204  fvar_Master *current, *tmp;
205  HASH_ITER(hh, table->masters, current, tmp) {
206  json_object_push(_masters, current->name,
208  }
209  json_object_push(t, "masters", _masters);
210  json_object_push(root, "fvar", t);
211  }
212 }
213 
214 // JSON conversion functions
215 // dump
216 
217 static json_value *json_new_VQSegment(const vq_Segment *s, const table_fvar *fvar) {
218  switch (s->type) {
219  case VQ_STILL:;
220  return json_new_position(s->val.still);
221  case VQ_DELTA:;
223  json_object_push(d, "delta", json_new_position(s->val.delta.quantity));
224  if (!s->val.delta.touched) {
225  json_object_push(d, "implicit", json_boolean_new(!s->val.delta.touched));
226  }
227  json_object_push(d, "on", json_new_VQRegion(s->val.delta.region, fvar));
228  return d;
229  default:;
230  return json_integer_new(0);
231  }
232 }
233 json_value *json_new_VQ(const VQ z, const table_fvar *fvar) {
234 
235  if (!z.shift.length) {
236  return preserialize(json_new_position(iVQ.getStill(z)));
237  } else {
238  json_value *a = json_array_new(z.shift.length + 1);
240  for (size_t j = 0; j < z.shift.length; j++) {
241  json_array_push(a, json_new_VQSegment(&z.shift.items[j], fvar));
242  }
243  return preserialize(a);
244  }
245 }
246 
247 json_value *json_new_VV(const VV x, const table_fvar *fvar) {
248  const vf_Axes *axes = &fvar->axes;
249  if (axes && axes->length == x.length) {
250  json_value *_coord = json_object_new(axes->length);
251  for (size_t m = 0; m < x.length; m++) {
252  vf_Axis *axis = &axes->items[m];
253  char tag[4] = {(axis->tag & 0xff000000) >> 24, (axis->tag & 0xff0000) >> 16,
254  (axis->tag & 0xff00) >> 8, (axis->tag & 0xff)};
255  json_object_push_length(_coord, 4, tag, json_new_position(x.items[m]));
256  }
257  return preserialize(_coord);
258  } else {
259  json_value *_coord = json_array_new(x.length);
260  for (size_t m = 0; m < x.length; m++) {
261  json_array_push(_coord, json_new_position(x.items[m]));
262  }
263  return preserialize(_coord);
264  }
265 }
266 json_value *json_new_VVp(const VV *x, const table_fvar *fvar) {
267  const vf_Axes *axes = &fvar->axes;
268 
269  if (axes && axes->length == x->length) {
270  json_value *_coord = json_object_new(axes->length);
271  for (size_t m = 0; m < x->length; m++) {
272  vf_Axis *axis = &axes->items[m];
273  char tag[4] = {(axis->tag & 0xff000000) >> 24, (axis->tag & 0xff0000) >> 16,
274  (axis->tag & 0xff00) >> 8, (axis->tag & 0xff)};
275  json_object_push_length(_coord, 4, tag, json_new_position(x->items[m]));
276  }
277  return preserialize(_coord);
278 
279  } else {
280  json_value *_coord = json_array_new(x->length);
281  for (size_t m = 0; m < x->length; m++) {
282  json_array_push(_coord, json_new_position(x->items[m]));
283  }
284  return preserialize(_coord);
285  }
286 }
287 // parse
288 VQ json_vqOf(const json_value *cv, const table_fvar *fvar) {
289  return iVQ.createStill(json_numof(cv));
290 }
291 
293  if (vq_AxisSpanIsOne(s)) {
294  return json_string_new("*");
295  } else {
297  json_object_push(a, "start", json_new_position(s->start));
298  json_object_push(a, "peak", json_new_position(s->peak));
299  json_object_push(a, "end", json_new_position(s->end));
300  return a;
301  }
302 }
304  const vf_Axes *axes = &fvar->axes;
305  if (axes && axes->length == rs->dimensions) {
307  for (size_t j = 0; j < rs->dimensions; j++) {
309  }
310  return r;
311  } else {
313  for (size_t j = 0; j < rs->dimensions; j++) {
315  }
316  return r;
317  }
318 }
320  const fvar_Master *m = table_iFvar.findMasterByRegion(fvar, rs);
321  if (m && m->name) {
322  return json_string_new_length((unsigned int)sdslen(m->name), m->name);
323  } else {
324  return json_new_VQRegion_Explicit(rs, fvar);
325  }
326 }
vf_iAxes
Definition: CPAL.d:20196
fvar_iInstance
Definition: CPAL.d:20212
fvar_iInstanceList
Definition: CPAL.d:20214
static uint16_t be16(uint16_t x)
Definition: bin-io.h:163
static uint32_t be32(uint32_t x)
Definition: bin-io.h:166
#define OTFCC_CHR(a, b, c, d)
Definition: caryll-font.c:7
int z
Definition: dviconv.c:26
long hh
Definition: dvi2xx.h:579
struct rect data
Definition: dvipdfm.c:64
#define caryll_standardRefTypeMethods(T)
Definition: element-impl.h:134
caryll_standardRefTypeFn(table_fvar, initFvar, disposeFvar)
static const fvar_Master * fvar_findMasterByRegion(const table_fvar *fvar, const vq_Region *region)
Definition: fvar.c:58
static INLINE void disposeFvarInstance(fvar_Instance *inst)
Definition: fvar.c:12
caryll_standardVectorImpl(fvar_InstanceList, fvar_Instance, fvar_iInstance, fvar_iInstanceList)
static INLINE void disposeFvarMaster(fvar_Master *m)
Definition: fvar.c:19
static INLINE void initFvarInstance(fvar_Instance *inst)
Definition: fvar.c:8
caryll_ElementInterfaceOf(table_fvar)
Definition: fvar.c:65
static INLINE void disposeFvar(table_fvar *fvar)
Definition: fvar.c:29
json_value * json_new_VQRegion_Explicit(const vq_Region *rs, const table_fvar *fvar)
Definition: fvar.c:303
VQ json_vqOf(const json_value *cv, const table_fvar *fvar)
Definition: fvar.c:288
json_value * json_new_VVp(const VV *x, const table_fvar *fvar)
Definition: fvar.c:266
static INLINE void initFvar(table_fvar *fvar)
Definition: fvar.c:24
table_fvar * otfcc_readFvar(const otfcc_Packet packet, const otfcc_Options *options)
Definition: fvar.c:98
static json_value * json_new_VQSegment(const vq_Segment *s, const table_fvar *fvar)
Definition: fvar.c:217
static const vq_Region * fvar_registerRegion(table_fvar *fvar, MOVE vq_Region *region)
Definition: fvar.c:41
json_value * json_new_VQ(const VQ z, const table_fvar *fvar)
Definition: fvar.c:233
caryll_standardType(fvar_Instance, fvar_iInstance, initFvarInstance, disposeFvarInstance)
json_value * json_new_VV(const VV x, const table_fvar *fvar)
Definition: fvar.c:247
void otfcc_dumpFvar(const table_fvar *table, json_value *root, const otfcc_Options *options)
Definition: fvar.c:171
static json_value * json_new_VQAxisSpan(const vq_AxisSpan *s)
Definition: fvar.c:292
json_value * json_new_VQRegion(const vq_Region *rs, const table_fvar *fvar)
Definition: fvar.c:319
#define s
Definition: afcover.h:80
#define a(n)
Definition: gpos-common.c:148
#define d(n)
Definition: gpos-common.c:151
const unsigned char FREE
Definition: image.cpp:34
table_iFvar
Definition: fvar.h:38
json_value * json_boolean_new(int)
json_value * json_array_new(size_t length)
json_value * json_string_new_length(unsigned int length, const char *)
json_value * json_array_push(json_value *array, json_value *)
json_value * json_string_new(const char *)
json_value * json_object_push(json_value *object, const char *name, json_value *)
json_value * json_integer_new(int64_t)
json_value * json_object_new(size_t length)
json_value * json_double_new(double)
json_value * json_object_push_length(json_value *object, unsigned int name_length, const char *name, json_value *)
static double json_numof(const json_value *cv)
Definition: json-funcs.h:62
static json_value * preserialize(MOVE json_value *x)
Definition: json-funcs.h:187
static json_value * json_new_position(pos_t z)
Definition: json-funcs.h:67
static json_value * json_object_push_tag(json_value *a, uint32_t tag, json_value *b)
Definition: json-funcs.h:55
#define NULL
Definition: ftobjs.h:61
unsigned short uint16_t
Definition: stdint.h:79
unsigned int uint32_t
Definition: stdint.h:80
#define INLINE
Definition: port.h:26
static const unsigned char cv[]
Definition: nkf.c:555
#define root
Definition: ctangleboot.c:69
#define logWarning(...)
Definition: aliases.h:14
uint8_t * font_file_pointer
Definition: aliases.h:41
#define FOR_TABLE(name, table)
Definition: aliases.h:33
#define loggedStep(...)
Definition: aliases.h:6
float x
Definition: cordic.py:15
#define NEW_CLEAN_1(ptr)
Definition: otfcc-alloc.h:71
int k
Definition: otp-parser.c:70
static struct Point current
Definition: picttoppm.c:134
@ MOVE
Definition: pl-parser.h:87
int r
Definition: ppmqvga.c:68
int32_t f16dot16
Definition: primitives.h:9
double otfcc_from_fixed(const f16dot16 x)
Definition: primitives.c:14
bstring c int memset(void *s, int c, int length)
sds sdscatsds(sds s, const sds t)
void sdsfree(sds s)
sds sdsfromlonglong(long long value)
static size_t sdslen(const sds s)
Definition: sds.h:91
sds sdsnew(const char *init)
char * sds
Definition: sds.h:41
uint16_t majorVersion
Definition: fvar.c:72
uint16_t axisCount
Definition: fvar.c:76
uint16_t instanceCount
Definition: fvar.c:78
uint16_t axisSize
Definition: fvar.c:77
uint16_t reserved1
Definition: fvar.c:75
uint16_t instanceSize
Definition: fvar.c:79
uint16_t axesArrayOffset
Definition: fvar.c:74
uint16_t minorVersion
Definition: fvar.c:73
uint16_t flags
Definition: fvar.c:93
f16dot16 coordinates[]
Definition: fvar.c:94
uint16_t subfamilyNameID
Definition: fvar.c:92
Definition: vq.h:37
Definition: CPAL.d:17782
f16dot16 defaultValue
Definition: fvar.c:85
uint16_t axisNameID
Definition: fvar.c:88
uint16_t flags
Definition: fvar.c:87
uint32_t axisTag
Definition: fvar.c:83
f16dot16 maxValue
Definition: fvar.c:86
f16dot16 minValue
Definition: fvar.c:84
uint16_t subfamilyNameID
Definition: fvar.h:10
VV coordinates
Definition: fvar.h:12
uint16_t postScriptNameID
Definition: fvar.h:13
uint16_t flags
Definition: fvar.h:11
Definition: regions.h:31
Definition: dvips.h:235
fvar_Master * masters
Definition: fvar.h:30
vf_Axes axes
Definition: fvar.h:28
fvar_InstanceList instances
Definition: fvar.h:29
Definition: table.h:30
Definition: xmlparse.c:179
vf_Axis * items
Definition: CPAL.d:20195
size_t length
Definition: CPAL.d:20195
Definition: axis.h:8
pos_t defaultValue
Definition: axis.h:11
uint16_t flags
Definition: axis.h:13
uint16_t axisNameID
Definition: axis.h:14
pos_t maxValue
Definition: axis.h:12
pos_t minValue
Definition: axis.h:10
uint32_t tag
Definition: axis.h:9
vq_AxisSpan spans[]
Definition: region.h:20
shapeid_t dimensions
Definition: region.h:19
Definition: vq.h:13
pointer region
Definition: t1imager.h:37
int j
Definition: t4ht.c:1589
m
Definition: tex4ht.c:3990
bool vq_AxisSpanIsOne(const vq_AxisSpan *a)
Definition: region.c:27
#define VQ_REGION_SIZE(n)
Definition: region.h:32
void vq_deleteRegion(MOVE vq_Region *region)
Definition: region.c:11
TT_Instance instance
Definition: ttf2pfb.c:161
#define FAIL(ec)
#define HASH_ADD_KEYPTR(hh, head, keyptr, keylen_in, add)
Definition: uthash.h:417
#define HASH_DEL(head, delptr)
Definition: uthash.h:498
#define HASH_ITER(hh, head, el, tmp)
Definition: uthash.h:1131
#define HASH_CNT(hh, head)
Definition: uthash.h:1138
#define HASH_COUNT(head)
Definition: uthash.h:1137
#define HASH_FIND(hh, head, keyptr, keylen, out)
Definition: uthash.h:168
iVQ
Definition: vq.h:60
@ VQ_DELTA
Definition: vq.h:12
@ VQ_STILL
Definition: vq.h:12
iVV
Definition: vv.h:15