summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-07-20 16:07:46 +0200
committerTor Andersson <tor.andersson@artifex.com>2012-07-20 16:40:20 +0200
commit0c52b314e922708903f76c3a4cecfcbbeff069e8 (patch)
treebd970f5134e0a03d806f79dadf9b1059a46e1588
parent2bfb37fd1d0b0eecd001cb61ffcd15887c4603f7 (diff)
downloadmupdf-0c52b314e922708903f76c3a4cecfcbbeff069e8.tar.xz
Prefer the more specific name if BaseName and FontName differ.
Also strip the subset prefix.
-rw-r--r--pdf/pdf_font.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index 58fbc74a..bfd1d97d 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -411,7 +411,6 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
int kind;
char *basefont;
- char *fontname;
char *estrings[256];
char ebuffer[256][32];
int i, k, n;
@@ -422,7 +421,6 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
fz_var(etable);
basefont = pdf_to_name(pdf_dict_gets(dict, "BaseFont"));
- fontname = clean_font_name(basefont);
/* Load font file */
fz_try(ctx)
@@ -433,7 +431,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
if (descriptor)
pdf_load_font_descriptor(fontdesc, xref, descriptor, NULL, basefont);
else
- pdf_load_builtin_font(ctx, fontdesc, fontname);
+ pdf_load_builtin_font(ctx, fontdesc, clean_font_name(basefont));
/* Some chinese documents mistakenly consider WinAnsiEncoding to be codepage 936 */
if (!*fontdesc->font->name &&
@@ -982,15 +980,25 @@ static void
pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *dict, char *collection, char *basefont)
{
pdf_obj *obj1, *obj2, *obj3, *obj;
- char *fontname;
- char *origname;
+ char *fontname, *origname, *p;
FT_Face face;
fz_context *ctx = xref->ctx;
- if (!strchr(basefont, ',') || strchr(basefont, '+'))
- origname = pdf_to_name(pdf_dict_gets(dict, "FontName"));
- else
+ /* The descriptor's FontName should be the same as the font's BaseFont. */
+ origname = pdf_to_name(pdf_dict_gets(dict, "FontName"));
+ if (!origname)
+ origname = basefont;
+
+ /* Prefer BaseFont if it has a style suffix */
+ if (strchr(basefont, ','))
origname = basefont;
+
+ /* Strip the SUBSET+ prefix */
+ p = strchr(origname, '+');
+ if (p)
+ origname = p + 1;
+
+ /* Look through list of alternate names for built in fonts */
fontname = clean_font_name(origname);
fontdesc->flags = pdf_to_int(pdf_dict_gets(dict, "Flags"));
@@ -1019,7 +1027,6 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *d
pdf_load_builtin_font(ctx, fontdesc, fontname);
else
pdf_load_system_font(ctx, fontdesc, fontname, collection);
- /* RJW: "cannot load font descriptor (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */
}
}
else
@@ -1028,11 +1035,8 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *d
pdf_load_builtin_font(ctx, fontdesc, fontname);
else
pdf_load_system_font(ctx, fontdesc, fontname, collection);
- /* RJW: "cannot load font descriptor (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */
}
- fz_strlcpy(fontdesc->font->name, fontname, sizeof fontdesc->font->name);
-
/* Check for DynaLab fonts that must use hinting */
face = fontdesc->font->ft_face;
if (ft_kind(face) == TRUETYPE)