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)  

GDEF.c
Go to the documentation of this file.
1 #include "GDEF.h"
2 
3 #include "otl/private.h"
4 
5 
7  .init = NULL,
8  .copy = NULL,
9  .dispose = NULL,
10 };
11 caryll_standardVectorImpl(otl_CaretValueList, otl_CaretValue, otl_iCaretValue, otl_iCaretValueList);
12 
14  v->glyph = Handle.empty();
15  otl_iCaretValueList.init(&v->carets);
16 }
18  Handle.dispose(&v->glyph);
19  otl_iCaretValueList.dispose(&v->carets);
20 }
22  .init = initGdefLigCaretRec,
23  .copy = NULL,
24  .dispose = deleteGdefLigCaretRec,
25 };
26 caryll_standardVectorImpl(otl_LigCaretTable, otl_CaretValueRecord, otl_iCaretValueRecord,
27  otl_iLigCaretTable);
28 
29 static INLINE void initGDEF(table_GDEF *gdef) {
30  gdef->glyphClassDef = NULL;
31  gdef->markAttachClassDef = NULL;
32  otl_iLigCaretTable.init(&gdef->ligCarets);
33 }
34 static INLINE void disposeGDEF(table_GDEF *gdef) {
35  if (!gdef) return;
36  if (gdef->glyphClassDef) ClassDef.free(gdef->glyphClassDef);
37  if (gdef->markAttachClassDef) ClassDef.free(gdef->markAttachClassDef);
38  otl_iLigCaretTable.dispose(&gdef->ligCarets);
39 }
40 
42 
44  uint32_t offset) {
46  v.format = 0;
47  v.coordiante = 0;
48  v.pointIndex = 0xFFFF;
49  checkLength(offset + 4);
50 
51  v.format = read_16u(data + offset);
52  if (v.format == 2) { // attach to glyph point
53  v.pointIndex = read_16u(data + offset + 2);
54  } else {
55  v.coordiante = (pos_t)read_16u(data + offset + 2);
56  }
57 FAIL:
58  return v;
59 }
61  uint32_t offset) {
63  otl_iCaretValueRecord.init(&g);
64  checkLength(offset + 2);
65  shapeid_t caretCount = read_16u(data + offset);
66  checkLength(offset + 2 + caretCount * 2);
67 
68  for (glyphid_t j = 0; j < caretCount; j++) {
69  otl_iCaretValueList.push(
70  &g.carets,
71  readCaretValue(data, tableLength, offset + read_16u(data + offset + 2 + j * 2)));
72  }
73 FAIL:;
74  return g;
75 }
76 
78  table_GDEF *gdef = NULL;
79  FOR_TABLE(OTFCC_CHR('G','D','E','F'), table) {
81  uint32_t tableLength = table.length;
82  checkLength(12);
83  gdef = table_iGDEF.create();
84  uint16_t classdefOffset = read_16u(data + 4);
85  if (classdefOffset) {
86  gdef->glyphClassDef = ClassDef.read(data, tableLength, classdefOffset);
87  }
88  uint16_t ligCaretOffset = read_16u(data + 8);
89  if (ligCaretOffset) {
90  checkLength(ligCaretOffset + 4);
91  otl_Coverage *cov =
92  Coverage.read(data, tableLength, ligCaretOffset + read_16u(data + ligCaretOffset));
93  if (!cov || cov->numGlyphs != read_16u(data + ligCaretOffset + 2)) goto FAIL;
94  checkLength(ligCaretOffset + 4 + cov->numGlyphs * 2);
95  for (glyphid_t j = 0; j < cov->numGlyphs; j++) {
97  data, tableLength,
98  ligCaretOffset + read_16u(data + ligCaretOffset + 4 + j * 2));
99  v.glyph = Handle.dup(cov->glyphs[j]);
100  otl_iLigCaretTable.push(&gdef->ligCarets, v);
101  }
102  Coverage.free(cov);
103  }
104  uint16_t markAttachDefOffset = read_16u(data + 10);
105  if (markAttachDefOffset) {
106  gdef->markAttachClassDef = ClassDef.read(data, tableLength, markAttachDefOffset);
107  }
108  return gdef;
109 
110  FAIL:
111  DELETE(table_iGDEF.free, gdef);
112  }
113  return gdef;
114 }
115 
117  json_value *_carets = json_object_new(gdef->ligCarets.length);
118  for (glyphid_t j = 0; j < gdef->ligCarets.length; j++) {
119  sds name = gdef->ligCarets.items[j].glyph.name;
120  json_value *_record = json_array_new(gdef->ligCarets.items[j].carets.length);
121 
122  for (glyphid_t k = 0; k < gdef->ligCarets.items[j].carets.length; k++) {
123  json_value *_cv = json_object_new(1);
124  if (gdef->ligCarets.items[j].carets.items[k].format == 2) {
126  _cv, "atPoint",
127  json_integer_new(gdef->ligCarets.items[j].carets.items[k].pointIndex));
128  } else {
130  _cv, "at",
131  json_integer_new(gdef->ligCarets.items[j].carets.items[k].coordiante));
132  }
133  json_array_push(_record, _cv);
134  }
135  json_object_push(_carets, name, preserialize(_record));
136  }
137  return _carets;
138 }
139 
141  if (!gdef) return;
142  loggedStep("GDEF") {
143  json_value *_gdef = json_object_new(4);
144  if (gdef->glyphClassDef) {
145  json_object_push(_gdef, "glyphClassDef", ClassDef.dump(gdef->glyphClassDef));
146  }
147  if (gdef->markAttachClassDef) {
148  json_object_push(_gdef, "markAttachClassDef", ClassDef.dump(gdef->markAttachClassDef));
149  }
150  if (gdef->ligCarets.length) {
151  json_object_push(_gdef, "ligCarets", dumpGDEFLigCarets(gdef));
152  }
153  json_object_push(root, "GDEF", _gdef);
154  }
155 }
156 
157 static void ligCaretFromJson(const json_value *_carets, otl_LigCaretTable *lc) {
158  if (!_carets || _carets->type != json_object) return;
159 
160  for (glyphid_t j = 0; j < _carets->u.object.length; j++) {
161  json_value *a = _carets->u.object.values[j].value;
162  if (!a || a->type != json_array) continue;
164  otl_iCaretValueRecord.init(&v);
165  v.glyph = Handle.fromName(
166  sdsnewlen(_carets->u.object.values[j].name, _carets->u.object.values[j].name_length));
167  shapeid_t caretCount = a->u.array.length;
168  for (glyphid_t k = 0; k < caretCount; k++) {
169  otl_CaretValue caret;
170  caret.format = 1;
171  caret.coordiante = 0;
172  caret.pointIndex = 0xFFFF;
173  json_value *_caret = a->u.array.values[k];
174  if (_caret && _caret->type == json_object) {
175  if (json_obj_get_type(_caret, "atPoint", json_integer)) {
176  caret.format = 2;
177  caret.pointIndex = json_obj_getint(_caret, "atPoint");
178  } else {
179  caret.coordiante = json_obj_getnum(_caret, "at");
180  }
181  }
182  otl_iCaretValueList.push(&v.carets, caret);
183  }
184  otl_iLigCaretTable.push(lc, v);
185  }
186 }
187 
189  table_GDEF *gdef = NULL;
190  json_value *table = NULL;
191  if ((table = json_obj_get_type(root, "GDEF", json_object))) {
192  loggedStep("GDEF") {
193  gdef = table_iGDEF.create();
194  gdef->glyphClassDef = ClassDef.parse(json_obj_get(table, "glyphClassDef"));
195  gdef->markAttachClassDef = ClassDef.parse(json_obj_get(table, "markAttachClassDef"));
196  ligCaretFromJson(json_obj_get(table, "ligCarets"), &gdef->ligCarets);
197  }
198  }
199  return gdef;
200 }
201 
203  bk_Block *bcr = bk_new_Block(b16, cr->carets.length, // CaretCount
204  bkover);
205  for (glyphid_t j = 0; j < cr->carets.length; j++) {
206  bk_push(bcr, p16,
207  bk_new_Block(b16, cr->carets.items[j].format, // format
208  b16,
209  cr->carets.items[j].format == 2
210  ? cr->carets.items[j].pointIndex // Point index
211  : (int16_t)cr->carets.items[j].coordiante, // X coordinate
212  bkover), // CaretValue
213  bkover);
214  }
215  return bcr;
216 }
217 
218 static bk_Block *writeLigCarets(const otl_LigCaretTable *lc) {
219  otl_Coverage *cov = Coverage.create();
220  for (glyphid_t j = 0; j < lc->length; j++) {
221  Coverage.push(cov, Handle.dup(lc->items[j].glyph));
222  }
223  bk_Block *lct = bk_new_Block(p16, bk_newBlockFromBuffer(Coverage.build(cov)), // Coverage
224  b16, lc->length, // LigGlyphCount
225  bkover);
226  for (glyphid_t j = 0; j < lc->length; j++) {
227  bk_push(lct, p16, writeLigCaretRec(&(lc->items[j])), bkover);
228  }
229  Coverage.free(cov);
230  return lct;
231 }
232 
234  if (!gdef) return NULL;
235  bk_Block *bGlyphClassDef = NULL;
236  bk_Block *bAttachList = NULL;
237  bk_Block *bLigCaretList = NULL;
238  bk_Block *bMarkAttachClassDef = NULL;
239 
240  if (gdef->glyphClassDef) {
241  bGlyphClassDef = bk_newBlockFromBuffer(ClassDef.build(gdef->glyphClassDef));
242  }
243  if (gdef->ligCarets.length) { bLigCaretList = writeLigCarets(&gdef->ligCarets); }
244  if (gdef->markAttachClassDef) {
245  bMarkAttachClassDef = bk_newBlockFromBuffer(ClassDef.build(gdef->markAttachClassDef));
246  }
247  bk_Block *root = bk_new_Block(b32, 0x10000, // Version
248  p16, bGlyphClassDef, // GlyphClassDef
249  p16, bAttachList, // AttachList
250  p16, bLigCaretList, // LigCaretList
251  p16, bMarkAttachClassDef, // MarkAttachClassDef
252  bkover);
253  return bk_build_Block(root);
254 }
#define name
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
bk_Block * bk_newBlockFromBuffer(MOVE caryll_Buffer *buf)
Definition: bkblock.c:98
bk_Block * bk_new_Block(int type0,...)
Definition: bkblock.c:72
bk_Block * bk_push(bk_Block *b, int type0,...)
Definition: bkblock.c:81
@ b16
Definition: bkblock.h:17
@ p16
Definition: bkblock.h:19
@ bkover
Definition: bkblock.h:15
@ b32
Definition: bkblock.h:18
caryll_Buffer * bk_build_Block(bk_Block *root)
Definition: bkgraph.c:396
#define OTFCC_CHR(a, b, c, d)
Definition: caryll-font.c:7
int v
Definition: dviconv.c:10
struct rect data
Definition: dvipdfm.c:64
#define a(n)
Definition: gpos-common.c:148
json_value * json_array_new(size_t length)
json_value * json_array_push(json_value *array, json_value *)
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)
static json_value * preserialize(MOVE json_value *x)
Definition: json-funcs.h:187
static json_value * json_obj_get(const json_value *obj, const char *key)
Definition: json-funcs.h:26
static double json_obj_getnum(const json_value *obj, const char *key)
Definition: json-funcs.h:81
static json_value * json_obj_get_type(const json_value *obj, const char *key, const json_type type)
Definition: json-funcs.h:34
static int32_t json_obj_getint(const json_value *obj, const char *key)
Definition: json-funcs.h:93
#define NULL
Definition: ftobjs.h:61
signed short int16_t
Definition: stdint.h:76
unsigned short uint16_t
Definition: stdint.h:79
unsigned int uint32_t
Definition: stdint.h:80
#define INLINE
Definition: port.h:26
#define root
Definition: ctangleboot.c:69
#define ClassDef
Definition: aliases.h:55
#define Handle
Definition: aliases.h:45
uint8_t * font_file_pointer
Definition: aliases.h:41
#define Coverage
Definition: aliases.h:58
#define FOR_TABLE(name, table)
Definition: aliases.h:33
#define loggedStep(...)
Definition: aliases.h:6
#define DELETE(fn, ptr)
Definition: otfcc-alloc.h:76
int k
Definition: otp-parser.c:70
int g
Definition: ppmqvga.c:68
static int offset
Definition: ppmtogif.c:642
double pos_t
Definition: primitives.h:24
uint16_t shapeid_t
Definition: primitives.h:19
uint16_t glyphid_t
Definition: primitives.h:14
@ json_array
Definition: json.h:86
@ json_integer
Definition: json.h:87
@ json_object
Definition: json.h:85
#define checkLength(offset)
Definition: common.h:13
static unsigned long int lc(mp_ptr rp, gmp_randstate_t rstate)
Definition: randlc2x.c:72
sds sdsnewlen(const void *init, size_t initlen)
char * sds
Definition: sds.h:41
unsigned int name_length
Definition: json.h:103
char * name
Definition: json.h:102
struct _json_value * value
Definition: json.h:105
json_type type
Definition: json.h:113
unsigned int length
Definition: json.h:123
struct _json_value::@1795::@1798 object
json_object_entry * values
Definition: json.h:132
union _json_value::@1795 u
pos_t coordiante
Definition: GDEF.h:8
int16_t pointIndex
Definition: GDEF.h:9
int8_t format
Definition: GDEF.h:7
otfcc_GlyphHandle * glyphs
Definition: coverage.h:8
glyphid_t numGlyphs
Definition: coverage.h:6
OWNING otl_LigCaretTable ligCarets
Definition: GDEF.h:26
OWNING otl_ClassDef * markAttachClassDef
Definition: GDEF.h:25
OWNING otl_ClassDef * glyphClassDef
Definition: GDEF.h:24
Definition: table.h:30
int j
Definition: t4ht.c:1589
caryll_standardVectorImpl(otl_CaretValueList, otl_CaretValue, otl_iCaretValue, otl_iCaretValueList)
static INLINE void disposeGDEF(table_GDEF *gdef)
Definition: GDEF.c:34
static bk_Block * writeLigCaretRec(otl_CaretValueRecord *cr)
Definition: GDEF.c:202
static INLINE void initGdefLigCaretRec(otl_CaretValueRecord *v)
Definition: GDEF.c:13
static otl_CaretValue readCaretValue(const font_file_pointer data, uint32_t tableLength, uint32_t offset)
Definition: GDEF.c:43
static bk_Block * writeLigCarets(const otl_LigCaretTable *lc)
Definition: GDEF.c:218
caryll_Buffer * otfcc_buildGDEF(const table_GDEF *gdef, const otfcc_Options *options)
Definition: GDEF.c:233
static otl_CaretValueRecord readLigCaretRecord(const font_file_pointer data, uint32_t tableLength, uint32_t offset)
Definition: GDEF.c:60
static void ligCaretFromJson(const json_value *_carets, otl_LigCaretTable *lc)
Definition: GDEF.c:157
table_GDEF * otfcc_readGDEF(const otfcc_Packet packet, const otfcc_Options *options)
Definition: GDEF.c:77
static json_value * dumpGDEFLigCarets(const table_GDEF *gdef)
Definition: GDEF.c:116
static INLINE void initGDEF(table_GDEF *gdef)
Definition: GDEF.c:29
caryll_ElementInterfaceOf(otl_CaretValue)
Definition: GDEF.c:6
caryll_standardRefType(table_GDEF, table_iGDEF, initGDEF, disposeGDEF)
table_GDEF * otfcc_parseGDEF(const json_value *root, const otfcc_Options *options)
Definition: GDEF.c:188
void otfcc_dumpGDEF(const table_GDEF *gdef, json_value *root, const otfcc_Options *options)
Definition: GDEF.c:140
static void deleteGdefLigCaretRec(otl_CaretValueRecord *v)
Definition: GDEF.c:17
#define FAIL(ec)
char cr[]
Definition: vlna.c:107