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)  

gsub-reverse.c
Go to the documentation of this file.
1 #include "gsub-reverse.h"
2 
4  subtable->match = NULL;
5  subtable->to = NULL;
6 }
8  if (subtable->match)
9  for (tableid_t j = 0; j < subtable->matchCount; j++) {
10  Coverage.free(subtable->match[j]);
11  }
12  if (subtable->to) Coverage.free(subtable->to);
13 }
14 
17 
18 static void reverseBacktracks(otl_Coverage **match, tableid_t inputIndex) {
19  if (inputIndex > 0) {
20  tableid_t start = 0;
21  tableid_t end = inputIndex - 1;
22  while (end > start) {
23  otl_Coverage *tmp = match[start];
24  match[start] = match[end];
25  match[end] = tmp;
26  end--, start++;
27  }
28  }
29 }
30 
32  uint32_t offset, const glyphid_t maxGlyphs,
33  const otfcc_Options *options) {
34  subtable_gsub_reverse *subtable = iSubtable_gsub_reverse.create();
35  checkLength(offset + 6);
36 
37  tableid_t nBacktrack = read_16u(data + offset + 4);
38  checkLength(offset + 6 + nBacktrack * 2);
39 
40  tableid_t nForward = read_16u(data + offset + 6 + nBacktrack * 2);
41  checkLength(offset + 8 + (nBacktrack + nForward) * 2);
42 
43  tableid_t nReplacement = read_16u(data + offset + 8 + (nBacktrack + nForward) * 2);
44  checkLength(offset + 10 + (nBacktrack + nForward + nReplacement) * 2);
45 
46  subtable->matchCount = nBacktrack + nForward + 1;
47  NEW(subtable->match, subtable->matchCount);
48  subtable->inputIndex = nBacktrack;
49 
50  for (tableid_t j = 0; j < nBacktrack; j++) {
51  uint32_t covOffset = offset + read_16u(data + offset + 6 + j * 2);
52  subtable->match[j] = Coverage.read(data, tableLength, covOffset);
53  }
54  {
55  uint32_t covOffset = offset + read_16u(data + offset + 2);
56  subtable->match[subtable->inputIndex] = Coverage.read(data, tableLength, covOffset);
57  if (nReplacement != subtable->match[subtable->inputIndex]->numGlyphs) goto FAIL;
58  }
59  for (tableid_t j = 0; j < nForward; j++) {
60  uint32_t covOffset = offset + read_16u(data + offset + 8 + nBacktrack * 2 + j * 2);
61  subtable->match[nBacktrack + 1 + j] = Coverage.read(data, tableLength, covOffset);
62  }
63 
64  NEW(subtable->to);
65  subtable->to->numGlyphs = nReplacement;
66  NEW(subtable->to->glyphs, nReplacement);
67  for (tableid_t j = 0; j < nReplacement; j++) {
68  subtable->to->glyphs[j] =
69  Handle.fromIndex(read_16u(data + offset + 10 + (nBacktrack + nForward + j) * 2));
70  }
71  reverseBacktracks(subtable->match, subtable->inputIndex);
72  return (otl_Subtable *)subtable;
73 
74 FAIL:
75  iSubtable_gsub_reverse.free(subtable);
76  return NULL;
77 }
78 
80  const subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse);
81  json_value *_st = json_object_new(3);
82  json_value *_match = json_array_new(subtable->matchCount);
83  for (tableid_t j = 0; j < subtable->matchCount; j++) {
84  json_array_push(_match, Coverage.dump(subtable->match[j]));
85  }
86  json_object_push(_st, "match", _match);
87  json_object_push(_st, "to", Coverage.dump(subtable->to));
88  json_object_push(_st, "inputIndex", json_integer_new(subtable->inputIndex));
89  return _st;
90 }
91 
93  json_value *_match = json_obj_get_type(_subtable, "match", json_array);
94  json_value *_to = json_obj_get_type(_subtable, "to", json_array);
95  if (!_match || !_to) return NULL;
96 
97  subtable_gsub_reverse *subtable = iSubtable_gsub_reverse.create();
98 
99  subtable->matchCount = _match->u.array.length;
100  NEW(subtable->match, subtable->matchCount);
101 
102  subtable->inputIndex = json_obj_getnum_fallback(_subtable, "inputIndex", 0);
103 
104  for (tableid_t j = 0; j < subtable->matchCount; j++) {
105  subtable->match[j] = Coverage.parse(_match->u.array.values[j]);
106  }
107  subtable->to = Coverage.parse(_to);
108  return (otl_Subtable *)subtable;
109 }
110 
112  const subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse);
113  reverseBacktracks(subtable->match, subtable->inputIndex);
114 
115  bk_Block *root = bk_new_Block(b16, 1, // format
117  subtable->match[subtable->inputIndex])), // coverage
118  bkover);
119  bk_push(root, b16, subtable->inputIndex, bkover);
120  for (tableid_t j = 0; j < subtable->inputIndex; j++) {
121  bk_push(root, p16, bk_newBlockFromBuffer(Coverage.build(subtable->match[j])), bkover);
122  }
123  bk_push(root, b16, subtable->matchCount - subtable->inputIndex - 1, bkover);
124  for (tableid_t j = subtable->inputIndex + 1; j < subtable->matchCount; j++) {
125  bk_push(root, p16, bk_newBlockFromBuffer(Coverage.build(subtable->match[j])), bkover);
126  }
127  bk_push(root, b16, subtable->to->numGlyphs, bkover);
128  for (tableid_t j = 0; j < subtable->to->numGlyphs; j++) {
129  bk_push(root, b16, subtable->to->glyphs[j].index, bkover);
130  }
131 
132  return bk_build_Block(root);
133 }
#define match
Definition: aptex-macros.h:359
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
caryll_Buffer * bk_build_Block(bk_Block *root)
Definition: bkgraph.c:396
struct rect data
Definition: dvipdfm.c:64
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 * json_obj_get_type(const json_value *obj, const char *key, const json_type type)
Definition: json-funcs.h:34
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
unsigned int uint32_t
Definition: stdint.h:80
#define INLINE
Definition: port.h:26
#define root
Definition: ctangleboot.c:69
#define Handle
Definition: aliases.h:45
uint8_t * font_file_pointer
Definition: aliases.h:41
#define Coverage
Definition: aliases.h:58
iSubtable_gsub_reverse
Definition: otl.d:20813
otl_BuildHeuristics
Definition: otl.d:20979
static int offset
Definition: ppmtogif.c:642
uint16_t tableid_t
Definition: primitives.h:17
uint16_t glyphid_t
Definition: primitives.h:14
@ json_array
Definition: json.h:86
#define checkLength(offset)
Definition: common.h:13
unsigned int length
Definition: json.h:123
json_object_entry * values
Definition: json.h:132
union _json_value::@1795 u
struct _json_value::@1795::@1799 array
glyphid_t index
Definition: handle.h:20
otfcc_GlyphHandle * glyphs
Definition: coverage.h:8
glyphid_t numGlyphs
Definition: coverage.h:6
OWNING otl_Coverage ** match
Definition: otl.h:108
tableid_t inputIndex
Definition: otl.h:107
tableid_t matchCount
Definition: otl.h:106
OWNING otl_Coverage * to
Definition: otl.h:109
int j
Definition: t4ht.c:1589
caryll_Buffer * otfcc_build_gsub_reverse(const otl_Subtable *_subtable, otl_BuildHeuristics heuristics)
Definition: gsub-reverse.c:111
json_value * otl_gsub_dump_reverse(const otl_Subtable *_subtable)
Definition: gsub-reverse.c:79
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_Subtable * otl_gsub_parse_reverse(const json_value *_subtable, const otfcc_Options *options)
Definition: gsub-reverse.c:92
caryll_standardRefType(subtable_gsub_reverse, iSubtable_gsub_reverse, initGsubReverse, disposeGsubReverse)
static INLINE void disposeGsubReverse(subtable_gsub_reverse *subtable)
Definition: gsub-reverse.c:7
static INLINE void initGsubReverse(subtable_gsub_reverse *subtable)
Definition: gsub-reverse.c:3
static void reverseBacktracks(otl_Coverage **match, tableid_t inputIndex)
Definition: gsub-reverse.c:18
subtable_gsub_reverse gsub_reverse
Definition: otl.h:191
#define FAIL(ec)
@ start
Definition: preamble.c:52
#define end(cp)
Definition: zic.c:71