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-single.c
Go to the documentation of this file.
1 #include "gsub-single.h"
2 
4  entry->from = Handle.empty();
5  entry->to = Handle.empty();
6 }
9  dst->from = Handle.dup(src->from);
10  dst->to = Handle.dup(src->to);
11 }
13  Handle.dispose(&entry->from);
14  Handle.dispose(&entry->to);
15 }
16 
18  .init = gss_entry_ctor, .copy = gss_entry_copyctor, .dispose = gss_entry_dtor};
19 
22 
24  uint32_t subtableOffset, const glyphid_t maxGlyphs,
25  const otfcc_Options *options) {
26  subtable_gsub_single *subtable = iSubtable_gsub_single.create();
27  otl_Coverage *from = NULL;
28  otl_Coverage *to = NULL;
29  if (tableLength < subtableOffset + 6) goto FAIL;
30 
31  uint16_t subtableFormat = read_16u(data + subtableOffset);
32  from = Coverage.read(data, tableLength, subtableOffset + read_16u(data + subtableOffset + 2));
33  if (!from || from->numGlyphs == 0) goto FAIL;
34 
35  if (subtableFormat == 1) {
36  NEW(to);
37  to->numGlyphs = from->numGlyphs;
38  NEW(to->glyphs, to->numGlyphs);
39 
40  uint16_t delta = read_16u(data + subtableOffset + 4);
41  for (glyphid_t j = 0; j < from->numGlyphs; j++) {
42  to->glyphs[j] = Handle.fromIndex(from->glyphs[j].index + delta);
43  }
44  } else {
45  glyphid_t toglyphs = read_16u(data + subtableOffset + 4);
46  if (tableLength < subtableOffset + 6 + toglyphs * 2 || toglyphs != from->numGlyphs)
47  goto FAIL;
48  NEW(to);
49  to->numGlyphs = toglyphs;
50  NEW(to->glyphs, to->numGlyphs);
51 
52  for (glyphid_t j = 0; j < to->numGlyphs; j++) {
53  to->glyphs[j] = Handle.fromIndex(read_16u(data + subtableOffset + 6 + j * 2));
54  }
55  }
56  goto OK;
57 FAIL:
58  iSubtable_gsub_single.free(subtable);
59  if (from) Coverage.free(from);
60  if (to) Coverage.free(to);
61  return NULL;
62 OK:
63  for (glyphid_t j = 0; j < from->numGlyphs; j++) {
65  .from = Handle.dup(from->glyphs[j]), // from
66  .to = Handle.dup(to->glyphs[j]), // to
67  }));
68  }
69  if (from) Coverage.free(from);
70  if (to) Coverage.free(to);
71  return (otl_Subtable *)subtable;
72 }
73 
75  const subtable_gsub_single *subtable = &(_subtable->gsub_single);
76  json_value *st = json_object_new(subtable->length);
77  for (size_t j = 0; j < subtable->length; j++) {
78  json_object_push(st, subtable->items[j].from.name,
79  json_string_new(subtable->items[j].to.name));
80  }
81  return st;
82 }
83 
85  subtable_gsub_single *subtable = iSubtable_gsub_single.create();
86  for (glyphid_t j = 0; j < _subtable->u.object.length; j++) {
87  if (_subtable->u.object.values[j].value &&
88  _subtable->u.object.values[j].value->type == json_string) {
89  glyph_handle from = Handle.fromName(sdsnewlen(
90  _subtable->u.object.values[j].name, _subtable->u.object.values[j].name_length));
92  Handle.fromName(sdsnewlen(_subtable->u.object.values[j].value->u.string.ptr,
93  _subtable->u.object.values[j].value->u.string.length));
94  iSubtable_gsub_single.push(subtable, ((otl_GsubSingleEntry){.from = from, .to = to}));
95  }
96  }
97  return (otl_Subtable *)subtable;
98 };
99 
101  const subtable_gsub_single *subtable = &(_subtable->gsub_single);
102  bool isConstantDifference = subtable->length > 0;
103  if (isConstantDifference) {
104  int32_t difference = subtable->items[0].to.index - subtable->items[0].from.index;
105  isConstantDifference = isConstantDifference && difference < 0x8000 && difference > -0x8000;
106  for (glyphid_t j = 1; j < subtable->length; j++) {
107  int32_t diffJ = subtable->items[j].to.index - subtable->items[j].from.index;
108  isConstantDifference = isConstantDifference && diffJ == difference
109  && diffJ < 0x8000 && diffJ > -0x8000;
110  }
111  }
112  otl_Coverage *cov = Coverage.create();
113  for (glyphid_t j = 0; j < subtable->length; j++) {
114  Coverage.push(cov, Handle.dup(subtable->items[j].from));
115  }
116 
117  caryll_Buffer *coverageBuf = Coverage.buildFormat(cov, heuristics & OTL_BH_GSUB_VERT ? 1 : 0);
118 
119  if (isConstantDifference && !(heuristics & OTL_BH_GSUB_VERT)) {
120  bk_Block *b =
121  bk_new_Block(b16, 1, // Format
122  p16, bk_newBlockFromBuffer(coverageBuf), // coverage
123  b16,
124  subtable->items[0].to.index - subtable->items[0].from.index, // delta
125  bkover);
126  Coverage.free(cov);
127  return bk_build_Block(b);
128  } else {
129  bk_Block *b = bk_new_Block(b16, 2, // Format
130  p16, bk_newBlockFromBuffer(coverageBuf), // coverage
131  b16, subtable->length, // quantity
132  bkover);
133  for (glyphid_t k = 0; k < subtable->length; k++) {
134  bk_push(b, b16, subtable->items[k].to.index, bkover);
135  }
136  Coverage.free(cov);
137  return bk_build_Block(b);
138  }
139 }
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
#define b
Definition: jpegint.h:372
struct rect data
Definition: dvipdfm.c:64
json_value * json_string_new(const char *)
json_value * json_object_push(json_value *object, const char *name, json_value *)
json_value * json_object_new(size_t length)
#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
signed int int32_t
Definition: stdint.h:77
#define COPY
Definition: gzguts.h:166
pdf_obj * entry
Definition: pdfdoc.c:64
#define Handle
Definition: aliases.h:45
uint8_t * font_file_pointer
Definition: aliases.h:41
#define Coverage
Definition: aliases.h:58
otl_BuildHeuristics
Definition: otl.d:20979
@ OTL_BH_GSUB_VERT
Definition: otl.d:20981
iSubtable_gsub_single
Definition: otl.d:20754
int k
Definition: otp-parser.c:70
#define MODIFY
Definition: ownership.h:7
static int delta
Definition: pbmtolj.c:36
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
real to[600]
Definition: pmxab.c:87
uint16_t glyphid_t
Definition: primitives.h:14
@ json_string
Definition: json.h:89
sds sdsnewlen(const void *init, size_t initlen)
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
OWNING sds name
Definition: handle.h:21
glyphid_t index
Definition: handle.h:20
otfcc_GlyphHandle * glyphs
Definition: coverage.h:8
glyphid_t numGlyphs
Definition: coverage.h:6
OWNING otfcc_GlyphHandle to
Definition: otl.h:49
OWNING otfcc_GlyphHandle from
Definition: otl.h:48
Definition: stemdb.c:56
otl_GsubSingleEntry * items
Definition: otl.d:20753
int j
Definition: t4ht.c:1589
static void gss_entry_ctor(MODIFY otl_GsubSingleEntry *entry)
Definition: gsub-single.c:3
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
caryll_Buffer * otfcc_build_gsub_single_subtable(const otl_Subtable *_subtable, otl_BuildHeuristics heuristics)
Definition: gsub-single.c:100
otl_Subtable * otl_gsub_parse_single(const json_value *_subtable, const otfcc_Options *options)
Definition: gsub-single.c:84
static caryll_ElementInterface(otl_GsubSingleEntry)
Definition: gsub-single.c:17
caryll_standardVectorImpl(subtable_gsub_single, otl_GsubSingleEntry, gss_typeinfo, iSubtable_gsub_single)
static void gss_entry_dtor(MODIFY otl_GsubSingleEntry *entry)
Definition: gsub-single.c:12
static void gss_entry_copyctor(MODIFY otl_GsubSingleEntry *dst, COPY const otl_GsubSingleEntry *src)
Definition: gsub-single.c:7
json_value * otl_gsub_dump_single(const otl_Subtable *_subtable)
Definition: gsub-single.c:74
subtable_gsub_single gsub_single
Definition: otl.h:187
#define FAIL(ec)
#define OK
Definition: vlna.c:3