[gs-commits] mupdf 1.16.1.28 Bug 701486: Use correct base URI to load
[email protected] (Tor Andersson)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 6f8cdc622dbd1770a74dc9b94a80c42b26d7bac7 Author: Tor Andersson <[email protected]> Date: Thu Sep 5 16:04:45 2019 +0200 Bug 701486: Use correct base URI to load font faces from stylesheets. diff --git a/source/html/css-apply.c b/source/html/css-apply.c index c788683..ba97386 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -776,15 +776,19 @@ fz_add_css_font_faces(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, c for (rule = css->rule; rule; rule = rule->next) { - sel = rule->selector; - while (sel) + if (!rule->loaded) { - if (sel->name && !strcmp(sel->name, "@font-face")) + rule->loaded = 1; + sel = rule->selector; + while (sel) { - fz_add_css_font_face(ctx, set, zip, base_uri, rule->declaration); - break; + if (sel->name && !strcmp(sel->name, "@font-face")) + { + fz_add_css_font_face(ctx, set, zip, base_uri, rule->declaration); + break; + } + sel = sel->next; } - sel = sel->next; } } } diff --git a/source/html/html-imp.h b/source/html/html-imp.h index 53e2ce3..62cdc03 100644 --- a/source/html/html-imp.h +++ b/source/html/html-imp.h @@ -59,6 +59,7 @@ struct fz_css_rule_s fz_css_selector *selector; fz_css_property *declaration; fz_css_rule *next; + int loaded; }; struct fz_css_selector_s diff --git a/source/html/html-parse.c b/source/html/html-parse.c index 6be0f5c..1f7dd13 100644 --- a/source/html/html-parse.c +++ b/source/html/html-parse.c @@ -916,14 +916,40 @@ static char *concat_text(fz_context *ctx, fz_xml *root) } static void -html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css *css, fz_xml *root) +html_load_css_link(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_css *css, fz_xml *root, const char *href) { - fz_xml *html, *head, *node; - fz_buffer *buf; char path[2048]; + char css_base_uri[2048]; + fz_buffer *buf; fz_var(buf); + fz_strlcpy(path, base_uri, sizeof path); + fz_strlcat(path, "/", sizeof path); + fz_strlcat(path, href, sizeof path); + fz_urldecode(path); + fz_cleanname(path); + + fz_dirname(css_base_uri, path, sizeof css_base_uri); + + buf = NULL; + fz_try(ctx) + { + buf = fz_read_archive_entry(ctx, zip, path); + fz_parse_css(ctx, css, fz_string_from_buffer(ctx, buf), path); + fz_add_css_font_faces(ctx, set, zip, css_base_uri, css); + } + fz_always(ctx) + fz_drop_buffer(ctx, buf); + fz_catch(ctx) + fz_warn(ctx, "ignoring stylesheet %s", path); +} + +static void +html_load_css(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_css *css, fz_xml *root) +{ + fz_xml *html, *head, *node; + html = fz_xml_find(root, "html"); head = fz_xml_find_down(html, "head"); for (node = fz_xml_down(head); node; node = fz_xml_next(node)) @@ -939,22 +965,7 @@ html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css *cs char *href = fz_xml_att(node, "href"); if (href) { - fz_strlcpy(path, base_uri, sizeof path); - fz_strlcat(path, "/", sizeof path); - fz_strlcat(path, href, sizeof path); - fz_urldecode(path); - fz_cleanname(path); - - buf = NULL; - fz_try(ctx) - { - buf = fz_read_archive_entry(ctx, zip, path); - fz_parse_css(ctx, css, fz_string_from_buffer(ctx, buf), path); - } - fz_always(ctx) - fz_drop_buffer(ctx, buf); - fz_catch(ctx) - fz_warn(ctx, "ignoring stylesheet %s", path); + html_load_css_link(ctx, set, zip, base_uri, css, root, href); } } } @@ -972,7 +983,7 @@ html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css *cs } static void -fb2_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css *css, fz_xml *root) +fb2_load_css(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_css *css, fz_xml *root) { fz_xml *fictionbook, *stylesheet; @@ -982,7 +993,10 @@ fb2_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css *css { char *s = concat_text(ctx, stylesheet); fz_try(ctx) + { fz_parse_css(ctx, css, s, "<stylesheet>"); + fz_add_css_font_faces(ctx, set, zip, base_uri, css); + } fz_catch(ctx) fz_warn(ctx, "ignoring inline stylesheet"); fz_free(ctx, s); @@ -1231,7 +1245,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha g.is_fb2 = 1; fz_parse_css(ctx, g.css, fb2_default_css, "<default:fb2>"); if (fz_use_document_css(ctx)) - fb2_load_css(ctx, g.zip, g.base_uri, g.css, root); + fb2_load_css(ctx, g.set, g.zip, g.base_uri, g.css, root); g.images = load_fb2_images(ctx, root); } else @@ -1239,14 +1253,15 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha g.is_fb2 = 0; fz_parse_css(ctx, g.css, html_default_css, "<default:html>"); if (fz_use_document_css(ctx)) - html_load_css(ctx, g.zip, g.base_uri, g.css, root); + html_load_css(ctx, g.set, g.zip, g.base_uri, g.css, root); g.images = NULL; } if (user_css) + { fz_parse_css(ctx, g.css, user_css, "<user>"); - - fz_add_css_font_faces(ctx, g.set, g.zip, g.base_uri, g.css); /* load @font-face fonts into font set */ + fz_add_css_font_faces(ctx, g.set, g.zip, ".", g.css); + } } fz_catch(ctx) { http://git.ghostscript.com/?p=mupdf.git;a=commit;h=6f8cdc622dbd1770a74dc9b94a80c42b26d7bac7 -- MuPDF library Artifex Software, Inc.