| 1 |
#include "maxp.h" |
| 2 |
|
| 3 |
#include "support/util.h" |
| 4 |
|
| 5 |
static INLINE void initMaxp(table_maxp *maxp) { |
| 6 |
memset(maxp, 0, sizeof(*maxp)); |
| 7 |
maxp->version = 0x10000; |
| 8 |
} |
| 9 |
static INLINE void disposeMaxp(MOVE table_maxp *maxp) { |
| 10 |
// trivial |
| 11 |
} |
| 12 |
caryll_standardRefType(table_maxp, table_iMaxp, initMaxp, disposeMaxp); |
| 13 |
|
| 14 |
table_maxp *otfcc_readMaxp(const otfcc_Packet packet, const otfcc_Options *options) { |
| 15 |
FOR_TABLE(OTFCC_CHR('m','a','x','p'), table) { |
| 16 |
font_file_pointer data = table.data; |
| 17 |
uint32_t length = table.length; |
| 18 |
|
| 19 |
if (length != 32 && length != 6) { |
| 20 |
logWarning("table 'maxp' corrupted.\n"); |
| 21 |
} else { |
| 22 |
table_maxp *maxp = table_iMaxp.create(); |
| 23 |
maxp->version = read_32s(data); |
| 24 |
maxp->numGlyphs = read_16u(data + 4); |
| 25 |
if (maxp->version == 0x00010000) { // TrueType Format 1 |
| 26 |
maxp->maxPoints = read_16u(data + 6); |
| 27 |
maxp->maxContours = read_16u(data + 8); |
| 28 |
maxp->maxCompositePoints = read_16u(data + 10); |
| 29 |
maxp->maxCompositeContours = read_16u(data + 12); |
| 30 |
maxp->maxZones = read_16u(data + 14); |
| 31 |
maxp->maxTwilightPoints = read_16u(data + 16); |
| 32 |
maxp->maxStorage = read_16u(data + 18); |
| 33 |
maxp->maxFunctionDefs = read_16u(data + 20); |
| 34 |
maxp->maxInstructionDefs = read_16u(data + 22); |
| 35 |
maxp->maxStackElements = read_16u(data + 24); |
| 36 |
maxp->maxSizeOfInstructions = read_16u(data + 26); |
| 37 |
maxp->maxComponentElements = read_16u(data + 28); |
| 38 |
maxp->maxComponentDepth = read_16u(data + 30); |
| 39 |
} else { // CFF OTF Format 0.5 |
| 40 |
maxp->maxPoints = 0; |
| 41 |
maxp->maxContours = 0; |
| 42 |
maxp->maxCompositePoints = 0; |
| 43 |
maxp->maxCompositeContours = 0; |
| 44 |
maxp->maxZones = 0; |
| 45 |
maxp->maxTwilightPoints = 0; |
| 46 |
maxp->maxStorage = 0; |
| 47 |
maxp->maxFunctionDefs = 0; |
| 48 |
maxp->maxInstructionDefs = 0; |
| 49 |
maxp->maxStackElements = 0; |
| 50 |
maxp->maxSizeOfInstructions = 0; |
| 51 |
maxp->maxComponentElements = 0; |
| 52 |
maxp->maxComponentDepth = 0; |
| 53 |
} |
| 54 |
return maxp; |
| 55 |
} |
| 56 |
} |
| 57 |
return NULL; |
| 58 |
} |
| 59 |
|
| 60 |
void otfcc_dumpMaxp(const table_maxp *table, json_value *root, const otfcc_Options *options) { |
| 61 |
if (!table) return; |
| 62 |
loggedStep("maxp") { |
| 63 |
json_value *maxp = json_object_new(15); |
| 64 |
json_object_push(maxp, "version", json_double_new(otfcc_from_fixed(table->version))); |
| 65 |
json_object_push(maxp, "numGlyphs", json_integer_new(table->numGlyphs)); |
| 66 |
json_object_push(maxp, "maxPoints", json_integer_new(table->maxPoints)); |
| 67 |
json_object_push(maxp, "maxContours", json_integer_new(table->maxContours)); |
| 68 |
json_object_push(maxp, "maxCompositePoints", json_integer_new(table->maxCompositePoints)); |
| 69 |
json_object_push(maxp, "maxCompositeContours", |
| 70 |
json_integer_new(table->maxCompositeContours)); |
| 71 |
json_object_push(maxp, "maxZones", json_integer_new(table->maxZones)); |
| 72 |
json_object_push(maxp, "maxTwilightPoints", json_integer_new(table->maxTwilightPoints)); |
| 73 |
json_object_push(maxp, "maxStorage", json_integer_new(table->maxStorage)); |
| 74 |
json_object_push(maxp, "maxFunctionDefs", json_integer_new(table->maxFunctionDefs)); |
| 75 |
json_object_push(maxp, "maxInstructionDefs", json_integer_new(table->maxInstructionDefs)); |
| 76 |
json_object_push(maxp, "maxStackElements", json_integer_new(table->maxStackElements)); |
| 77 |
json_object_push(maxp, "maxSizeOfInstructions", |
| 78 |
json_integer_new(table->maxSizeOfInstructions)); |
| 79 |
json_object_push(maxp, "maxComponentElements", |
| 80 |
json_integer_new(table->maxComponentElements)); |
| 81 |
json_object_push(maxp, "maxComponentDepth", json_integer_new(table->maxComponentDepth)); |
| 82 |
json_object_push(root, "maxp", maxp); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
table_maxp *otfcc_parseMaxp(const json_value *root, const otfcc_Options *options) { |
| 87 |
table_maxp *maxp = table_iMaxp.create(); |
| 88 |
json_value *table = NULL; |
| 89 |
if ((table = json_obj_get_type(root, "maxp", json_object))) { |
| 90 |
loggedStep("maxp") { |
| 91 |
maxp->version = otfcc_to_fixed(json_obj_getnum(table, "version")); |
| 92 |
maxp->numGlyphs = json_obj_getnum(table, "numGlyphs"); |
| 93 |
maxp->maxZones = json_obj_getnum(table, "maxZones"); |
| 94 |
maxp->maxTwilightPoints = json_obj_getnum(table, "maxTwilightPoints"); |
| 95 |
maxp->maxStorage = json_obj_getnum(table, "maxStorage"); |
| 96 |
maxp->maxFunctionDefs = json_obj_getnum(table, "maxFunctionDefs"); |
| 97 |
maxp->maxInstructionDefs = json_obj_getnum(table, "maxInstructionDefs"); |
| 98 |
maxp->maxStackElements = json_obj_getnum(table, "maxStackElements"); |
| 99 |
} |
| 100 |
} |
| 101 |
return maxp; |
| 102 |
} |
| 103 |
|
| 104 |
caryll_Buffer *otfcc_buildMaxp(const table_maxp *maxp, const otfcc_Options *options) { |
| 105 |
if (!maxp) return NULL; |
| 106 |
caryll_Buffer *buf = bufnew(); |
| 107 |
bufwrite32b(buf, maxp->version); |
| 108 |
bufwrite16b(buf, maxp->numGlyphs); |
| 109 |
if (maxp->version > 0x00005000) { |
| 110 |
bufwrite16b(buf, maxp->maxPoints); |
| 111 |
bufwrite16b(buf, maxp->maxContours); |
| 112 |
bufwrite16b(buf, maxp->maxCompositePoints); |
| 113 |
bufwrite16b(buf, maxp->maxCompositeContours); |
| 114 |
bufwrite16b(buf, maxp->maxZones); |
| 115 |
bufwrite16b(buf, maxp->maxTwilightPoints); |
| 116 |
bufwrite16b(buf, maxp->maxStorage); |
| 117 |
bufwrite16b(buf, maxp->maxFunctionDefs); |
| 118 |
bufwrite16b(buf, maxp->maxInstructionDefs); |
| 119 |
bufwrite16b(buf, maxp->maxStackElements); |
| 120 |
bufwrite16b(buf, maxp->maxSizeOfInstructions); |
| 121 |
bufwrite16b(buf, maxp->maxComponentElements); |
| 122 |
bufwrite16b(buf, maxp->maxComponentDepth); |
| 123 |
} |
| 124 |
return buf; |
| 125 |
} |