diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-03-29 16:44:07 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-03-31 13:00:23 +0200 |
commit | b6f4a4448a2f84fd29f367ce294e7131e9c2b752 (patch) | |
tree | a2a9a8028dd604fba46cfff4ced7c36a409c3691 /source/html | |
parent | 05c87deb80a08d4451ad656459f17eb586872516 (diff) | |
download | mupdf-b6f4a4448a2f84fd29f367ce294e7131e9c2b752.tar.xz |
html: Tweak how builtin font families are loaded.
Diffstat (limited to 'source/html')
-rw-r--r-- | source/html/html-font.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/source/html/html-font.c b/source/html/html-font.c index 64121416..389ddb34 100644 --- a/source/html/html-font.c +++ b/source/html/html-font.c @@ -1,37 +1,47 @@ #include "mupdf/html.h" -static const char *font_names[16] = -{ - "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic", - "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique", - "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique", - "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique", -}; - -fz_font * -fz_load_html_builtin_font(fz_context *ctx, fz_html_font_set *set, const char *family, int is_bold, int is_italic) +static fz_font * +fz_load_html_default_font(fz_context *ctx, fz_html_font_set *set, const char *family, int is_bold, int is_italic) { int is_mono = !strcmp(family, "monospace"); int is_sans = !strcmp(family, "sans-serif"); - int idx = is_mono * 8 + is_sans * 4 + is_bold * 2 + is_italic; + const char *real_family = is_mono ? "Courier" : is_sans ? "Helvetica" : "Times"; + int idx = (is_mono ? 8 : is_sans ? 4 : 0) + is_bold * 2 + is_italic; if (!set->fonts[idx]) { const char *data; int size; - data = fz_lookup_base14_font(ctx, font_names[idx], &size); + data = fz_lookup_builtin_font(ctx, real_family, is_bold, is_italic, &size); if (!data) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font: %s", font_names[idx]); - set->fonts[idx] = fz_new_font_from_memory(ctx, font_names[idx], data, size, 0, 1); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font: %s", real_family); + set->fonts[idx] = fz_new_font_from_memory(ctx, NULL, data, size, 0, 1); set->fonts[idx]->is_serif = !is_sans; } return set->fonts[idx]; } +void +fz_add_html_font_face(fz_context *ctx, fz_html_font_set *set, + const char *family, int is_bold, int is_italic, const char *src, + fz_font *font) +{ + fz_html_font_face *custom = fz_malloc_struct(ctx, fz_html_font_face); + custom->font = fz_keep_font(ctx, font); + custom->src = fz_strdup(ctx, src); + custom->family = fz_strdup(ctx, family); + custom->is_bold = is_bold; + custom->is_italic = is_italic; + custom->next = set->custom; + set->custom = custom; +} + fz_font * fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, int is_bold, int is_italic) { fz_html_font_face *custom; + const char *data; + int size; for (custom = set->custom; custom; custom = custom->next) { @@ -43,29 +53,23 @@ fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, in } } - if (!strcmp(family, "monospace") || - !strcmp(family, "sans-serif") || - !strcmp(family, "serif")) - return fz_load_html_builtin_font(ctx, set, family, is_bold, is_italic); - - return NULL; -} + data = fz_lookup_builtin_font(ctx, family, is_bold, is_italic, &size); + if (data) + { + fz_font *font = fz_new_font_from_memory(ctx, NULL, data, size, 0, 0); + if (is_bold && !font->is_bold) + font->fake_bold = 1; + if (is_italic && !font->is_italic) + font->fake_italic = 1; + fz_add_html_font_face(ctx, set, family, is_bold, is_italic, "<builtin>", font); + fz_drop_font(ctx, font); + return font; + } -void -fz_add_html_font_face(fz_context *ctx, fz_html_font_set *set, - const char *family, int is_bold, int is_italic, const char *src, - fz_font *font) -{ - fz_html_font_face *custom; + if (!strcmp(family, "monospace") || !strcmp(family, "sans-serif") || !strcmp(family, "serif")) + return fz_load_html_default_font(ctx, set, family, is_bold, is_italic); - custom = fz_malloc_struct(ctx, fz_html_font_face); - custom->font = fz_keep_font(ctx, font); - custom->src = fz_strdup(ctx, src); - custom->family = fz_strdup(ctx, family); - custom->is_bold = is_bold; - custom->is_italic = is_italic; - custom->next = set->custom; - set->custom = custom; + return NULL; } fz_html_font_set *fz_new_html_font_set(fz_context *ctx) |