diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-05-18 17:31:57 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-05-19 16:22:57 +0200 |
commit | c59e315a56d5f463ac329cb893082f06126d8660 (patch) | |
tree | 1af3d16532d7f7d295b8059c73af423f6b74e98f | |
parent | 5fbb1782eeb9a423799e4f4d98daf50fc25580a2 (diff) | |
download | mupdf-c59e315a56d5f463ac329cb893082f06126d8660.tar.xz |
epub: Support !important property declarations.
-rw-r--r-- | include/mupdf/html.h | 3 | ||||
-rw-r--r-- | source/html/css-apply.c | 16 | ||||
-rw-r--r-- | source/html/css-parse.c | 7 |
3 files changed, 17 insertions, 9 deletions
diff --git a/include/mupdf/html.h b/include/mupdf/html.h index 3f48af22..888ca91c 100644 --- a/include/mupdf/html.h +++ b/include/mupdf/html.h @@ -64,7 +64,8 @@ struct fz_css_property_s { char *name; fz_css_value *value; - int spec; + short spec; + short important; fz_css_property *next; }; diff --git a/source/html/css-apply.c b/source/html/css-apply.c index a4fe01d7..2333ef5d 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -189,15 +189,15 @@ count_selector_names(fz_css_selector *sel) return n; } -#define INLINE_SPECIFICITY 1000 +#define INLINE_SPECIFICITY 10000 static int -selector_specificity(fz_css_selector *sel) +selector_specificity(fz_css_selector *sel, int important) { int b = count_selector_ids(sel); int c = count_selector_atts(sel); int d = count_selector_names(sel); - return b * 100 + c * 10 + d; + return important * 1000 + b * 100 + c * 10 + d; } /* @@ -592,7 +592,7 @@ fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *css, fz_xml *nod if (match_selector(sel, node)) { for (prop = rule->declaration; prop; prop = prop->next) - add_property(match, prop->name, prop->value, selector_specificity(sel)); + add_property(match, prop->name, prop->value, selector_specificity(sel, prop->important)); break; } sel = sel->next; @@ -637,7 +637,7 @@ fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css_rule *css) if (sel->name && !strcmp(sel->name, "@page")) { for (prop = rule->declaration; prop; prop = prop->next) - add_property(match, prop->name, prop->value, selector_specificity(sel)); + add_property(match, prop->name, prop->value, selector_specificity(sel, prop->important)); break; } sel = sel->next; @@ -1098,7 +1098,9 @@ print_property(fz_css_property *prop) { printf("\t%s: ", prop->name); print_value(prop->value); - printf(" !%d;\n", prop->spec); + if (prop->important) + printf(" !important"); + printf(";\n"); } void @@ -1147,7 +1149,7 @@ print_rule(fz_css_rule *rule) for (sel = rule->selector; sel; sel = sel->next) { print_selector(sel); - printf(" !%d", selector_specificity(sel)); + printf(" /* %d */", selector_specificity(sel, 0)); if (sel->next) printf(", "); } diff --git a/source/html/css-parse.c b/source/html/css-parse.c index e57eb798..0946043e 100644 --- a/source/html/css-parse.c +++ b/source/html/css-parse.c @@ -58,6 +58,7 @@ static fz_css_property *fz_new_css_property(fz_context *ctx, const char *name, f prop->name = fz_strdup(ctx, name); prop->value = value; prop->spec = spec; + prop->important = 0; prop->next = NULL; return prop; } @@ -610,7 +611,11 @@ static fz_css_property *parse_declaration(struct lexbuf *buf) /* !important */ if (accept(buf, '!')) { - expect(buf, CSS_KEYWORD); + white(buf); + if (buf->lookahead != CSS_KEYWORD || strcmp(buf->string, "important")) + fz_css_error(buf, "expected keyword 'important' after '!'"); + p->important = 1; + next(buf); white(buf); } |