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)  

classdef.c
Go to the documentation of this file.
1 #include "support/util.h"
3 
5  if (cd->glyphs) {
6  for (glyphid_t j = 0; j < cd->numGlyphs; j++) {
7  Handle.dispose(&cd->glyphs[j]);
8  }
9  FREE(cd->glyphs);
10  }
11  FREE(cd->classes);
12 }
14 
15 static void growClassdef(otl_ClassDef *cd, uint32_t n) {
16  if (!n) return;
17  if (n > cd->capacity) {
18  if (!cd->capacity) cd->capacity = 0x10;
19  while (n > cd->capacity)
20  cd->capacity += (cd->capacity >> 1) & 0xFFFFFF;
21  RESIZE(cd->glyphs, cd->capacity);
22  RESIZE(cd->classes, cd->capacity);
23  }
24 }
26  cd->numGlyphs += 1;
27  growClassdef(cd, cd->numGlyphs);
28  cd->glyphs[cd->numGlyphs - 1] = h;
29  cd->classes[cd->numGlyphs - 1] = cls;
30  if (cls > cd->maxclass) cd->maxclass = cls;
31 }
32 
33 typedef struct {
34  int gid;
35  int covIndex;
38 
40  return a->covIndex - b->covIndex;
41 }
42 
43 static otl_ClassDef *readClassDef(const uint8_t *data, uint32_t tableLength, uint32_t offset) {
45  if (tableLength < offset + 4) return cd;
47  if (format == 1 && tableLength >= offset + 6) {
48  glyphid_t startGID = read_16u(data + offset + 2);
50  if (count && tableLength >= offset + 6 + count * 2) {
51  for (glyphid_t j = 0; j < count; j++) {
52  pushClassDef(cd, Handle.fromIndex(startGID + j), read_16u(data + offset + 6 + j * 2));
53  }
54  return cd;
55  }
56  } else if (format == 2) {
57  // The ranges may overlap.
58  // Use hashtable.
59  uint16_t rangeCount = read_16u(data + offset + 2);
60  if (tableLength < offset + 4 + rangeCount * 6) return cd;
62  for (uint16_t j = 0; j < rangeCount; j++) {
63  uint16_t start = read_16u(data + offset + 4 + 6 * j);
64  uint16_t end = read_16u(data + offset + 4 + 6 * j + 2);
65  uint16_t cls = read_16u(data + offset + 4 + 6 * j + 4);
66  for (int k = start; k <= end; k++) {
69  if (!item) {
70  NEW(item);
71  item->gid = k;
72  item->covIndex = cls;
73  HASH_ADD_INT(hash, gid, item);
74  }
75  }
76  }
78  coverage_entry *e, *tmp;
79  HASH_ITER(hh, hash, e, tmp) {
80  pushClassDef(cd, Handle.fromIndex(e->gid), e->covIndex);
81  HASH_DEL(hash, e);
82  FREE(e);
83  }
84  return cd;
85  }
86  return cd;
87 }
88 
92  for (glyphid_t j = 0; j < ocd->numGlyphs; j++) {
93  int gid = ocd->glyphs[j].index;
94  int cid = ocd->classes[j];
96  HASH_FIND_INT(hash, &gid, item);
97  if (!item) {
98  NEW(item);
99  item->gid = gid;
100  item->covIndex = cid;
101  HASH_ADD_INT(hash, gid, item);
102  }
103  }
104  for (glyphid_t j = 0; j < cov->numGlyphs; j++) {
105  int gid = cov->glyphs[j].index;
107  HASH_FIND_INT(hash, &gid, item);
108  if (!item) {
109  NEW(item);
110  item->gid = gid;
111  item->covIndex = 0;
112  HASH_ADD_INT(hash, gid, item);
113  }
114  }
115  coverage_entry *e, *tmp;
116  HASH_ITER(hh, hash, e, tmp) {
117  pushClassDef(cd, Handle.fromIndex(e->gid), e->covIndex);
118  HASH_DEL(hash, e);
119  FREE(e);
120  }
121  otl_iClassDef.free(ocd);
122  return cd;
123 }
124 
127  for (glyphid_t j = 0; j < cd->numGlyphs; j++) {
129  }
130  return preserialize(a);
131 }
132 
133 static otl_ClassDef *parseClassDef(const json_value *_cd) {
134  if (!_cd || _cd->type != json_object) return NULL;
136  for (glyphid_t j = 0; j < _cd->u.object.length; j++) {
138  json_value *_cid = _cd->u.object.values[j].value;
139  glyphclass_t cls = 0;
140  if (_cid->type == json_integer) {
141  cls = _cid->u.integer;
142  } else if (_cid->type == json_double) {
143  cls = _cid->u.dbl;
144  }
145  pushClassDef(cd, h, cls);
146  }
147  return cd;
148 }
149 
150 typedef struct {
154 
155 static int by_gid(const void *a, const void *b) {
156  return ((const classdef_sortrecord *)a)->gid - ((const classdef_sortrecord *)b)->gid;
157 }
159  caryll_Buffer *buf = bufnew();
160  bufwrite16b(buf, 2);
161  if (!cd->numGlyphs) { // no glyphs, return a blank classdef
162  bufwrite16b(buf, 0);
163  return buf;
164  }
165 
167  NEW(r, cd->numGlyphs);
168  glyphid_t jj = 0;
169  for (glyphid_t j = 0; j < cd->numGlyphs; j++) {
170  if (cd->classes[j]) {
171  r[jj].gid = cd->glyphs[j].index;
172  r[jj].cid = cd->classes[j];
173  jj++;
174  }
175  }
176  if (!jj) { // The classdef has only class 0
177  FREE(r);
178  bufwrite16b(buf, 0);
179  return buf;
180  }
181  qsort(r, jj, sizeof(classdef_sortrecord), by_gid);
182 
183  glyphid_t startGID = r[0].gid;
184  glyphid_t endGID = startGID;
185  glyphclass_t lastClass = r[0].cid;
186  glyphid_t nRanges = 0;
187  glyphid_t lastGID = startGID;
189  for (glyphid_t j = 1; j < jj; j++) {
190  glyphid_t current = r[j].gid;
191  if (current <= lastGID) continue;
192  if (current == endGID + 1 && r[j].cid == lastClass) {
193  endGID = current;
194  } else {
195  bufwrite16b(ranges, startGID);
196  bufwrite16b(ranges, endGID);
197  bufwrite16b(ranges, lastClass);
198  nRanges += 1;
199  startGID = endGID = current;
200  lastClass = r[j].cid;
201  }
202  lastGID = current;
203  }
204  bufwrite16b(ranges, startGID);
205  bufwrite16b(ranges, endGID);
206  bufwrite16b(ranges, lastClass);
207  nRanges += 1;
208  bufwrite16b(buf, nRanges);
210  FREE(r);
211  return buf;
212 }
213 
214 static void shrinkClassDef(otl_ClassDef *cd) {
215  glyphid_t k = 0;
216  for (glyphid_t j = 0; j < cd->numGlyphs; j++) {
217  if (cd->glyphs[j].name) {
218  cd->glyphs[k] = cd->glyphs[j];
219  cd->classes[k] = cd->classes[j];
220  k++;
221  } else {
222  Handle.dispose(&cd->glyphs[j]);
223  }
224  }
225  cd->numGlyphs = k;
226 }
227 
228 const struct __otfcc_IClassDef otl_iClassDef = {
230  .read = readClassDef,
231  .expand = expandClassDef,
232  .dump = dumpClassDef,
233  .parse = parseClassDef,
234  .build = buildClassDef,
235  .shrink = shrinkClassDef,
236  .push = pushClassDef,
237 };
#define count(a)
Definition: aptex-macros.h:781
#define hash
Definition: aptex.h:388
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
static int item
Definition: brushtopbm.c:66
static otl_ClassDef * expandClassDef(otl_Coverage *cov, otl_ClassDef *ocd)
Definition: classdef.c:89
static json_value * dumpClassDef(const otl_ClassDef *cd)
Definition: classdef.c:125
const struct __otfcc_IClassDef otl_iClassDef
Definition: classdef.c:228
static caryll_Buffer * buildClassDef(const otl_ClassDef *cd)
Definition: classdef.c:158
static int by_gid(const void *a, const void *b)
Definition: classdef.c:155
caryll_standardRefTypeFn(otl_ClassDef, disposeClassDef)
static otl_ClassDef * readClassDef(const uint8_t *data, uint32_t tableLength, uint32_t offset)
Definition: classdef.c:43
static void pushClassDef(otl_ClassDef *cd, MOVE otfcc_GlyphHandle h, glyphclass_t cls)
Definition: classdef.c:25
static int by_covIndex(coverage_entry *a, coverage_entry *b)
Definition: classdef.c:39
static void growClassdef(otl_ClassDef *cd, uint32_t n)
Definition: classdef.c:15
static INLINE void disposeClassDef(otl_ClassDef *cd)
Definition: classdef.c:4
static void shrinkClassDef(otl_ClassDef *cd)
Definition: classdef.c:214
static otl_ClassDef * parseClassDef(const json_value *_cd)
Definition: classdef.c:133
#define n
Definition: t4ht.c:1290
#define b
Definition: jpegint.h:372
int h
Definition: dviconv.c:9
long hh
Definition: dvi2xx.h:579
struct rect data
Definition: dvipdfm.c:64
#define caryll_standardRefTypeMethods(T)
Definition: element-impl.h:134
#define a(n)
Definition: gpos-common.c:148
const unsigned char FREE
Definition: image.cpp:34
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
#define NULL
Definition: ftobjs.h:61
#define NEW
Definition: gdkanji.c:77
unsigned short uint16_t
Definition: stdint.h:79
unsigned int uint32_t
Definition: stdint.h:80
unsigned char uint8_t
Definition: stdint.h:78
#define INLINE
Definition: port.h:26
#define buf
#define Handle
Definition: aliases.h:45
#define qsort
Definition: includes.h:72
#define RESIZE(ptr, n)
Definition: otfcc-alloc.h:77
int k
Definition: otp-parser.c:70
static int format
Definition: pbmclean.c:15
static struct Point current
Definition: picttoppm.c:134
@ MOVE
Definition: pl-parser.h:87
int r
Definition: ppmqvga.c:68
static int offset
Definition: ppmtogif.c:642
uint16_t glyphid_t
Definition: primitives.h:14
uint16_t glyphclass_t
Definition: primitives.h:15
void bufwrite_bufdel(caryll_Buffer *buf, caryll_Buffer *that)
Definition: buffer.c:163
void bufwrite16b(caryll_Buffer *buf, uint16_t x)
Definition: buffer.c:58
caryll_Buffer * bufnew(void)
Definition: buffer.c:4
@ json_double
Definition: json.h:88
@ json_integer
Definition: json.h:87
@ json_object
Definition: json.h:85
sds sdsnewlen(const void *init, size_t initlen)
ShellFileEnvironment e
Definition: sh6.c:388
otl_ClassDef *(* create)()
Definition: CPAL.d:19530
void(* free)(otl_ClassDef *)
Definition: CPAL.d:19530
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
int64_t integer
Definition: json.h:118
double dbl
Definition: json.h:119
glyphclass_t cid
Definition: classdef.c:152
Definition: classdef.c:33
int gid
Definition: classdef.c:34
UT_hash_handle hh
Definition: classdef.c:36
int covIndex
Definition: classdef.c:35
OWNING sds name
Definition: handle.h:21
glyphid_t index
Definition: handle.h:20
glyphclass_t * classes
Definition: classdef.h:11
glyphclass_t maxclass
Definition: classdef.h:9
glyphid_t numGlyphs
Definition: classdef.h:7
otfcc_GlyphHandle * glyphs
Definition: classdef.h:10
uint32_t capacity
Definition: classdef.h:8
otfcc_GlyphHandle * glyphs
Definition: coverage.h:8
glyphid_t numGlyphs
Definition: coverage.h:6
int j
Definition: t4ht.c:1589
#define HASH_DEL(head, delptr)
Definition: uthash.h:498
#define HASH_ITER(hh, head, el, tmp)
Definition: uthash.h:1131
#define HASH_SORT(head, cmpfcn)
Definition: uthash.h:960
#define HASH_FIND_INT(head, findint, out)
Definition: uthash.h:486
#define HASH_ADD_INT(head, intfield, add)
Definition: uthash.h:488
@ start
Definition: preamble.c:52
#define end(cp)
Definition: zic.c:71