diff options
Diffstat (limited to 'pdf/pdf_fapi.c')
-rw-r--r-- | pdf/pdf_fapi.c | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/pdf/pdf_fapi.c b/pdf/pdf_fapi.c index df92acc4..3e4420c4 100644 --- a/pdf/pdf_fapi.c +++ b/pdf/pdf_fapi.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019-2021 Artifex Software, Inc. +/* Copyright (C) 2019-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -550,7 +550,7 @@ pdfi_fapi_get_float(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, fl break; } if (v->type == PDF_INT) { - *ret = v->value.i; + *ret = (float)v->value.i; } else { *ret = (float)v->value.d; @@ -688,19 +688,24 @@ pdfi_fapi_get_gsubr(gs_fapi_font *ff, int index, byte *buf, int buf_length) } else { int leniv = (pfont->data.lenIV > 0 ? pfont->data.lenIV : 0); - pdf_string *subrstring; + pdf_string *subrstring = NULL; code = pdfi_array_get(pdffont2->ctx, pdffont2->GlobalSubrs, index, (pdf_obj **)&subrstring); if (code >= 0) { - code = subrstring->length - leniv; - if (buf && buf_length >= code) { - if (ff->need_decrypt && pfont->data.lenIV >= 0) { - decode_bytes(buf, subrstring->data, code + leniv, pfont->data.lenIV); - } - else { - memcpy(buf, subrstring->data, code); + if (subrstring->type == PDF_STRING) { + code = subrstring->length - leniv; + if (buf && buf_length >= code) { + if (ff->need_decrypt && pfont->data.lenIV >= 0) { + decode_bytes(buf, subrstring->data, code + leniv, pfont->data.lenIV); + } + else { + memcpy(buf, subrstring->data, code); + } } } + else { + code = gs_note_error(gs_error_invalidfont); + } pdfi_countdown(subrstring); } } @@ -746,19 +751,27 @@ pdfi_fapi_get_subr(gs_fapi_font *ff, int index, byte *buf, int buf_length) int leniv = (pfont->data.lenIV > 0 ? pfont->data.lenIV : 0); pdf_string *subrstring; - code = pdfi_array_get(pdffont2->ctx, pdffont2->Subrs, index, (pdf_obj **)&subrstring); + if (pdffont2->Subrs == NULL) + code = gs_note_error(gs_error_invalidfont); + else + code = pdfi_array_get(pdffont2->ctx, pdffont2->Subrs, index, (pdf_obj **)&subrstring); if (code >= 0) { - if (subrstring->length > 0) { - code = subrstring->length - leniv; - if (buf && buf_length >= code) { - if (ff->need_decrypt && pfont->data.lenIV >= 0) { - decode_bytes(buf, subrstring->data, code + leniv, pfont->data.lenIV); - } - else { - memcpy(buf, subrstring->data, code); + if (subrstring->type == PDF_STRING) { + if (subrstring->length > 0) { + code = subrstring->length - leniv; + if (buf && buf_length >= code) { + if (ff->need_decrypt && pfont->data.lenIV >= 0) { + decode_bytes(buf, subrstring->data, code + leniv, pfont->data.lenIV); + } + else { + memcpy(buf, subrstring->data, code); + } } } } + else { + code = gs_note_error(gs_error_invalidfont); + } pdfi_countdown(subrstring); } } @@ -914,7 +927,7 @@ pdfi_fapi_get_glyphname_or_cid(gs_text_enum_t *penum, gs_font_base * pbfont, gs_ else if (pbfont->FontType == ft_encrypted2) { pdf_font_cff *cfffont = (pdf_font_cff *)pbfont->client_data; pdf_name *glyphname = NULL; - pdf_string *charstring = NULL; + pdf_string *charstr = NULL; gs_const_string gname; code = (*ctx->get_glyph_name)((gs_font *)pbfont, ccode, &gname); @@ -928,22 +941,22 @@ pdfi_fapi_get_glyphname_or_cid(gs_text_enum_t *penum, gs_font_base * pbfont, gs_ pdfi_countdown(glyphname); return code; } - code = pdfi_dict_get_by_key(cfffont->ctx, cfffont->CharStrings, glyphname, (pdf_obj **)&charstring); + 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 **)&charstring); + code = pdfi_dict_get(cfffont->ctx, cfffont->CharStrings, ".notdef", (pdf_obj **)&charstr); } if (code < 0) return code; - I->ff.char_data = charstring->data; - I->ff.char_data_len = charstring->length; + I->ff.char_data = charstr->data; + I->ff.char_data_len = charstr->length; cr->client_char_code = 0; cr->char_codes[0] = 0; cr->is_glyph_index = true; - pdfi_countdown(charstring); + pdfi_countdown(charstr); return code; } else if (pbfont->FontType == ft_TrueType) { @@ -1184,8 +1197,6 @@ pdfi_fapi_get_glyph(gs_fapi_font * ff, gs_glyph char_code, byte * buf, int buf_l cstrlen = I->ff.char_data_len - leniv; if (buf && buf_length >= cstrlen) { - memcpy(buf, I->ff.char_data, I->ff.char_data_len); - if (ff->need_decrypt && pfont->data.lenIV >= 0) decode_bytes(buf, I->ff.char_data, cstrlen + leniv, leniv); else @@ -1364,7 +1375,7 @@ static int pdfi_fapi_build_char(gs_show_enum * penum, gs_gstate * pgs, gs_font * pfont, gs_char chr, gs_glyph glyph) { - int code; + int code = 0; gs_font_base *pbfont1; gs_fapi_server *I; @@ -1382,9 +1393,16 @@ pdfi_fapi_build_char(gs_show_enum * penum, gs_gstate * pgs, gs_font * pfont, I->ff.client_font_data2 = cidpfont; } } + /* If between the font's creation and now another interpreter has driven FAPI (i.e. in a Postscript Begin/EndPage + context, the FAPI server data may end up set appropriately for the other interpreter, if that's happened, put + ours back before trying to interpret the glyph. + */ + if (((gs_fapi_server *)pbfont1->FAPI)->ff.get_glyphname_or_cid != pdfi_fapi_get_glyphname_or_cid) { + code = pdfi_fapi_passfont((pdf_font *)pbfont1->client_data, 0, NULL, NULL, NULL, 0); + } - code = gs_fapi_do_char((gs_font *)pbfont1, pgs, (gs_text_enum_t *) penum, NULL, false, - NULL, NULL, chr, glyph, 0); + if (code >= 0) + code = gs_fapi_do_char((gs_font *)pbfont1, pgs, (gs_text_enum_t *) penum, NULL, false, NULL, NULL, chr, glyph, 0); return (code); } @@ -1452,9 +1470,7 @@ pdfi_fapi_passfont(pdf_font *font, int subfont, char *fapi_request, /* doesn't really matter for non-ttf */ *local_pdf_ff_stub.ttf_cmap_req = *nonsymbolic_req; } - /* The plfont should contain everything we need, but setting the client data for the server - * to pbfont makes as much sense as setting it to NULL. - */ + gs_fapi_set_servers_client_data(pbfont->memory, (const gs_fapi_font *)&local_pdf_ff_stub, (gs_font *)pbfont); |