diff options
-rw-r--r-- | pdf/pdf_font.c | 11 | ||||
-rw-r--r-- | pdf/pdf_font1.c | 52 | ||||
-rw-r--r-- | pdf/pdf_font11.c | 15 | ||||
-rw-r--r-- | pdf/pdf_font1C.c | 60 | ||||
-rw-r--r-- | pdf/pdf_fontTT.c | 32 |
5 files changed, 109 insertions, 61 deletions
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index 93d266f23..e96d8cec0 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -1990,10 +1990,10 @@ int pdfi_font_generate_pseudo_XUID(pdf_context *ctx, pdf_dict *fontdict, gs_font int i; uint32_t hash = 0; long *xvalues; - int xuidlen = 2; + int xuidlen = 3; sfilename(ctx->main_stream->s, &fn); - if (fn.size > 0 && fontdict->object_num != 0) { + if (fn.size > 0 && fontdict!= NULL && fontdict->object_num != 0) { for (i = 0; i < fn.size; i++) { hash = ((((hash & 0xf8000000) >> 27) ^ (hash << 5)) & 0x7ffffffff) ^ fn.data[i]; } @@ -2009,14 +2009,17 @@ int pdfi_font_generate_pseudo_XUID(pdf_context *ctx, pdf_dict *fontdict, gs_font } xvalues[0] = 1000000; /* "Private" value */ xvalues[1] = hash; + + xvalues[2] = ctx->device_state.HighLevelDevice ? pfont->id : 0; + if (uid_is_XUID(&pfont->UID)) { for (i = 0; i < uid_XUID_size(&pfont->UID); i++) { - xvalues[i + 2] = uid_XUID_values(&pfont->UID)[i]; + xvalues[i + 3] = uid_XUID_values(&pfont->UID)[i]; } uid_free(&pfont->UID, pfont->memory, "pdfi_font_generate_pseudo_XUID"); } else if (uid_is_valid(&pfont->UID)) - xvalues[2] = pfont->UID.id; + xvalues[3] = pfont->UID.id; uid_set_XUID(&pfont->UID, xvalues, xuidlen); } diff --git a/pdf/pdf_font1.c b/pdf/pdf_font1.c index aa0c9ac07..eec20d5a1 100644 --- a/pdf/pdf_font1.c +++ b/pdf/pdf_font1.c @@ -139,13 +139,13 @@ pdfi_t1_subr_data(gs_font_type1 *pfont, int index, bool global, gs_glyph_data_t code = gs_note_error(gs_error_rangecheck); } else { - pdf_string *subr_str; + pdf_string *subr_str = NULL; code = pdfi_array_get_type(pdffont1->ctx, pdffont1->Subrs, index, PDF_STRING, (pdf_obj **)&subr_str); if (code >= 0) { gs_glyph_data_from_bytes(pgd, subr_str->data, 0, subr_str->length, NULL); - /* decrementing is safe here, because the reference in the pdffont1->Subrs will persist */ - pdfi_countdown(subr_str); } + /* decrementing is safe here, because the reference in the pdffont1->Subrs will persist */ + pdfi_countdown(subr_str); } return code; } @@ -657,15 +657,6 @@ pdfi_read_type1_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dic pdfi_countdown(tmp); tmp = NULL; if (code == 1) { - /* Since the underlying font stream can be shared between font descriptors, - and the font descriptors can be shared between font objects, if we change - the encoding, we can't share cached glyphs with other instances of this - underlying font, so invalidate the UniqueID/XUID so the glyph cache won't - try. - */ - if (uid_is_XUID(&t1f->pfont->UID)) - uid_free(&t1f->pfont->UID, t1f->pfont->memory, "pdfi_read_type1_font"); - uid_set_invalid(&t1f->pfont->UID); } } else { @@ -678,6 +669,15 @@ pdfi_read_type1_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dic t1f->Encoding = fpriv.u.t1.Encoding; pdfi_countup(t1f->Encoding); } + /* Since the underlying font stream can be shared between font descriptors, + and the font descriptors can be shared between font objects, if we change + the encoding, we can't share cached glyphs with other instances of this + underlying font, so invalidate the UniqueID/XUID so the glyph cache won't + try. + */ + if (uid_is_XUID(&t1f->pfont->UID)) + uid_free(&t1f->pfont->UID, t1f->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&t1f->pfont->UID); t1f->CharStrings = fpriv.u.t1.CharStrings; pdfi_countup(t1f->CharStrings); @@ -686,6 +686,11 @@ pdfi_read_type1_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dic t1f->Subrs = fpriv.u.t1.Subrs; fpriv.u.t1.Subrs = NULL; + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, t1f->pfont); + if (code < 0) { + goto error; + } + t1f->blenddesignpositions = fpriv.u.t1.blenddesignpositions; pdfi_countup(t1f->blenddesignpositions); t1f->blenddesignmap = fpriv.u.t1.blenddesignmap; @@ -835,17 +840,6 @@ pdfi_copy_type1_font(pdf_context *ctx, pdf_font *spdffont, pdf_dict *font_dict, code = gs_error_undefined; pdfi_countdown(tmp); tmp = NULL; - if (code == 1) { - /* Since the underlying font stream can be shared between font descriptors, - and the font descriptors can be shared between font objects, if we change - the encoding, we can't share cached glyphs with other instances of this - underlying font, so invalidate the UniqueID/XUID so the glyph cache won't - try. - */ - if (uid_is_XUID(&font->pfont->UID)) - uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); - uid_set_invalid(&font->pfont->UID); - } } else { pdfi_countdown(tmp); @@ -858,6 +852,18 @@ pdfi_copy_type1_font(pdf_context *ctx, pdf_font *spdffont, pdf_dict *font_dict, pdfi_countup(font->Encoding); } + /* Since various aspects of the font may differ (widths, encoding, etc) + we cannot reliably use the UniqueID/XUID for copied fonts. + */ + if (uid_is_XUID(&font->pfont->UID)) + uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&font->pfont->UID); + + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, font->pfont); + if (code < 0) { + goto error; + } + if (ctx->args.ignoretounicode != true) { code = pdfi_dict_get(ctx, font_dict, "ToUnicode", (pdf_obj **)&tmp); if (code >= 0 && pdfi_type_of(tmp) == PDF_STREAM) { diff --git a/pdf/pdf_font11.c b/pdf/pdf_font11.c index 685ebe768..107101f65 100644 --- a/pdf/pdf_font11.c +++ b/pdf/pdf_font11.c @@ -442,10 +442,21 @@ int pdfi_read_cidtype2_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *str pdfi_countdown(obj); obj = NULL; + code = gs_type42_font_init((gs_font_type42 *)font->pfont, 0); if (code < 0) { goto error; } + if (uid_is_XUID(&font->pfont->UID)) + uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&font->pfont->UID); + font->pfont->id = gs_next_ids(ctx->memory, 1); + + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, font->pfont); + if (code < 0) + goto error; + + font->orig_glyph_info = font->pfont->procs.glyph_info; font->pfont->procs.glyph_info = pdfi_cidtype2_glyph_info; font->pfont->procs.enumerate_glyph = pdfi_cidtype2_enumerate_glyph; @@ -468,10 +479,6 @@ int pdfi_read_cidtype2_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *str cid2->cidata.orig_procs.get_outline = cid2->data.get_outline; cid2->data.get_glyph_index = pdfi_cidtype2_get_glyph_index; - code = pdfi_font_generate_pseudo_XUID(ctx, font->PDF_font, font->pfont); - if (code < 0) - goto error; - code = gs_definefont(ctx->font_dir, (gs_font *)font->pfont); if (code < 0) { goto error; diff --git a/pdf/pdf_font1C.c b/pdf/pdf_font1C.c index 6bebc5a2d..83398c34d 100644 --- a/pdf/pdf_font1C.c +++ b/pdf/pdf_font1C.c @@ -2446,10 +2446,10 @@ pdfi_read_cff_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dict, else { cffcid->W2 = NULL; } - code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, (gs_font_base *)cffcid->pfont); - if (code < 0) - uid_set_invalid(&cffcid->pfont->UID); - + if (uid_is_XUID(&cffcid->pfont->UID)) + uid_free(&cffcid->pfont->UID, cffcid->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&cffcid->pfont->UID); + cffcid->pfont->id = gs_next_ids(ctx->memory, 1); } else if (forcecid) { pdf_obj *obj; @@ -2655,10 +2655,10 @@ pdfi_read_cff_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dict, cffcid->W2 = NULL; } - code = pdfi_font_generate_pseudo_XUID(ctx, cffcid->PDF_font, ppdfont->pfont); - if (code < 0) - goto error; - + if (uid_is_XUID(&cffcid->pfont->UID)) + uid_free(&cffcid->pfont->UID, cffcid->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&cffcid->pfont->UID); + cffcid->pfont->id = gs_next_ids(ctx->memory, 1); } else { pdf_font_cff *cfffont; @@ -2757,6 +2757,9 @@ pdfi_read_cff_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dict, } else code = gs_error_undefined; + + if (code == 1) { + } pdfi_countdown(tmp); tmp = NULL; } @@ -2769,6 +2772,18 @@ pdfi_read_cff_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dict, cfffont->Encoding = cffpriv.pdfcffpriv.Encoding; cffpriv.pdfcffpriv.Encoding = NULL; } + + /* Since the underlying font stream can be shared between font descriptors, + and the font descriptors can be shared between font objects, if we change + the encoding, we can't share cached glyphs with other instances of this + underlying font, so invalidate the UniqueID/XUID so the glyph cache won't + try. + */ + if (uid_is_XUID(&cfffont->pfont->UID)) + uid_free(&cfffont->pfont->UID, cfffont->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&cfffont->pfont->UID); + cfffont->pfont->id = gs_next_ids(ctx->memory, 1); + if (ctx->args.ignoretounicode != true && font_dict != NULL) { code = pdfi_dict_get(ctx, font_dict, "ToUnicode", (pdf_obj **)&tounicode); if (code >= 0 && pdfi_type_of(tounicode) == PDF_STREAM) { @@ -2808,6 +2823,11 @@ error: } } else { + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, ppdfont->pfont); + if (code < 0) { + goto error; + } + code = gs_definefont(ctx->font_dir, (gs_font *) ppdfont->pfont); if (code >= 0) @@ -2817,6 +2837,7 @@ error: if (code >= 0 && ppdfont->object_num != 0) { (void)replace_cache_entry(ctx, (pdf_obj *) ppdfont); } + if (code >= 0) { *ppdffont = (pdf_font *) ppdfont; ppdfont = NULL; @@ -2971,17 +2992,6 @@ pdfi_copy_cff_font(pdf_context *ctx, pdf_font *spdffont, pdf_dict *font_dict, pd code = gs_error_undefined; pdfi_countdown(tmp); tmp = NULL; - if (code == 1) { - /* Since the underlying font stream can be shared between font descriptors, - and the font descriptors can be shared between font objects, if we change - the encoding, we can't share cached glyphs with other instances of this - underlying font, so invalidate the UniqueID/XUID so the glyph cache won't - try. - */ - if (uid_is_XUID(&font->pfont->UID)) - uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); - uid_set_invalid(&font->pfont->UID); - } } else { pdfi_countdown(tmp); @@ -2994,6 +3004,18 @@ pdfi_copy_cff_font(pdf_context *ctx, pdf_font *spdffont, pdf_dict *font_dict, pd pdfi_countup(font->Encoding); } + /* Since various aspects of the font may differ (widths, encoding, etc) + we cannot reliably use the UniqueID/XUID for copied fonts. + */ + if (uid_is_XUID(&font->pfont->UID)) + uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&font->pfont->UID); + + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, font->pfont); + if (code < 0) { + goto error; + } + if (ctx->args.ignoretounicode != true) { code = pdfi_dict_get(ctx, font_dict, "ToUnicode", (pdf_obj **)&tmp); if (code >= 0 && pdfi_type_of(tmp) == PDF_STREAM) { diff --git a/pdf/pdf_fontTT.c b/pdf/pdf_fontTT.c index 661c182a2..c8a74da1a 100644 --- a/pdf/pdf_fontTT.c +++ b/pdf/pdf_fontTT.c @@ -564,6 +564,15 @@ int pdfi_read_truetype_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *str font->descflags = descflags; } + if (uid_is_XUID(&font->pfont->UID)) + uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&font->pfont->UID); + + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, font->pfont); + if (code < 0) { + goto error; + } + if ((font->descflags & 4) == 0) { /* Horrid hacky solution */ /* We don't want to draw the TTF notdef */ @@ -690,17 +699,6 @@ pdfi_copy_truetype_font(pdf_context *ctx, pdf_font *spdffont, pdf_dict *font_dic code = gs_error_undefined; pdfi_countdown(tmp); tmp = NULL; - if (code == 1) { - /* Since the underlying font stream can be shared between font descriptors, - and the font descriptors can be shared between font objects, if we change - the encoding, we can't share cached glyphs with other instances of this - underlying font, so invalidate the UniqueID/XUID so the glyph cache won't - try. - */ - if (uid_is_XUID(&font->pfont->UID)) - uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); - uid_set_invalid(&font->pfont->UID); - } } else { pdfi_countdown(tmp); @@ -708,6 +706,18 @@ pdfi_copy_truetype_font(pdf_context *ctx, pdf_font *spdffont, pdf_dict *font_dic code = 0; } + /* Since various aspects of the font may differ (widths, encoding, etc) + we cannot reliably use the UniqueID/XUID for copied fonts. + */ + if (uid_is_XUID(&font->pfont->UID)) + uid_free(&font->pfont->UID, font->pfont->memory, "pdfi_read_type1_font"); + uid_set_invalid(&font->pfont->UID); + + code = pdfi_font_generate_pseudo_XUID(ctx, font_dict, font->pfont); + if (code < 0) { + goto error; + } + if (code <= 0) { font->Encoding = spdffont->Encoding; pdfi_countup(font->Encoding); |