From 1aff0b640e22e7eddc8c17a09f1d0636174e9926 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Thu, 18 Sep 2003 01:39:25 +0000 Subject: [PATCH] Added option to print crop marks. Suggested by Red Planet . git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@299 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/glabels-batch.c | 8 +- glabels2/src/print-dialog.c | 79 +++++++++++++------- glabels2/src/print.c | 141 +++++++++++++++++++++++++++++++---- glabels2/src/print.h | 18 +++-- 4 files changed, 195 insertions(+), 51 deletions(-) diff --git a/glabels2/src/glabels-batch.c b/glabels2/src/glabels-batch.c index dbef6eeb..94da88af 100644 --- a/glabels2/src/glabels-batch.c +++ b/glabels2/src/glabels-batch.c @@ -80,6 +80,7 @@ main (int argc, char **argv) GnomePrintConfig *config = NULL; glLabel *label = NULL; glXMLLabelStatus status; + glPrintFlags flags; bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR); textdomain (GETTEXT_PACKAGE); @@ -117,6 +118,10 @@ main (int argc, char **argv) } poptFreeContext (pctx); + flags.outline = outline_flag; + flags.reverse = reverse_flag; + flags.crop_marks = FALSE; + /* initialize components */ gl_merge_init (); gl_paper_init (); @@ -132,8 +137,7 @@ main (int argc, char **argv) job = gnome_print_job_new (NULL); } - gl_print_batch (job, label, n_sheets, n_copies, - outline_flag, reverse_flag); + gl_print_batch (job, label, n_sheets, n_copies, &flags); g_object_unref (label); } diff --git a/glabels2/src/print-dialog.c b/glabels2/src/print-dialog.c index bb31dcdb..767226e5 100644 --- a/glabels2/src/print-dialog.c +++ b/glabels2/src/print-dialog.c @@ -3,7 +3,7 @@ * * print.c: Print module * - * Copyright (C) 2001 Jim Evins . + * Copyright (C) 2001-2003 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,6 +61,7 @@ GnomePrintConfig *gnome_printer_selector_get_config (GtkWidget *psel); /* remember state of dialog. */ static gboolean outline_flag = FALSE; static gboolean reverse_flag = FALSE; +static gboolean crop_marks_flag = FALSE; static gboolean collate_flag = FALSE; static gint first = 1, last = 1, n_sheets = 0, n_copies = 1; @@ -75,16 +76,25 @@ static void print_response (GtkDialog *dlg, gint response, glLabel *label); -static void print_sheets (GnomePrintConfig *config, glLabel * label, - gboolean preview_flag, - gint n_sheets, gint first, gint last, - gboolean outline_flag, gboolean reverse_flag); - -static void print_sheets_merge (GnomePrintConfig *config, glLabel * label, - gboolean preview_flag, - gint n_copies, gint first, - gboolean collate_flag, - gboolean outline_flag, gboolean reverse_flag); +static void print_sheets (GnomePrintConfig *config, + glLabel *label, + gboolean preview_flag, + gint n_sheets, + gint first, + gint last, + gboolean outline_flag, + gboolean reverse_flag, + gboolean crop_marks_flag); + +static void print_sheets_merge (GnomePrintConfig *config, + glLabel *label, + gboolean preview_flag, + gint n_copies, + gint first, + gboolean collate_flag, + gboolean outline_flag, + gboolean reverse_flag, + gboolean crop_marks_flag); /*****************************************************************************/ @@ -151,7 +161,7 @@ job_page_new (GtkWidget *dlg, glMerge *merge; GtkWidget *wframe; GtkWidget *copies = NULL, *prmerge = NULL; - GtkWidget *wvbox, *outline_check, *reverse_check; + GtkWidget *wvbox, *outline_check, *reverse_check, *crop_marks_check; gint n_records; vbox = gl_hig_vbox_new (GL_HIG_VBOX_OUTER); @@ -212,6 +222,14 @@ job_page_new (GtkWidget *dlg, reverse_flag); g_object_set_data (G_OBJECT(dlg), "reverse_check", reverse_check); + /* add Crop marks check button */ + crop_marks_check = + gtk_check_button_new_with_label (_("print crop marks")); + gl_hig_category_add_widget (GL_HIG_CATEGORY(wframe), crop_marks_check); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (crop_marks_check), + crop_marks_flag); + g_object_set_data (G_OBJECT(dlg), "crop_marks_check", crop_marks_check); + gtk_widget_show_all (wframe); return vbox; @@ -249,7 +267,7 @@ print_response (GtkDialog *dlg, glLabel *label) { GtkWidget *copies, *prmerge; - GtkWidget *outline_check, *reverse_check; + GtkWidget *outline_check, *reverse_check, *crop_marks_check; GtkWidget *printer_select; GnomePrintConfig *config; glMerge *merge; @@ -264,6 +282,8 @@ print_response (GtkDialog *dlg, "outline_check"); reverse_check = g_object_get_data (G_OBJECT(dlg), "reverse_check"); + crop_marks_check = g_object_get_data (G_OBJECT(dlg), + "crop_marks_check"); printer_select = g_object_get_data (G_OBJECT(dlg), "printer_select"); @@ -276,6 +296,9 @@ print_response (GtkDialog *dlg, reverse_flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (reverse_check)); + crop_marks_flag = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (crop_marks_check)); merge = gl_label_get_merge (label); @@ -286,7 +309,7 @@ print_response (GtkDialog *dlg, print_sheets (config, label, (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW), n_sheets, first, last, - outline_flag, reverse_flag); + outline_flag, reverse_flag, crop_marks_flag); } else { @@ -298,7 +321,8 @@ print_response (GtkDialog *dlg, n_copies, first, collate_flag, outline_flag, - reverse_flag); + reverse_flag, + crop_marks_flag); g_object_unref (G_OBJECT(merge)); } break; @@ -322,13 +346,17 @@ print_sheets (GnomePrintConfig *config, gint first, gint last, gboolean outline_flag, - gboolean reverse_flag) + gboolean reverse_flag, + gboolean crop_marks_flag) { GnomePrintJob *job; + glPrintFlags flags; job = gnome_print_job_new (config); - gl_print_simple (job, label, n_sheets, first, last, - outline_flag, reverse_flag); + flags.outline = outline_flag; + flags.reverse = reverse_flag; + flags.crop_marks = crop_marks_flag; + gl_print_simple (job, label, n_sheets, first, last, &flags); gnome_print_job_close (job); if (preview_flag) { @@ -353,19 +381,20 @@ print_sheets_merge (GnomePrintConfig *config, gint first, gboolean collate_flag, gboolean outline_flag, - gboolean reverse_flag) + gboolean reverse_flag, + gboolean crop_marks_flag) { GnomePrintJob *job; + glPrintFlags flags; job = gnome_print_job_new (config); + flags.outline = outline_flag; + flags.reverse = reverse_flag; + flags.crop_marks = crop_marks_flag; if ( collate_flag ) { - gl_print_merge_collated (job, label, - n_copies, first, - outline_flag, reverse_flag); + gl_print_merge_collated (job, label, n_copies, first, &flags); } else { - gl_print_merge_uncollated (job, label, - n_copies, first, - outline_flag, reverse_flag); + gl_print_merge_uncollated (job, label, n_copies, first, &flags); } gnome_print_job_close (job); diff --git a/glabels2/src/print.c b/glabels2/src/print.c index ed3e8d88..737e312b 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -43,6 +43,9 @@ #define ARC_FINE 2 /* Resolution in degrees of large arcs */ #define ARC_COURSE 5 /* Resolution in degrees of small arcs */ +#define TICK_OFFSET 2.25 +#define TICK_LENGTH 18.0 + /*=========================================================================*/ /* Private types. */ /*=========================================================================*/ @@ -80,6 +83,8 @@ static void print_page_begin (PrintInfo *pi); static void print_page_end (PrintInfo *pi); +static void print_crop_marks (PrintInfo *pi); + static void print_label (PrintInfo *pi, glLabel *label, gdouble x, @@ -166,8 +171,7 @@ gl_print_simple (GnomePrintJob *job, gint n_sheets, gint first, gint last, - gboolean outline_flag, - gboolean reverse_flag) + glPrintFlags *flags) { PrintInfo *pi; gint i_sheet, i_label; @@ -182,12 +186,15 @@ gl_print_simple (GnomePrintJob *job, for (i_sheet = 0; i_sheet < n_sheets; i_sheet++) { print_page_begin (pi); + if (flags->crop_marks) { + print_crop_marks (pi); + } for (i_label = first - 1; i_label < last; i_label++) { print_label (pi, label, origins[i_label].x, origins[i_label].y, - NULL, outline_flag, reverse_flag); + NULL, flags->outline, flags->reverse); } @@ -209,8 +216,7 @@ gl_print_merge_collated (GnomePrintJob *job, glLabel *label, gint n_copies, gint first, - gboolean outline_flag, - gboolean reverse_flag) + glPrintFlags *flags) { glMerge *merge; const GList *record_list; @@ -242,13 +248,16 @@ gl_print_merge_collated (GnomePrintJob *job, if ((i_label == 0) || (i_sheet == 0)) { i_sheet++; print_page_begin (pi); + if (flags->crop_marks) { + print_crop_marks (pi); + } } print_label (pi, label, origins[i_label].x, origins[i_label].y, record, - outline_flag, reverse_flag); + flags->outline, flags->reverse); i_label = (i_label + 1) % n_labels_per_page; if (i_label == 0) { @@ -277,8 +286,7 @@ gl_print_merge_uncollated (GnomePrintJob *job, glLabel *label, gint n_copies, gint first, - gboolean outline_flag, - gboolean reverse_flag) + glPrintFlags *flags) { glMerge *merge; const GList *record_list; @@ -312,13 +320,16 @@ gl_print_merge_uncollated (GnomePrintJob *job, if ((i_label == 0) || (i_sheet == 0)) { i_sheet++; print_page_begin (pi); + if (flags->crop_marks) { + print_crop_marks (pi); + } } print_label (pi, label, origins[i_label].x, origins[i_label].y, record, - outline_flag, reverse_flag); + flags->outline, flags->reverse); i_label = (i_label + 1) % n_labels_per_page; if (i_label == 0) { @@ -347,8 +358,7 @@ gl_print_batch (GnomePrintJob *job, glLabel *label, gint n_sheets, gint n_copies, - gboolean outline_flag, - gboolean reverse_flag) + glPrintFlags *flags) { gint n_per_page; glMerge *merge; @@ -362,11 +372,9 @@ gl_print_batch (GnomePrintJob *job, if ( merge == NULL ) { n_per_page = gl_template_get_n_labels(template); - gl_print_simple (job, label, n_sheets, 1, n_per_page, - outline_flag, reverse_flag); + gl_print_simple (job, label, n_sheets, 1, n_per_page, flags); } else { - gl_print_merge_collated (job, label, n_copies, 1, - outline_flag, reverse_flag); + gl_print_merge_collated (job, label, n_copies, 1, flags); } gl_template_free (&template); @@ -479,6 +487,108 @@ print_page_end (PrintInfo *pi) gl_debug (DEBUG_PRINT, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Print crop tick marks. */ +/*---------------------------------------------------------------------------*/ +static void +print_crop_marks (PrintInfo *pi) +{ + gdouble w, h, page_w, page_h; + GList *p; + glTemplateLayout *layout; + gdouble xmin, ymin, xmax, ymax, dx, dy; + gdouble x1, y1, x2, y2, x3, y3, x4, y4; + gint ix, iy, nx, ny; + + gl_debug (DEBUG_PRINT, "START"); + + gl_template_get_label_size (pi->template, &w, &h); + + page_w = pi->page_width; + page_h = pi->page_height; + + gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25); + gnome_print_setopacity (pi->pc, 1.0); + gnome_print_setlinewidth (pi->pc, 0.25); + + for (p=pi->template->label.any.layouts; p != NULL; p=p->next) { + + layout = (glTemplateLayout *)p->data; + + xmin = layout->x0; + ymin = layout->y0; + xmax = layout->x0 + layout->dx*(layout->nx - 1) + w; + ymax = layout->y0 + layout->dy*(layout->ny - 1) + h; + + dx = layout->dx; + dy = layout->dy; + + nx = layout->nx; + ny = layout->ny; + + for (ix=0; ix < nx; ix++) { + + x1 = xmin + ix*dx; + x2 = x1 + w; + + y1 = MAX((ymin - TICK_OFFSET), 0.0); + y2 = MAX((y1 - TICK_LENGTH), 0.0); + + y3 = MIN((ymax + TICK_OFFSET), page_h); + y4 = MIN((y3 + TICK_LENGTH), page_h); + + gnome_print_moveto (pi->pc, x1, y1); + gnome_print_lineto (pi->pc, x1, y2); + gnome_print_stroke (pi->pc); + + gnome_print_moveto (pi->pc, x2, y1); + gnome_print_lineto (pi->pc, x2, y2); + gnome_print_stroke (pi->pc); + + gnome_print_moveto (pi->pc, x1, y3); + gnome_print_lineto (pi->pc, x1, y4); + gnome_print_stroke (pi->pc); + + gnome_print_moveto (pi->pc, x2, y3); + gnome_print_lineto (pi->pc, x2, y4); + gnome_print_stroke (pi->pc); + + } + + for (iy=0; iy < ny; iy++) { + + y1 = ymin + iy*dy; + y2 = y1 + h; + + x1 = MAX((xmin - TICK_OFFSET), 0.0); + x2 = MAX((x1 - TICK_LENGTH), 0.0); + + x3 = MIN((xmax + TICK_OFFSET), page_w); + x4 = MIN((x3 + TICK_LENGTH), page_w); + + gnome_print_moveto (pi->pc, x1, y1); + gnome_print_lineto (pi->pc, x2, y1); + gnome_print_stroke (pi->pc); + + gnome_print_moveto (pi->pc, x1, y2); + gnome_print_lineto (pi->pc, x2, y2); + gnome_print_stroke (pi->pc); + + gnome_print_moveto (pi->pc, x3, y1); + gnome_print_lineto (pi->pc, x4, y1); + gnome_print_stroke (pi->pc); + + gnome_print_moveto (pi->pc, x3, y2); + gnome_print_lineto (pi->pc, x4, y2); + gnome_print_stroke (pi->pc); + + } + + } + + gl_debug (DEBUG_PRINT, "END"); +} + /*---------------------------------------------------------------------------*/ /* PRIVATE. Print i'th label. */ /*---------------------------------------------------------------------------*/ @@ -1323,4 +1433,3 @@ create_clipped_circle_path (GnomePrintContext *pc, gl_debug (DEBUG_PRINT, "END"); } - diff --git a/glabels2/src/print.h b/glabels2/src/print.h index bdf3010f..07c77bf8 100644 --- a/glabels2/src/print.h +++ b/glabels2/src/print.h @@ -29,34 +29,36 @@ G_BEGIN_DECLS +typedef struct { + gboolean outline; + gboolean reverse; + gboolean crop_marks; +} glPrintFlags; + void gl_print_simple (GnomePrintJob *job, glLabel *label, gint n_sheets, gint first, gint last, - gboolean outline_flag, - gboolean reverse_flag); + glPrintFlags *flags); void gl_print_merge_collated (GnomePrintJob *job, glLabel *label, gint n_copies, gint first, - gboolean outline_flag, - gboolean reverse_flag); + glPrintFlags *flags); void gl_print_merge_uncollated (GnomePrintJob *job, glLabel *label, gint n_copies, gint first, - gboolean outline_flag, - gboolean reverse_flag); + glPrintFlags *flags); void gl_print_batch (GnomePrintJob *job, glLabel *label, gint n_sheets, gint n_bcopies, - gboolean outline_flag, - gboolean reverse_flag); + glPrintFlags *flags); G_END_DECLS -- 2.39.5