summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-05-14 00:19:44 +0200
committerTor Andersson <tor.andersson@artifex.com>2015-05-15 16:12:23 +0200
commit5179418ae7f4497ad6fec2e7d1ac2a8ad7492fd8 (patch)
treea974080219ab4ecf51594d88a29d8d0b45ce46a4 /source/html
parenteaaca0513d26fa9e7cc515dbba950536c0005c06 (diff)
downloadmupdf-5179418ae7f4497ad6fec2e7d1ac2a8ad7492fd8.tar.xz
epub: Apply @page selector margins.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/css-apply.c23
-rw-r--r--source/html/epub-doc.c11
-rw-r--r--source/html/html-doc.c14
-rw-r--r--source/html/html-layout.c3
4 files changed, 43 insertions, 8 deletions
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);