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 /*=========================================================================*/
51 typedef struct _PrintInfo {
52 /* gnome print context */
53 GnomePrintContext *pc;
55 /* gnome print configuration */
56 GnomePrintConfig *config;
58 /* gLabels Template */
60 gboolean label_rotate_flag;
71 /*=========================================================================*/
72 /* Private function prototypes. */
73 /*=========================================================================*/
74 static PrintInfo *print_info_new (GnomePrintMaster *master,
77 static void print_info_free (PrintInfo **pi);
80 static void print_page_begin (PrintInfo *pi);
82 static void print_page_end (PrintInfo *pi);
84 static void print_label (PrintInfo *pi,
88 glMergeRecord *record,
89 gboolean outline_flag,
90 gboolean reverse_flag);
93 static void draw_label (PrintInfo *pi,
95 glMergeRecord *record);
98 static void draw_object (PrintInfo *pi,
99 glLabelObject *object,
100 glMergeRecord *record);
102 static void draw_text_object (PrintInfo *pi,
104 glMergeRecord *record);
106 static void draw_box_object (PrintInfo *pi,
109 static void draw_line_object (PrintInfo *pi,
110 glLabelLine *object);
112 static void draw_ellipse_object (PrintInfo *pi,
113 glLabelEllipse *object);
115 static void draw_image_object (PrintInfo *pi,
116 glLabelImage *object);
118 static void draw_barcode_object (PrintInfo *pi,
119 glLabelBarcode *object,
120 glMergeRecord *record);
123 static void draw_outline (PrintInfo *pi,
126 static void clip_to_outline (PrintInfo *pi,
130 static void create_rectangle_path (GnomePrintContext *pc,
136 static void create_ellipse_path (GnomePrintContext *pc,
142 static void create_rounded_rectangle_path (GnomePrintContext *pc,
149 /*****************************************************************************/
150 /* Simple (no merge data) print command. */
151 /*****************************************************************************/
153 gl_print_simple (GnomePrintMaster *master,
158 gboolean outline_flag,
159 gboolean reverse_flag)
162 gint i_sheet, i_label;
163 glTemplateOrigin *origins;
165 gl_debug (DEBUG_PRINT, "START");
167 pi = print_info_new (master, label);
169 origins = gl_template_get_origins (pi->template);
171 for (i_sheet = 0; i_sheet < n_sheets; i_sheet++) {
173 print_page_begin (pi);
175 for (i_label = first - 1; i_label < last; i_label++) {
177 print_label (pi, label,
178 origins[i_label].x, origins[i_label].y,
179 NULL, outline_flag, reverse_flag);
188 print_info_free (&pi);
190 gl_debug (DEBUG_PRINT, "END");
193 /*****************************************************************************/
194 /* Merge print command (collated copies) */
195 /*****************************************************************************/
197 gl_print_merge_collated (GnomePrintMaster *master,
202 gboolean outline_flag,
203 gboolean reverse_flag)
206 gint i_sheet, i_label, n_labels_per_page, i_copy;
207 glMergeRecord *record;
209 glTemplateOrigin *origins;
211 gl_debug (DEBUG_PRINT, "START");
213 pi = print_info_new (master, label);
215 n_labels_per_page = gl_template_get_n_labels (pi->template);
216 origins = gl_template_get_origins (pi->template);
221 for ( p=record_list; p!=NULL; p=p->next ) {
222 record = (glMergeRecord *)p->data;
224 if ( record->select_flag ) {
225 for (i_copy = 0; i_copy < n_copies; i_copy++) {
227 if ((i_label == 0) || (i_sheet == 0)) {
228 print_page_begin (pi);
231 print_label (pi, label,
235 outline_flag, reverse_flag);
237 i_label = (i_label + 1) % n_labels_per_page;
251 print_info_free (&pi);
253 gl_debug (DEBUG_PRINT, "END");
256 /*****************************************************************************/
257 /* Merge print command (uncollated copies) */
258 /*****************************************************************************/
260 gl_print_merge_uncollated (GnomePrintMaster *master,
265 gboolean outline_flag,
266 gboolean reverse_flag)
269 gint i_sheet, i_label, n_labels_per_page, i_copy;
270 glMergeRecord *record;
272 glTemplateOrigin *origins;
274 gl_debug (DEBUG_PRINT, "START");
276 pi = print_info_new (master, label);
278 n_labels_per_page = gl_template_get_n_labels (pi->template);
279 origins = gl_template_get_origins (pi->template);
284 for (i_copy = 0; i_copy < n_copies; i_copy++) {
286 for ( p=record_list; p!=NULL; p=p->next ) {
287 record = (glMergeRecord *)p->data;
289 if ( record->select_flag ) {
292 if ((i_label == 0) || (i_sheet == 0)) {
293 print_page_begin (pi);
296 print_label (pi, label,
300 outline_flag, reverse_flag);
302 i_label = (i_label + 1) % n_labels_per_page;
316 print_info_free (&pi);
318 gl_debug (DEBUG_PRINT, "END");
321 /*****************************************************************************/
322 /* Batch print. Call appropriate function above. */
323 /*****************************************************************************/
325 gl_print_batch (GnomePrintMaster *master,
329 gboolean outline_flag,
330 gboolean reverse_flag)
333 GList *record_list = NULL;
335 glTemplate *template;
337 gl_debug (DEBUG_PRINT, "START");
339 merge = gl_label_get_merge (label);
340 template = gl_label_get_template (label);
342 if ( merge == NULL ) {
343 n_per_page = gl_template_get_n_labels(template);
345 gl_print_simple (master, label, n_sheets, 1, n_per_page,
346 outline_flag, reverse_flag);
348 record_list = gl_merge_read_record_list (merge);
350 gl_print_merge_collated (master, label, record_list,
352 outline_flag, reverse_flag);
354 gl_template_free (&template);
356 g_object_unref (G_OBJECT(merge));
358 gl_debug (DEBUG_PRINT, "END");
361 /*---------------------------------------------------------------------------*/
362 /* PRIVATE. new print info structure */
363 /*---------------------------------------------------------------------------*/
365 print_info_new (GnomePrintMaster *master,
368 PrintInfo *pi = g_new0 (PrintInfo, 1);
369 glTemplate *template;
370 const GnomePrintPaper *paper = NULL;
372 gl_debug (DEBUG_PRINT, "START");
374 template = gl_label_get_template (label);
376 if (template == NULL) {
377 g_warning ("Label has no template");
381 pi->pc = gnome_print_master_get_context (master);
382 pi->config = gnome_print_master_get_config (master);
384 if ((template != NULL) && (template->page_size != NULL)) {
386 gl_debug (DEBUG_PRINT,
387 "setting page size = \"%s\"", template->page_size);
390 /* Currently cannot set page size directly from name, */
391 /* since we must set Ids not Names and there is no */
392 /* way to do the reverse lookup of Id from Name. */
393 /* Sometimes they are the same, but not always */
394 /* (e.g. for the name "US Letter" id="USLetter" */
395 /* So we use the "Custom" Id. */
396 paper = gnome_print_paper_get_by_name (template->page_size);
397 gnome_print_config_set (pi->config,
398 GNOME_PRINT_KEY_PAPER_SIZE,
400 gnome_print_config_set_length (pi->config,
401 GNOME_PRINT_KEY_PAPER_WIDTH,
403 GNOME_PRINT_PS_UNIT);
404 gnome_print_config_set_length (pi->config,
405 GNOME_PRINT_KEY_PAPER_HEIGHT,
407 GNOME_PRINT_PS_UNIT);
409 g_warning ("Cannot determine correct page size.");
410 paper = gnome_print_paper_get_by_name (GL_PRINT_DEFAULT_PAPER);
411 gnome_print_config_set (pi->config,
412 GNOME_PRINT_KEY_PAPER_SIZE,
413 GL_PRINT_DEFAULT_PAPER);
415 pi->page_width = paper->width;
416 pi->page_height = paper->height;
418 pi->template = template;
419 pi->label_rotate_flag = gl_label_get_rotate_flag (label);
423 gl_debug (DEBUG_PRINT, "END");
428 /*---------------------------------------------------------------------------*/
429 /* PRIVATE. free print info structure */
430 /*---------------------------------------------------------------------------*/
432 print_info_free (PrintInfo **pi)
434 gl_debug (DEBUG_PRINT, "START");
436 gl_template_free (&(*pi)->template);
438 gnome_print_context_close ((*pi)->pc);
443 gl_debug (DEBUG_PRINT, "END");
446 /*---------------------------------------------------------------------------*/
447 /* PRIVATE. Begin a new page. */
448 /*---------------------------------------------------------------------------*/
450 print_page_begin (PrintInfo *pi)
456 str = g_strdup_printf ("sheet%02d", pi->sheet);
457 gnome_print_beginpage (pi->pc, str);
460 /* Translate and scale, so that our origin is at the upper left. */
461 gnome_print_translate (pi->pc, 0.0, pi->page_height);
462 gnome_print_scale (pi->pc, 1.0, -1.0);
465 /*---------------------------------------------------------------------------*/
466 /* PRIVATE. End a page. */
467 /*---------------------------------------------------------------------------*/
469 print_page_end (PrintInfo *pi)
471 gnome_print_showpage (pi->pc);
474 /*---------------------------------------------------------------------------*/
475 /* PRIVATE. Print i'th label. */
476 /*---------------------------------------------------------------------------*/
478 print_label (PrintInfo *pi,
482 glMergeRecord *record,
483 gboolean outline_flag,
484 gboolean reverse_flag)
486 gdouble width, height;
487 glTemplate *template;
489 gl_debug (DEBUG_PRINT, "START");
491 template = gl_label_get_template (label);
493 gl_label_get_size (label, &width, &height);
495 gnome_print_gsave (pi->pc);
497 /* Transform coordinate system to be relative to upper corner */
498 /* of the current label */
499 gnome_print_translate (pi->pc, x, y);
500 if (gl_label_get_rotate_flag (label)) {
501 gl_debug (DEBUG_PRINT, "Rotate flag set");
502 gnome_print_rotate (pi->pc, -90.0);
503 gnome_print_translate (pi->pc, -width, 0.0);
505 if ( reverse_flag ) {
506 gnome_print_translate (pi->pc, width, 0.0);
507 gnome_print_scale (pi->pc, -1.0, 1.0);
510 draw_outline (pi, label);
512 clip_to_outline (pi, label);
513 draw_label (pi, label, record);
515 gnome_print_grestore (pi->pc);
517 gl_template_free (&template);
519 gl_debug (DEBUG_PRINT, "END");
522 /*---------------------------------------------------------------------------*/
523 /* PRIVATE. Draw label. */
524 /*---------------------------------------------------------------------------*/
526 draw_label (PrintInfo *pi,
528 glMergeRecord *record)
531 glLabelObject *object;
533 gl_debug (DEBUG_PRINT, "START");
535 for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
536 object = (glLabelObject *) p_obj->data;
538 draw_object (pi, object, record);
541 gl_debug (DEBUG_PRINT, "END");
544 /*---------------------------------------------------------------------------*/
545 /* PRIVATE. Draw object. */
546 /*---------------------------------------------------------------------------*/
548 draw_object (PrintInfo *pi,
549 glLabelObject *object,
550 glMergeRecord *record)
555 gl_debug (DEBUG_PRINT, "START");
557 gl_label_object_get_position (object, &x0, &y0);
558 gl_label_object_get_applied_affine (object, affine);
560 gnome_print_gsave (pi->pc);
562 gnome_print_translate (pi->pc, x0, y0);
563 gnome_print_concat (pi->pc, affine);
565 if (GL_IS_LABEL_TEXT(object)) {
566 draw_text_object (pi, GL_LABEL_TEXT(object), record);
567 } else if (GL_IS_LABEL_BOX(object)) {
568 draw_box_object (pi, GL_LABEL_BOX(object));
569 } else if (GL_IS_LABEL_LINE(object)) {
570 draw_line_object (pi, GL_LABEL_LINE(object));
571 } else if (GL_IS_LABEL_ELLIPSE(object)) {
572 draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object));
573 } else if (GL_IS_LABEL_IMAGE(object)) {
574 draw_image_object (pi, GL_LABEL_IMAGE(object));
575 } else if (GL_IS_LABEL_BARCODE(object)) {
576 draw_barcode_object (pi, GL_LABEL_BARCODE(object),
580 gnome_print_grestore (pi->pc);
582 gl_debug (DEBUG_PRINT, "END");
585 /*---------------------------------------------------------------------------*/
586 /* PRIVATE. Draw text object. */
587 /*---------------------------------------------------------------------------*/
589 draw_text_object (PrintInfo *pi,
591 glMergeRecord *record)
596 gdouble x_offset, y_offset, w, object_w, object_h;
601 GnomeFontWeight font_weight;
602 gboolean font_italic_flag;
604 GtkJustification just;
605 GnomeGlyphList *glyphlist;
610 gl_debug (DEBUG_PRINT, "START");
612 gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
613 lines = gl_label_text_get_lines (object);
614 gl_label_text_get_props (object,
615 &font_family, &font_size, &font_weight,
619 font = gnome_font_find_closest_from_weight_slant (
624 gnome_print_setfont (pi->pc, font);
626 gnome_print_setrgbcolor (pi->pc,
627 GL_COLOR_F_RED (color),
628 GL_COLOR_F_GREEN (color),
629 GL_COLOR_F_BLUE (color));
630 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color));
632 text = gl_text_node_lines_expand (lines, record);
633 line = g_strsplit (text, "\n", -1);
636 art_affine_identity (affine);
638 for (i = 0; line[i] != NULL; i++) {
640 glyphlist = gnome_glyphlist_from_text_dumb (font, color,
644 gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
648 case GTK_JUSTIFY_LEFT:
651 case GTK_JUSTIFY_CENTER:
652 x_offset = (object_w - w) / 2.0;
654 case GTK_JUSTIFY_RIGHT:
655 x_offset = object_w - w;
659 break; /* shouldn't happen */
662 y_offset = (i + 1) * font_size
663 + gnome_font_get_descender (font);
665 gnome_print_moveto (pi->pc, x_offset, y_offset);
667 gnome_print_gsave (pi->pc);
668 gnome_print_scale (pi->pc, 1.0, -1.0);
669 gnome_print_show (pi->pc, line[i]);
670 gnome_print_grestore (pi->pc);
675 gl_text_node_lines_free (&lines);
676 g_free (font_family);
678 gl_debug (DEBUG_PRINT, "END");
681 /*---------------------------------------------------------------------------*/
682 /* PRIVATE. Draw box object. */
683 /*---------------------------------------------------------------------------*/
685 draw_box_object (PrintInfo *pi,
690 guint line_color, fill_color;
692 gl_debug (DEBUG_PRINT, "START");
694 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
695 line_width = gl_label_box_get_line_width (object);
696 line_color = gl_label_box_get_line_color (object);
697 fill_color = gl_label_box_get_fill_color (object);
699 /* Paint fill color */
700 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
701 gnome_print_setrgbcolor (pi->pc,
702 GL_COLOR_F_RED (fill_color),
703 GL_COLOR_F_GREEN (fill_color),
704 GL_COLOR_F_BLUE (fill_color));
705 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
706 gnome_print_fill (pi->pc);
709 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
710 gnome_print_setrgbcolor (pi->pc,
711 GL_COLOR_F_RED (line_color),
712 GL_COLOR_F_GREEN (line_color),
713 GL_COLOR_F_BLUE (line_color));
714 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
715 gnome_print_setlinewidth (pi->pc, line_width);
716 gnome_print_stroke (pi->pc);
718 gl_debug (DEBUG_PRINT, "END");
721 /*---------------------------------------------------------------------------*/
722 /* PRIVATE. Draw line object. */
723 /*---------------------------------------------------------------------------*/
725 draw_line_object (PrintInfo *pi,
732 gl_debug (DEBUG_PRINT, "START");
734 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
735 line_width = gl_label_line_get_line_width (object);
736 line_color = gl_label_line_get_line_color (object);
738 gnome_print_moveto (pi->pc, 0.0, 0.0);
739 gnome_print_lineto (pi->pc, w, h);
740 gnome_print_setrgbcolor (pi->pc,
741 GL_COLOR_F_RED (line_color),
742 GL_COLOR_F_GREEN (line_color),
743 GL_COLOR_F_BLUE (line_color));
744 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
745 gnome_print_setlinewidth (pi->pc, line_width);
746 gnome_print_stroke (pi->pc);
748 gl_debug (DEBUG_PRINT, "END");
751 /*---------------------------------------------------------------------------*/
752 /* PRIVATE. Draw ellipse object. */
753 /*---------------------------------------------------------------------------*/
755 draw_ellipse_object (PrintInfo *pi,
756 glLabelEllipse *object)
758 gdouble x0, y0, rx, ry, w, h;
760 guint line_color, fill_color;
762 gl_debug (DEBUG_PRINT, "START");
764 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
765 line_width = gl_label_ellipse_get_line_width (object);
766 line_color = gl_label_ellipse_get_line_color (object);
767 fill_color = gl_label_ellipse_get_fill_color (object);
774 /* Paint fill color */
775 create_ellipse_path (pi->pc, x0, y0, rx, ry);
776 gnome_print_setrgbcolor (pi->pc,
777 GL_COLOR_F_RED (fill_color),
778 GL_COLOR_F_GREEN (fill_color),
779 GL_COLOR_F_BLUE (fill_color));
780 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
781 gnome_print_fill (pi->pc);
784 create_ellipse_path (pi->pc, x0, y0, rx, ry);
785 gnome_print_setrgbcolor (pi->pc,
786 GL_COLOR_F_RED (line_color),
787 GL_COLOR_F_GREEN (line_color),
788 GL_COLOR_F_BLUE (line_color));
789 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
790 gnome_print_setlinewidth (pi->pc, line_width);
791 gnome_print_stroke (pi->pc);
793 gl_debug (DEBUG_PRINT, "END");
796 /*---------------------------------------------------------------------------*/
797 /* PRIVATE. Draw image object. */
798 /*---------------------------------------------------------------------------*/
800 draw_image_object (PrintInfo *pi,
801 glLabelImage *object)
804 const GdkPixbuf *pixbuf;
806 gint image_w, image_h, image_stride;
807 gboolean image_alpha_flag;
810 gl_debug (DEBUG_PRINT, "START");
812 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
814 pixbuf = gl_label_image_get_pixbuf (object);
815 image_data = gdk_pixbuf_get_pixels (pixbuf);
816 image_w = gdk_pixbuf_get_width (pixbuf);
817 image_h = gdk_pixbuf_get_height (pixbuf);
818 image_stride = gdk_pixbuf_get_rowstride(pixbuf);
819 image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf);
821 gnome_print_gsave (pi->pc);
822 gnome_print_translate (pi->pc, 0.0, h);
823 gnome_print_scale (pi->pc, w, -h);
824 if (image_alpha_flag) {
825 ret = gnome_print_rgbaimage (pi->pc, image_data,
826 image_w, image_h, image_stride);
827 gl_debug (DEBUG_PRINT, "Ret a = %d", ret);
829 ret = gnome_print_rgbimage (pi->pc, image_data,
830 image_w, image_h, image_stride);
831 gl_debug (DEBUG_PRINT, "Ret = %d", ret);
833 gnome_print_grestore (pi->pc);
835 gl_debug (DEBUG_PRINT, "END");
838 /*---------------------------------------------------------------------------*/
839 /* PRIVATE. Draw box object. */
840 /*---------------------------------------------------------------------------*/
842 draw_barcode_object (PrintInfo *pi,
843 glLabelBarcode *object,
844 glMergeRecord *record)
848 glBarcodeChar *bchar;
852 gchar *text, *cstring;
853 glTextNode *text_node;
854 glBarcodeStyle style;
859 gl_debug (DEBUG_PRINT, "START");
861 text_node = gl_label_barcode_get_data (object);
862 gl_label_barcode_get_props (object,
863 &style, &text_flag, &color, &scale);
865 text = gl_text_node_expand (text_node, record);
866 gbc = gl_barcode_new (style, text_flag, scale, text);
868 gl_text_node_free (&text_node);
872 font = gnome_font_find_closest_from_weight_slant (
873 GL_BARCODE_FONT_FAMILY,
874 GL_BARCODE_FONT_WEIGHT,
876 gnome_print_setfont (pi->pc, font);
878 gnome_print_setrgbcolor (pi->pc,
879 GL_COLOR_F_RED (color),
880 GL_COLOR_F_GREEN (color),
881 GL_COLOR_F_BLUE (color));
882 gnome_print_setopacity (pi->pc,
883 GL_COLOR_F_ALPHA (color));
885 y_offset = 12.0 - gnome_font_get_descender (font);
886 gnome_print_moveto (pi->pc, 0.0, y_offset);
888 gnome_print_gsave (pi->pc);
889 gnome_print_scale (pi->pc, 1.0, -1.0);
890 gnome_print_show (pi->pc, _("Invalid barcode"));
891 gnome_print_grestore (pi->pc);
895 for (li = gbc->lines; li != NULL; li = li->next) {
896 line = (glBarcodeLine *) li->data;
898 gnome_print_moveto (pi->pc, line->x, line->y);
899 gnome_print_lineto (pi->pc, line->x, line->y + line->length);
900 gnome_print_setrgbcolor (pi->pc,
901 GL_COLOR_F_RED (color),
902 GL_COLOR_F_GREEN (color),
903 GL_COLOR_F_BLUE (color));
904 gnome_print_setopacity (pi->pc,
905 GL_COLOR_F_ALPHA (color));
906 gnome_print_setlinewidth (pi->pc, line->width);
907 gnome_print_stroke (pi->pc);
910 for (li = gbc->chars; li != NULL; li = li->next) {
911 bchar = (glBarcodeChar *) li->data;
913 font = gnome_font_find_closest_from_weight_slant (
914 GL_BARCODE_FONT_FAMILY,
915 GL_BARCODE_FONT_WEIGHT,
916 FALSE, bchar->fsize);
917 gnome_print_setfont (pi->pc, font);
919 gnome_print_setrgbcolor (pi->pc,
920 GL_COLOR_F_RED (color),
921 GL_COLOR_F_GREEN (color),
922 GL_COLOR_F_BLUE (color));
923 gnome_print_setopacity (pi->pc,
924 GL_COLOR_F_ALPHA (color));
927 bchar->y + bchar->fsize -
928 gnome_font_get_descender (font);
929 gnome_print_moveto (pi->pc, bchar->x, y_offset);
931 cstring = g_strdup_printf ("%c", bchar->c);
932 gnome_print_gsave (pi->pc);
933 gnome_print_scale (pi->pc, 1.0, -1.0);
934 gnome_print_show (pi->pc, cstring);
935 gnome_print_grestore (pi->pc);
940 gl_barcode_free (&gbc);
944 gl_debug (DEBUG_PRINT, "END");
947 /*---------------------------------------------------------------------------*/
948 /* PRIVATE. Draw outline. */
949 /*---------------------------------------------------------------------------*/
951 draw_outline (PrintInfo *pi,
956 glTemplate *template;
958 gl_debug (DEBUG_PRINT, "START");
960 template = gl_label_get_template (label);
962 gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
963 gnome_print_setopacity (pi->pc, 1.0);
964 gnome_print_setlinewidth (pi->pc, 0.25);
966 switch (template->label.style) {
968 case GL_TEMPLATE_STYLE_RECT:
969 gl_label_get_size (label, &w, &h);
970 r = template->label.rect.r;
972 /* simple rectangle */
973 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
975 /* rectangle with rounded corners */
976 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
979 gnome_print_stroke (pi->pc);
982 case GL_TEMPLATE_STYLE_ROUND:
984 r1 = template->label.round.r;
985 create_ellipse_path (pi->pc, r1, r1, r1, r1);
986 gnome_print_stroke (pi->pc);
989 case GL_TEMPLATE_STYLE_CD:
990 /* CD style, round label w/ concentric round hole */
991 r1 = template->label.cd.r1;
992 r2 = template->label.cd.r2;
993 create_ellipse_path (pi->pc, r1, r1, r1, r1);
994 gnome_print_stroke (pi->pc);
995 create_ellipse_path (pi->pc, r1, r1, r2, r2);
996 gnome_print_stroke (pi->pc);
1000 g_warning ("Unknown template label style");
1004 gl_template_free (&template);
1006 gl_debug (DEBUG_PRINT, "END");
1009 /*---------------------------------------------------------------------------*/
1010 /* PRIVATE. Clip to outline. */
1011 /*---------------------------------------------------------------------------*/
1013 clip_to_outline (PrintInfo *pi,
1018 glTemplate *template;
1020 gl_debug (DEBUG_PRINT, "START");
1022 template = gl_label_get_template (label);
1024 switch (template->label.style) {
1026 case GL_TEMPLATE_STYLE_RECT:
1027 gl_label_get_size (label, &w, &h);
1028 r = template->label.rect.r;
1030 /* simple rectangle */
1031 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
1033 /* rectangle with rounded corners */
1034 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
1037 gnome_print_clip (pi->pc);
1040 case GL_TEMPLATE_STYLE_ROUND:
1041 r1 = template->label.round.r;
1042 create_ellipse_path (pi->pc, r1, r1, r1, r1);
1043 gnome_print_clip (pi->pc);
1046 case GL_TEMPLATE_STYLE_CD:
1047 r1 = template->label.cd.r1;
1048 create_ellipse_path (pi->pc, r1, r1, r1, r1);
1049 gnome_print_clip (pi->pc);
1053 g_warning ("Unknown template label style");
1057 gl_template_free (&template);
1059 gl_debug (DEBUG_PRINT, "END");
1062 /*---------------------------------------------------------------------------*/
1063 /* PRIVATE. Path creation utilities. */
1064 /*---------------------------------------------------------------------------*/
1066 create_rectangle_path (GnomePrintContext *pc,
1072 gl_debug (DEBUG_PRINT, "START");
1074 gnome_print_newpath (pc);
1075 gnome_print_moveto (pc, x0, y0);
1076 gnome_print_lineto (pc, x0 + w, y0);
1077 gnome_print_lineto (pc, x0 + w, y0 + h);
1078 gnome_print_lineto (pc, x0, y0 + h);
1079 gnome_print_lineto (pc, x0, y0);
1080 gnome_print_closepath (pc);
1082 gl_debug (DEBUG_PRINT, "END");
1086 create_ellipse_path (GnomePrintContext *pc,
1095 gl_debug (DEBUG_PRINT, "START");
1097 gnome_print_newpath (pc);
1098 gnome_print_moveto (pc, x0 + rx, y0);
1099 for (i_theta = 2; i_theta <= 360; i_theta += 2) {
1100 x = x0 + rx * cos (i_theta * G_PI / 180.0);
1101 y = y0 + ry * sin (i_theta * G_PI / 180.0);
1102 gnome_print_lineto (pc, x, y);
1104 gnome_print_closepath (pc);
1106 gl_debug (DEBUG_PRINT, "END");
1110 create_rounded_rectangle_path (GnomePrintContext *pc,
1120 gl_debug (DEBUG_PRINT, "START");
1122 gnome_print_newpath (pc);
1124 gnome_print_moveto (pc, x0 + r, y0);
1125 for (i_theta = 5; i_theta <= 90; i_theta += 5) {
1126 x = x0 + r - r * sin (i_theta * G_PI / 180.0);
1127 y = y0 + r - r * cos (i_theta * G_PI / 180.0);
1128 gnome_print_lineto (pc, x, y);
1130 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1131 x = x0 + r - r * cos (i_theta * G_PI / 180.0);
1132 y = y0 + (h - r) + r * sin (i_theta * G_PI / 180.0);
1133 gnome_print_lineto (pc, x, y);
1135 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1136 x = x0 + (w - r) + r * sin (i_theta * G_PI / 180.0);
1137 y = y0 + (h - r) + r * cos (i_theta * G_PI / 180.0);
1138 gnome_print_lineto (pc, x, y);
1140 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1141 x = x0 + (w - r) + r * cos (i_theta * G_PI / 180.0);
1142 y = y0 + r - r * sin (i_theta * G_PI / 180.0);
1143 gnome_print_lineto (pc, x, y);
1145 gnome_print_lineto (pc, x0 + r, y0);
1147 gnome_print_closepath (pc);
1149 gl_debug (DEBUG_PRINT, "END");