/* * Create an Identity-* CMap (for both 1 and 2-byte encodings) */ fz_error pdf_newidentitycmap(pdf_cmap **cmapp, int wmode, int bytes) { fz_error error; pdf_cmap *cmap; error = pdf_newcmap(&cmap); if (error) return fz_rethrow(error, "cannot create cmap"); sprintf(cmap->cmapname, "Identity-%c", wmode ? 'V' : 'H'); error = pdf_addcodespace(cmap, 0x0000, 0xffff, bytes); if (error) { pdf_dropcmap(cmap); return fz_rethrow(error, "cannot add code space"); } error = pdf_maprangetorange(cmap, 0x0000, 0xffff, 0); if (error) { pdf_dropcmap(cmap); return fz_rethrow(error, "cannot map <0000> to <ffff>"); } error = pdf_sortcmap(cmap); if (error) { pdf_dropcmap(cmap); return fz_rethrow(error, "cannot sort cmap"); } pdf_setwmode(cmap, wmode); *cmapp = cmap; return fz_okay; }
/* * Create an Identity-* CMap (for both 1 and 2-byte encodings) */ pdf_cmap * pdf_newidentitycmap(int wmode, int bytes) { pdf_cmap *cmap = pdf_newcmap(); sprintf(cmap->cmapname, "Identity-%c", wmode ? 'V' : 'H'); pdf_addcodespace(cmap, 0x0000, 0xffff, bytes); pdf_maprangetorange(cmap, 0x0000, 0xffff, 0); pdf_sortcmap(cmap); pdf_setwmode(cmap, wmode); return cmap; }
static fz_error parsecodespacerange(pdf_cmap *cmap, fz_stream *file) { fz_error error; char buf[256]; pdf_token_e tok; int len; int lo, hi; while (1) { error = lexcmap(&tok, file, buf, sizeof buf, &len); if (error) return fz_rethrow(error, "syntaxerror in cmap"); if (tok == TENDCODESPACERANGE) return fz_okay; else if (tok == PDF_TSTRING) { lo = codefromstring(buf, len); error = lexcmap(&tok, file, buf, sizeof buf, &len); if (error) return fz_rethrow(error, "syntaxerror in cmap"); if (tok == PDF_TSTRING) { hi = codefromstring(buf, len); pdf_addcodespace(cmap, lo, hi, len); } else break; } else break; } return fz_throw("expected string or endcodespacerange"); }