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

Function cmap_parse

internal/cbm/pdf/pdf_font.c:793–919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

791 "begincidrange", "begincidchar", "beginnotdefrange"};
792
793static pdf_cmap_t *cmap_parse(pdf_doc_t *d, const unsigned char *data, size_t len) {
794 if (!d->scratch_arena_live) {
795 cbm_arena_init_lazy(&d->scratch_arena, CBM_ARENA_DEFAULT_BLOCK_SIZE);
796 d->scratch_arena_live = true;
797 }
798 CBMArena *tmp = &d->scratch_arena;
799 CBMArena *saved = d->cur;
800 d->cur = tmp;
801 cm_build_t b;
802 memset(&b, 0, sizeof(b));
803 pdf_val_t **buf = NULL;
804 int nbuf = 0;
805 int cap = 0;
806 char state[32] = "";
807 bool in_state = false;
808 bool failed = false;
809 size_t pos = 0;
810 for (;;) {
811 pdf_tok_t t;
812 pdf_lex(d, data, len, &pos, &t);
813 if (t.kind == PT_EOF || d->nomem) {
814 break;
815 }
816 if (t.kind == PT_KW) {
817 bool begun = false;
818 for (size_t i = 0; i < sizeof(CM_BEGIN) / sizeof(CM_BEGIN[0]); i++) {
819 if (pdf_kw_is(&t, CM_BEGIN[i])) {
820 snprintf(state, sizeof(state), "%s", CM_BEGIN[i] + 5);
821 in_state = true;
822 nbuf = 0;
823 begun = true;
824 break;
825 }
826 }
827 if (!begun && in_state && t.n >= 3 && memcmp(t.s, "end", 3) == 0) {
828 d->cur = saved;
829 cm_flush(d, &b, state, buf, nbuf);
830 d->cur = tmp;
831 in_state = false;
832 nbuf = 0;
833 cbm_arena_rewind(tmp);
834 }
835 continue;
836 }
837 if (!in_state) {
838 continue;
839 }
840 pdf_val_t *v = NULL;
841 if (t.kind == PT_STR || t.kind == PT_NUM || t.kind == PT_NAME) {
842 v = (pdf_val_t *)pdf_calloc(d, sizeof(*v));
843 if (v) {
844 v->kind = t.kind == PT_STR ? PV_STR : t.kind == PT_NUM ? PV_NUM : PV_NAME;
845 v->is_int = t.is_int;
846 v->num = t.num;
847 v->inum = t.inum;
848 v->s = t.s;
849 v->n = t.n;
850 }

Callers 2

font_init_type0Function · 0.85
font_newFunction · 0.85

Calls 13

cbm_arena_init_lazyFunction · 0.85
pdf_lexFunction · 0.85
pdf_kw_isFunction · 0.85
cm_flushFunction · 0.85
cbm_arena_rewindFunction · 0.85
pdf_callocFunction · 0.85
pdf_parse_content_arrayFunction · 0.85
cbm_reallocFunction · 0.85
cbm_freeFunction · 0.85
cbm_arena_callocFunction · 0.85
el_finishFunction · 0.85
pdf_bigFunction · 0.85

Tested by

no test coverage detected