Debian Codegraph @

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

raw
1 #include "vhea.h"
2
3 #include "support/util.h"
4
5 static INLINE void initVhea(table_vhea *vhea) {
6 memset(vhea, 0, sizeof(*vhea));
7 vhea->version = 0x10000;
8 }
9 static INLINE void disposeVhea(MOVE table_vhea *vhea) {
10 // trivial
11 }
12 caryll_standardRefType(table_vhea, table_iVhea, initVhea, disposeVhea);
13
14 table_vhea *otfcc_readVhea(const otfcc_Packet packet, const otfcc_Options *options) {
15 table_vhea *vhea = NULL;
16 FOR_TABLE(OTFCC_CHR('v','h','e','a'), table) {
17 font_file_pointer data = table.data;
18 size_t length = table.length;
19 if (length >= 36) {
20 NEW(vhea);
21 vhea->version = read_32s(data);
22 vhea->ascent = read_16s(data + 4);
23 vhea->descent = read_16s(data + 6);
24 vhea->lineGap = read_16s(data + 8);
25 vhea->advanceHeightMax = read_16s(data + 10);
26 vhea->minTop = read_16s(data + 12);
27 vhea->minBottom = read_16s(data + 14);
28 vhea->yMaxExtent = read_16s(data + 16);
29 vhea->caretSlopeRise = read_16s(data + 18);
30 vhea->caretSlopeRun = read_16s(data + 20);
31 vhea->caretOffset = read_16s(data + 22);
32 vhea->dummy0 = 0;
33 vhea->dummy1 = 0;
34 vhea->dummy2 = 0;
35 vhea->dummy3 = 0;
36 vhea->metricDataFormat = 0;
37 vhea->numOfLongVerMetrics = read_16u(data + 34);
38 return vhea;
39 } else {
40 logWarning("Table 'vhea' corrupted.")
41 }
42 }
43 return NULL;
44 }
45 void otfcc_dumpVhea(const table_vhea *table, json_value *root, const otfcc_Options *options) {
46 if (!table) return;
47 json_value *vhea = json_object_new(11);
48 loggedStep("vhea") {
49 json_object_push(vhea, "version", json_double_new(otfcc_from_fixed(table->version)));
50 json_object_push(vhea, "ascent", json_integer_new(table->ascent));
51 json_object_push(vhea, "descent", json_integer_new(table->descent));
52 json_object_push(vhea, "lineGap", json_integer_new(table->lineGap));
53 json_object_push(vhea, "advanceHeightMax", json_integer_new(table->advanceHeightMax));
54 json_object_push(vhea, "minTop", json_integer_new(table->minTop));
55 json_object_push(vhea, "minBottom", json_integer_new(table->minBottom));
56 json_object_push(vhea, "yMaxExtent", json_integer_new(table->yMaxExtent));
57 json_object_push(vhea, "caretSlopeRise", json_integer_new(table->caretSlopeRise));
58 json_object_push(vhea, "caretSlopeRun", json_integer_new(table->caretSlopeRun));
59 json_object_push(vhea, "caretOffset", json_integer_new(table->caretOffset));
60 json_object_push(root, "vhea", vhea);
61 }
62 }
63
64 table_vhea *otfcc_parseVhea(const json_value *root, const otfcc_Options *options) {
65 table_vhea *vhea = NULL;
66 json_value *table = NULL;
67 if ((table = json_obj_get_type(root, "vhea", json_object))) {
68 vhea = table_iVhea.create();
69 if (!vhea) return NULL;
70 loggedStep("vhea") {
71 vhea->version = otfcc_to_fixed(json_obj_getnum(table, "version"));
72 vhea->ascent = json_obj_getnum_fallback(table, "ascent", 0);
73 vhea->descent = json_obj_getnum_fallback(table, "descent", 0);
74 vhea->lineGap = json_obj_getnum_fallback(table, "lineGap", 0);
75 vhea->advanceHeightMax = json_obj_getnum_fallback(table, "advanceHeightMax", 0);
76 vhea->minTop = json_obj_getnum_fallback(table, "minTop", 0);
77 vhea->minBottom = json_obj_getnum_fallback(table, "minBottom", 0);
78 vhea->yMaxExtent = json_obj_getnum_fallback(table, "yMaxExtent", 0);
79 vhea->caretSlopeRise = json_obj_getnum_fallback(table, "caretSlopeRise", 0);
80 vhea->caretSlopeRun = json_obj_getnum_fallback(table, "caretSlopeRun", 0);
81 vhea->caretOffset = json_obj_getnum_fallback(table, "caretOffset", 0);
82 }
83 }
84 return vhea;
85 }
86
87 caryll_Buffer *otfcc_buildVhea(const table_vhea *vhea, const otfcc_Options *options) {
88 if (!vhea) return NULL;
89 caryll_Buffer *buf = bufnew();
90 bufwrite32b(buf, vhea->version);
91 bufwrite16b(buf, vhea->ascent);
92 bufwrite16b(buf, vhea->descent);
93 bufwrite16b(buf, vhea->lineGap);
94 bufwrite16b(buf, vhea->advanceHeightMax);
95 bufwrite16b(buf, vhea->minTop);
96 bufwrite16b(buf, vhea->minBottom);
97 bufwrite16b(buf, vhea->yMaxExtent);
98 bufwrite16b(buf, vhea->caretSlopeRise);
99 bufwrite16b(buf, vhea->caretSlopeRun);
100 bufwrite16b(buf, vhea->caretOffset);
101 bufwrite16b(buf, 0);
102 bufwrite16b(buf, 0);
103 bufwrite16b(buf, 0);
104 bufwrite16b(buf, 0);
105 bufwrite16b(buf, 0);
106 bufwrite16b(buf, vhea->numOfLongVerMetrics);
107 return buf;
108 }