diff options
Diffstat (limited to 'pdf/pdf_fapi.c')
-rw-r--r-- | pdf/pdf_fapi.c | 166 |
1 files changed, 103 insertions, 63 deletions
diff --git a/pdf/pdf_fapi.c b/pdf/pdf_fapi.c index 3e4420c4..7fb7c954 100644 --- a/pdf/pdf_fapi.c +++ b/pdf/pdf_fapi.c @@ -35,12 +35,14 @@ #include "pdf_dict.h" #include "pdf_array.h" #include "pdf_font.h" -#include "pdf_font.h" #include "gscencs.h" #include "gsagl.h" #include "gxfont1.h" /* for gs_font_type1_s */ #include "gscrypt1.h" /* for crypt_c1 */ +extern single_glyph_list_t SingleGlyphList[]; + + /* forward declarations for the pdfi_ff_stub definition */ static int pdfi_fapi_get_word(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, unsigned short *ret); @@ -70,6 +72,9 @@ static int pdfi_fapi_serialize_tt_font(gs_fapi_font * ff, void *buf, int buf_size); static int +pdfi_fapi_retrieve_tt_font(gs_fapi_font * ff, void **buf, int *buf_size); + +static int pdfi_fapi_get_charstring(gs_fapi_font *ff, int index, byte *buf, ushort buf_length); static int @@ -130,6 +135,7 @@ static const gs_fapi_font pdfi_ff_stub = { pdfi_fapi_get_raw_subr, /* get_raw_subr */ pdfi_fapi_get_glyph, /* get_glyph */ pdfi_fapi_serialize_tt_font, /* serialize_tt_font */ + pdfi_fapi_retrieve_tt_font, /* retrieve_tt_font */ pdfi_fapi_get_charstring, /* get_charstring */ pdfi_fapi_get_charstring_name, /* get_charstring_name */ pdfi_get_glyphdirectory_data, /* get_GlyphDirectory_data_ptr */ @@ -248,7 +254,7 @@ pdfi_fapi_get_word(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, uns { if (pfont->FontType == ft_encrypted2) { pdf_font_cff *pdffont2 = (pdf_font_cff *)pfont->client_data; - *ret = pdffont2->NumGlobalSubrs; + *ret = pdffont2->GlobalSubrs == NULL ? 0 : pdfi_array_size(pdffont2->GlobalSubrs); } else { *ret = 0; @@ -260,11 +266,11 @@ pdfi_fapi_get_word(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, uns { if (pfont->FontType == ft_encrypted) { pdf_font_type1 *pdffont1 = (pdf_font_type1 *)pfont->client_data; - *ret = pdffont1->NumSubrs; + *ret = pdffont1->Subrs == NULL ? 0 : pdfi_array_size(pdffont1->Subrs); } else if (pfont->FontType == ft_encrypted2) { pdf_font_cff *pdffont2 = (pdf_font_cff *)pfont->client_data; - *ret = pdffont2->NumSubrs; + *ret = pdffont2->Subrs == NULL ? 0 : pdfi_array_size(pdffont2->Subrs); } else { *ret = 0; @@ -395,7 +401,7 @@ pdfi_fapi_get_word(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, uns pdf_font_type1 *pdffont1 = (pdf_font_type1 *)pfont->client_data; if (pdffont1->blendfontbbox != NULL) { pdf_array *suba; - pdf_num *v; + double d; int ind, aind; ind = index % 4; aind = (index - ind) / 4; @@ -404,17 +410,13 @@ pdfi_fapi_get_word(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, uns *ret = 0; break; } - code = pdfi_array_get(pdffont1->ctx, suba, ind, (pdf_obj **)&v); + code = pdfi_array_get_number(pdffont1->ctx, suba, ind, &d); pdfi_countdown(suba); if (code < 0) { *ret = 0; break; } - if (v->type == PDF_INT) - *ret = (unsigned short)v->value.i; - else - *ret = (unsigned short)v->value.d; - pdfi_countdown(v); + *ret = (unsigned short)d; } else { *ret = 0; @@ -447,8 +449,13 @@ pdfi_fapi_get_long(gs_fapi_font * ff, gs_fapi_font_feature var_id, int index, un pdf_font_type1 *pdffont1 = (pdf_font_type1 *)pfont->client_data; int i; *ret = 0; - for (i = 0; i < pdffont1->NumSubrs; i++) { - *ret += pdffont1->Subrs[i].size; + for (i = 0; i < (pdffont1->Subrs == NULL ? 0 : pdfi_array_size(pdffont1->Subrs)); i++) { + pdf_string *subr_str = NULL; + code = pdfi_array_get_type(pdffont1->ctx, pdffont1->Subrs, i, PDF_STRING, (pdf_obj **)&subr_str); + if (code >= 0) { + *ret += subr_str->length; + } + pdfi_countdown(subr_str); } } } @@ -520,7 +527,7 @@ pdfi_fapi_get_float(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, fl { int array_index, subind; pdf_array *suba; - pdf_num *v; + double d; pdf_font_type1 *pdffont1 = (pdf_font_type1 *)pbfont->client_data; *ret = 0; @@ -543,19 +550,13 @@ pdfi_fapi_get_float(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, fl break; } - code = pdfi_array_get(pdffont1->ctx, suba, subind, (pdf_obj**)&v); + code = pdfi_array_get_number(pdffont1->ctx, suba, subind, &d); pdfi_countdown(suba); if (code < 0) { code = 0; break; } - if (v->type == PDF_INT) { - *ret = (float)v->value.i; - } - else { - *ret = (float)v->value.d; - } - pdfi_countdown(v); + *ret = (float)d; } break; case gs_fapi_font_feature_BlendDesignMapArrayValue: @@ -580,15 +581,11 @@ pdfi_fapi_get_float(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, fl pdfi doesn't, hence the multiplications by 64. */ if ((i * 64) + (j * 64) + k == index) { - pdf_num *n; - code = pdfi_array_get(pdffont1->ctx, suba, i, (pdf_obj **)&n); + double d; + code = pdfi_array_get_number(pdffont1->ctx, suba, i, &d); if (code < 0) continue; - if (n->type == PDF_INT) - *ret = (float)n->value.i; - else - *ret = (float)n->value.d; - pdfi_countdown(n); + *ret = (float)d; pdfi_countdown(subsuba); pdfi_countdown(suba); goto gotit; @@ -683,7 +680,7 @@ pdfi_fapi_get_gsubr(gs_fapi_font *ff, int index, byte *buf, int buf_length) int code = 0; if (pfont->FontType == ft_encrypted2) { pdf_font_cff *pdffont2 = (pdf_font_cff *)pfont->client_data; - if (index > pdffont2->NumGlobalSubrs) { + if (index > (pdffont2->GlobalSubrs == NULL ? 0 : pdfi_array_size(pdffont2->GlobalSubrs))) { code = gs_error_rangecheck; } else { @@ -692,7 +689,7 @@ pdfi_fapi_get_gsubr(gs_fapi_font *ff, int index, byte *buf, int buf_length) code = pdfi_array_get(pdffont2->ctx, pdffont2->GlobalSubrs, index, (pdf_obj **)&subrstring); if (code >= 0) { - if (subrstring->type == PDF_STRING) { + if (pdfi_type_of(subrstring) == PDF_STRING) { code = subrstring->length - leniv; if (buf && buf_length >= code) { if (ff->need_decrypt && pfont->data.lenIV >= 0) { @@ -724,27 +721,35 @@ pdfi_fapi_get_subr(gs_fapi_font *ff, int index, byte *buf, int buf_length) if (pfont->FontType == ft_encrypted) { pdf_font_type1 *pdffont1 = (pdf_font_type1 *)pfont->client_data; - if (index > pdffont1->NumSubrs) { + if (index > (pdffont1->Subrs == NULL ? 0 : pdfi_array_size(pdffont1->Subrs))) { code = gs_note_error(gs_error_rangecheck); } else { int leniv = (pfont->data.lenIV > 0 ? pfont->data.lenIV : 0); - if (pdffont1->Subrs[index].size > 0) { - code = pdffont1->Subrs[index].size - leniv; + pdf_string *subr_str = NULL; + + code = pdfi_array_get_type(pdffont1->ctx, pdffont1->Subrs, index, PDF_STRING, (pdf_obj **)&subr_str); + if (code >= 0) { + code = subr_str->length - leniv; if (buf && buf_length >= code) { if (ff->need_decrypt && pfont->data.lenIV >= 0) { - decode_bytes(buf, pdffont1->Subrs[index].data, code + leniv, pfont->data.lenIV); + decode_bytes(buf, subr_str->data, code + leniv, pfont->data.lenIV); } else { - memcpy(buf, pdffont1->Subrs[index].data, code); + memcpy(buf, subr_str->data, code); } } } + else { + /* Ignore invalid or missing subrs */ + code = 0; + } + pdfi_countdown(subr_str); } } else if (pfont->FontType == ft_encrypted2) { pdf_font_cff *pdffont2 = (pdf_font_cff *)pfont->client_data; - if (index > pdffont2->NumSubrs) { + if (index > (pdffont2->Subrs == NULL ? 0 : pdfi_array_size(pdffont2->Subrs))) { code = gs_error_rangecheck; } else { @@ -756,7 +761,7 @@ pdfi_fapi_get_subr(gs_fapi_font *ff, int index, byte *buf, int buf_length) else code = pdfi_array_get(pdffont2->ctx, pdffont2->Subrs, index, (pdf_obj **)&subrstring); if (code >= 0) { - if (subrstring->type == PDF_STRING) { + if (pdfi_type_of(subrstring) == PDF_STRING) { if (subrstring->length > 0) { code = subrstring->length - leniv; if (buf && buf_length >= code) { @@ -790,14 +795,23 @@ pdfi_fapi_get_raw_subr(gs_fapi_font *ff, int index, byte *buf, int buf_length) if (pfont->FontType == ft_encrypted) { pdf_font_type1 *pdffont1 = (pdf_font_type1 *)pfont->client_data; - if (index > pdffont1->NumSubrs) { + if (index > (pdffont1->Subrs == NULL ? 0 : pdfi_array_size(pdffont1->Subrs))) { code = gs_error_rangecheck; } else { - code = pdffont1->Subrs[index].size; - if (buf && buf_length >= code) { - memcpy(buf, pdffont1->Subrs[index].data, code); + pdf_string *subr_str = NULL; + code = pdfi_array_get_type(pdffont1->ctx, pdffont1->Subrs, index, PDF_STRING, (pdf_obj **)&subr_str); + if (code >= 0) { + code = subr_str->length; + if (buf && buf_length >= code) { + memcpy(buf, subr_str->data, code); + } + } + else { + /* Ignore missing or invalid subrs */ + code = 0; } + pdfi_countdown(subr_str); } } return code; @@ -815,8 +829,6 @@ pdfi_fapi_get_charstring_name(gs_fapi_font *ff, int index, byte *buf, ushort buf return 0; } -extern single_glyph_list_t SingleGlyphList[]; - static int pdfi_fapi_get_glyphname_or_cid(gs_text_enum_t *penum, gs_font_base * pbfont, gs_string * charstring, gs_string * name, gs_glyph ccode, gs_string * enc_char_name, @@ -835,8 +847,8 @@ pdfi_fapi_get_glyphname_or_cid(gs_text_enum_t *penum, gs_font_base * pbfont, gs_ if (pttfont->substitute == false) { gid = ccode; - if (pttfont->cidtogidmap.size > (ccode << 1) + 1) { - gid = pttfont->cidtogidmap.data[ccode << 1] << 8 | pttfont->cidtogidmap.data[(ccode << 1) + 1]; + if (pttfont->cidtogidmap != NULL && pttfont->cidtogidmap->length > (ccode << 1) + 1) { + gid = pttfont->cidtogidmap->data[ccode << 1] << 8 | pttfont->cidtogidmap->data[(ccode << 1) + 1]; } cr->client_char_code = ccode; cr->char_codes[0] = gid; @@ -933,8 +945,9 @@ pdfi_fapi_get_glyphname_or_cid(gs_text_enum_t *penum, gs_font_base * pbfont, gs_ code = (*ctx->get_glyph_name)((gs_font *)pbfont, ccode, &gname); if (code >= 0) { code = pdfi_name_alloc(ctx, (byte *) gname.data, gname.size, (pdf_obj **) &glyphname); - if (code >= 0) - pdfi_countup(glyphname); + if (code < 0) + return code; + pdfi_countup(glyphname); } if (code < 0) { @@ -942,10 +955,12 @@ pdfi_fapi_get_glyphname_or_cid(gs_text_enum_t *penum, gs_font_base * pbfont, gs_ return code; } code = pdfi_dict_get_by_key(cfffont->ctx, cfffont->CharStrings, glyphname, (pdf_obj **)&charstr); - pdfi_countdown(glyphname); if (code < 0) { - code = pdfi_dict_get(cfffont->ctx, cfffont->CharStrings, ".notdef", (pdf_obj **)&charstr); + code = pdfi_map_glyph_name_via_agl(cfffont->CharStrings, glyphname, &charstr); + if (code < 0) + code = pdfi_dict_get(cfffont->ctx, cfffont->CharStrings, ".notdef", (pdf_obj **)&charstr); } + pdfi_countdown(glyphname); if (code < 0) return code; @@ -1121,7 +1136,6 @@ pdfi_fapi_get_glyph(gs_fapi_font * ff, gs_glyph char_code, byte * buf, int buf_l pdf_name *encn; int cstrlen = 0; - /* This should only get called for Postscript-type fonts */ if (ff->is_type1) { if (pbfont->FontType == ft_encrypted) { @@ -1137,14 +1151,18 @@ pdfi_fapi_get_glyph(gs_fapi_font * ff, gs_glyph char_code, byte * buf, int buf_l return code; pdfi_countup(glyphname); code = pdfi_dict_get_by_key(pdffont1->ctx, pdffont1->CharStrings, glyphname, (pdf_obj **)&charstring); - pdfi_countdown(glyphname); if (code < 0) { - code = pdfi_dict_get(pdffont1->ctx, pdffont1->CharStrings, ".notdef", (pdf_obj **)&charstring); + code = pdfi_map_glyph_name_via_agl(pdffont1->CharStrings, glyphname, &charstring); if (code < 0) { - code = gs_note_error(gs_error_invalidfont); - goto done; + code = pdfi_dict_get(pdffont1->ctx, pdffont1->CharStrings, ".notdef", (pdf_obj **)&charstring); + if (code < 0) { + pdfi_countdown(glyphname); + code = gs_note_error(gs_error_invalidfont); + goto done; + } } } + pdfi_countdown(glyphname); cstrlen = charstring->length - leniv; if (buf != NULL && cstrlen <= buf_length) { if (ff->need_decrypt && pfont1->data.lenIV >= 0) @@ -1261,7 +1279,16 @@ pdfi_fapi_get_glyph(gs_fapi_font * ff, gs_glyph char_code, byte * buf, int buf_l } } else { - code = gs_error_invalidaccess; + gs_font_type42 *pfont42 = (gs_font_type42 *)pbfont; + gs_glyph_data_t pgd; + + code = pfont42->data.get_outline(pfont42, char_code, &pgd); + cstrlen = pgd.bits.size; + if (code >= 0) { + if (buf && buf_length >= cstrlen) { + memcpy(buf, pgd.bits.data, cstrlen); + } + } } done: if (code < 0) @@ -1277,6 +1304,19 @@ pdfi_fapi_serialize_tt_font(gs_fapi_font * ff, void *buf, int buf_size) } static int +pdfi_fapi_retrieve_tt_font(gs_fapi_font * ff, void **buf, int *buf_size) +{ + gs_font_type42 *pfonttt = (gs_font_type42 *) ff->client_font_data; + pdf_font_truetype *pdfttf = (pdf_font_truetype *)pfonttt->client_data; + + *buf = pdfttf->sfnt->data; + *buf_size = pdfttf->sfnt->length; + + return 0; +} + + +static int pdfi_get_glyphdirectory_data(gs_fapi_font * ff, int char_code, const byte ** ptr) { @@ -1439,6 +1479,7 @@ pdfi_fapi_passfont(pdf_font *font, int subfont, char *fapi_request, char *fapi_id = NULL; int code = 0; gs_string fdata; + gs_string *fdatap = &fdata; gs_font_base *pbfont = (gs_font_base *)font->pfont; gs_fapi_font local_pdf_ff_stub = pdfi_ff_stub; gs_fapi_ttf_cmap_request symbolic_req[GS_FAPI_NUM_TTF_CMAP_REQ] = {{3, 0}, {1, 0}, {3, 1}, {3, 10}, {-1, -1}}; @@ -1450,16 +1491,15 @@ pdfi_fapi_passfont(pdf_font *font, int subfont, char *fapi_request, } if (font->pdfi_font_type == e_pdf_font_truetype) { - fdata.data = ((pdf_font_truetype *)font)->sfnt.data; - fdata.size = ((pdf_font_truetype *)font)->sfnt.size; + fdatap = NULL; } else if (font->pdfi_font_type == e_pdf_cidfont_type2) { - fdata.data = ((pdf_cidfont_type2 *)font)->sfnt.data; - fdata.size = ((pdf_cidfont_type2 *)font)->sfnt.size; + fdatap->data = ((pdf_cidfont_type2 *)font)->sfnt->data; + fdatap->size = ((pdf_cidfont_type2 *)font)->sfnt->length; } else { - fdata.data = font_data; - fdata.size = font_data_len; + fdatap->data = font_data; + fdatap->size = font_data_len; } if (font->pdfi_font_type == e_pdf_font_truetype) { @@ -1476,7 +1516,7 @@ pdfi_fapi_passfont(pdf_font *font, int subfont, char *fapi_request, (gs_font *)pbfont); code = - gs_fapi_passfont((gs_font *)pbfont, subfont, (char *)file_name, &fdata, + gs_fapi_passfont((gs_font *)pbfont, subfont, (char *)file_name, fdatap, (char *)fapi_request, NULL, (char **)&fapi_id, (gs_fapi_get_server_param_callback) pdfi_get_server_param); |