summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2022-05-19 15:16:32 +0100
committerRobin Watts <Robin.Watts@artifex.com>2022-06-03 11:46:29 +0100
commit1911b064d3fa2c14d6fbdd971c8c55a59fcc141f (patch)
treed5f94e984f875b20d42cb8dc9470cf24cb250d66
parent1149c5ab914c7695caa8951bb8213f4241c51104 (diff)
downloadghostpdl-9.56.1-backport.tar.gz
Bug 705298: Change priority of font mapsghostpdl-9.56.1-backport
The pdfi fontmap code prioritized explicit mappings from the Fontmap file, over mappings generated automatically from the FONTPATH option. Turns out, it should be the other way around. Secondly, the pdfi code would "sanitize" the font name to look for before consulting either font map, where we should check the name as read from the PDF before trying the sanitized version.
-rw-r--r--pdf/pdf_fmap.c37
-rw-r--r--pdf/pdf_font.c139
2 files changed, 103 insertions, 73 deletions
diff --git a/pdf/pdf_fmap.c b/pdf/pdf_fmap.c
index ee05af1c5..25da9d21f 100644
--- a/pdf/pdf_fmap.c
+++ b/pdf/pdf_fmap.c
@@ -814,22 +814,7 @@ pdf_fontmap_lookup_font(pdf_context *ctx, pdf_name *fname, pdf_obj **mapname, in
return code;
}
- code = pdfi_dict_get_by_key(ctx, ctx->pdffontmap, fname, &mname);
- if (code >= 0) {
- /* Fontmap can map in multiple "jump" i.e.
- name -> substitute name
- subsitute name -> file name
- So we want to loop until we no more hits.
- */
- while(1) {
- pdf_obj *mname2;
- code = pdfi_dict_get_by_key(ctx, ctx->pdffontmap, (pdf_name *)mname, &mname2);
- if (code < 0) break;
- pdfi_countdown(mname);
- mname = mname2;
- }
- }
- else if (ctx->pdfnativefontmap != NULL) {
+ if (ctx->pdfnativefontmap != NULL) {
pdf_obj *record;
code = pdfi_dict_get_by_key(ctx, ctx->pdfnativefontmap, fname, &record);
if (code < 0)
@@ -850,7 +835,27 @@ pdf_fontmap_lookup_font(pdf_context *ctx, pdf_name *fname, pdf_obj **mapname, in
}
}
}
+ else {
+ code = gs_error_undefined;
+ }
+ if (code < 0) {
+ code = pdfi_dict_get_by_key(ctx, ctx->pdffontmap, fname, &mname);
+ if (code >= 0) {
+ /* Fontmap can map in multiple "jump" i.e.
+ name -> substitute name
+ subsitute name -> file name
+ So we want to loop until we no more hits.
+ */
+ while(1) {
+ pdf_obj *mname2;
+ code = pdfi_dict_get_by_key(ctx, ctx->pdffontmap, (pdf_name *)mname, &mname2);
+ if (code < 0) break;
+ pdfi_countdown(mname);
+ mname = mname2;
+ }
+ }
+ }
if (mname != NULL && mname->type == PDF_STRING && pdfi_fmap_file_exists(ctx, (pdf_string *)mname)) {
*mapname = mname;
code = 0;
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index fa716056d..f16193d14 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -533,6 +533,7 @@ pdfi_open_font_substitute_file(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *
pdf_obj *fontname = NULL;
stream *s;
const char *fn;
+ bool f_retry = true;
code = pdfi_dict_knownget_type(ctx, font_dict, "BaseFont", PDF_NAME, &basefont);
if (code < 0 || basefont == NULL || ((pdf_name *)basefont)->length == 0)
@@ -558,74 +559,98 @@ pdfi_open_font_substitute_file(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *
if (((pdf_name *)fontname)->length < gp_file_name_sizeof) {
memcpy(fontfname, ((pdf_name *)fontname)->data, ((pdf_name *)fontname)->length);
fontfname[((pdf_name *)fontname)->length] = '\0';
- fn = pdfi_clean_font_name(fontfname);
- if (fn != NULL) {
- pdfi_countdown(fontname);
+ pdfi_countdown(fontname);
- code = pdfi_name_alloc(ctx, (byte *)fn, strlen(fn), (pdf_obj **) &fontname);
- if (code < 0)
- return code;
- pdfi_countup(fontname);
- }
- }
- code = pdf_fontmap_lookup_font(ctx, (pdf_name *) fontname, &mapname, findex);
- if (code < 0) {
- mapname = fontname;
- pdfi_countup(mapname);
- code = 0;
+ code = pdfi_name_alloc(ctx, (byte *)fontfname, strlen(fontfname), (pdf_obj **) &fontname);
+ if (code < 0)
+ return code;
+ pdfi_countup(fontname);
}
- if (mapname->type == PDF_NAME || mapname->type == PDF_STRING) {
- pdf_name *mname = (pdf_name *) mapname;
- if (mname->length + 1 < gp_file_name_sizeof) {
- memcpy(fontfname, mname->data, mname->length);
- fontfname[mname->length] = '\0';
+
+ do {
+ code = pdf_fontmap_lookup_font(ctx, (pdf_name *) fontname, &mapname, findex);
+ if (code < 0) {
+ if (((pdf_name *)fontname)->length < gp_file_name_sizeof) {
+ memcpy(fontfname, ((pdf_name *)fontname)->data, ((pdf_name *)fontname)->length);
+ fontfname[((pdf_name *)fontname)->length] = '\0';
+ fn = pdfi_clean_font_name(fontfname);
+ if (fn != NULL) {
+ pdfi_countdown(fontname);
+
+ code = pdfi_name_alloc(ctx, (byte *)fn, strlen(fn), (pdf_obj **) &fontname);
+ if (code < 0)
+ return code;
+ pdfi_countup(fontname);
+ }
+ }
+ code = pdf_fontmap_lookup_font(ctx, (pdf_name *) fontname, &mapname, findex);
+ if (code < 0) {
+ mapname = fontname;
+ pdfi_countup(mapname);
+ code = 0;
+ }
+ }
+ if (mapname->type == PDF_NAME || mapname->type == PDF_STRING) {
+ pdf_name *mname = (pdf_name *) mapname;
+ if (mname->length + 1 < gp_file_name_sizeof) {
+ memcpy(fontfname, mname->data, mname->length);
+ fontfname[mname->length] = '\0';
+ }
+ else {
+ pdfi_countdown(mapname);
+ pdfi_countdown(fontname);
+ return_error(gs_error_invalidfileaccess);
+ }
}
else {
pdfi_countdown(mapname);
pdfi_countdown(fontname);
return_error(gs_error_invalidfileaccess);
}
- }
- else {
- pdfi_countdown(mapname);
- pdfi_countdown(fontname);
- return_error(gs_error_invalidfileaccess);
- }
- code = pdfi_open_font_file(ctx, fontfname, strlen(fontfname), &s);
- if (code >= 0) {
- gs_const_string fname;
- if (basefont) {
- pdfi_print_string(ctx, "Loading font ");
- pdfi_print_font_name(ctx, (pdf_name *)basefont);
- pdfi_print_string(ctx, " (or substitute) from ");
- }
- else {
- pdfi_print_string(ctx, "Loading nameless font from ");
- }
- sfilename(s, &fname);
- if (fname.size < gp_file_name_sizeof) {
- memcpy(fontfname, fname.data, fname.size);
- fontfname[fname.size] = '\0';
- }
- else {
- strcpy(fontfname, "unnamed file");
- }
- pdfi_print_string(ctx, fontfname);
- pdfi_print_string(ctx, "\n");
-
- sfseek(s, 0, SEEK_END);
- *buflen = sftell(s);
- sfseek(s, 0, SEEK_SET);
- *buf = gs_alloc_bytes(ctx->memory, *buflen, "pdfi_open_t1_font_file(buf)");
- if (*buf != NULL) {
- sfread(*buf, 1, *buflen, s);
+ code = pdfi_open_font_file(ctx, fontfname, strlen(fontfname), &s);
+ if (code < 0 && f_retry && mapname->type == PDF_NAME) {
+ pdfi_countdown(fontname);
+ fontname = mapname;
+ mapname = NULL;
+ f_retry = false;
+ continue;
}
- else {
- code = gs_note_error(gs_error_VMerror);
+ if (code >= 0) {
+ gs_const_string fname;
+ if (basefont) {
+ pdfi_print_string(ctx, "Loading font ");
+ pdfi_print_font_name(ctx, (pdf_name *)basefont);
+ pdfi_print_string(ctx, " (or substitute) from ");
+ }
+ else {
+ pdfi_print_string(ctx, "Loading nameless font from ");
+ }
+ sfilename(s, &fname);
+ if (fname.size < gp_file_name_sizeof) {
+ memcpy(fontfname, fname.data, fname.size);
+ fontfname[fname.size] = '\0';
+ }
+ else {
+ strcpy(fontfname, "unnamed file");
+ }
+ pdfi_print_string(ctx, fontfname);
+ pdfi_print_string(ctx, "\n");
+
+ sfseek(s, 0, SEEK_END);
+ *buflen = sftell(s);
+ sfseek(s, 0, SEEK_SET);
+ *buf = gs_alloc_bytes(ctx->memory, *buflen, "pdfi_open_t1_font_file(buf)");
+ if (*buf != NULL) {
+ sfread(*buf, 1, *buflen, s);
+ }
+ else {
+ code = gs_note_error(gs_error_VMerror);
+ }
+ sfclose(s);
}
- sfclose(s);
- }
+ break;
+ } while (1);
pdfi_countdown(basefont);
pdfi_countdown(mapname);