summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/html/epub-doc.c19
-rw-r--r--source/html/html-doc.c5
2 files changed, 16 insertions, 8 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index 0729e438..deb45f92 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -36,6 +36,13 @@ struct epub_page_s
int number;
};
+static int count_chapter_pages(epub_chapter *ch)
+{
+ if (ch->html->root->b > 0)
+ return ceilf(ch->html->root->b / ch->html->page_h);
+ return 1;
+}
+
static int
epub_resolve_link(fz_context *ctx, fz_document *doc_, const char *dest, float *xp, float *yp)
{
@@ -92,7 +99,7 @@ epub_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em)
{
ch->start = count;
fz_layout_html(ctx, ch->html, w, h, em);
- count += ceilf(ch->html->root->b / ch->html->page_h);
+ count += count_chapter_pages(ch);
}
epub_update_outline(ctx, doc_, doc->outline);
@@ -105,7 +112,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->b / ch->html->page_h);
+ count += count_chapter_pages(ch);
return count;
}
@@ -125,7 +132,7 @@ 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->b / ch->html->page_h);
+ int cn = count_chapter_pages(ch);
if (n < count + cn)
{
bbox->x0 = 0;
@@ -152,7 +159,7 @@ epub_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix *
for (ch = doc->spine; ch; ch = ch->next)
{
- int cn = ceilf(ch->html->root->b / ch->html->page_h);
+ int cn = count_chapter_pages(ch);
if (n < count + cn)
{
fz_draw_html(ctx, dev, ctm, ch->html, n-count);
@@ -173,7 +180,7 @@ epub_load_links(fz_context *ctx, fz_page *page_)
for (ch = doc->spine; ch; ch = ch->next)
{
- int cn = ceilf(ch->html->root->b / ch->html->page_h);
+ int cn = count_chapter_pages(ch);
if (n < count + cn)
return fz_load_html_links(ctx, ch->html, n - count, ch->path, doc);
count += cn;
@@ -191,7 +198,7 @@ epub_make_bookmark(fz_context *ctx, fz_document *doc_, int n)
for (ch = doc->spine; ch; ch = ch->next)
{
- int cn = ceilf(ch->html->root->b / ch->html->page_h);
+ int cn = count_chapter_pages(ch);
if (n < count + cn)
return fz_make_html_bookmark(ctx, ch->html, n - count);
count += cn;
diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index c43c7f3c..98bb082a 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -56,8 +56,9 @@ static int
htdoc_count_pages(fz_context *ctx, fz_document *doc_)
{
html_document *doc = (html_document*)doc_;
- int count = ceilf(doc->html->root->b / doc->html->page_h);
- return count;
+ if (doc->html->root->b > 0)
+ return ceilf(doc->html->root->b / doc->html->page_h);
+ return 1;
}
static void