summaryrefslogtreecommitdiff
path: root/src/book.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/book.vala')
-rw-r--r--src/book.vala78
1 files changed, 35 insertions, 43 deletions
diff --git a/src/book.vala b/src/book.vala
index a4e6cdd..97e49a8 100644
--- a/src/book.vala
+++ b/src/book.vala
@@ -13,7 +13,20 @@ public class Book
{
private List<Page> pages;
- private bool needs_saving;
+ public uint n_pages { get { return pages.length (); } }
+
+ private bool needs_saving_;
+ public bool needs_saving
+ {
+ get { return needs_saving_; }
+ set
+ {
+ if (needs_saving_ == value)
+ return;
+ needs_saving_ = value;
+ needs_saving_changed ();
+ }
+ }
public signal void page_added (Page page);
public signal void page_removed (Page page);
@@ -49,20 +62,17 @@ public class Book
private void page_changed_cb (Page page)
{
- set_needs_saving (true);
+ needs_saving = true;
}
- public Page append_page (int width, int height, int dpi, ScanDirection scan_direction)
+ public void append_page (Page page)
{
- var page = new Page (width, height, dpi, scan_direction);
page.pixels_changed.connect (page_changed_cb);
page.crop_changed.connect (page_changed_cb);
pages.append (page);
page_added (page);
- set_needs_saving (true);
-
- return page;
+ needs_saving = true;
}
public void move_page (Page page, uint location)
@@ -70,7 +80,7 @@ public class Book
pages.remove (page);
pages.insert (page, (int) location);
reordered ();
- set_needs_saving (true);
+ needs_saving = true;
}
public void delete_page (Page page)
@@ -79,12 +89,7 @@ public class Book
page.crop_changed.disconnect (page_changed_cb);
page_removed (page);
pages.remove (page);
- set_needs_saving (true);
- }
-
- public uint get_n_pages ()
- {
- return pages.length ();
+ needs_saving = true;
}
public Page get_page (int page_number)
@@ -101,7 +106,7 @@ public class Book
private File make_indexed_file (string uri, int i)
{
- if (get_n_pages () == 1)
+ if (n_pages == 1)
return File.new_for_uri (uri);
/* Insert index before extension */
@@ -113,7 +118,7 @@ public class Book
suffix = basename.slice (extension_index, basename.length);
prefix = uri.slice (0, uri.length - suffix.length);
}
- var width = get_n_pages ().to_string().length;
+ var width = n_pages.to_string().length;
var number_format = "%%0%dd".printf (width);
var filename = prefix + "-" + number_format.printf (i + 1) + suffix;
return File.new_for_uri (filename);
@@ -121,7 +126,7 @@ public class Book
private void save_multi_file (string type, int quality, File file) throws Error
{
- for (var i = 0; i < get_n_pages (); i++)
+ for (var i = 0; i < n_pages; i++)
{
var page = get_page (i);
page.save (type, quality, make_indexed_file (file.get_uri (), i));
@@ -144,14 +149,14 @@ public class Book
var writer = new PsWriter (stream);
var surface = writer.surface;
- for (var i = 0; i < get_n_pages (); i++)
+ for (var i = 0; i < n_pages; i++)
{
var page = get_page (i);
var image = page.get_image (true);
- var width = image.get_width () * 72.0 / page.get_dpi ();
- var height = image.get_height () * 72.0 / page.get_dpi ();
+ var width = image.get_width () * 72.0 / page.dpi;
+ var height = image.get_height () * 72.0 / page.dpi;
surface.set_size (width, height);
- save_ps_pdf_surface (surface, image, page.get_dpi ());
+ save_ps_pdf_surface (surface, image, page.dpi);
surface.show_page ();
saving (i);
}
@@ -248,22 +253,22 @@ public class Book
writer.write_string ("<<\n");
writer.write_string ("/Type /Pages\n");
writer.write_string ("/Kids [");
- for (var i = 0; i < get_n_pages (); i++)
+ for (var i = 0; i < n_pages; i++)
writer.write_string (" %u 0 R".printf (pages_number + 1 + (i*3)));
writer.write_string (" ]\n");
- writer.write_string ("/Count %u\n".printf (get_n_pages ()));
+ writer.write_string ("/Count %u\n".printf (n_pages));
writer.write_string (">>\n");
writer.write_string ("endobj\n");
- for (var i = 0; i < get_n_pages (); i++)
+ for (var i = 0; i < n_pages; i++)
{
var page = get_page (i);
var image = page.get_image (true);
var width = image.get_width ();
var height = image.get_height ();
unowned uint8[] pixels = image.get_pixels ();
- var page_width = width * 72.0 / page.get_dpi ();
- var page_height = height * 72.0 / page.get_dpi ();
+ var page_width = width * 72.0 / page.dpi;
+ var page_height = height * 72.0 / page.dpi;
int depth = 8;
string color_space = "DeviceRGB";
@@ -271,7 +276,7 @@ public class Book
char[] width_buffer = new char[double.DTOSTR_BUF_SIZE];
char[] height_buffer = new char[double.DTOSTR_BUF_SIZE];
uint8[] data;
- if (page.is_color ())
+ if (page.is_color)
{
depth = 8;
color_space = "DeviceRGB";
@@ -292,7 +297,7 @@ public class Book
}
}
}
- else if (page.get_depth () == 2)
+ else if (page.depth == 2)
{
int shift_count = 6;
depth = 2;
@@ -336,7 +341,7 @@ public class Book
}
}
}
- else if (page.get_depth () == 1)
+ else if (page.depth == 1)
{
int mask = 0x80;
@@ -397,7 +402,7 @@ public class Book
/* Try if JPEG compression is better */
if (depth > 1)
{
- var jpeg_data = compress_jpeg (image, quality, page.get_dpi ());
+ var jpeg_data = compress_jpeg (image, quality, page.dpi);
if (jpeg_data.length < compressed_data.length)
{
filter = "DCTDecode";
@@ -509,19 +514,6 @@ public class Book
break;
}
}
-
- public void set_needs_saving (bool needs_saving)
- {
- var needed_saving = this.needs_saving;
- this.needs_saving = needs_saving;
- if (needed_saving != needs_saving)
- needs_saving_changed ();
- }
-
- public bool get_needs_saving ()
- {
- return needs_saving;
- }
}
private class PDFWriter