Merge lp:~firgeis/pantheon-print/image-support into lp:~elementary-apps/pantheon-print/trunk

Proposed by Ezequiel Lewin
Status: Rejected
Rejected by: Danielle Foré
Proposed branch: lp:~firgeis/pantheon-print/image-support
Merge into: lp:~elementary-apps/pantheon-print/trunk
Diff against target: 135 lines (+80/-9)
2 files modified
CMakeLists.txt (+3/-0)
src/pantheon-print.vala (+77/-9)
To merge this branch: bzr merge lp:~firgeis/pantheon-print/image-support
Reviewer Review Type Date Requested Status
kay van der Zander (community) Needs Fixing
Review via email: mp+247499@code.launchpad.net

Description of the change

Support for image printing. If the image is larger than set page, it will scale to fit

To post a comment you must log in.
Revision history for this message
kay van der Zander (kay20) wrote :

Hey thanks for your time to fix the bug.
Please forgive me if the comments are hars. They are only ment for positive building critisism.

Please fix the comments then i will review it again. If it satificed it will be approved

review: Needs Fixing
Revision history for this message
Danielle Foré (danrabbit) wrote :

Rejecting since it seems to be abandoned

Unmerged revisions

11. By Ezequiel Lewin

Support for image printing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-03-15 14:43:29 +0000
3+++ CMakeLists.txt 2015-01-24 01:24:48 +0000
4@@ -35,5 +35,8 @@
5 --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi/ -g --save-temps
6 )
7 add_executable (pantheon-print ${VALA_C})
8+find_library (M_LIB m)
9+target_link_libraries (pantheon-print ${M_LIB})
10+
11 install(TARGETS pantheon-print RUNTIME DESTINATION bin)
12 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/print.contract DESTINATION share/contractor)
13
14=== modified file 'src/pantheon-print.vala'
15--- src/pantheon-print.vala 2014-08-06 07:58:36 +0000
16+++ src/pantheon-print.vala 2015-01-24 01:24:48 +0000
17@@ -17,6 +17,8 @@
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21+using Gdk;
22+using GLib.Math;
23
24 public class CustomOperation : Gtk.PrintOperation {
25 const int FONT_SIZE = 12;
26@@ -28,11 +30,33 @@
27 int height;
28 int width;
29 int line_count;
30-
31- public CustomOperation (string[] args, Gtk.Window main_window) {
32- var file = File.new_for_commandline_arg (args[1]);
33-
34- if (file.query_exists ()) {
35+ Pixbuf pixbuf;
36+
37+ public CustomOperation (string[] args, Gtk.Window main_window) {
38+ File file = null;
39+
40+ try {
41+ file = File.new_for_commandline_arg (args[1]);
42+ } catch (Error e) {
43+ error ("%s", e.message);
44+ }
45+
46+
47+ if (!file.query_exists ()) {
48+ return;
49+ }
50+
51+ //We will check for an image first, if not we will assume text
52+ try {
53+ this.pixbuf = new Pixbuf.from_file (file.get_path ());
54+ } catch (Error e) {
55+
56+ }
57+
58+ bool is_image = (pixbuf == null) ? false : true;
59+
60+
61+ if (!is_image) {
62 try {
63 var dis = new DataInputStream (file.read ());
64 string line;
65@@ -51,9 +75,17 @@
66 setup.set_bottom_margin (15, Gtk.Unit.MM);
67 setup.set_right_margin (20, Gtk.Unit.MM);
68 setup.set_left_margin (20, Gtk.Unit.MM);
69- set_default_page_setup (setup);
70- begin_print.connect (beginprint);
71- draw_page.connect (drawpage);
72+ set_default_page_setup (setup);
73+
74+ if (is_image) {
75+ begin_print.connect (beginprint_image);
76+ draw_page.connect (drawpage_image);
77+ }
78+ else {
79+ begin_print.connect (beginprint);
80+ draw_page.connect (drawpage);
81+ }
82+
83 }
84
85 void beginprint (Gtk.PrintContext print_context) {
86@@ -121,6 +153,42 @@
87 }
88 }
89
90+ void beginprint_image (Gtk.PrintContext print_context) {
91+
92+ height = (int)print_context.get_height ();
93+ width = (int)print_context.get_width ();
94+
95+ set_n_pages (1);
96+ }
97+
98+ void drawpage_image(Gtk.PrintContext print_context, int page_num) {
99+ context = print_context.get_cairo_context ();
100+ context.set_source_rgb (0, 0, 0);
101+
102+ //We will fit the image to the page
103+ double scale = 1;
104+
105+ if (pixbuf.width > width) {
106+ scale -= (1.0 - ((double)width / (double)pixbuf.width));
107+ }
108+
109+ if (pixbuf.height * scale > height) {
110+ scale -= (1.0 - ((double)height / (pixbuf.height * scale)));
111+ }
112+
113+ if (scale < 1) {
114+ int dest_width = int.parse (GLib.Math.round (pixbuf.width * scale).to_string ());
115+ int dest_height = int.parse (GLib.Math.round (pixbuf.height * scale).to_string ());
116+
117+ pixbuf = pixbuf.scale_simple(dest_width, dest_height, InterpType.BILINEAR);
118+ }
119+
120+ cairo_set_source_pixbuf (context, pixbuf, 0, 0);
121+
122+ context.rectangle(0, 0, pixbuf.get_width (), pixbuf.get_height ());
123+ context.fill ();
124+ }
125+
126 }
127
128 public static void main (string[] args) {
129@@ -129,4 +197,4 @@
130 var operation = new CustomOperation (args, main_window);
131
132 operation.run (Gtk.PrintOperationAction.PRINT_DIALOG, main_window);
133-}
134\ No newline at end of file
135+}

Subscribers

People subscribed via source and target branches