Debian Codegraph @

texk/web2c/mfluadir/otfcc/lib/table/VORG.c

raw
1 #include "VORG.h"
2
3 #include "support/util.h"
4
5 static INLINE void disposeVORG(table_VORG *vorg) {
6 FREE(vorg->entries);
7 }
8
9 caryll_standardRefType(table_VORG, table_iVORG, disposeVORG);
10
11 table_VORG *otfcc_readVORG(const otfcc_Packet packet, const otfcc_Options *options) {
12 FOR_TABLE(OTFCC_CHR('V','O','R','G'), table) {
13 font_file_pointer data = table.data;
14 uint32_t length = table.length;
15 if (length < 8) goto VORG_CORRUPTED;
16 uint16_t numVertOriginYMetrics = read_16u(data + 6);
17 if (length < 8 + 4 * numVertOriginYMetrics) goto VORG_CORRUPTED;
18
19 table_VORG *vorg = table_iVORG.create();
20 vorg->defaultVerticalOrigin = read_16s(data + 4);
21 vorg->numVertOriginYMetrics = numVertOriginYMetrics;
22 NEW(vorg->entries, numVertOriginYMetrics);
23 for (uint16_t j = 0; j < numVertOriginYMetrics; j++) {
24 vorg->entries[j].gid = read_16u(data + 8 + 4 * j);
25 vorg->entries[j].verticalOrigin = read_16s(data + 8 + 4 * j + 2);
26 }
27 return vorg;
28 VORG_CORRUPTED:
29 logWarning("Table 'VORG' corrupted.");
30 }
31 return NULL;
32 }
33
34 caryll_Buffer *otfcc_buildVORG(const table_VORG *table, const otfcc_Options *options) {
35 if (!table) return NULL;
36 caryll_Buffer *buf = bufnew();
37 bufwrite16b(buf, 1);
38 bufwrite16b(buf, 0);
39 bufwrite16b(buf, table->defaultVerticalOrigin);
40 bufwrite16b(buf, table->numVertOriginYMetrics);
41 for (uint16_t j = 0; j < table->numVertOriginYMetrics; j++) {
42 bufwrite16b(buf, table->entries[j].gid);
43 bufwrite16b(buf, table->entries[j].verticalOrigin);
44 }
45 return buf;
46 }