diff options
-rw-r--r-- | include/mupdf/fitz/context.h | 10 | ||||
-rw-r--r-- | source/fitz/context.c | 12 | ||||
-rw-r--r-- | source/html/css-apply.c | 27 | ||||
-rw-r--r-- | source/html/html-layout.c | 6 |
4 files changed, 41 insertions, 14 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 9966b36f..b9363ebd 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -349,6 +349,16 @@ const char *fz_user_css(fz_context *ctx); void fz_set_user_css(fz_context *ctx, const char *text); /* + fz_use_document_css: Return whether to respect document styles in HTML and EPUB. +*/ +int fz_use_document_css(fz_context *ctx); + +/* + fz_set_use_document_css: Toggle whether to respect document styles in HTML and EPUB. +*/ +void fz_set_use_document_css(fz_context *ctx, int use); + +/* Locking functions MuPDF is kept deliberately free of any knowledge of particular diff --git a/source/fitz/context.c b/source/fitz/context.c index 3e79bbea..f62cd9d7 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -35,6 +35,7 @@ struct fz_style_context_s { int refs; char *user_css; + int use_document_css; }; static void fz_new_style_context(fz_context *ctx) @@ -44,6 +45,7 @@ static void fz_new_style_context(fz_context *ctx) ctx->style = fz_malloc_struct(ctx, fz_style_context); ctx->style->refs = 1; ctx->style->user_css = NULL; + ctx->style->use_document_css = 1; } } @@ -65,6 +67,16 @@ static void fz_drop_style_context(fz_context *ctx) } } +void fz_set_use_document_css(fz_context *ctx, int use) +{ + ctx->style->use_document_css = use; +} + +int fz_use_document_css(fz_context *ctx) +{ + return ctx->style->use_document_css; +} + void fz_set_user_css(fz_context *ctx, const char *user_css) { fz_free(ctx, ctx->style->user_css); diff --git a/source/html/css-apply.c b/source/html/css-apply.c index e5e4def4..f3e28ddd 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -644,22 +644,25 @@ fz_match_css(fz_context *ctx, fz_css_match *match, fz_css *css, fz_xml *node) } } - s = fz_xml_att(node, "style"); - if (s) + if (fz_use_document_css(ctx)) { - fz_try(ctx) + s = fz_xml_att(node, "style"); + if (s) { - prop = fz_parse_css_properties(ctx, css->pool, s); - while (prop) + fz_try(ctx) { - add_property(match, prop->name, prop->value, INLINE_SPECIFICITY); - prop = prop->next; + prop = fz_parse_css_properties(ctx, css->pool, s); + while (prop) + { + add_property(match, prop->name, prop->value, INLINE_SPECIFICITY); + prop = prop->next; + } + /* We can "leak" the property here, since it is freed along with the pool allocator. */ + } + fz_catch(ctx) + { + fz_warn(ctx, "ignoring style attribute"); } - /* We can "leak" the property here, since it is freed along with the pool allocator. */ - } - fz_catch(ctx) - { - fz_warn(ctx, "ignoring style attribute"); } } diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 95f2a76b..b958a3a3 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -2545,14 +2545,16 @@ 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>"); - fb2_load_css(ctx, g.zip, g.base_uri, g.css, xml); + if (fz_use_document_css(ctx)) + fb2_load_css(ctx, g.zip, g.base_uri, g.css, xml); g.images = load_fb2_images(ctx, xml); } else { g.is_fb2 = 0; fz_parse_css(ctx, g.css, html_default_css, "<default:html>"); - html_load_css(ctx, g.zip, g.base_uri, g.css, xml); + if (fz_use_document_css(ctx)) + html_load_css(ctx, g.zip, g.base_uri, g.css, xml); g.images = NULL; } |