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)  

gpos-common.c
Go to the documentation of this file.
1 #include "gpos-common.h"
2 
4  Handle.dispose(&entry->glyph);
5 }
6 static caryll_ElementInterface(otl_MarkRecord) gss_typeinfo = {
7  .init = NULL, .copy = NULL, .dispose = deleteMarkArrayItem};
8 
10 
12  uint32_t tableLength, uint32_t offset) {
13  checkLength(offset + 2);
14  glyphid_t markCount = read_16u(data + offset);
15  for (glyphid_t j = 0; j < markCount; j++) {
16  glyphclass_t markClass = read_16u(data + offset + 2 + j * 4);
17  uint16_t delta = read_16u(data + offset + 2 + j * 4 + 2);
18  if (delta) {
19  otl_iMarkArray.push(
20  array,
21  ((otl_MarkRecord){.glyph = Handle.dup(cov->glyphs[j]),
22  .markClass = markClass,
23  .anchor = otl_read_anchor(data, tableLength, offset + delta)}));
24  } else {
25  otl_iMarkArray.push(array, ((otl_MarkRecord){.glyph = Handle.dup(cov->glyphs[j]),
26  .markClass = markClass,
27  .anchor = otl_anchor_absent()}));
28  }
29  }
30 FAIL:
31  return;
32 }
33 
35  return strcmp(a->className, b->className);
36 }
38  const otfcc_Options *options) {
39  for (glyphid_t j = 0; j < _marks->u.object.length; j++) {
41  char *gname = _marks->u.object.values[j].name;
42  json_value *anchorRecord = _marks->u.object.values[j].value;
43  mark.glyph = Handle.fromName(sdsnewlen(gname, _marks->u.object.values[j].name_length));
44  mark.markClass = 0;
45  mark.anchor = otl_anchor_absent();
46 
47  if (!anchorRecord || anchorRecord->type != json_object) {
48  otl_iMarkArray.push(array, mark);
49  continue;
50  }
51  json_value *_className = json_obj_get_type(anchorRecord, "class", json_string);
52  if (!_className) {
53  otl_iMarkArray.push(array, mark);
54  continue;
55  }
56 
57  sds className = sdsnewlen(_className->u.string.ptr, _className->u.string.length);
59  HASH_FIND_STR(*h, className, s);
60  if (!s) {
61  NEW(s);
62  s->className = className;
63  s->classID = HASH_COUNT(*h);
64  HASH_ADD_STR(*h, className, s);
65  } else {
66  sdsfree(className);
67  }
68  mark.markClass = s->classID;
69  mark.anchor.present = true;
70  mark.anchor.x = json_obj_getnum(anchorRecord, "x");
71  mark.anchor.y = json_obj_getnum(anchorRecord, "y");
72  otl_iMarkArray.push(array, mark);
73  }
74 
76  glyphid_t jAnchorIndex = 0;
78  foreach_hash(s, *h) {
79  s->classID = jAnchorIndex;
80  jAnchorIndex++;
81  }
82  for (glyphid_t j = 0; j < array->length; j++) {
83  if (!array->items[j].anchor.present) continue;
84  json_value *anchorRecord = _marks->u.object.values[j].value;
85  json_value *_className = json_obj_get_type(anchorRecord, "class", json_string);
86  sds className = sdsnewlen(_className->u.string.ptr, _className->u.string.length);
88  HASH_FIND_STR(*h, className, s);
89  if (s) {
90  array->items[j].markClass = s->classID;
91  } else {
92  array->items[j].markClass = 0;
93  }
94  sdsfree(className);
95  }
96 }
97 
99  otl_Anchor anchor = {.present = false, .x = 0, .y = 0};
100  return anchor;
101 }
103  otl_Anchor anchor = {.present = false, .x = 0, .y = 0};
104  checkLength(offset + 6);
105  anchor.present = true;
106  anchor.x = read_16s(data + offset + 2);
107  anchor.y = read_16s(data + offset + 4);
108  return anchor;
109 FAIL:
110  anchor.present = false;
111  anchor.x = 0;
112  anchor.y = 0;
113  return anchor;
114 }
116  if (a.present) {
120  return v;
121  } else {
122  return json_null_new();
123  }
124 }
126  otl_Anchor anchor = {.present = false, .x = 0, .y = 0};
127  if (!v || v->type != json_object) return anchor;
128  anchor.present = true;
129  anchor.x = json_obj_getnum_fallback(v, "x", 0);
130  anchor.y = json_obj_getnum_fallback(v, "y", 0);
131  return anchor;
132 }
133 
135  if (!a.present) return NULL;
136  return bk_new_Block(b16, 1, // format
137  b16, (int16_t)a.x, // x
138  b16, (int16_t)a.y, // y
139  bkover);
140 }
141 
142 // GPOS position value constants
143 const uint8_t FORMAT_DX = 1;
144 const uint8_t FORMAT_DY = 2;
147 
148 #define a(n) n + 0, n + 1, n + 1, n + 2 // 2 bits
149 #define b(n) a(n + 0), a(n + 1), a(n + 1), a(n + 2) // 4 bits
150 #define c(n) b(n + 0), b(n + 1), b(n + 1), b(n + 2) // 6 bits
151 #define d(n) c(n + 0), c(n + 1), c(n + 1), c(n + 2) // 8 bits
152 const uint8_t bits_in[0x100] = {d(0)};
153 #undef d
154 #undef c
155 #undef b
156 #undef a
157 
158 // Length of a position value in bytes
160  return bits_in[format & 0xFF] << 1;
161 }
163  otl_PositionValue v = {0.0, 0.0, 0.0, 0.0};
164  return v;
165 }
166 // Read a position value from SFNT
168  uint16_t format) {
169  otl_PositionValue v = {0.0, 0.0, 0.0, 0.0};
170  if (tableLength < offset + position_format_length(format)) return v;
171  if (format & FORMAT_DX) { v.dx = read_16s(data + offset), offset += 2; };
172  if (format & FORMAT_DY) { v.dy = read_16s(data + offset), offset += 2; };
173  if (format & FORMAT_DWIDTH) { v.dWidth = read_16s(data + offset), offset += 2; };
174  if (format & FORMAT_DHEIGHT) { v.dHeight = read_16s(data + offset), offset += 2; };
175  return v;
176 }
179  if (value.dx) json_object_push(v, "dx", json_new_position(value.dx));
180  if (value.dy) json_object_push(v, "dy", json_new_position(value.dy));
181  if (value.dWidth) json_object_push(v, "dWidth", json_new_position(value.dWidth));
182  if (value.dHeight) json_object_push(v, "dHeight", json_new_position(value.dHeight));
183  return preserialize(v);
184 }
186  otl_PositionValue v = {0.0, 0.0, 0.0, 0.0};
187  if (!pos || pos->type != json_object) return v;
188  v.dx = json_obj_getnum(pos, "dx");
189  v.dy = json_obj_getnum(pos, "dy");
190  v.dWidth = json_obj_getnum(pos, "dWidth");
191  v.dHeight = json_obj_getnum(pos, "dHeight");
192  return v;
193 }
194 // The required format of a position value
196  return (v.dx ? FORMAT_DX : 0) | (v.dy ? FORMAT_DY : 0) | (v.dWidth ? FORMAT_DWIDTH : 0) |
197  (v.dHeight ? FORMAT_DHEIGHT : 0);
198 }
199 // Write gpos position value
201  if (format & FORMAT_DX) bufwrite16b(buf, (int16_t)v.dx);
202  if (format & FORMAT_DY) bufwrite16b(buf, (int16_t)v.dy);
203  if (format & FORMAT_DWIDTH) bufwrite16b(buf, (int16_t)v.dWidth);
204  if (format & FORMAT_DHEIGHT) bufwrite16b(buf, (int16_t)v.dHeight);
205 }
206 
209  if (format & FORMAT_DX) bk_push(b, b16, (int16_t)v.dx, bkover);
210  if (format & FORMAT_DY) bk_push(b, b16, (int16_t)v.dy, bkover);
211  if (format & FORMAT_DWIDTH) bk_push(b, b16, (int16_t)v.dWidth, bkover);
212  if (format & FORMAT_DHEIGHT) bk_push(b, b16, (int16_t)v.dHeight, bkover);
213  return b;
214 }
#define mark
Definition: aptex-macros.h:374
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
static int16_t read_16s(const uint8_t *src)
Definition: bin-io.h:153
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
@ bkover
Definition: bkblock.h:15
int v
Definition: dviconv.c:10
int h
Definition: dviconv.c:9
int strcmp()
Definition: coll.cpp:143
struct rect data
Definition: dvipdfm.c:64
#define s
Definition: afcover.h:80
bk_Block * bkFromAnchor(otl_Anchor a)
Definition: gpos-common.c:134
otl_Anchor otl_parse_anchor(json_value *v)
Definition: gpos-common.c:125
static caryll_ElementInterface(otl_MarkRecord)
Definition: gpos-common.c:6
const uint8_t bits_in[0x100]
Definition: gpos-common.c:152
void otl_parseMarkArray(json_value *_marks, otl_MarkArray *array, otl_ClassnameHash **h, const otfcc_Options *options)
Definition: gpos-common.c:37
uint8_t required_position_format(otl_PositionValue v)
Definition: gpos-common.c:195
#define a(n)
Definition: gpos-common.c:148
const uint8_t FORMAT_DY
Definition: gpos-common.c:144
void write_gpos_value(caryll_Buffer *buf, otl_PositionValue v, uint16_t format)
Definition: gpos-common.c:200
json_value * otl_dump_anchor(otl_Anchor a)
Definition: gpos-common.c:115
const uint8_t FORMAT_DX
Definition: gpos-common.c:143
json_value * gpos_dump_value(otl_PositionValue value)
Definition: gpos-common.c:177
otl_PositionValue read_gpos_value(font_file_pointer data, uint32_t tableLength, uint32_t offset, uint16_t format)
Definition: gpos-common.c:167
#define b(n)
Definition: gpos-common.c:149
const uint8_t FORMAT_DWIDTH
Definition: gpos-common.c:145
static int compare_classHash(otl_ClassnameHash *a, otl_ClassnameHash *b)
Definition: gpos-common.c:34
void otl_readMarkArray(otl_MarkArray *array, otl_Coverage *cov, font_file_pointer data, uint32_t tableLength, uint32_t offset)
Definition: gpos-common.c:11
otl_Anchor otl_read_anchor(font_file_pointer data, uint32_t tableLength, uint32_t offset)
Definition: gpos-common.c:102
bk_Block * bk_gpos_value(otl_PositionValue v, uint16_t format)
Definition: gpos-common.c:207
#define d(n)
Definition: gpos-common.c:151
otl_Anchor otl_anchor_absent()
Definition: gpos-common.c:98
otl_PositionValue gpos_parse_value(json_value *pos)
Definition: gpos-common.c:185
caryll_standardVectorImpl(otl_MarkArray, otl_MarkRecord, gss_typeinfo, otl_iMarkArray)
static void deleteMarkArrayItem(otl_MarkRecord *entry)
Definition: gpos-common.c:3
otl_PositionValue position_zero()
Definition: gpos-common.c:162
uint8_t position_format_length(uint16_t format)
Definition: gpos-common.c:159
const uint8_t FORMAT_DHEIGHT
Definition: gpos-common.c:146
json_value * json_null_new(void)
json_value * json_object_push(json_value *object, const char *name, json_value *)
json_value * json_object_new(size_t length)
static json_value * preserialize(MOVE json_value *x)
Definition: json-funcs.h:187
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 json_value * json_new_position(pos_t z)
Definition: json-funcs.h:67
static double json_obj_getnum_fallback(const json_value *obj, const char *key, double fallback)
Definition: json-funcs.h:105
#define NULL
Definition: ftobjs.h:61
#define NEW
Definition: gdkanji.c:77
signed short int16_t
Definition: stdint.h:76
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 buf
pdf_obj * entry
Definition: pdfdoc.c:64
#define foreach_hash(id, range)
Definition: aliases.h:39
#define Handle
Definition: aliases.h:45
uint8_t * font_file_pointer
Definition: aliases.h:41
const int * pos
Definition: combiners.h:905
otl_iMarkArray
Definition: otl.d:20851
static int format
Definition: pbmclean.c:15
static int delta
Definition: pbmtolj.c:36
static int offset
Definition: ppmtogif.c:642
uint16_t glyphid_t
Definition: primitives.h:14
uint16_t glyphclass_t
Definition: primitives.h:15
void bufwrite16b(caryll_Buffer *buf, uint16_t x)
Definition: buffer.c:58
@ json_string
Definition: json.h:89
@ json_object
Definition: json.h:85
#define checkLength(offset)
Definition: common.h:13
sds sdsnewlen(const void *init, size_t initlen)
void sdsfree(sds s)
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
char * ptr
Definition: json.h:124
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
struct _json_value::@1795::@1797 string
bool present
Definition: otl.h:122
pos_t x
Definition: otl.h:123
pos_t y
Definition: otl.h:124
otfcc_GlyphHandle * glyphs
Definition: coverage.h:8
int j
Definition: t4ht.c:1589
Definition: obx.h:51
#define FAIL(ec)
#define HASH_FIND_STR(head, findstr, out)
Definition: uthash.h:480
#define HASH_COUNT(head)
Definition: uthash.h:1137
#define HASH_SORT(head, cmpfcn)
Definition: uthash.h:960
#define HASH_ADD_STR(head, strfield, add)
Definition: uthash.h:482