| 1 |
#include "hhea.h" |
| 2 |
|
| 3 |
#include "support/util.h" |
| 4 |
|
| 5 |
static INLINE void initHhea(table_hhea *hhea) { |
| 6 |
memset(hhea, 0, sizeof(*hhea)); |
| 7 |
hhea->version = 0x10000; |
| 8 |
} |
| 9 |
static INLINE void disposeHhea(MOVE table_hhea *hhea) { |
| 10 |
// trivial |
| 11 |
} |
| 12 |
caryll_standardRefType(table_hhea, table_iHhea, initHhea, disposeHhea); |
| 13 |
|
| 14 |
table_hhea *otfcc_readHhea(const otfcc_Packet packet, const otfcc_Options *options) { |
| 15 |
FOR_TABLE(OTFCC_CHR('h','h','e','a'), table) { |
| 16 |
font_file_pointer data = table.data; |
| 17 |
uint32_t length = table.length; |
| 18 |
|
| 19 |
if (length < 36) { |
| 20 |
logWarning("table 'hhea' corrupted.\n"); |
| 21 |
} else { |
| 22 |
table_hhea *hhea; |
| 23 |
NEW(hhea); |
| 24 |
hhea->version = read_32s(data); |
| 25 |
hhea->ascender = read_16u(data + 4); |
| 26 |
hhea->descender = read_16u(data + 6); |
| 27 |
hhea->lineGap = read_16u(data + 8); |
| 28 |
hhea->advanceWidthMax = read_16u(data + 10); |
| 29 |
hhea->minLeftSideBearing = read_16u(data + 12); |
| 30 |
hhea->minRightSideBearing = read_16u(data + 14); |
| 31 |
hhea->xMaxExtent = read_16u(data + 16); |
| 32 |
hhea->caretSlopeRise = read_16u(data + 18); |
| 33 |
hhea->caretSlopeRun = read_16u(data + 20); |
| 34 |
hhea->caretOffset = read_16u(data + 22); |
| 35 |
hhea->reserved[0] = read_16u(data + 24); |
| 36 |
hhea->reserved[1] = read_16u(data + 26); |
| 37 |
hhea->reserved[2] = read_16u(data + 28); |
| 38 |
hhea->reserved[3] = read_16u(data + 30); |
| 39 |
hhea->metricDataFormat = read_16u(data + 32); |
| 40 |
hhea->numberOfMetrics = read_16u(data + 34); |
| 41 |
return hhea; |
| 42 |
} |
| 43 |
} |
| 44 |
return NULL; |
| 45 |
} |
| 46 |
|
| 47 |
void otfcc_dumpHhea(const table_hhea *table, json_value *root, const otfcc_Options *options) { |
| 48 |
if (!table) return; |
| 49 |
loggedStep("hhea") { |
| 50 |
json_value *hhea = json_object_new(13); |
| 51 |
json_object_push(hhea, "version", json_double_new(otfcc_from_fixed(table->version))); |
| 52 |
json_object_push(hhea, "ascender", json_integer_new(table->ascender)); |
| 53 |
json_object_push(hhea, "descender", json_integer_new(table->descender)); |
| 54 |
json_object_push(hhea, "lineGap", json_integer_new(table->lineGap)); |
| 55 |
json_object_push(hhea, "advanceWidthMax", json_integer_new(table->advanceWidthMax)); |
| 56 |
json_object_push(hhea, "minLeftSideBearing", json_integer_new(table->minLeftSideBearing)); |
| 57 |
json_object_push(hhea, "minRightSideBearing", json_integer_new(table->minRightSideBearing)); |
| 58 |
json_object_push(hhea, "xMaxExtent", json_integer_new(table->xMaxExtent)); |
| 59 |
json_object_push(hhea, "caretSlopeRise", json_integer_new(table->caretSlopeRise)); |
| 60 |
json_object_push(hhea, "caretSlopeRun", json_integer_new(table->caretSlopeRun)); |
| 61 |
json_object_push(hhea, "caretOffset", json_integer_new(table->caretOffset)); |
| 62 |
json_object_push(root, "hhea", hhea); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
table_hhea *otfcc_parseHhea(const json_value *root, const otfcc_Options *options) { |
| 67 |
table_hhea *hhea = table_iHhea.create(); |
| 68 |
json_value *table = NULL; |
| 69 |
if ((table = json_obj_get_type(root, "hhea", json_object))) { |
| 70 |
loggedStep("hhea") { |
| 71 |
hhea->version = otfcc_to_fixed(json_obj_getnum_fallback(table, "version", 0)); |
| 72 |
hhea->ascender = json_obj_getnum_fallback(table, "ascender", 0); |
| 73 |
hhea->descender = json_obj_getnum_fallback(table, "descender", 0); |
| 74 |
hhea->lineGap = json_obj_getnum_fallback(table, "lineGap", 0); |
| 75 |
hhea->advanceWidthMax = json_obj_getnum_fallback(table, "advanceWidthMax", 0); |
| 76 |
hhea->minLeftSideBearing = json_obj_getnum_fallback(table, "minLeftSideBearing", 0); |
| 77 |
hhea->minRightSideBearing = json_obj_getnum_fallback(table, "minRightSideBearing", 0); |
| 78 |
hhea->xMaxExtent = json_obj_getnum_fallback(table, "xMaxExtent", 0); |
| 79 |
hhea->caretSlopeRise = json_obj_getnum_fallback(table, "caretSlopeRise", 0); |
| 80 |
hhea->caretSlopeRun = json_obj_getnum_fallback(table, "caretSlopeRun", 0); |
| 81 |
hhea->caretOffset = json_obj_getnum_fallback(table, "caretOffset", 0); |
| 82 |
} |
| 83 |
} |
| 84 |
return hhea; |
| 85 |
} |
| 86 |
|
| 87 |
caryll_Buffer *otfcc_buildHhea(const table_hhea *hhea, const otfcc_Options *options) { |
| 88 |
if (!hhea) return NULL; |
| 89 |
caryll_Buffer *buf = bufnew(); |
| 90 |
bufwrite32b(buf, hhea->version); |
| 91 |
bufwrite16b(buf, hhea->ascender); |
| 92 |
bufwrite16b(buf, hhea->descender); |
| 93 |
bufwrite16b(buf, hhea->lineGap); |
| 94 |
bufwrite16b(buf, hhea->advanceWidthMax); |
| 95 |
bufwrite16b(buf, hhea->minLeftSideBearing); |
| 96 |
bufwrite16b(buf, hhea->minRightSideBearing); |
| 97 |
bufwrite16b(buf, hhea->xMaxExtent); |
| 98 |
bufwrite16b(buf, hhea->caretSlopeRise); |
| 99 |
bufwrite16b(buf, hhea->caretSlopeRun); |
| 100 |
bufwrite16b(buf, hhea->caretOffset); |
| 101 |
bufwrite16b(buf, hhea->reserved[0]); |
| 102 |
bufwrite16b(buf, hhea->reserved[1]); |
| 103 |
bufwrite16b(buf, hhea->reserved[2]); |
| 104 |
bufwrite16b(buf, hhea->reserved[3]); |
| 105 |
bufwrite16b(buf, 0); |
| 106 |
bufwrite16b(buf, hhea->numberOfMetrics); |
| 107 |
return buf; |
| 108 |
} |