summaryrefslogtreecommitdiff
path: root/src/book-view.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-12-14 11:36:54 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-12-14 11:36:54 +0100
commitcebf725978b32756700671a646aaed9677f6f219 (patch)
tree8aad7e2e09ba66c6ab36da556f7b8265b31898a6 /src/book-view.vala
parent13eec502b99e47e9910b5610869236698e1a8a13 (diff)
parenta632195d632be90e0da0ed0eef4b0987ed4bea6c (diff)
Merge branch 'release/3.26.2-1'3.26.2-1
Diffstat (limited to 'src/book-view.vala')
-rw-r--r--src/book-view.vala47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/book-view.vala b/src/book-view.vala
index 069525e..9a9c9bb 100644
--- a/src/book-view.vala
+++ b/src/book-view.vala
@@ -295,26 +295,30 @@ public class BookView : Gtk.Box
private void layout_into (int width, int height, out int book_width, out int book_height)
{
+ var pages = new List<PageView> ();
+ for (var i = 0; i < book.n_pages; i++)
+ pages.append (get_nth_page (i));
+
/* Get maximum page resolution */
int max_dpi = 0;
- for (var i = 0; i < book.n_pages; i++)
+ foreach (var page in pages)
{
- var page = book.get_page (i);
- if (page.dpi > max_dpi)
- max_dpi = page.dpi;
+ var p = page.page;
+ if (p.dpi > max_dpi)
+ max_dpi = p.dpi;
}
/* Get area required to fit all pages */
int max_width = 0, max_height = 0;
- for (var i = 0; i < book.n_pages; i++)
+ foreach (var page in pages)
{
- var page = book.get_page (i);
- var w = page.width;
- var h = page.height;
+ var p = page.page;
+ var w = p.width;
+ var h = p.height;
/* Scale to the same DPI */
- w = (int) ((double)w * max_dpi / page.dpi + 0.5);
- h = (int) ((double)h * max_dpi / page.dpi + 0.5);
+ w = (int) ((double)w * max_dpi / p.dpi + 0.5);
+ h = (int) ((double)h * max_dpi / p.dpi + 0.5);
if (w > max_width)
max_width = w;
@@ -329,9 +333,8 @@ public class BookView : Gtk.Box
int spacing = 12;
book_width = 0;
book_height = 0;
- for (var i = 0; i < book.n_pages; i++)
+ foreach (var page in pages)
{
- var page = get_nth_page (i);
var p = page.page;
/* NOTE: Using double to avoid overflow for large images */
@@ -351,16 +354,14 @@ public class BookView : Gtk.Box
var h = page.height;
if (h > book_height)
book_height = h;
- book_width += page.width;
- if (i != 0)
- book_width += spacing;
+ book_width += page.width + spacing;
}
+ if (pages != null)
+ book_width -= spacing;
int x_offset = 0;
- for (var i = 0; i < book.n_pages; i++)
+ foreach (var page in pages)
{
- var page = get_nth_page (i);
-
/* Layout pages left to right */
page.x_offset = x_offset;
x_offset += page.width + spacing;
@@ -432,18 +433,18 @@ public class BookView : Gtk.Box
private bool draw_cb (Gtk.Widget widget, Cairo.Context context)
{
- if (book.n_pages == 0)
- return false;
-
layout ();
double left, top, right, bottom;
context.clip_extents (out left, out top, out right, out bottom);
- /* Render each page */
+ var pages = new List<PageView> ();
for (var i = 0; i < book.n_pages; i++)
+ pages.append (get_nth_page (i));
+
+ /* Render each page */
+ foreach (var page in pages)
{
- var page = get_nth_page (i);
var left_edge = page.x_offset - x_offset;
var right_edge = page.x_offset + page.width - x_offset;