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)  

build.c
Go to the documentation of this file.
1 #include "../glyf.h"
2 
3 #include "support/util.h"
5 
7  if (!buflen(flags)) return (flags);
8  caryll_Buffer *shrunk = bufnew();
9  bufwrite8(shrunk, flags->data[0]);
10  int repeating = 0;
11  for (size_t j = 1; j < buflen(flags); j++) {
12  if (flags->data[j] == flags->data[j - 1]) {
13  if (repeating && repeating < 0xFE) {
14  shrunk->data[shrunk->cursor - 1] += 1;
15  repeating += 1;
16  } else if (repeating == 0) {
17  shrunk->data[shrunk->cursor - 1] |= GLYF_FLAG_REPEAT;
18  bufwrite8(shrunk, 1);
19  repeating += 1;
20  } else {
21  repeating = 0;
22  bufwrite8(shrunk, flags->data[j]);
23  }
24  } else {
25  repeating = 0;
26  bufwrite8(shrunk, flags->data[j]);
27  }
28  }
29  buffree(flags);
30  return shrunk;
31 }
32 
33 // serialize
34 #define EPSILON (1e-5)
35 static void glyf_build_simple(const glyf_Glyph *g, caryll_Buffer *gbuf) {
37  caryll_Buffer *xs = bufnew();
38  caryll_Buffer *ys = bufnew();
39 
40  bufwrite16b(gbuf, g->contours.length);
41  bufwrite16b(gbuf, (int16_t)g->stat.xMin);
42  bufwrite16b(gbuf, (int16_t)g->stat.yMin);
43  bufwrite16b(gbuf, (int16_t)g->stat.xMax);
44  bufwrite16b(gbuf, (int16_t)g->stat.yMax);
45 
46  // endPtsOfContours[n]
47  shapeid_t ptid = 0;
48  for (shapeid_t j = 0; j < g->contours.length; j++) {
49  ptid += g->contours.items[j].length;
50  bufwrite16b(gbuf, ptid - 1);
51  }
52 
53  // instructions
54  bufwrite16b(gbuf, g->instructionsLength);
55  if (g->instructions) bufwrite_bytes(gbuf, g->instructionsLength, g->instructions);
56 
57  // flags and points
58  bufclear(flags);
59  bufclear(xs);
60  bufclear(ys);
61  int32_t cx = 0;
62  int32_t cy = 0;
63  for (shapeid_t cj = 0; cj < g->contours.length; cj++) {
64  for (shapeid_t k = 0; k < g->contours.items[cj].length; k++) {
65  glyf_Point *p = &(g->contours.items[cj].items[k]);
66  uint8_t flag = (p->onCurve & MASK_ON_CURVE) ? GLYF_FLAG_ON_CURVE : 0;
67  int32_t px = round(iVQ.getStill(p->x));
68  int32_t py = round(iVQ.getStill(p->y));
69  int16_t dx = (int16_t)(px - cx);
70  int16_t dy = (int16_t)(py - cy);
71  if (dx == 0) {
73  } else if (dx >= -0xFF && dx <= 0xFF) {
75  if (dx > 0) {
77  bufwrite8(xs, dx);
78  } else {
79  bufwrite8(xs, -dx);
80  }
81  } else {
82  bufwrite16b(xs, dx);
83  }
84 
85  if (dy == 0) {
87  } else if (dy >= -0xFF && dy <= 0xFF) {
89  if (dy > 0) {
91  bufwrite8(ys, dy);
92  } else {
93  bufwrite8(ys, -dy);
94  }
95  } else {
96  bufwrite16b(ys, dy);
97  }
99  cx = px;
100  cy = py;
101  }
102  }
104  bufwrite_buf(gbuf, flags);
105  bufwrite_buf(gbuf, xs);
106  bufwrite_buf(gbuf, ys);
107 
108  buffree(flags);
109  buffree(xs);
110  buffree(ys);
111 }
112 static void glyf_build_composite(const glyf_Glyph *g, caryll_Buffer *gbuf) {
113  bufwrite16b(gbuf, (-1));
114  bufwrite16b(gbuf, (int16_t)g->stat.xMin);
115  bufwrite16b(gbuf, (int16_t)g->stat.yMin);
116  bufwrite16b(gbuf, (int16_t)g->stat.xMax);
117  bufwrite16b(gbuf, (int16_t)g->stat.yMax);
118  for (shapeid_t rj = 0; rj < g->references.length; rj++) {
119  glyf_ComponentReference *r = &(g->references.items[rj]);
120  uint16_t flags =
121  (rj < g->references.length - 1 ? MORE_COMPONENTS
122  : g->instructionsLength > 0 ? WE_HAVE_INSTRUCTIONS : 0);
123  bool outputAnchor = r->isAnchored == REF_ANCHOR_CONSOLIDATED;
124 
125  union {
126  uint16_t pointid;
127  int16_t coord;
128  } arg1, arg2;
129 
130  // flags
131  if (outputAnchor) {
132  arg1.pointid = r->outer;
133  arg2.pointid = r->inner;
134  if (!(arg1.pointid < 0x100 && arg2.pointid < 0x100)) { flags |= ARG_1_AND_2_ARE_WORDS; }
135  } else {
137  arg1.coord = iVQ.getStill(r->x);
138  arg2.coord = iVQ.getStill(r->y);
139  if (!(arg1.coord < 128 && arg1.coord >= -128 && arg2.coord < 128 &&
140  arg2.coord >= -128)) {
142  }
143  }
144  if (fabs(r->b) > EPSILON || fabs(r->c) > EPSILON) {
146  } else if (fabs(r->a - 1) > EPSILON || fabs(r->d - 1) > EPSILON) {
147  if (fabs(r->a - r->d) > EPSILON) {
149  } else {
151  }
152  }
153  if (r->roundToGrid) flags |= ROUND_XY_TO_GRID;
154  if (r->useMyMetrics) flags |= USE_MY_METRICS;
156  bufwrite16b(gbuf, flags);
157  bufwrite16b(gbuf, r->glyph.index);
159  bufwrite16b(gbuf, arg1.pointid);
160  bufwrite16b(gbuf, arg2.pointid);
161  } else {
162  bufwrite8(gbuf, arg1.pointid);
163  bufwrite8(gbuf, arg2.pointid);
164  }
165  if (flags & WE_HAVE_A_SCALE) {
166  bufwrite16b(gbuf, otfcc_to_f2dot14(r->a));
167  } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) {
168  bufwrite16b(gbuf, otfcc_to_f2dot14(r->a));
169  bufwrite16b(gbuf, otfcc_to_f2dot14(r->d));
170  } else if (flags & WE_HAVE_A_TWO_BY_TWO) {
171  bufwrite16b(gbuf, otfcc_to_f2dot14(r->a));
172  bufwrite16b(gbuf, otfcc_to_f2dot14(r->b));
173  bufwrite16b(gbuf, otfcc_to_f2dot14(r->c));
174  bufwrite16b(gbuf, otfcc_to_f2dot14(r->d));
175  }
176  }
177  if (g->instructionsLength) {
178  bufwrite16b(gbuf, g->instructionsLength);
179  if (g->instructions) bufwrite_bytes(gbuf, g->instructionsLength, g->instructions);
180  }
181 }
183  const otfcc_Options *options) {
184  caryll_Buffer *bufglyf = bufnew();
185  caryll_Buffer *bufloca = bufnew();
186  if (table && head) {
187  caryll_Buffer *gbuf = bufnew();
188  uint32_t *loca;
189  NEW(loca, table->length + 1);
190  for (glyphid_t j = 0; j < table->length; j++) {
191  loca[j] = (uint32_t)bufglyf->cursor;
192  glyf_Glyph *g = table->items[j];
193  bufclear(gbuf);
194  if (g->contours.length > 0) {
195  glyf_build_simple(g, gbuf);
196  } else if (g->references.length > 0) {
197  glyf_build_composite(g, gbuf);
198  }
199  // pad extra zeroes
200  buflongalign(gbuf);
201  bufwrite_buf(bufglyf, gbuf);
202  }
203  loca[table->length] = (uint32_t)bufglyf->cursor;
204  if (bufglyf->cursor >= 0x20000) {
205  head->indexToLocFormat = 1;
206  } else {
207  head->indexToLocFormat = 0;
208  }
209  // write loca table
210  for (uint32_t j = 0; j <= table->length; j++) {
211  if (head->indexToLocFormat) {
212  bufwrite32b(bufloca, loca[j]);
213  } else {
214  bufwrite16b(bufloca, loca[j] >> 1);
215  }
216  }
217  buffree(gbuf);
218  FREE(loca);
219  }
220  table_GlyfAndLocaBuffers pair = {bufglyf, bufloca};
221  return pair;
222 }
#define buflen
Definition: afm2pl.c:181
long int flag
Definition: f2c.h:53
#define EPSILON
Definition: build.c:34
static void glyf_build_simple(const glyf_Glyph *g, caryll_Buffer *gbuf)
Definition: build.c:35
static void glyf_build_composite(const glyf_Glyph *g, caryll_Buffer *gbuf)
Definition: build.c:112
static caryll_Buffer * shrinkFlags(caryll_Buffer *flags)
Definition: build.c:6
table_GlyfAndLocaBuffers otfcc_buildGlyf(const table_glyf *table, table_head *head, const otfcc_Options *options)
Definition: build.c:182
const unsigned char FREE
Definition: image.cpp:34
@ REF_ANCHOR_CONSOLIDATED
Definition: glyf.h:50
small capitals from c petite p
Definition: afcover.h:72
#define WE_HAVE_A_SCALE
Definition: ttgload.c:73
#define MORE_COMPONENTS
Definition: ttgload.c:75
#define USE_MY_METRICS
Definition: ttgload.c:79
#define UNSCALED_COMPONENT_OFFSET
Definition: ttgload.c:82
#define ARGS_ARE_XY_VALUES
Definition: ttgload.c:71
#define ROUND_XY_TO_GRID
Definition: ttgload.c:72
int int cy
Definition: gdfx.h:13
int cx
Definition: gdfx.h:12
#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
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78
#define WE_HAVE_INSTRUCTIONS
Definition: tt_glyf.c:196
#define WE_HAVE_AN_X_AND_Y_SCALE
Definition: tt_glyf.c:194
#define WE_HAVE_A_TWO_BY_TWO
Definition: tt_glyf.c:195
#define ARG_1_AND_2_ARE_WORDS
Definition: tt_glyf.c:188
#define fabs(x)
Definition: cpascal.h:211
@ GLYF_FLAG_X_SHORT
Definition: glyf.h:35
@ GLYF_FLAG_REPEAT
Definition: glyf.h:37
@ GLYF_FLAG_POSITIVE_Y
Definition: glyf.h:41
@ GLYF_FLAG_SAME_X
Definition: glyf.h:38
@ GLYF_FLAG_POSITIVE_X
Definition: glyf.h:40
@ GLYF_FLAG_ON_CURVE
Definition: glyf.h:34
@ GLYF_FLAG_SAME_Y
Definition: glyf.h:39
@ GLYF_FLAG_Y_SHORT
Definition: glyf.h:36
@ MASK_ON_CURVE
Definition: glyf.h:59
int k
Definition: otp-parser.c:70
#define round(a)
Definition: pbmtopk.c:22
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
int g
Definition: ppmqvga.c:68
int r
Definition: ppmqvga.c:68
uint16_t shapeid_t
Definition: primitives.h:19
uint16_t glyphid_t
Definition: primitives.h:14
int16_t otfcc_to_f2dot14(const double x)
Definition: primitives.c:9
#define flags
#define arg1(arg)
void bufwrite_buf(caryll_Buffer *buf, caryll_Buffer *that)
Definition: buffer.c:156
void bufclear(caryll_Buffer *buf)
Definition: buffer.c:24
void bufwrite32b(caryll_Buffer *buf, uint32_t x)
Definition: buffer.c:82
void buflongalign(caryll_Buffer *buf)
Definition: buffer.c:176
void bufwrite8(caryll_Buffer *buf, uint8_t byte)
Definition: buffer.c:49
void buffree(caryll_Buffer *buf)
Definition: buffer.c:10
void bufwrite16b(caryll_Buffer *buf, uint16_t x)
Definition: buffer.c:58
void bufwrite_bytes(caryll_Buffer *buf, size_t size, const uint8_t *str)
Definition: buffer.c:149
caryll_Buffer * bufnew(void)
Definition: buffer.c:4
#define uint32_t
Definition: stdint.in.h:168
#define int16_t
Definition: stdint.in.h:160
size_t cursor
Definition: buffer.h:11
uint8_t * data
Definition: buffer.h:14
Definition: libppm5.c:414
Definition: ttf.h:354
Definition: head.h:6
Definition: table.h:30
int j
Definition: t4ht.c:1589
iVQ
Definition: vq.h:60