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)  

caryll-sfnt-builder.c
Go to the documentation of this file.
1 #include "support/util.h"
2 #include "otfcc/sfnt-builder.h"
3 
4 #define OTFCC_CHR(a,b,c,d) ( ((a)<<24) | ((b)<<16) | ((c)<<8) | (d) )
5 
7  uint32_t actualLength = (uint32_t)buflen(buffer);
9  uint32_t sum = 0;
10  {
11  uint32_t *start = (uint32_t *)buffer->data;
12  uint32_t *end = start + ((actualLength + 3) & ~3) / sizeof(uint32_t);
13  while (start < end) {
14  sum += otfcc_endian_convert32(*start++);
15  }
16  }
17  return sum;
18 }
19 
22  NEW(table);
23  table->tag = tag;
24  table->length = (uint32_t)buflen(buffer);
26  table->buffer = buffer;
27 
28  uint32_t sum = 0;
29  {
30  uint32_t *start = (uint32_t *)buffer->data;
31  uint32_t *end = start + ((table->length + 3) & ~3) / sizeof(uint32_t);
32  while (start < end) {
33  sum += otfcc_endian_convert32(*start++);
34  }
35  }
36  table->checksum = sum;
37  return table;
38 }
39 
41  otfcc_SFNTBuilder *builder;
42  NEW(builder);
43  builder->count = 0;
44  builder->header = header;
45  builder->tables = NULL;
46  builder->options = options;
47  return builder;
48 }
49 
51  if (!builder) return;
53  HASH_ITER(hh, builder->tables, item, tmp) {
54  HASH_DEL(builder->tables, item);
55  buffree(item->buffer);
56  FREE(item);
57  }
58  FREE(builder);
59 }
60 
62  if (!builder || !buffer) return;
64  const otfcc_Options *options = builder->options;
65  HASH_FIND_INT(builder->tables, &tag, item);
66  if (!item) {
68  HASH_ADD_INT(builder->tables, tag, item);
69  logProgress("OpenType table %c%c%c%c successfully built.\n", (tag >> 24) & 0xff,
70  (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff);
71  } else {
72  buffree(buffer);
73  }
74 }
75 
77  return (a->tag - b->tag);
78 }
79 
82  if (!builder) return buffer;
83  uint16_t nTables = HASH_COUNT(builder->tables);
84  uint16_t searchRange = (nTables < 16 ? 8 : nTables < 32 ? 16 : nTables < 64 ? 32 : 64) * 16;
85  bufwrite32b(buffer, builder->header);
86  bufwrite16b(buffer, nTables);
87  bufwrite16b(buffer, searchRange);
88  bufwrite16b(buffer, (nTables < 16 ? 3 : nTables < 32 ? 4 : nTables < 64 ? 5 : 6));
89  bufwrite16b(buffer, nTables * 16 - searchRange);
90 
92  size_t offset = 12 + nTables * 16;
93  size_t headOffset = offset;
94  HASH_SORT(builder->tables, byTag);
95  foreach_hash(table, builder->tables) {
96  // write table directory
98  bufwrite32b(buffer, table->checksum);
100  bufwrite32b(buffer, table->length);
101  size_t cp = buffer->cursor;
103  bufwrite_buf(buffer, table->buffer);
104  bufseek(buffer, cp);
105  // record where the [head] is
106  if (table->tag == OTFCC_CHR('h','e','a','d')) { headOffset = offset; }
107  offset += buflen(table->buffer);
108  }
109 
110  // write head.checksumAdjust
111  uint32_t wholeChecksum = buf_checksum(buffer);
112  bufseek(buffer, headOffset + 8);
113  bufwrite32b(buffer, 0xB1B0AFBA - wholeChecksum);
114  return buffer;
115 }
cp
Definition: action.c:1035
#define buflen
Definition: afm2pl.c:181
struct @88 table[500]
static uint32_t otfcc_endian_convert32(uint32_t i)
Definition: bin-io.h:43
static char * options
Definition: bmeps.c:236
static int item
Definition: brushtopbm.c:66
void otfcc_SFNTBuilder_pushTable(otfcc_SFNTBuilder *builder, uint32_t tag, caryll_Buffer *buffer)
caryll_Buffer * otfcc_SFNTBuilder_serialize(otfcc_SFNTBuilder *builder)
#define OTFCC_CHR(a, b, c, d)
static uint32_t buf_checksum(caryll_Buffer *buffer)
static int byTag(otfcc_SFNTTableEntry *a, otfcc_SFNTTableEntry *b)
otfcc_SFNTBuilder * otfcc_newSFNTBuilder(uint32_t header, const otfcc_Options *options)
void otfcc_deleteSFNTBuilder(otfcc_SFNTBuilder *builder)
static otfcc_SFNTTableEntry * createSegment(uint32_t tag, caryll_Buffer *buffer)
#define b
Definition: jpegint.h:372
long hh
Definition: dvi2xx.h:579
#define a(n)
Definition: gpos-common.c:148
const unsigned char FREE
Definition: image.cpp:34
#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
union hdr header
Definition: pbmtomacp.c:291
#define foreach_hash(id, range)
Definition: aliases.h:39
#define logProgress(...)
Definition: aliases.h:20
static int offset
Definition: ppmtogif.c:642
void bufwrite_buf(caryll_Buffer *buf, caryll_Buffer *that)
Definition: buffer.c:156
void bufwrite32b(caryll_Buffer *buf, uint32_t x)
Definition: buffer.c:82
void buflongalign(caryll_Buffer *buf)
Definition: buffer.c:176
void buffree(caryll_Buffer *buf)
Definition: buffer.c:10
void bufseek(caryll_Buffer *buf, size_t pos)
Definition: buffer.c:21
void bufwrite16b(caryll_Buffer *buf, uint16_t x)
Definition: buffer.c:58
caryll_Buffer * bufnew(void)
Definition: buffer.c:4
#define uint32_t
Definition: stdint.in.h:168
Definition: utils.c:300
otfcc_SFNTTableEntry * tables
Definition: sfnt-builder.h:20
const otfcc_Options * options
Definition: sfnt-builder.h:21
Definition: table.h:30
unsigned long tag
Definition: xmlparse.c:179
tag int tag
Definition: tex4ht.c:2554
#define HASH_DEL(head, delptr)
Definition: uthash.h:498
#define HASH_ITER(hh, head, el, tmp)
Definition: uthash.h:1131
#define HASH_COUNT(head)
Definition: uthash.h:1137
#define HASH_SORT(head, cmpfcn)
Definition: uthash.h:960
#define HASH_FIND_INT(head, findint, out)
Definition: uthash.h:486
#define HASH_ADD_INT(head, intfield, add)
Definition: uthash.h:488
@ start
Definition: preamble.c:52
#define buffer
Definition: xmlparse.c:611
#define end(cp)
Definition: zic.c:71