diff options
-rw-r--r-- | include/mupdf/html.h | 1 | ||||
-rw-r--r-- | source/html/css-apply.c | 23 | ||||
-rw-r--r-- | source/html/epub-doc.c | 11 | ||||
-rw-r--r-- | source/html/html-doc.c | 14 | ||||
-rw-r--r-- | source/html/html-layout.c | 3 |
5 files changed, 44 insertions, 8 deletions
diff --git a/include/mupdf/html.h b/include/mupdf/html.h index 557809df..6a5cdc90 100644 --- a/include/mupdf/html.h +++ b/include/mupdf/html.h @@ -185,6 +185,7 @@ fz_css_property *fz_parse_css_properties(fz_context *ctx, const char *source); void fz_drop_css(fz_context *ctx, fz_css_rule *rule); void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *rule, fz_xml *node); +void fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css_rule *css); int fz_get_css_match_display(fz_css_match *node); void fz_default_css_style(fz_context *ctx, fz_css_style *style); diff --git a/source/html/css-apply.c b/source/html/css-apply.c index d72079e8..6d99c07d 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -623,6 +623,29 @@ fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *css, fz_xml *nod } } +void +fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css_rule *css) +{ + fz_css_rule *rule; + fz_css_selector *sel; + fz_css_property *prop; + + for (rule = css; rule; rule = rule->next) + { + sel = rule->selector; + while (sel) + { + 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)); + break; + } + sel = sel->next; + } + } +} + static fz_css_value * value_from_raw_property(fz_css_match *match, const char *name) { diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index b7b24c42..90c86493 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -37,10 +37,13 @@ epub_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em) epub_document *doc = (epub_document*)doc_; epub_chapter *ch; - doc->page_margin[T] = em; - doc->page_margin[B] = em; - doc->page_margin[L] = 0; - doc->page_margin[R] = 0; + if (doc->spine && doc->spine->box) + { + doc->page_margin[T] = fz_from_css_number(doc->spine->box->style.margin[T], em, em); + doc->page_margin[B] = fz_from_css_number(doc->spine->box->style.margin[B], em, em); + doc->page_margin[L] = fz_from_css_number(doc->spine->box->style.margin[L], em, em); + doc->page_margin[R] = fz_from_css_number(doc->spine->box->style.margin[R], em, em); + } doc->page_w = w - doc->page_margin[L] - doc->page_margin[R]; doc->page_h = h - doc->page_margin[T] - doc->page_margin[B]; diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 90033717..04286f7c 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -44,13 +44,19 @@ static void htdoc_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em) { html_document *doc = (html_document*)doc_; - doc->page_margin[T] = em; - doc->page_margin[B] = em; - doc->page_margin[L] = 0; - doc->page_margin[R] = 0; + + if (doc->box) + { + doc->page_margin[T] = fz_from_css_number(doc->box->style.margin[T], em, em); + doc->page_margin[B] = fz_from_css_number(doc->box->style.margin[B], em, em); + doc->page_margin[L] = fz_from_css_number(doc->box->style.margin[L], em, em); + doc->page_margin[R] = fz_from_css_number(doc->box->style.margin[R], em, em); + } + doc->page_w = w - doc->page_margin[L] - doc->page_margin[R]; doc->page_h = h - doc->page_margin[T] - doc->page_margin[B]; doc->em = em; + fz_layout_html(ctx, doc->box, doc->page_w, doc->page_h, doc->em); } diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 5fd3937b..52171ef8 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -3,6 +3,7 @@ enum { T, R, B, L }; static const char *default_css = +"@page{margin:1em 0}" "html,address,blockquote,body,dd,div,dl,dt,h1,h2,h3,h4,h5,h6,ol,p,ul,center,hr,pre{display:block}" "span{display:inline}" "li{display:list-item}" @@ -1262,6 +1263,8 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha match.up = NULL; match.count = 0; + fz_match_css_at_page(ctx, &match, css); + fz_apply_css_style(ctx, set, &box->style, &match); generate_boxes(ctx, set, zip, base_uri, xml, box, css, &match, 0); |