MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / ttf_reverse

Function ttf_reverse

internal/cbm/pdf/pdf_font.c:1137–1237  ·  view source on GitHub ↗

The prototype's ttf_reverse_cmap: gid -> code point + 1 (0: none), or NULL. */

Source from the content-addressed store, hash-verified

1135
1136/* The prototype's ttf_reverse_cmap: gid -> code point + 1 (0: none), or NULL. */
1137static uint32_t *ttf_reverse(pdf_doc_t *d, const unsigned char *p, size_t len) {
1138 uint32_t num;
1139 if (!rd16(p, len, 4, &num)) {
1140 return NULL;
1141 }
1142 size_t off = 0;
1143 bool found = false;
1144 for (uint32_t i = 0; i < num; i++) {
1145 size_t r = 12 + 16 * (size_t)i;
1146 if (r + 4 <= len && memcmp(p + r, "cmap", 4) == 0) {
1147 uint32_t o;
1148 if (!rd32(p, len, r + 8, &o)) {
1149 return NULL;
1150 }
1151 off = o;
1152 found = true;
1153 break;
1154 }
1155 if (r >= len) {
1156 break;
1157 }
1158 }
1159 if (!found) {
1160 return NULL;
1161 }
1162 uint32_t n;
1163 if (!rd16(p, len, off + 2, &n)) {
1164 return NULL;
1165 }
1166 ttf_sub_t *subs =
1167 (ttf_sub_t *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)(n ? n : 1) * sizeof(*subs));
1168 uint32_t *rev = (uint32_t *)pdf_big(d, PDF_GID_SPACE * sizeof(uint32_t));
1169 uint32_t *nxt =
1170 (uint32_t *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (PDF_GID_SPACE + 1) * sizeof(uint32_t));
1171 if (!subs || !rev || !nxt) {
1172 cbm_free(CBM_MEM_CLASS_EXTRACT, subs);
1173 cbm_free(CBM_MEM_CLASS_EXTRACT, nxt);
1174 d->nomem = true;
1175 return NULL;
1176 }
1177 bool bad = false;
1178 for (uint32_t i = 0; i < n; i++) {
1179 uint32_t pl;
1180 uint32_t en;
1181 uint32_t o;
1182 size_t at = off + 4 + 8 * (size_t)i;
1183 if (!rd16(p, len, at, &pl) || !rd16(p, len, at + 2, &en) || !rd32(p, len, at + 4, &o)) {
1184 bad = true;
1185 break;
1186 }
1187 subs[i].pe = (pl << 16) | en;
1188 subs[i].off = (uint64_t)off + o;
1189 subs[i].order = (int)i;
1190 uint32_t pe = subs[i].pe;
1191 subs[i].rank = pe == 0x0003000AU ? 0
1192 : pe == 0x00030001U ? 1
1193 : pe == 0x00000004U ? 2
1194 : pe == 0x00000003U ? 3

Callers 1

font_revFunction · 0.85

Calls 7

rd16Function · 0.85
rd32Function · 0.85
cbm_allocFunction · 0.85
pdf_bigFunction · 0.85
cbm_freeFunction · 0.85
ttf_fmt4Function · 0.85
ttf_fmt12Function · 0.85

Tested by

no test coverage detected