2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * print.c: Print module
6 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <libgnomeprint/gnome-print-paper.h>
29 #include <libgnomeprintui/gnome-printer-dialog.h>
33 #include "label-text.h"
34 #include "label-box.h"
35 #include "label-line.h"
36 #include "label-ellipse.h"
37 #include "label-image.h"
38 #include "label-barcode.h"
45 #define GL_PRINT_DEFAULT_PAPER "US Letter"
47 /*===========================================*/
49 /*===========================================*/
50 typedef struct _PrintInfo {
51 /* gnome print context */
52 GnomePrintContext *pc;
54 /* gnome print configuration */
55 GnomePrintConfig *config;
57 /* gLabels Template */
59 gboolean label_rotate_flag;
63 /*===========================================*/
64 /* Private function prototypes. */
65 /*===========================================*/
66 static PrintInfo *print_info_new (GnomePrintMaster * master, glLabel * label);
67 static void print_info_free (PrintInfo ** pi);
69 static void print_label (PrintInfo * pi, glLabel * label, gdouble x, gdouble y,
70 glMergeRecord * record, gboolean outline_flag,
71 gboolean reverse_flag);
73 static void draw_label (PrintInfo * pi, glLabel * label,
74 glMergeRecord * record);
76 static void draw_text_object (PrintInfo * pi, glLabelText * object,
77 glMergeRecord * record);
78 static void draw_box_object (PrintInfo * pi, glLabelBox * object);
79 static void draw_line_object (PrintInfo * pi, glLabelLine * object);
80 static void draw_ellipse_object (PrintInfo * pi, glLabelEllipse * object);
81 static void draw_image_object (PrintInfo * pi, glLabelImage * object);
82 static void draw_barcode_object (PrintInfo * pi, glLabelBarcode * object,
83 glMergeRecord * record);
85 static void draw_outline (PrintInfo * pi, glLabel * label);
86 static void clip_to_outline (PrintInfo * pi, glLabel * label);
88 static void create_rectangle_path (GnomePrintContext * pc,
89 gdouble x0, gdouble y0,
90 gdouble w, gdouble h);
91 static void create_ellipse_path (GnomePrintContext * pc,
92 gdouble x0, gdouble y0,
93 gdouble rx, gdouble ry);
94 static void create_rounded_rectangle_path (GnomePrintContext * pc,
95 gdouble x0, gdouble y0,
96 gdouble w, gdouble h, gdouble r);
98 /*****************************************************************************/
99 /* Simple (no merge data) print command. */
100 /*****************************************************************************/
102 gl_print_simple (GnomePrintMaster * master,
107 gboolean outline_flag,
108 gboolean reverse_flag)
111 gint i_sheet, i_label;
112 gchar *page_str = NULL;
113 glTemplateOrigin *origins;
115 gl_debug (DEBUG_PRINT, "START");
117 pi = print_info_new (master, label);
119 origins = gl_template_get_origins (pi->template);
121 for (i_sheet = 0; i_sheet < n_sheets; i_sheet++) {
123 page_str = g_strdup_printf ("sheet %d", i_sheet + 1);
124 gnome_print_beginpage (pi->pc, page_str);
127 for (i_label = first - 1; i_label < last; i_label++) {
129 print_label (pi, label,
130 origins[i_label].x, origins[i_label].y,
131 NULL, outline_flag, reverse_flag);
135 gnome_print_showpage (pi->pc);
140 print_info_free (&pi);
142 gl_debug (DEBUG_PRINT, "END");
145 /*****************************************************************************/
146 /* Merge print command (collated copies) */
147 /*****************************************************************************/
149 gl_print_merge_collated (GnomePrintMaster * master,
154 gboolean outline_flag,
155 gboolean reverse_flag)
158 gint i_sheet, i_label, n_labels_per_page, i_copy;
160 glMergeRecord *record;
162 glTemplateOrigin *origins;
164 gl_debug (DEBUG_PRINT, "START");
166 pi = print_info_new (master, label);
168 n_labels_per_page = gl_template_get_n_labels (pi->template);
169 origins = gl_template_get_origins (pi->template);
174 for ( p=record_list; p!=NULL; p=p->next ) {
175 record = (glMergeRecord *)p->data;
177 if ( record->select_flag ) {
178 for (i_copy = 0; i_copy < n_copies; i_copy++) {
180 if ((i_label == 0) || (i_sheet == 0)) {
181 str = g_strdup_printf ("sheet %d",
183 gnome_print_beginpage (pi->pc, str);
187 print_label (pi, label,
191 outline_flag, reverse_flag);
193 i_label = (i_label + 1) % n_labels_per_page;
195 gnome_print_showpage (pi->pc);
202 gnome_print_showpage (pi->pc);
207 print_info_free (&pi);
209 gl_debug (DEBUG_PRINT, "END");
212 /*****************************************************************************/
213 /* Merge print command (uncollated copies) */
214 /*****************************************************************************/
216 gl_print_merge_uncollated (GnomePrintMaster * master,
221 gboolean outline_flag,
222 gboolean reverse_flag)
225 gint i_sheet, i_label, n_labels_per_page, i_copy;
227 glMergeRecord *record;
229 glTemplateOrigin *origins;
231 gl_debug (DEBUG_PRINT, "START");
233 pi = print_info_new (master, label);
235 n_labels_per_page = gl_template_get_n_labels (pi->template);
236 origins = gl_template_get_origins (pi->template);
241 for (i_copy = 0; i_copy < n_copies; i_copy++) {
243 for ( p=record_list; p!=NULL; p=p->next ) {
244 record = (glMergeRecord *)p->data;
246 if ( record->select_flag ) {
249 if ((i_label == 0) || (i_sheet == 0)) {
250 str = g_strdup_printf ("sheet %d",
252 gnome_print_beginpage (pi->pc, str);
256 print_label (pi, label,
260 outline_flag, reverse_flag);
262 i_label = (i_label + 1) % n_labels_per_page;
264 gnome_print_showpage (pi->pc);
271 gnome_print_showpage (pi->pc);
276 print_info_free (&pi);
278 gl_debug (DEBUG_PRINT, "END");
281 /*****************************************************************************/
282 /* Batch print. Call appropriate function above. */
283 /*****************************************************************************/
285 gl_print_batch (GnomePrintMaster * master, glLabel * label,
286 gint n_sheets, gint n_copies,
287 gboolean outline_flag, gboolean reverse_flag)
290 GList *record_list = NULL;
292 glTemplate *template;
294 gl_debug (DEBUG_PRINT, "START");
296 merge = gl_label_get_merge (label);
297 template = gl_label_get_template (label);
299 if ( merge->type == GL_MERGE_NONE ) {
300 n_per_page = gl_template_get_n_labels(template);
302 gl_print_simple (master, label, n_sheets, 1, n_per_page,
303 outline_flag, reverse_flag);
305 record_list = gl_merge_read_data (merge->type,
309 gl_print_merge_collated (master, label, record_list,
311 outline_flag, reverse_flag);
313 gl_merge_free (&merge);
314 gl_template_free (&template);
316 gl_debug (DEBUG_PRINT, "END");
319 /*---------------------------------------------------------------------------*/
320 /* PRIVATE. new print info structure */
321 /*---------------------------------------------------------------------------*/
323 print_info_new (GnomePrintMaster * master,
326 PrintInfo *pi = g_new0 (PrintInfo, 1);
327 glTemplate *template;
329 gl_debug (DEBUG_PRINT, "START");
331 template = gl_label_get_template (label);
333 if (template == NULL) {
334 g_warning ("Label has no template");
338 pi->pc = gnome_print_master_get_context (master);
339 pi->config = gnome_print_master_get_config (master);
341 if ((template != NULL) && (template->page_size != NULL)) {
342 const GnomePrintPaper *paper = NULL;
344 gl_debug (DEBUG_PRINT,
345 "setting page size = \"%s\"", template->page_size);
348 /* Currently cannot set page size directly from name, */
349 /* since we must set Ids not Names and there is no */
350 /* way to do the reverse lookup of Id from Name. */
351 /* Sometimes they are the same, but not always */
352 /* (e.g. for the name "US Letter" id="USLetter" */
353 /* So we use the "Custom" Id. */
354 paper = gnome_print_paper_get_by_name (template->page_size);
355 gnome_print_config_set (pi->config,
356 GNOME_PRINT_KEY_PAPER_SIZE,
358 gnome_print_config_set_length (pi->config,
359 GNOME_PRINT_KEY_PAPER_WIDTH,
361 GNOME_PRINT_PS_UNIT);
362 gnome_print_config_set_length (pi->config,
363 GNOME_PRINT_KEY_PAPER_HEIGHT,
365 GNOME_PRINT_PS_UNIT);
367 gnome_print_config_set (pi->config,
368 GNOME_PRINT_KEY_PAPER_SIZE,
369 GL_PRINT_DEFAULT_PAPER);
372 pi->template = template;
373 pi->label_rotate_flag = gl_label_get_rotate_flag (label);
375 gl_debug (DEBUG_PRINT, "END");
380 /*---------------------------------------------------------------------------*/
381 /* PRIVATE. free print info structure */
382 /*---------------------------------------------------------------------------*/
384 print_info_free (PrintInfo ** pi)
386 gl_debug (DEBUG_PRINT, "START");
388 gl_template_free (&(*pi)->template);
390 gnome_print_context_close ((*pi)->pc);
395 gl_debug (DEBUG_PRINT, "END");
398 /*---------------------------------------------------------------------------*/
399 /* PRIVATE. Print i'th label. */
400 /*---------------------------------------------------------------------------*/
402 print_label (PrintInfo *pi,
406 glMergeRecord *record,
407 gboolean outline_flag,
408 gboolean reverse_flag)
411 gdouble width, height;
412 glTemplate *template;
414 gl_debug (DEBUG_PRINT, "START");
416 template = gl_label_get_template (label);
418 gl_label_get_size (label, &width, &height);
420 gnome_print_gsave (pi->pc);
422 /* Transform coordinate system to be relative to upper corner */
423 /* of the current label */
424 gnome_print_translate (pi->pc, x, y);
425 if (gl_label_get_rotate_flag (label)) {
426 gl_debug (DEBUG_PRINT, "Rotate flag set");
427 gnome_print_rotate (pi->pc, 90.0);
428 gnome_print_scale (pi->pc, 1.0, -1.0);
430 gl_debug (DEBUG_PRINT, "Rotate flag NOT set");
431 art_affine_scale (a, 1.0, -1.0);
433 gnome_print_concat (pi->pc, a);
435 if ( reverse_flag ) {
436 gnome_print_translate (pi->pc, width, 0.0);
437 art_affine_scale (a, -1.0, 1.0);
438 gnome_print_concat (pi->pc, a);
441 draw_outline (pi, label);
443 clip_to_outline (pi, label);
444 draw_label (pi, label, record);
446 gnome_print_grestore (pi->pc);
448 gl_template_free (&template);
450 gl_debug (DEBUG_PRINT, "END");
453 /*---------------------------------------------------------------------------*/
454 /* PRIVATE. Draw label. */
455 /*---------------------------------------------------------------------------*/
457 draw_label (PrintInfo * pi,
459 glMergeRecord * record)
462 glLabelObject *object;
464 gl_debug (DEBUG_PRINT, "START");
466 for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
467 object = (glLabelObject *) p_obj->data;
469 if (GL_IS_LABEL_TEXT(object)) {
470 draw_text_object (pi, GL_LABEL_TEXT(object), record);
471 } else if (GL_IS_LABEL_BOX(object)) {
472 draw_box_object (pi, GL_LABEL_BOX(object));
473 } else if (GL_IS_LABEL_LINE(object)) {
474 draw_line_object (pi, GL_LABEL_LINE(object));
475 } else if (GL_IS_LABEL_ELLIPSE(object)) {
476 draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object));
477 } else if (GL_IS_LABEL_IMAGE(object)) {
478 draw_image_object (pi, GL_LABEL_IMAGE(object));
479 } else if (GL_IS_LABEL_BARCODE(object)) {
480 draw_barcode_object (pi, GL_LABEL_BARCODE(object),
486 gl_debug (DEBUG_PRINT, "END");
489 /*---------------------------------------------------------------------------*/
490 /* PRIVATE. Draw text object. */
491 /*---------------------------------------------------------------------------*/
493 draw_text_object (PrintInfo * pi,
494 glLabelText * object,
495 glMergeRecord * record)
500 gdouble x_offset, y_offset, w, object_w, object_h;
507 GnomeFontWeight font_weight;
508 gboolean font_italic_flag;
510 GtkJustification just;
511 GnomeGlyphList *glyphlist;
516 gl_debug (DEBUG_PRINT, "START");
518 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x0, &y0);
519 gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
520 lines = gl_label_text_get_lines (object);
521 gl_label_text_get_props (object,
522 &font_family, &font_size, &font_weight,
526 font = gnome_font_find_closest_from_weight_slant (
531 gnome_print_setfont (pi->pc, font);
533 gnome_print_setrgbcolor (pi->pc,
534 GL_COLOR_F_RED (color),
535 GL_COLOR_F_GREEN (color),
536 GL_COLOR_F_BLUE (color));
537 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color));
539 text = gl_text_node_lines_expand (lines, record);
540 line = g_strsplit (text, "\n", -1);
543 art_affine_identity (affine);
545 for (i = 0; line[i] != NULL; i++) {
547 glyphlist = gnome_glyphlist_from_text_dumb (font, color,
551 gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
555 case GTK_JUSTIFY_LEFT:
558 case GTK_JUSTIFY_CENTER:
559 x_offset = (object_w - w) / 2.0;
561 case GTK_JUSTIFY_RIGHT:
562 x_offset = object_w - w;
566 break; /* shouldn't happen */
569 y_offset = (i + 1) * font_size
570 + gnome_font_get_descender (font);
574 gnome_print_moveto (pi->pc, x, y);
576 gnome_print_gsave (pi->pc);
577 gnome_print_scale (pi->pc, 1.0, -1.0);
578 gnome_print_show (pi->pc, line[i]);
579 gnome_print_grestore (pi->pc);
584 gl_text_node_lines_free (&lines);
585 g_free (font_family);
587 gl_debug (DEBUG_PRINT, "END");
590 /*---------------------------------------------------------------------------*/
591 /* PRIVATE. Draw box object. */
592 /*---------------------------------------------------------------------------*/
594 draw_box_object (PrintInfo * pi,
599 guint line_color, fill_color;
601 gl_debug (DEBUG_PRINT, "START");
603 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
604 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
605 line_width = gl_label_box_get_line_width (object);
606 line_color = gl_label_box_get_line_color (object);
607 fill_color = gl_label_box_get_fill_color (object);
609 /* Paint fill color */
610 create_rectangle_path (pi->pc, x, y, w, h);
611 gnome_print_setrgbcolor (pi->pc,
612 GL_COLOR_F_RED (fill_color),
613 GL_COLOR_F_GREEN (fill_color),
614 GL_COLOR_F_BLUE (fill_color));
615 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
616 gnome_print_fill (pi->pc);
619 create_rectangle_path (pi->pc, x, y, w, h);
620 gnome_print_setrgbcolor (pi->pc,
621 GL_COLOR_F_RED (line_color),
622 GL_COLOR_F_GREEN (line_color),
623 GL_COLOR_F_BLUE (line_color));
624 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
625 gnome_print_setlinewidth (pi->pc, line_width);
626 gnome_print_stroke (pi->pc);
628 gl_debug (DEBUG_PRINT, "END");
631 /*---------------------------------------------------------------------------*/
632 /* PRIVATE. Draw line object. */
633 /*---------------------------------------------------------------------------*/
635 draw_line_object (PrintInfo * pi,
636 glLabelLine * object)
642 gl_debug (DEBUG_PRINT, "START");
644 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
645 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
646 line_width = gl_label_line_get_line_width (object);
647 line_color = gl_label_line_get_line_color (object);
649 gnome_print_moveto (pi->pc, x, y);
650 gnome_print_lineto (pi->pc, x + w, y + h);
651 gnome_print_setrgbcolor (pi->pc,
652 GL_COLOR_F_RED (line_color),
653 GL_COLOR_F_GREEN (line_color),
654 GL_COLOR_F_BLUE (line_color));
655 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
656 gnome_print_setlinewidth (pi->pc, line_width);
657 gnome_print_stroke (pi->pc);
659 gl_debug (DEBUG_PRINT, "END");
662 /*---------------------------------------------------------------------------*/
663 /* PRIVATE. Draw ellipse object. */
664 /*---------------------------------------------------------------------------*/
666 draw_ellipse_object (PrintInfo * pi,
667 glLabelEllipse * object)
669 gdouble x, y, x0, y0, rx, ry, w, h;
671 guint line_color, fill_color;
673 gl_debug (DEBUG_PRINT, "START");
675 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
676 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
677 line_width = gl_label_ellipse_get_line_width (object);
678 line_color = gl_label_ellipse_get_line_color (object);
679 fill_color = gl_label_ellipse_get_fill_color (object);
686 /* Paint fill color */
687 create_ellipse_path (pi->pc, x0, y0, rx, ry);
688 gnome_print_setrgbcolor (pi->pc,
689 GL_COLOR_F_RED (fill_color),
690 GL_COLOR_F_GREEN (fill_color),
691 GL_COLOR_F_BLUE (fill_color));
692 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
693 gnome_print_fill (pi->pc);
696 create_ellipse_path (pi->pc, x0, y0, rx, ry);
697 gnome_print_setrgbcolor (pi->pc,
698 GL_COLOR_F_RED (line_color),
699 GL_COLOR_F_GREEN (line_color),
700 GL_COLOR_F_BLUE (line_color));
701 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
702 gnome_print_setlinewidth (pi->pc, line_width);
703 gnome_print_stroke (pi->pc);
705 gl_debug (DEBUG_PRINT, "END");
708 /*---------------------------------------------------------------------------*/
709 /* PRIVATE. Draw image object. */
710 /*---------------------------------------------------------------------------*/
712 draw_image_object (PrintInfo * pi,
713 glLabelImage * object)
716 const GdkPixbuf *pixbuf;
718 gint image_w, image_h, image_stride;
719 gboolean image_alpha_flag;
722 gl_debug (DEBUG_PRINT, "START");
724 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
725 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
727 pixbuf = gl_label_image_get_pixbuf (object);
728 image_data = gdk_pixbuf_get_pixels (pixbuf);
729 image_w = gdk_pixbuf_get_width (pixbuf);
730 image_h = gdk_pixbuf_get_height (pixbuf);
731 image_stride = gdk_pixbuf_get_rowstride(pixbuf);
732 image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf);
734 gnome_print_gsave (pi->pc);
735 gnome_print_translate (pi->pc, x, y+h);
736 gnome_print_scale (pi->pc, w, -h);
737 if (image_alpha_flag) {
738 ret = gnome_print_rgbaimage (pi->pc, image_data,
739 image_w, image_h, image_stride);
740 gl_debug (DEBUG_PRINT, "Ret a = %d", ret);
742 ret = gnome_print_rgbimage (pi->pc, image_data,
743 image_w, image_h, image_stride);
744 gl_debug (DEBUG_PRINT, "Ret = %d", ret);
746 gnome_print_grestore (pi->pc);
748 gl_debug (DEBUG_PRINT, "END");
751 /*---------------------------------------------------------------------------*/
752 /* PRIVATE. Draw box object. */
753 /*---------------------------------------------------------------------------*/
755 draw_barcode_object (PrintInfo * pi,
756 glLabelBarcode * object,
757 glMergeRecord * record)
761 glBarcodeChar *bchar;
763 gdouble x, y, y_offset;
765 gchar *text, *cstring;
766 glTextNode *text_node;
767 glBarcodeStyle style;
772 gl_debug (DEBUG_PRINT, "START");
774 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
775 text_node = gl_label_barcode_get_data (object);
776 gl_label_barcode_get_props (object,
777 &style, &text_flag, &color, &scale);
779 text = gl_text_node_expand (text_node, record);
780 gbc = gl_barcode_new (style, text_flag, scale, text);
782 gl_text_node_free (&text_node);
786 font = gnome_font_find_closest_from_weight_slant (
787 GL_BARCODE_FONT_FAMILY,
788 GL_BARCODE_FONT_WEIGHT,
790 gnome_print_setfont (pi->pc, font);
792 gnome_print_setrgbcolor (pi->pc,
793 GL_COLOR_F_RED (color),
794 GL_COLOR_F_GREEN (color),
795 GL_COLOR_F_BLUE (color));
796 gnome_print_setopacity (pi->pc,
797 GL_COLOR_F_ALPHA (color));
799 y_offset = 12.0 - gnome_font_get_descender (font);
800 gnome_print_moveto (pi->pc, x, y + y_offset);
802 gnome_print_gsave (pi->pc);
803 gnome_print_scale (pi->pc, 1.0, -1.0);
804 gnome_print_show (pi->pc, _("Invalid barcode"));
805 gnome_print_grestore (pi->pc);
809 for (li = gbc->lines; li != NULL; li = li->next) {
810 line = (glBarcodeLine *) li->data;
812 gnome_print_moveto (pi->pc, x + line->x, y + line->y);
813 gnome_print_lineto (pi->pc, x + line->x,
814 y + line->y + line->length);
815 gnome_print_setrgbcolor (pi->pc,
816 GL_COLOR_F_RED (color),
817 GL_COLOR_F_GREEN (color),
818 GL_COLOR_F_BLUE (color));
819 gnome_print_setopacity (pi->pc,
820 GL_COLOR_F_ALPHA (color));
821 gnome_print_setlinewidth (pi->pc, line->width);
822 gnome_print_stroke (pi->pc);
825 for (li = gbc->chars; li != NULL; li = li->next) {
826 bchar = (glBarcodeChar *) li->data;
828 font = gnome_font_find_closest_from_weight_slant (
829 GL_BARCODE_FONT_FAMILY,
830 GL_BARCODE_FONT_WEIGHT,
831 FALSE, bchar->fsize);
832 gnome_print_setfont (pi->pc, font);
834 gnome_print_setrgbcolor (pi->pc,
835 GL_COLOR_F_RED (color),
836 GL_COLOR_F_GREEN (color),
837 GL_COLOR_F_BLUE (color));
838 gnome_print_setopacity (pi->pc,
839 GL_COLOR_F_ALPHA (color));
842 bchar->y + bchar->fsize -
843 gnome_font_get_descender (font);
844 gnome_print_moveto (pi->pc, x + bchar->x, y + y_offset);
846 cstring = g_strdup_printf ("%c", bchar->c);
847 gnome_print_gsave (pi->pc);
848 gnome_print_scale (pi->pc, 1.0, -1.0);
849 gnome_print_show (pi->pc, cstring);
850 gnome_print_grestore (pi->pc);
855 gl_barcode_free (&gbc);
859 gl_debug (DEBUG_PRINT, "END");
862 /*---------------------------------------------------------------------------*/
863 /* PRIVATE. Draw outline. */
864 /*---------------------------------------------------------------------------*/
866 draw_outline (PrintInfo * pi,
871 glTemplate *template;
873 gl_debug (DEBUG_PRINT, "START");
875 template = gl_label_get_template (label);
877 gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
878 gnome_print_setopacity (pi->pc, 1.0);
879 gnome_print_setlinewidth (pi->pc, 0.25);
881 switch (template->label.style) {
883 case GL_TEMPLATE_STYLE_RECT:
884 gl_label_get_size (label, &w, &h);
885 r = template->label.rect.r;
887 /* simple rectangle */
888 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
890 /* rectangle with rounded corners */
891 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
894 gnome_print_stroke (pi->pc);
897 case GL_TEMPLATE_STYLE_ROUND:
899 r1 = template->label.round.r;
900 create_ellipse_path (pi->pc, r1, r1, r1, r1);
901 gnome_print_stroke (pi->pc);
904 case GL_TEMPLATE_STYLE_CD:
905 /* CD style, round label w/ concentric round hole */
906 r1 = template->label.cd.r1;
907 r2 = template->label.cd.r2;
908 create_ellipse_path (pi->pc, r1, r1, r1, r1);
909 gnome_print_stroke (pi->pc);
910 create_ellipse_path (pi->pc, r1, r1, r2, r2);
911 gnome_print_stroke (pi->pc);
915 g_warning ("Unknown template label style");
919 gl_template_free (&template);
921 gl_debug (DEBUG_PRINT, "END");
924 /*---------------------------------------------------------------------------*/
925 /* PRIVATE. Clip to outline. */
926 /*---------------------------------------------------------------------------*/
928 clip_to_outline (PrintInfo * pi,
933 glTemplate *template;
935 gl_debug (DEBUG_PRINT, "START");
937 template = gl_label_get_template (label);
939 switch (template->label.style) {
941 case GL_TEMPLATE_STYLE_RECT:
942 gl_label_get_size (label, &w, &h);
943 r = template->label.rect.r;
945 /* simple rectangle */
946 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
948 /* rectangle with rounded corners */
949 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
952 gnome_print_clip (pi->pc);
955 case GL_TEMPLATE_STYLE_ROUND:
956 r1 = template->label.round.r;
957 create_ellipse_path (pi->pc, r1, r1, r1, r1);
958 gnome_print_clip (pi->pc);
961 case GL_TEMPLATE_STYLE_CD:
962 r1 = template->label.cd.r1;
963 create_ellipse_path (pi->pc, r1, r1, r1, r1);
964 gnome_print_clip (pi->pc);
968 g_warning ("Unknown template label style");
972 gl_template_free (&template);
974 gl_debug (DEBUG_PRINT, "END");
977 /*---------------------------------------------------------------------------*/
978 /* PRIVATE. Path creation utilities. */
979 /*---------------------------------------------------------------------------*/
981 create_rectangle_path (GnomePrintContext * pc,
987 gl_debug (DEBUG_PRINT, "START");
989 gnome_print_newpath (pc);
990 gnome_print_moveto (pc, x0, y0);
991 gnome_print_lineto (pc, x0 + w, y0);
992 gnome_print_lineto (pc, x0 + w, y0 + h);
993 gnome_print_lineto (pc, x0, y0 + h);
994 gnome_print_lineto (pc, x0, y0);
995 gnome_print_closepath (pc);
997 gl_debug (DEBUG_PRINT, "END");
1001 create_ellipse_path (GnomePrintContext * pc,
1010 gl_debug (DEBUG_PRINT, "START");
1012 gnome_print_newpath (pc);
1013 gnome_print_moveto (pc, x0 + rx, y0);
1014 for (i_theta = 2; i_theta <= 360; i_theta += 2) {
1015 x = x0 + rx * cos (i_theta * M_PI / 180.0);
1016 y = y0 + ry * sin (i_theta * M_PI / 180.0);
1017 gnome_print_lineto (pc, x, y);
1019 gnome_print_closepath (pc);
1021 gl_debug (DEBUG_PRINT, "END");
1025 create_rounded_rectangle_path (GnomePrintContext * pc,
1035 gl_debug (DEBUG_PRINT, "START");
1037 gnome_print_newpath (pc);
1039 gnome_print_moveto (pc, x0 + r, y0);
1040 for (i_theta = 5; i_theta <= 90; i_theta += 5) {
1041 x = x0 + r - r * sin (i_theta * M_PI / 180.0);
1042 y = y0 + r - r * cos (i_theta * M_PI / 180.0);
1043 gnome_print_lineto (pc, x, y);
1045 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1046 x = x0 + r - r * cos (i_theta * M_PI / 180.0);
1047 y = y0 + (h - r) + r * sin (i_theta * M_PI / 180.0);
1048 gnome_print_lineto (pc, x, y);
1050 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1051 x = x0 + (w - r) + r * sin (i_theta * M_PI / 180.0);
1052 y = y0 + (h - r) + r * cos (i_theta * M_PI / 180.0);
1053 gnome_print_lineto (pc, x, y);
1055 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1056 x = x0 + (w - r) + r * cos (i_theta * M_PI / 180.0);
1057 y = y0 + r - r * sin (i_theta * M_PI / 180.0);
1058 gnome_print_lineto (pc, x, y);
1060 gnome_print_lineto (pc, x0 + r, y0);
1062 gnome_print_closepath (pc);
1064 gl_debug (DEBUG_PRINT, "END");