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)  

read.c
Go to the documentation of this file.
1 #include "private.h"
2 
3 #define LOOKUP_READER(llt, fn) \
4  case llt: \
5  return fn(data, tableLength, subtableOffset, maxGlyphs, options);
6 
8  uint32_t subtableOffset, otl_LookupType lookupType,
9  const glyphid_t maxGlyphs, const otfcc_Options *options) {
10  switch (lookupType) {
28  default:
29  return NULL;
30  }
31 }
32 
35  checkLength(base + 6);
36  tableid_t rid = read_16u(data + base + 2);
37  if (rid < features->length) {
38  lang->requiredFeature = features->items[rid];
39  } else {
40  lang->requiredFeature = NULL;
41  }
42  tableid_t featureCount = read_16u(data + base + 4);
43  for (tableid_t j = 0; j < featureCount; j++) {
44  tableid_t featureIndex = read_16u(data + base + 6 + 2 * j);
45  if (featureIndex < features->length) {
46  otl_iFeatureRefList.push(&lang->features, features->items[featureIndex]);
47  }
48  }
49  return;
50 FAIL:
51  otl_iFeatureRefList.dispose(&lang->features);
52  lang->requiredFeature = NULL;
53  return;
54 }
55 
57  otl_LookupType lookup_type_base,
58  const otfcc_Options *options) {
59  table_OTL *table = table_iOTL.create();
60  if (!table) goto FAIL;
61  checkLength(10);
62  uint32_t scriptListOffset = read_16u(data + 4);
63  checkLength(scriptListOffset + 2);
64  uint32_t featureListOffset = read_16u(data + 6);
65  checkLength(featureListOffset + 2);
66  uint32_t lookupListOffset = read_16u(data + 8);
67  checkLength(lookupListOffset + 2);
68 
69  // parse lookup list
70  {
71  tableid_t lookupCount = read_16u(data + lookupListOffset);
72  checkLength(lookupListOffset + 2 + lookupCount * 2);
73  for (tableid_t j = 0; j < lookupCount; j++) {
75  otl_iLookupPtr.init(&lookup);
76  lookup->_offset = lookupListOffset + read_16u(data + lookupListOffset + 2 + 2 * j);
77  checkLength(lookup->_offset + 6);
78  lookup->type = read_16u(data + lookup->_offset) + lookup_type_base;
79  otl_iLookupList.push(&table->lookups, lookup);
80  }
81  }
82 
83  // parse feature list
84  {
85  tableid_t featureCount = read_16u(data + featureListOffset);
86  checkLength(featureListOffset + 2 + featureCount * 6);
87  tableid_t lnk = 0;
88  for (tableid_t j = 0; j < featureCount; j++) {
90  otl_iFeaturePtr.init(&feature);
91  uint32_t tag = read_32u(data + featureListOffset + 2 + j * 6);
92  if (options->glyph_name_prefix) {
93  feature->name = sdscatprintf(sdsempty(), "%c%c%c%c_%s_%05d", (tag >> 24) & 0xFF,
94  (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff,
95  options->glyph_name_prefix, j);
96  } else {
97  feature->name = sdscatprintf(sdsempty(), "%c%c%c%c_%05d", (tag >> 24) & 0xFF,
98  (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff, j);
99  }
100  uint32_t featureOffset =
101  featureListOffset + read_16u(data + featureListOffset + 2 + j * 6 + 4);
102 
103  checkLength(featureOffset + 4);
104  tableid_t lookupCount = read_16u(data + featureOffset + 2);
105  checkLength(featureOffset + 4 + lookupCount * 2);
106  for (tableid_t k = 0; k < lookupCount; k++) {
107  tableid_t lookupid = read_16u(data + featureOffset + 4 + k * 2);
108  if (lookupid < table->lookups.length) {
109  otl_Lookup *lookup = table->lookups.items[lookupid];
110  if (!lookup->name) {
111  if (options->glyph_name_prefix) {
112  lookup->name = sdscatprintf(sdsempty(), "lookup_%s_%c%c%c%c_%d",
113  options->glyph_name_prefix,
114  (tag >> 24) & 0xFF, (tag >> 16) & 0xFF,
115  (tag >> 8) & 0xff, tag & 0xff, lnk++);
116  } else {
117  lookup->name = sdscatprintf(sdsempty(), "lookup_%c%c%c%c_%d",
118  (tag >> 24) & 0xFF, (tag >> 16) & 0xFF,
119  (tag >> 8) & 0xff, tag & 0xff, lnk++);
120  }
121  }
123  }
124  }
125  otl_iFeatureList.push(&table->features, feature);
126  }
127  }
128 
129  // parse script list
130  {
131  tableid_t scriptCount = read_16u(data + scriptListOffset);
132  checkLength(scriptListOffset + 2 + 6 * scriptCount);
133 
134  uint32_t nLanguageCombinations = 0;
135  for (tableid_t j = 0; j < scriptCount; j++) {
136  uint32_t scriptOffset =
137  scriptListOffset + read_16u(data + scriptListOffset + 2 + 6 * j + 4);
138  checkLength(scriptOffset + 4);
139 
140  tableid_t defaultLangSystem = read_16u(data + scriptOffset);
141  nLanguageCombinations +=
142  (defaultLangSystem ? 1 : 0) + read_16u(data + scriptOffset + 2);
143  }
144 
145  for (tableid_t j = 0; j < scriptCount; j++) {
146  uint32_t tag = read_32u(data + scriptListOffset + 2 + 6 * j);
147  uint32_t scriptOffset =
148  scriptListOffset + read_16u(data + scriptListOffset + 2 + 6 * j + 4);
149  tableid_t defaultLangSystem = read_16u(data + scriptOffset);
150  if (defaultLangSystem) {
152  otl_iLanguageSystem.init(&lang);
153  lang->name = sdscatprintf(sdsempty(), "%c%c%c%c%cDFLT", (tag >> 24) & 0xFF,
154  (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff,
156  parseLanguage(data, tableLength, scriptOffset + defaultLangSystem, lang,
157  &table->features);
158  otl_iLangSystemList.push(&table->languages, lang);
159  }
160  tableid_t langSysCount = read_16u(data + scriptOffset + 2);
161  for (tableid_t k = 0; k < langSysCount; k++) {
162  uint32_t langTag = read_32u(data + scriptOffset + 4 + 6 * k);
163  tableid_t langSys = read_16u(data + scriptOffset + 4 + 6 * k + 4);
165  otl_iLanguageSystem.init(&lang);
166  lang->name =
167  sdscatprintf(sdsempty(), "%c%c%c%c%c%c%c%c%c", (tag >> 24) & 0xFF,
168  (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff,
169  SCRIPT_LANGUAGE_SEPARATOR, (langTag >> 24) & 0xFF,
170  (langTag >> 16) & 0xFF, (langTag >> 8) & 0xff, langTag & 0xff);
171  parseLanguage(data, tableLength, scriptOffset + langSys, lang, &table->features);
172  otl_iLangSystemList.push(&table->languages, lang);
173  }
174  }
175  }
176 
177  // name all lookups
178  for (tableid_t j = 0; j < table->lookups.length; j++) {
179  if (!table->lookups.items[j]->name) {
180  if (options->glyph_name_prefix) {
181  table->lookups.items[j]->name =
182  sdscatprintf(sdsempty(), "lookup_%s_%02x_%d", options->glyph_name_prefix,
183  table->lookups.items[j]->type, j);
184  } else {
185  table->lookups.items[j]->name =
186  sdscatprintf(sdsempty(), "lookup_%02x_%d", table->lookups.items[j]->type, j);
187  }
188  }
189  }
190  return table;
191 FAIL:
192  if (table) table_iOTL.free(table);
193  return NULL;
194 }
195 
197  glyphid_t maxGlyphs, const otfcc_Options *options) {
198  lookup->flags = read_16u(data + lookup->_offset + 2);
199  tableid_t subtableCount = read_16u(data + lookup->_offset + 4);
200  if (!subtableCount || tableLength < lookup->_offset + 6 + 2 * subtableCount) {
202  return;
203  }
204  for (tableid_t j = 0; j < subtableCount; j++) {
205  uint32_t subtableOffset = lookup->_offset + read_16u(data + lookup->_offset + 6 + j * 2);
206  otl_Subtable *subtable = otfcc_readOtl_subtable(data, tableLength, subtableOffset,
207  lookup->type, maxGlyphs, options);
208  otl_iSubtableList.push(&lookup->subtables, subtable);
209  }
211  lookup->type = 0;
212  for (tableid_t j = 0; j < lookup->subtables.length; j++) {
213  if (lookup->subtables.items[j]) {
214  lookup->type = lookup->subtables.items[j]->extend.type;
215  break;
216  }
217  }
218  if (lookup->type) {
219  for (tableid_t j = 0; j < lookup->subtables.length; j++) {
220  if (lookup->subtables.items[j] &&
221  lookup->subtables.items[j]->extend.type == lookup->type) {
222  // this subtable is valid
223  otl_Subtable *st = lookup->subtables.items[j]->extend.subtable;
224  FREE(lookup->subtables.items[j]);
225  lookup->subtables.items[j] = st;
226  } else if (lookup->subtables.items[j]) {
227  // type mismatch, delete this subtable
228  otl_Lookup *temp;
229  otl_iLookupPtr.init(&temp);
230  temp->type = lookup->subtables.items[j]->extend.type;
231  otl_iSubtableList.push(&temp->subtables,
232  lookup->subtables.items[j]->extend.subtable);
234  FREE(lookup->subtables.items[j]);
235  }
236  }
237  } else {
238  otl_iSubtableList.disposeDependent(&lookup->subtables, lookup);
239  return;
240  }
241  }
244 }
245 
247  glyphid_t maxGlyphs) {
248  table_OTL *otl = NULL;
249  FOR_TABLE(tag, table) {
251  uint32_t length = table.length;
253  (tag == OTFCC_CHR('G','S','U','B')
255  : tag == OTFCC_CHR('G','P','O','S') ? otl_type_gpos_unknown : otl_type_unknown),
256  options);
257  if (!otl) goto FAIL;
258  for (tableid_t j = 0; j < otl->lookups.length; j++) {
259  otfcc_readOtl_lookup(data, length, otl->lookups.items[j], maxGlyphs, options);
260  }
261  return otl;
262  FAIL:
263  if (otl) table_iOTL.free(otl);
264  otl = NULL;
265  }
266  return NULL;
267 }
struct @88 table[500]
int lookup(const char *)
static uint32_t read_32u(const uint8_t *src)
Definition: bin-io.h:132
static uint16_t read_16u(const uint8_t *src)
Definition: bin-io.h:121
#define OTFCC_CHR(a, b, c, d)
Definition: caryll-font.c:7
feature
Definition: control.c:37
char * temp
Definition: dvidvi.c:137
struct rect data
Definition: dvipdfm.c:64
const FcChar8 lang[6]
Definition: fcfreetype.c:56
int base
Definition: gsftopk.c:1502
const unsigned char FREE
Definition: image.cpp:34
otl_LookupType
Definition: otl.h:9
@ otl_type_gsub_context
Definition: otl.h:17
@ otl_type_gpos_markToLigature
Definition: otl.h:27
@ otl_type_gsub_single
Definition: otl.h:13
@ otl_type_gpos_context
Definition: otl.h:29
@ otl_type_gsub_chaining
Definition: otl.h:18
@ otl_type_gsub_alternate
Definition: otl.h:15
@ otl_type_gpos_chaining
Definition: otl.h:30
@ otl_type_gpos_pair
Definition: otl.h:24
@ otl_type_gpos_cursive
Definition: otl.h:25
@ otl_type_gpos_extend
Definition: otl.h:31
@ otl_type_gpos_markToMark
Definition: otl.h:28
@ otl_type_gpos_single
Definition: otl.h:23
@ otl_type_gsub_unknown
Definition: otl.h:12
@ otl_type_gsub_extend
Definition: otl.h:19
@ otl_type_gpos_markToBase
Definition: otl.h:26
@ otl_type_gpos_unknown
Definition: otl.h:22
@ otl_type_unknown
Definition: otl.h:10
@ otl_type_gsub_reverse
Definition: otl.h:20
@ otl_type_gsub_multiple
Definition: otl.h:14
@ otl_type_gsub_ligature
Definition: otl.h:16
otl_iSubtableList
Definition: otl.h:206
#define NULL
Definition: ftobjs.h:61
unsigned int uint32_t
Definition: stdint.h:80
#define length(c)
Definition: ctangleboot.c:65
uint8_t * font_file_pointer
Definition: aliases.h:41
#define FOR_TABLE(name, table)
Definition: aliases.h:33
#define DELETE(fn, ptr)
Definition: otfcc-alloc.h:76
static const Mapping features[]
Definition: otfdescrip.cc:537
static tableid_t featureIndex(const otl_Feature *feature, const table_OTL *table)
Definition: build.c:222
void otfcc_delete_lookup(otl_Lookup *lookup)
Definition: otl.c:38
otl_Subtable * otl_read_gsub_multi(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gsub-multi.c:14
otl_Subtable * otl_read_gpos_markToLigature(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
otl_Subtable * otfcc_readOtl_gsub_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: extend.c:24
otl_Subtable * otl_read_gsub_single(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gsub-single.c:23
otl_iLookupPtr
Definition: otl.d:20919
otl_Subtable * otl_read_gpos_cursive(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gpos-cursive.c:14
otl_iLookupList
Definition: otl.d:20921
otl_iFeatureRefList
Definition: otl.d:20942
otl_Subtable * otl_read_gpos_markToSingle(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
otl_Subtable * otl_read_gsub_ligature(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gsub-ligature.c:13
otl_Subtable * otfcc_readOtl_gpos_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: extend.c:30
otl_Subtable * otl_read_gsub_reverse(const font_file_pointer data, uint32_t tableLength, uint32_t offset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gsub-reverse.c:31
otl_iFeaturePtr
Definition: otl.d:20935
otl_iLookupRefList
Definition: otl.d:20927
otl_Subtable * otl_read_gpos_single(const font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gpos-single.c:14
otl_iFeatureList
Definition: otl.d:20937
otl_iLangSystemList
Definition: otl.d:20952
table_iOTL
Definition: otl.d:20959
otl_Subtable * otl_read_gpos_pair(const font_file_pointer data, uint32_t tableLength, uint32_t offset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: gpos-pair.c:35
otl_iLanguageSystem
Definition: otl.d:20950
int k
Definition: otp-parser.c:70
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst st
uint16_t tableid_t
Definition: primitives.h:17
uint16_t glyphid_t
Definition: primitives.h:14
static table_OTL * otfcc_readOtl_common(font_file_pointer data, uint32_t tableLength, otl_LookupType lookup_type_base, const otfcc_Options *options)
Definition: read.c:56
otl_Subtable * otfcc_readOtl_subtable(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, otl_LookupType lookupType, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: read.c:7
table_OTL * otfcc_readOtl(otfcc_Packet packet, const otfcc_Options *options, uint32_t tag, glyphid_t maxGlyphs)
Definition: read.c:246
static void otfcc_readOtl_lookup(font_file_pointer data, uint32_t tableLength, otl_Lookup *lookup, glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: read.c:196
#define LOOKUP_READER(llt, fn)
Definition: read.c:3
static void parseLanguage(font_file_pointer data, uint32_t tableLength, uint32_t base, otl_LanguageSystem *lang, otl_FeatureList *features)
Definition: read.c:33
otl_Subtable * otl_read_chaining(const font_file_pointer data, uint32_t tableLength, uint32_t offset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: read.c:391
otl_Subtable * otl_read_contextual(const font_file_pointer data, uint32_t tableLength, uint32_t offset, const glyphid_t maxGlyphs, const otfcc_Options *options)
Definition: read.c:213
#define checkLength(offset)
Definition: common.h:13
sds sdscatprintf(sds s, const char *fmt,...)
sds sdsempty(void)
uint16 * lookups
Definition: parsettfatt.c:194
Definition: zic.c:306
uint16 type
Definition: parsettfatt.c:198
uint16 flags
Definition: parsettfatt.c:199
size_t length
Definition: otl.d:20920
otl_LookupPtr * items
Definition: otl.d:20920
Definition: stemdb.c:56
Definition: otl.h:253
otl_LookupList lookups
Definition: otl.h:254
Definition: table.h:30
Definition: xmlparse.c:179
int j
Definition: t4ht.c:1589
#define FAIL(ec)
const char SCRIPT_LANGUAGE_SEPARATOR
Definition: constants.c:3