Debian Codegraph @

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

raw
1 #include "vmtx.h"
2
3 #include "support/util.h"
4
5 static INLINE void disposeVmtx(MOVE table_vmtx *table) {
6 if (table->metrics != NULL) FREE(table->metrics);
7 if (table->topSideBearing != NULL) FREE(table->topSideBearing);
8 }
9
10 caryll_standardRefType(table_vmtx, table_iVmtx, disposeVmtx);
11
12 table_vmtx *otfcc_readVmtx(const otfcc_Packet packet, const otfcc_Options *options,
13 table_vhea *vhea, table_maxp *maxp) {
14 if (!vhea || !maxp || vhea->numOfLongVerMetrics == 0 ||
15 maxp->numGlyphs < vhea->numOfLongVerMetrics)
16 return NULL;
17 FOR_TABLE(OTFCC_CHR('v','m','t','x'), table) {
18 font_file_pointer data = table.data;
19 uint32_t length = table.length;
20
21 table_vmtx *vmtx = NULL;
22
23 glyphid_t count_a = vhea->numOfLongVerMetrics;
24 glyphid_t count_k = maxp->numGlyphs - vhea->numOfLongVerMetrics;
25 if (length < count_a * 4 + count_k * 2) goto vmtx_CORRUPTED;
26
27 NEW(vmtx);
28 NEW(vmtx->metrics, count_a);
29 NEW(vmtx->topSideBearing, count_k);
30
31 for (glyphid_t ia = 0; ia < count_a; ia++) {
32 vmtx->metrics[ia].advanceHeight = read_16u(data + ia * 4);
33 vmtx->metrics[ia].tsb = read_16s(data + ia * 4 + 2);
34 }
35
36 for (glyphid_t ik = 0; ik < count_k; ik++) {
37 vmtx->topSideBearing[ik] = read_16s(data + count_a * 4 + ik * 2);
38 }
39
40 return vmtx;
41 vmtx_CORRUPTED:
42 logWarning("Table 'vmtx' corrupted.\n");
43 if (vmtx) { table_iVmtx.free(vmtx), vmtx = NULL; }
44 }
45 return NULL;
46 }
47
48 caryll_Buffer *otfcc_buildVmtx(const table_vmtx *vmtx, glyphid_t count_a, glyphid_t count_k,
49 const otfcc_Options *options) {
50 if (!vmtx) return NULL;
51 caryll_Buffer *buf = bufnew();
52 if (vmtx->metrics) {
53 for (glyphid_t j = 0; j < count_a; j++) {
54 bufwrite16b(buf, vmtx->metrics[j].advanceHeight);
55 bufwrite16b(buf, vmtx->metrics[j].tsb);
56 }
57 }
58 if (vmtx->topSideBearing) {
59 for (glyphid_t j = 0; j < count_k; j++) {
60 bufwrite16b(buf, vmtx->topSideBearing[j]);
61 }
62 }
63 return buf;
64 }