summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-12-14 15:27:24 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-12-16 02:16:58 +0100
commit845875985942c1df3db94e7b73fccdc413c25a63 (patch)
tree3198bdbf2069f2cf28729aebeb909a07a6c5dc0c /source/html
parentbf8fa993e6403991bfcad13ccfb2873e32c37194 (diff)
downloadmupdf-845875985942c1df3db94e7b73fccdc413c25a63.tar.xz
Move page size and margins into fz_html struct.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/epub-doc.c49
-rw-r--r--source/html/html-doc.c48
-rw-r--r--source/html/html-layout.c37
3 files changed, 50 insertions, 84 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index ed52484c..590004f6 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -21,8 +21,6 @@ struct epub_chapter_s
{
char *path;
int start;
- float page_w, page_h, em;
- float page_margin[4];
fz_html *html;
epub_chapter *next;
};
@@ -55,8 +53,8 @@ epub_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest, float *x
float y = fz_find_html_target(ctx, ch->html, s+1);
if (y >= 0)
{
- int page = y / ch->page_h;
- if (yp) *yp = y - page * ch->page_h;
+ int page = y / ch->html->page_h;
+ if (yp) *yp = y - page * ch->html->page_h;
return ch->start + page;
}
return -1;
@@ -89,15 +87,8 @@ epub_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em)
for (ch = doc->spine; ch; ch = ch->next)
{
ch->start = count;
- ch->em = em;
- ch->page_margin[T] = fz_from_css_number(ch->html->root->style.margin[T], em, em);
- ch->page_margin[B] = fz_from_css_number(ch->html->root->style.margin[B], em, em);
- ch->page_margin[L] = fz_from_css_number(ch->html->root->style.margin[L], em, em);
- ch->page_margin[R] = fz_from_css_number(ch->html->root->style.margin[R], em, em);
- ch->page_w = w - ch->page_margin[L] - ch->page_margin[R];
- ch->page_h = h - ch->page_margin[T] - ch->page_margin[B];
- fz_layout_html(ctx, ch->html, ch->page_w, ch->page_h, ch->em);
- count += ceilf(ch->html->root->h / ch->page_h);
+ fz_layout_html(ctx, ch->html, w, h, em);
+ count += ceilf(ch->html->root->h / ch->html->page_h);
}
epub_update_outline(ctx, doc_, doc->outline);
@@ -110,7 +101,7 @@ epub_count_pages(fz_context *ctx, fz_document *doc_)
epub_chapter *ch;
int count = 0;
for (ch = doc->spine; ch; ch = ch->next)
- count += ceilf(ch->html->root->h / ch->page_h);
+ count += ceilf(ch->html->root->h / ch->html->page_h);
return count;
}
@@ -130,13 +121,13 @@ epub_bound_page(fz_context *ctx, fz_page *page_, fz_rect *bbox)
for (ch = doc->spine; ch; ch = ch->next)
{
- int cn = ceilf(ch->html->root->h / ch->page_h);
+ int cn = ceilf(ch->html->root->h / ch->html->page_h);
if (n < count + cn)
{
bbox->x0 = 0;
bbox->y0 = 0;
- bbox->x1 = ch->page_w + ch->page_margin[L] + ch->page_margin[R];
- bbox->y1 = ch->page_h + ch->page_margin[T] + ch->page_margin[B];
+ bbox->x1 = ch->html->page_w + ch->html->page_margin[L] + ch->html->page_margin[R];
+ bbox->y1 = ch->html->page_h + ch->html->page_margin[T] + ch->html->page_margin[B];
return bbox;
}
count += cn;
@@ -152,17 +143,15 @@ epub_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix *
epub_page *page = (epub_page*)page_;
epub_document *doc = page->doc;
epub_chapter *ch;
- fz_matrix local_ctm = *ctm;
int n = page->number;
int count = 0;
for (ch = doc->spine; ch; ch = ch->next)
{
- int cn = ceilf(ch->html->root->h / ch->page_h);
+ int cn = ceilf(ch->html->root->h / ch->html->page_h);
if (n < count + cn)
{
- fz_pre_translate(&local_ctm, ch->page_margin[L], ch->page_margin[T]);
- fz_draw_html(ctx, dev, &local_ctm, ch->html, (n-count) * ch->page_h, (n-count+1) * ch->page_h);
+ fz_draw_html(ctx, dev, ctm, ch->html, n-count);
break;
}
count += cn;
@@ -177,26 +166,12 @@ epub_load_links(fz_context *ctx, fz_page *page_)
epub_chapter *ch;
int n = page->number;
int count = 0;
- fz_link *head, *link;
for (ch = doc->spine; ch; ch = ch->next)
{
- int cn = ceilf(ch->html->root->h / ch->page_h);
+ int cn = ceilf(ch->html->root->h / ch->html->page_h);
if (n < count + cn)
- {
- head = fz_load_html_links(ctx, ch->html, n - count, ch->page_h, ch->path);
- for (link = head; link; link = link->next)
- {
- link->doc = doc;
-
- /* Adjust for page margins */
- link->rect.x0 += ch->page_margin[L];
- link->rect.x1 += ch->page_margin[L];
- link->rect.y0 += ch->page_margin[T];
- link->rect.y1 += ch->page_margin[T];
- }
- return head;
- }
+ return fz_load_html_links(ctx, ch->html, n - count, ch->path);
count += cn;
}
diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index 8d602030..05a86d83 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -10,8 +10,6 @@ struct html_document_s
fz_document super;
fz_archive *zip;
fz_html_font_set *set;
- float page_w, page_h, em;
- float page_margin[4];
fz_html *html;
};
@@ -41,8 +39,8 @@ htdoc_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest, float *
float y = fz_find_html_target(ctx, doc->html, s+1);
if (y >= 0)
{
- int page = y / doc->page_h;
- if (yp) *yp = y - page * doc->page_h;
+ int page = y / doc->html->page_h;
+ if (yp) *yp = y - page * doc->html->page_h;
return page;
}
}
@@ -54,7 +52,7 @@ static int
htdoc_count_pages(fz_context *ctx, fz_document *doc_)
{
html_document *doc = (html_document*)doc_;
- int count = ceilf(doc->html->root->h / doc->page_h);
+ int count = ceilf(doc->html->root->h / doc->html->page_h);
return count;
}
@@ -63,19 +61,7 @@ htdoc_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em)
{
html_document *doc = (html_document*)doc_;
- if (doc->html && doc->html->root)
- {
- doc->page_margin[T] = fz_from_css_number(doc->html->root->style.margin[T], em, em);
- doc->page_margin[B] = fz_from_css_number(doc->html->root->style.margin[B], em, em);
- doc->page_margin[L] = fz_from_css_number(doc->html->root->style.margin[L], em, em);
- doc->page_margin[R] = fz_from_css_number(doc->html->root->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->html, doc->page_w, doc->page_h, doc->em);
+ fz_layout_html(ctx, doc->html, w, h, em);
}
static void
@@ -90,8 +76,8 @@ htdoc_bound_page(fz_context *ctx, fz_page *page_, fz_rect *bbox)
html_document *doc = page->doc;
bbox->x0 = 0;
bbox->y0 = 0;
- bbox->x1 = doc->page_w + doc->page_margin[L] + doc->page_margin[R];
- bbox->y1 = doc->page_h + doc->page_margin[T] + doc->page_margin[B];
+ bbox->x1 = doc->html->page_w + doc->html->page_margin[L] + doc->html->page_margin[R];
+ bbox->y1 = doc->html->page_h + doc->html->page_margin[T] + doc->html->page_margin[B];
return bbox;
}
@@ -100,12 +86,7 @@ htdoc_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix
{
html_page *page = (html_page*)page_;
html_document *doc = page->doc;
- fz_matrix local_ctm = *ctm;
- int n = page->number;
-
- fz_pre_translate(&local_ctm, doc->page_margin[L], doc->page_margin[T]);
-
- fz_draw_html(ctx, dev, &local_ctm, doc->html, n * doc->page_h, (n+1) * doc->page_h);
+ fz_draw_html(ctx, dev, ctm, doc->html, page->number);
}
static fz_link *
@@ -113,20 +94,7 @@ htdoc_load_links(fz_context *ctx, fz_page *page_)
{
html_page *page = (html_page*)page_;
html_document *doc = page->doc;
- fz_link *head, *link;
-
- head = fz_load_html_links(ctx, doc->html, page->number, doc->page_h, "");
- for (link = head; link; link = link->next)
- {
- link->doc = doc;
-
- /* Adjust for page margins */
- link->rect.x0 += doc->page_margin[L];
- link->rect.x1 += doc->page_margin[L];
- link->rect.y0 += doc->page_margin[T];
- link->rect.y1 += doc->page_margin[T];
- }
- return head;
+ return fz_load_html_links(ctx, doc->html, page->number, "");
}
static fz_page *
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index b958a3a3..547ecf96 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -1865,23 +1865,25 @@ static void draw_block_box(fz_context *ctx, fz_html_box *box, float page_top, fl
}
void
-fz_draw_html(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_html *html, float page_top, float page_bot)
+fz_draw_html(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_html *html, int page)
{
fz_matrix local_ctm = *ctm;
hb_buffer_t *hb_buf = NULL;
int unlocked = 0;
+ float page_top = page * html->page_h;
+ float page_bot = (page + 1) * html->page_h;
fz_var(hb_buf);
fz_var(unlocked);
- hb_lock(ctx);
+ fz_pre_translate(&local_ctm, html->page_margin[L], html->page_margin[T] - page_top);
+ hb_lock(ctx);
fz_try(ctx)
{
hb_buf = hb_buffer_create();
hb_unlock(ctx);
unlocked = 1;
- fz_pre_translate(&local_ctm, 0, -page_top);
draw_block_box(ctx, html->root, page_top, page_bot, dev, &local_ctm, hb_buf);
}
fz_always(ctx)
@@ -2014,11 +2016,24 @@ static fz_link *load_link_box(fz_context *ctx, fz_html_box *box, fz_link *head,
}
fz_link *
-fz_load_html_links(fz_context *ctx, fz_html *html, int page, int page_h, const char *file)
+fz_load_html_links(fz_context *ctx, fz_html *html, int page, const char *file)
{
+ fz_link *link, *head;
char dir[2048];
fz_dirname(dir, file, sizeof dir);
- return load_link_box(ctx, html->root, NULL, page, page_h, dir, file);
+
+ head = load_link_box(ctx, html->root, NULL, page, html->page_h, dir, file);
+
+ for (link = head; link; link = link->next)
+ {
+ /* Adjust for page margins */
+ link->rect.x0 += html->page_margin[L];
+ link->rect.x1 += html->page_margin[L];
+ link->rect.y0 += html->page_margin[T];
+ link->rect.y1 += html->page_margin[T];
+ }
+
+ return head;
}
static fz_html_flow *
@@ -2328,6 +2343,14 @@ fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em)
fz_var(hb_buf);
fz_var(unlocked);
+ html->page_margin[T] = fz_from_css_number(html->root->style.margin[T], em, em);
+ html->page_margin[B] = fz_from_css_number(html->root->style.margin[B], em, em);
+ html->page_margin[L] = fz_from_css_number(html->root->style.margin[L], em, em);
+ html->page_margin[R] = fz_from_css_number(html->root->style.margin[R], em, em);
+
+ html->page_w = w - html->page_margin[L] - html->page_margin[R];
+ html->page_h = h - html->page_margin[T] - html->page_margin[B];
+
hb_lock(ctx);
fz_try(ctx)
@@ -2337,12 +2360,12 @@ fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em)
hb_unlock(ctx);
box->em = em;
- box->w = w;
+ box->w = html->page_w;
box->h = 0;
if (box->down)
{
- layout_block(ctx, box->down, box, h, 0, hb_buf);
+ layout_block(ctx, box->down, box, html->page_h, 0, hb_buf);
box->h = box->down->h;
}
}