[glabels/vala] Added initial print support.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/vala] Added initial print support.
- Date: Thu, 19 Apr 2012 03:00:52 +0000 (UTC)
commit 73441dc7b176870b6d8e36cf5f39e0211b427fb4
Author: Jim Evins <evins snaught com>
Date: Wed Apr 18 23:00:17 2012 -0400
Added initial print support.
TODO | 5 +-
glabels/Makefile.am | 3 +-
glabels/file.vala | 9 ++
glabels/label.vala | 191 +++++++++++++++++++++++++++++++++++++-
glabels/mini_preview.vala | 11 +--
glabels/print.vala | 216 ------------------------------------------
glabels/print_op.vala | 91 ++++++++++++++++++
glabels/print_op_dialog.vala | 40 ++++++++
glabels/ui.vala | 23 +-----
9 files changed, 339 insertions(+), 250 deletions(-)
---
diff --git a/TODO b/TODO
index 1df9f05..7c6c0df 100644
--- a/TODO
+++ b/TODO
@@ -5,12 +5,15 @@ Use Cases
Case #1: one or more sheets of identical labels/cards. Examples: return address labels,
business cards, multiple copies of a CD label.
+ 1.A: Only a partial sheet of labels is printed. E.g. use only labels 5,6,7&8.
+
Case #2: Document merge from external data source. Each label has an identical design
but varies in the data that is pulled from the data source. Each data record
produces a unique label. Examples: address labels from an address list,
name tags.
-Case #3: A sheet contains multiple sets of identical label/cards.
+Case #3: A sheet contains multiple sets of identical label/cards. E.g. labels 1-5 are
+ of one design and labels 6-12 are a second design.
Development plan
diff --git a/glabels/Makefile.am b/glabels/Makefile.am
index 5530527..1c0e83b 100644
--- a/glabels/Makefile.am
+++ b/glabels/Makefile.am
@@ -47,7 +47,8 @@ glabels_4_SOURCES = \
new_label_dialog.vala \
object_editor.vala \
prefs.vala \
- print.vala \
+ print_op.vala \
+ print_op_dialog.vala \
property_editor.vala \
template_history.vala \
ui.vala \
diff --git a/glabels/file.vala b/glabels/file.vala
index 4f5b662..22613c9 100644
--- a/glabels/file.vala
+++ b/glabels/file.vala
@@ -411,6 +411,15 @@ namespace glabels
}
+ public void print( Label label, Window window )
+ {
+ PrintOpDialog op = new PrintOpDialog( label );
+
+ op.run( Gtk.PrintOperationAction.PRINT_DIALOG, window );
+ /* TODO: save print settings? */
+ }
+
+
private void close( Window window )
{
bool close_flag = true;
diff --git a/glabels/label.vala b/glabels/label.vala
index b43845d..e839b1b 100644
--- a/glabels/label.vala
+++ b/glabels/label.vala
@@ -1,6 +1,6 @@
/* label.vala
*
- * Copyright (C) 2011 Jim Evins <evins snaught com>
+ * Copyright (C) 2011-2012 Jim Evins <evins snaught com>
*
* This file is part of gLabels.
*
@@ -68,6 +68,20 @@ namespace glabels
private string cp_desc;
+ /* Print Model */
+ private const double OUTLINE_WIDTH = 0.25;
+ private const double TICK_OFFSET = 2.25;
+ private const double TICK_LENGTH = 18.0;
+
+ public Label label { get; private set; }
+
+ public bool outline_flag { get; set; }
+ public bool reverse_flag { get; set; }
+ public bool crop_marks_flag { get; set; }
+
+ public int n_pages { get; set; default = 1; }
+
+
/**
* Filename
*/
@@ -1472,6 +1486,181 @@ namespace glabels
}
+ /*
+ * Print Model
+ */
+ public void print_simple_sheet( Cairo.Context cr, int i_page )
+ {
+ if ( crop_marks_flag )
+ {
+ print_crop_marks( cr );
+ }
+
+ TemplateFrame frame = template.frames.first().data;
+ Gee.ArrayList<TemplateCoord?> origins = frame.get_origins();
+
+ foreach ( TemplateCoord origin in origins )
+ {
+ print_label( cr, origin.x, origin.y, null );
+ }
+ }
+
+
+ private void print_crop_marks( Cairo.Context cr )
+ {
+ TemplateFrame frame = template.frames.first().data;
+
+ double w, h;
+ frame.get_size( out w, out h );
+
+ cr.save();
+
+ cr.set_source_rgb( 0, 0, 0 );
+ cr.set_line_width( OUTLINE_WIDTH );
+
+ foreach ( TemplateLayout layout in frame.layouts )
+ {
+
+ double xmin = layout.x0;
+ double ymin = layout.y0;
+ double xmax = layout.x0 + layout.dx*(layout.nx - 1) + w;
+ double ymax = layout.y0 + layout.dy*(layout.ny - 1) + h;
+
+ for ( int ix=0; ix < layout.nx; ix++ )
+ {
+ double x1 = xmin + ix*layout.dx;
+ double x2 = x1 + w;
+
+ double y1 = double.max((ymin - TICK_OFFSET), 0.0);
+ double y2 = double.max((y1 - TICK_LENGTH), 0.0);
+
+ double y3 = double.min((ymax + TICK_OFFSET), template.page_height);
+ double y4 = double.min((y3 + TICK_LENGTH), template.page_height);
+
+ cr.move_to( x1, y1 );
+ cr.line_to( x1, y2 );
+ cr.stroke();
+
+ cr.move_to( x2, y1 );
+ cr.line_to( x2, y2 );
+ cr.stroke();
+
+ cr.move_to( x1, y3 );
+ cr.line_to( x1, y4 );
+ cr.stroke();
+
+ cr.move_to( x2, y3 );
+ cr.line_to( x2, y4 );
+ cr.stroke();
+ }
+
+ for (int iy=0; iy < layout.ny; iy++ )
+ {
+ double y1 = ymin + iy*layout.dy;
+ double y2 = y1 + h;
+
+ double x1 = double.max((xmin - TICK_OFFSET), 0.0);
+ double x2 = double.max((x1 - TICK_LENGTH), 0.0);
+
+ double x3 = double.min((xmax + TICK_OFFSET), template.page_width);
+ double x4 = double.min((x3 + TICK_LENGTH), template.page_width);
+
+ cr.move_to( x1, y1 );
+ cr.line_to( x2, y1 );
+ cr.stroke();
+
+ cr.move_to( x1, y2 );
+ cr.line_to( x2, y2 );
+ cr.stroke();
+
+ cr.move_to( x3, y1 );
+ cr.line_to( x4, y1 );
+ cr.stroke();
+
+ cr.move_to( x3, y2 );
+ cr.line_to( x4, y2 );
+ cr.stroke();
+ }
+
+ }
+
+ cr.restore();
+ }
+
+
+ private void print_label( Cairo.Context cr,
+ double x,
+ double y,
+ MergeRecord? record )
+ {
+ double w, h;
+ get_size( out w, out h );
+
+ cr.save();
+
+ /* Transform coordinate system to be relative to upper corner */
+ /* of the current label */
+ cr.translate( x, y );
+
+ cr.save();
+
+ clip_to_outline( cr );
+
+ cr.save();
+
+ /* Special transformations. */
+ if ( rotate )
+ {
+ cr.rotate( Math.PI/2 );
+ cr.translate( 0, -h );
+ }
+ if ( reverse_flag )
+ {
+ cr.translate( w, 0 );
+ cr.scale( -1, 1 );
+ }
+
+ draw( cr, false, record );
+
+ cr.restore(); /* From special transformations. */
+
+ cr.restore(); /* From clip to outline. */
+
+ if ( outline_flag )
+ {
+ draw_outline( cr );
+ }
+
+ cr.restore(); /* From translation. */
+ }
+
+
+ private void draw_outline( Cairo.Context cr )
+ {
+ cr.save();
+
+ cr.set_source_rgb( 0, 0, 0 );
+ cr.set_line_width( OUTLINE_WIDTH );
+
+ TemplateFrame frame = template.frames.first().data;
+ frame.cairo_path( cr, false );
+
+ cr.stroke();
+
+ cr.restore();
+ }
+
+
+ private void clip_to_outline( Cairo.Context cr )
+ {
+ TemplateFrame frame = template.frames.first().data;
+ frame.cairo_path( cr, true );
+
+ cr.set_fill_rule( Cairo.FillRule.EVEN_ODD );
+ cr.clip();
+ }
+
+
}
}
diff --git a/glabels/mini_preview.vala b/glabels/mini_preview.vala
index 3fff2f2..d7ecb5d 100644
--- a/glabels/mini_preview.vala
+++ b/glabels/mini_preview.vala
@@ -43,7 +43,7 @@ namespace glabels
private Gtk.DrawingArea canvas;
- private Template? template;
+ private Template? template;
private Gee.ArrayList<TemplateCoord?> origins;
private Gee.ArrayList<TemplateCoord?> centers;
@@ -408,15 +408,8 @@ namespace glabels
private void draw_rich_preview( Cairo.Context cr )
{
- Print print = new Print();
-
- print.label = label;
- print.outline_flag = false;
- print.reverse_flag = false;
- print.crop_marks_flag = false;
-
/* TODO: test for merge. */
- print.print_simple_sheet( cr );
+ label.print_simple_sheet( cr, 0 );
}
diff --git a/glabels/print_op.vala b/glabels/print_op.vala
new file mode 100644
index 0000000..54585ff
--- /dev/null
+++ b/glabels/print_op.vala
@@ -0,0 +1,91 @@
+/* print_op.vala
+ *
+ * Copyright (C) 2012 Jim Evins <evins snaught com>
+ *
+ * This file is part of gLabels.
+ *
+ * gLabels is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gLabels is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+using GLib;
+using libglabels;
+
+namespace glabels
+{
+
+ public class PrintOp : Gtk.PrintOperation
+ {
+ public Label label { get; private set; }
+
+
+ public PrintOp( Label label )
+ {
+ this.label = label;
+
+ set_page_size();
+
+ begin_print.connect( on_begin_print );
+ draw_page.connect( on_draw_page );
+ }
+
+
+ private void set_page_size()
+ {
+ Paper? paper = Db.lookup_paper_from_id( label.template.paper_id );
+
+ Gtk.PaperSize psize;
+ if ( paper == null )
+ {
+ string name = Gtk.PaperSize.get_default();
+ psize = new Gtk.PaperSize( name );
+ }
+ else if ( Db.is_paper_id_other( paper.id ) )
+ {
+ psize = new Gtk.PaperSize.custom( paper.id, paper.name,
+ label.template.page_width, label.template.page_height,
+ Gtk.Unit.POINTS );
+ }
+ else
+ {
+ psize = new Gtk.PaperSize( paper.pwg_size );
+ }
+
+ Gtk.PageSetup su = new Gtk.PageSetup();
+ su.set_paper_size( psize );
+ set_default_page_setup( su );
+ }
+
+
+ private void on_begin_print( Gtk.PrintContext context )
+ {
+ set_n_pages( label.n_pages );
+ }
+
+
+ private void on_draw_page( Gtk.PrintContext context, int i_page )
+ {
+ Cairo.Context cr = context.get_cairo_context();
+
+ if ( label.merge is MergeNone )
+ {
+ label.print_simple_sheet( cr, i_page );
+ }
+ }
+
+
+ }
+
+}
+
diff --git a/glabels/print_op_dialog.vala b/glabels/print_op_dialog.vala
new file mode 100644
index 0000000..e37c65f
--- /dev/null
+++ b/glabels/print_op_dialog.vala
@@ -0,0 +1,40 @@
+/* print_op_dialog.vala
+ *
+ * Copyright (C) 2012 Jim Evins <evins snaught com>
+ *
+ * This file is part of gLabels.
+ *
+ * gLabels is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gLabels is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+using GLib;
+using libglabels;
+
+namespace glabels
+{
+
+ public class PrintOpDialog : PrintOp
+ {
+
+ public PrintOpDialog( Label label )
+ {
+ base( label );
+ }
+
+
+ }
+
+}
+
diff --git a/glabels/ui.vala b/glabels/ui.vala
index 9905f8d..6f0cf84 100644
--- a/glabels/ui.vala
+++ b/glabels/ui.vala
@@ -993,28 +993,7 @@ namespace glabels
private void on_file_print( Gtk.Action action )
{
- /*
- glPrintOpDialog *op;
- GtkPrintOperationResult result;
-
- op = gl_print_op_dialog_new (GL_VIEW(window->view)->label);
-
- if (window->print_settings)
- {
- gl_print_op_set_settings (GL_PRINT_OP (op), window->print_settings);
- }
-
- result = gtk_print_operation_run (GTK_PRINT_OPERATION (op),
- GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- GTK_WINDOW (window ),
- NULL);
-
- if ( result == GTK_PRINT_OPERATION_RESULT_APPLY )
- {
- gl_print_op_free_settings (window->print_settings);
- window->print_settings = gl_print_op_get_settings (GL_PRINT_OP (op));
- }
- */
+ File.print( window.view.label, window );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]