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->type == GL_MERGE_NONE ) {
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_data (merge->type,
352 gl_print_merge_collated (master, label, record_list,
354 outline_flag, reverse_flag);
356 gl_merge_free (&merge);
357 gl_template_free (&template);
359 gl_debug (DEBUG_PRINT, "END");
362 /*---------------------------------------------------------------------------*/
363 /* PRIVATE. new print info structure */
364 /*---------------------------------------------------------------------------*/
366 print_info_new (GnomePrintMaster *master,
369 PrintInfo *pi = g_new0 (PrintInfo, 1);
370 glTemplate *template;
371 const GnomePrintPaper *paper = NULL;
373 gl_debug (DEBUG_PRINT, "START");
375 template = gl_label_get_template (label);
377 if (template == NULL) {
378 g_warning ("Label has no template");
382 pi->pc = gnome_print_master_get_context (master);
383 pi->config = gnome_print_master_get_config (master);
385 if ((template != NULL) && (template->page_size != NULL)) {
387 gl_debug (DEBUG_PRINT,
388 "setting page size = \"%s\"", template->page_size);
391 /* Currently cannot set page size directly from name, */
392 /* since we must set Ids not Names and there is no */
393 /* way to do the reverse lookup of Id from Name. */
394 /* Sometimes they are the same, but not always */
395 /* (e.g. for the name "US Letter" id="USLetter" */
396 /* So we use the "Custom" Id. */
397 paper = gnome_print_paper_get_by_name (template->page_size);
398 gnome_print_config_set (pi->config,
399 GNOME_PRINT_KEY_PAPER_SIZE,
401 gnome_print_config_set_length (pi->config,
402 GNOME_PRINT_KEY_PAPER_WIDTH,
404 GNOME_PRINT_PS_UNIT);
405 gnome_print_config_set_length (pi->config,
406 GNOME_PRINT_KEY_PAPER_HEIGHT,
408 GNOME_PRINT_PS_UNIT);
410 g_warning ("Cannot determine correct page size.");
411 paper = gnome_print_paper_get_by_name (GL_PRINT_DEFAULT_PAPER);
412 gnome_print_config_set (pi->config,
413 GNOME_PRINT_KEY_PAPER_SIZE,
414 GL_PRINT_DEFAULT_PAPER);
416 pi->page_width = paper->width;
417 pi->page_height = paper->height;
419 pi->template = template;
420 pi->label_rotate_flag = gl_label_get_rotate_flag (label);
424 gl_debug (DEBUG_PRINT, "END");
429 /*---------------------------------------------------------------------------*/
430 /* PRIVATE. free print info structure */
431 /*---------------------------------------------------------------------------*/
433 print_info_free (PrintInfo **pi)
435 gl_debug (DEBUG_PRINT, "START");
437 gl_template_free (&(*pi)->template);
439 gnome_print_context_close ((*pi)->pc);
444 gl_debug (DEBUG_PRINT, "END");
447 /*---------------------------------------------------------------------------*/
448 /* PRIVATE. Begin a new page. */
449 /*---------------------------------------------------------------------------*/
451 print_page_begin (PrintInfo *pi)
457 str = g_strdup_printf ("sheet%02d", pi->sheet);
458 gnome_print_beginpage (pi->pc, str);
461 /* Translate and scale, so that our origin is at the upper left. */
462 gnome_print_translate (pi->pc, 0.0, pi->page_height);
463 gnome_print_scale (pi->pc, 1.0, -1.0);
466 /*---------------------------------------------------------------------------*/
467 /* PRIVATE. End a page. */
468 /*---------------------------------------------------------------------------*/
470 print_page_end (PrintInfo *pi)
472 gnome_print_showpage (pi->pc);
475 /*---------------------------------------------------------------------------*/
476 /* PRIVATE. Print i'th label. */
477 /*---------------------------------------------------------------------------*/
479 print_label (PrintInfo *pi,
483 glMergeRecord *record,
484 gboolean outline_flag,
485 gboolean reverse_flag)
487 gdouble width, height;
488 glTemplate *template;
490 gl_debug (DEBUG_PRINT, "START");
492 template = gl_label_get_template (label);
494 gl_label_get_size (label, &width, &height);
496 gnome_print_gsave (pi->pc);
498 /* Transform coordinate system to be relative to upper corner */
499 /* of the current label */
500 gnome_print_translate (pi->pc, x, y);
501 if (gl_label_get_rotate_flag (label)) {
502 gl_debug (DEBUG_PRINT, "Rotate flag set");
503 gnome_print_rotate (pi->pc, -90.0);
504 gnome_print_translate (pi->pc, -width, 0.0);
506 if ( reverse_flag ) {
507 gnome_print_translate (pi->pc, width, 0.0);
508 gnome_print_scale (pi->pc, -1.0, 1.0);
511 draw_outline (pi, label);
513 clip_to_outline (pi, label);
514 draw_label (pi, label, record);
516 gnome_print_grestore (pi->pc);
518 gl_template_free (&template);
520 gl_debug (DEBUG_PRINT, "END");
523 /*---------------------------------------------------------------------------*/
524 /* PRIVATE. Draw label. */
525 /*---------------------------------------------------------------------------*/
527 draw_label (PrintInfo *pi,
529 glMergeRecord *record)
532 glLabelObject *object;
534 gl_debug (DEBUG_PRINT, "START");
536 for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
537 object = (glLabelObject *) p_obj->data;
539 draw_object (pi, object, record);
542 gl_debug (DEBUG_PRINT, "END");
545 /*---------------------------------------------------------------------------*/
546 /* PRIVATE. Draw object. */
547 /*---------------------------------------------------------------------------*/
549 draw_object (PrintInfo *pi,
550 glLabelObject *object,
551 glMergeRecord *record)
556 gl_debug (DEBUG_PRINT, "START");
558 gl_label_object_get_position (object, &x0, &y0);
559 gl_label_object_get_applied_affine (object, affine);
561 gnome_print_gsave (pi->pc);
563 gnome_print_translate (pi->pc, x0, y0);
564 gnome_print_concat (pi->pc, affine);
566 if (GL_IS_LABEL_TEXT(object)) {
567 draw_text_object (pi, GL_LABEL_TEXT(object), record);
568 } else if (GL_IS_LABEL_BOX(object)) {
569 draw_box_object (pi, GL_LABEL_BOX(object));
570 } else if (GL_IS_LABEL_LINE(object)) {
571 draw_line_object (pi, GL_LABEL_LINE(object));
572 } else if (GL_IS_LABEL_ELLIPSE(object)) {
573 draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object));
574 } else if (GL_IS_LABEL_IMAGE(object)) {
575 draw_image_object (pi, GL_LABEL_IMAGE(object));
576 } else if (GL_IS_LABEL_BARCODE(object)) {
577 draw_barcode_object (pi, GL_LABEL_BARCODE(object),
581 gnome_print_grestore (pi->pc);
583 gl_debug (DEBUG_PRINT, "END");
586 /*---------------------------------------------------------------------------*/
587 /* PRIVATE. Draw text object. */
588 /*---------------------------------------------------------------------------*/
590 draw_text_object (PrintInfo *pi,
592 glMergeRecord *record)
597 gdouble x_offset, y_offset, w, object_w, object_h;
602 GnomeFontWeight font_weight;
603 gboolean font_italic_flag;
605 GtkJustification just;
606 GnomeGlyphList *glyphlist;
611 gl_debug (DEBUG_PRINT, "START");
613 gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
614 lines = gl_label_text_get_lines (object);
615 gl_label_text_get_props (object,
616 &font_family, &font_size, &font_weight,
620 font = gnome_font_find_closest_from_weight_slant (
625 gnome_print_setfont (pi->pc, font);
627 gnome_print_setrgbcolor (pi->pc,
628 GL_COLOR_F_RED (color),
629 GL_COLOR_F_GREEN (color),
630 GL_COLOR_F_BLUE (color));
631 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color));
633 text = gl_text_node_lines_expand (lines, record);
634 line = g_strsplit (text, "\n", -1);
637 art_affine_identity (affine);
639 for (i = 0; line[i] != NULL; i++) {
641 glyphlist = gnome_glyphlist_from_text_dumb (font, color,
645 gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
649 case GTK_JUSTIFY_LEFT:
652 case GTK_JUSTIFY_CENTER:
653 x_offset = (object_w - w) / 2.0;
655 case GTK_JUSTIFY_RIGHT:
656 x_offset = object_w - w;
660 break; /* shouldn't happen */
663 y_offset = (i + 1) * font_size
664 + gnome_font_get_descender (font);
666 gnome_print_moveto (pi->pc, x_offset, y_offset);
668 gnome_print_gsave (pi->pc);
669 gnome_print_scale (pi->pc, 1.0, -1.0);
670 gnome_print_show (pi->pc, line[i]);
671 gnome_print_grestore (pi->pc);
676 gl_text_node_lines_free (&lines);
677 g_free (font_family);
679 gl_debug (DEBUG_PRINT, "END");
682 /*---------------------------------------------------------------------------*/
683 /* PRIVATE. Draw box object. */
684 /*---------------------------------------------------------------------------*/
686 draw_box_object (PrintInfo *pi,
691 guint line_color, fill_color;
693 gl_debug (DEBUG_PRINT, "START");
695 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
696 line_width = gl_label_box_get_line_width (object);
697 line_color = gl_label_box_get_line_color (object);
698 fill_color = gl_label_box_get_fill_color (object);
700 /* Paint fill color */
701 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
702 gnome_print_setrgbcolor (pi->pc,
703 GL_COLOR_F_RED (fill_color),
704 GL_COLOR_F_GREEN (fill_color),
705 GL_COLOR_F_BLUE (fill_color));
706 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
707 gnome_print_fill (pi->pc);
710 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
711 gnome_print_setrgbcolor (pi->pc,
712 GL_COLOR_F_RED (line_color),
713 GL_COLOR_F_GREEN (line_color),
714 GL_COLOR_F_BLUE (line_color));
715 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
716 gnome_print_setlinewidth (pi->pc, line_width);
717 gnome_print_stroke (pi->pc);
719 gl_debug (DEBUG_PRINT, "END");
722 /*---------------------------------------------------------------------------*/
723 /* PRIVATE. Draw line object. */
724 /*---------------------------------------------------------------------------*/
726 draw_line_object (PrintInfo *pi,
733 gl_debug (DEBUG_PRINT, "START");
735 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
736 line_width = gl_label_line_get_line_width (object);
737 line_color = gl_label_line_get_line_color (object);
739 gnome_print_moveto (pi->pc, 0.0, 0.0);
740 gnome_print_lineto (pi->pc, w, h);
741 gnome_print_setrgbcolor (pi->pc,
742 GL_COLOR_F_RED (line_color),
743 GL_COLOR_F_GREEN (line_color),
744 GL_COLOR_F_BLUE (line_color));
745 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
746 gnome_print_setlinewidth (pi->pc, line_width);
747 gnome_print_stroke (pi->pc);
749 gl_debug (DEBUG_PRINT, "END");
752 /*---------------------------------------------------------------------------*/
753 /* PRIVATE. Draw ellipse object. */
754 /*---------------------------------------------------------------------------*/
756 draw_ellipse_object (PrintInfo *pi,
757 glLabelEllipse *object)
759 gdouble x0, y0, rx, ry, w, h;
761 guint line_color, fill_color;
763 gl_debug (DEBUG_PRINT, "START");
765 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
766 line_width = gl_label_ellipse_get_line_width (object);
767 line_color = gl_label_ellipse_get_line_color (object);
768 fill_color = gl_label_ellipse_get_fill_color (object);
775 /* Paint fill color */
776 create_ellipse_path (pi->pc, x0, y0, rx, ry);
777 gnome_print_setrgbcolor (pi->pc,
778 GL_COLOR_F_RED (fill_color),
779 GL_COLOR_F_GREEN (fill_color),
780 GL_COLOR_F_BLUE (fill_color));
781 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
782 gnome_print_fill (pi->pc);
785 create_ellipse_path (pi->pc, x0, y0, rx, ry);
786 gnome_print_setrgbcolor (pi->pc,
787 GL_COLOR_F_RED (line_color),
788 GL_COLOR_F_GREEN (line_color),
789 GL_COLOR_F_BLUE (line_color));
790 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
791 gnome_print_setlinewidth (pi->pc, line_width);
792 gnome_print_stroke (pi->pc);
794 gl_debug (DEBUG_PRINT, "END");
797 /*---------------------------------------------------------------------------*/
798 /* PRIVATE. Draw image object. */
799 /*---------------------------------------------------------------------------*/
801 draw_image_object (PrintInfo *pi,
802 glLabelImage *object)
805 const GdkPixbuf *pixbuf;
807 gint image_w, image_h, image_stride;
808 gboolean image_alpha_flag;
811 gl_debug (DEBUG_PRINT, "START");
813 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
815 pixbuf = gl_label_image_get_pixbuf (object);
816 image_data = gdk_pixbuf_get_pixels (pixbuf);
817 image_w = gdk_pixbuf_get_width (pixbuf);
818 image_h = gdk_pixbuf_get_height (pixbuf);
819 image_stride = gdk_pixbuf_get_rowstride(pixbuf);
820 image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf);
822 gnome_print_gsave (pi->pc);
823 gnome_print_translate (pi->pc, 0.0, h);
824 gnome_print_scale (pi->pc, w, -h);
825 if (image_alpha_flag) {
826 ret = gnome_print_rgbaimage (pi->pc, image_data,
827 image_w, image_h, image_stride);
828 gl_debug (DEBUG_PRINT, "Ret a = %d", ret);
830 ret = gnome_print_rgbimage (pi->pc, image_data,
831 image_w, image_h, image_stride);
832 gl_debug (DEBUG_PRINT, "Ret = %d", ret);
834 gnome_print_grestore (pi->pc);
836 gl_debug (DEBUG_PRINT, "END");
839 /*---------------------------------------------------------------------------*/
840 /* PRIVATE. Draw box object. */
841 /*---------------------------------------------------------------------------*/
843 draw_barcode_object (PrintInfo *pi,
844 glLabelBarcode *object,
845 glMergeRecord *record)
849 glBarcodeChar *bchar;
853 gchar *text, *cstring;
854 glTextNode *text_node;
855 glBarcodeStyle style;
860 gl_debug (DEBUG_PRINT, "START");
862 text_node = gl_label_barcode_get_data (object);
863 gl_label_barcode_get_props (object,
864 &style, &text_flag, &color, &scale);
866 text = gl_text_node_expand (text_node, record);
867 gbc = gl_barcode_new (style, text_flag, scale, text);
869 gl_text_node_free (&text_node);
873 font = gnome_font_find_closest_from_weight_slant (
874 GL_BARCODE_FONT_FAMILY,
875 GL_BARCODE_FONT_WEIGHT,
877 gnome_print_setfont (pi->pc, font);
879 gnome_print_setrgbcolor (pi->pc,
880 GL_COLOR_F_RED (color),
881 GL_COLOR_F_GREEN (color),
882 GL_COLOR_F_BLUE (color));
883 gnome_print_setopacity (pi->pc,
884 GL_COLOR_F_ALPHA (color));
886 y_offset = 12.0 - gnome_font_get_descender (font);
887 gnome_print_moveto (pi->pc, 0.0, y_offset);
889 gnome_print_gsave (pi->pc);
890 gnome_print_scale (pi->pc, 1.0, -1.0);
891 gnome_print_show (pi->pc, _("Invalid barcode"));
892 gnome_print_grestore (pi->pc);
896 for (li = gbc->lines; li != NULL; li = li->next) {
897 line = (glBarcodeLine *) li->data;
899 gnome_print_moveto (pi->pc, line->x, line->y);
900 gnome_print_lineto (pi->pc, line->x, line->y + line->length);
901 gnome_print_setrgbcolor (pi->pc,
902 GL_COLOR_F_RED (color),
903 GL_COLOR_F_GREEN (color),
904 GL_COLOR_F_BLUE (color));
905 gnome_print_setopacity (pi->pc,
906 GL_COLOR_F_ALPHA (color));
907 gnome_print_setlinewidth (pi->pc, line->width);
908 gnome_print_stroke (pi->pc);
911 for (li = gbc->chars; li != NULL; li = li->next) {
912 bchar = (glBarcodeChar *) li->data;
914 font = gnome_font_find_closest_from_weight_slant (
915 GL_BARCODE_FONT_FAMILY,
916 GL_BARCODE_FONT_WEIGHT,
917 FALSE, bchar->fsize);
918 gnome_print_setfont (pi->pc, font);
920 gnome_print_setrgbcolor (pi->pc,
921 GL_COLOR_F_RED (color),
922 GL_COLOR_F_GREEN (color),
923 GL_COLOR_F_BLUE (color));
924 gnome_print_setopacity (pi->pc,
925 GL_COLOR_F_ALPHA (color));
928 bchar->y + bchar->fsize -
929 gnome_font_get_descender (font);
930 gnome_print_moveto (pi->pc, bchar->x, y_offset);
932 cstring = g_strdup_printf ("%c", bchar->c);
933 gnome_print_gsave (pi->pc);
934 gnome_print_scale (pi->pc, 1.0, -1.0);
935 gnome_print_show (pi->pc, cstring);
936 gnome_print_grestore (pi->pc);
941 gl_barcode_free (&gbc);
945 gl_debug (DEBUG_PRINT, "END");
948 /*---------------------------------------------------------------------------*/
949 /* PRIVATE. Draw outline. */
950 /*---------------------------------------------------------------------------*/
952 draw_outline (PrintInfo *pi,
957 glTemplate *template;
959 gl_debug (DEBUG_PRINT, "START");
961 template = gl_label_get_template (label);
963 gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
964 gnome_print_setopacity (pi->pc, 1.0);
965 gnome_print_setlinewidth (pi->pc, 0.25);
967 switch (template->label.style) {
969 case GL_TEMPLATE_STYLE_RECT:
970 gl_label_get_size (label, &w, &h);
971 r = template->label.rect.r;
973 /* simple rectangle */
974 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
976 /* rectangle with rounded corners */
977 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
980 gnome_print_stroke (pi->pc);
983 case GL_TEMPLATE_STYLE_ROUND:
985 r1 = template->label.round.r;
986 create_ellipse_path (pi->pc, r1, r1, r1, r1);
987 gnome_print_stroke (pi->pc);
990 case GL_TEMPLATE_STYLE_CD:
991 /* CD style, round label w/ concentric round hole */
992 r1 = template->label.cd.r1;
993 r2 = template->label.cd.r2;
994 create_ellipse_path (pi->pc, r1, r1, r1, r1);
995 gnome_print_stroke (pi->pc);
996 create_ellipse_path (pi->pc, r1, r1, r2, r2);
997 gnome_print_stroke (pi->pc);
1001 g_warning ("Unknown template label style");
1005 gl_template_free (&template);
1007 gl_debug (DEBUG_PRINT, "END");
1010 /*---------------------------------------------------------------------------*/
1011 /* PRIVATE. Clip to outline. */
1012 /*---------------------------------------------------------------------------*/
1014 clip_to_outline (PrintInfo *pi,
1019 glTemplate *template;
1021 gl_debug (DEBUG_PRINT, "START");
1023 template = gl_label_get_template (label);
1025 switch (template->label.style) {
1027 case GL_TEMPLATE_STYLE_RECT:
1028 gl_label_get_size (label, &w, &h);
1029 r = template->label.rect.r;
1031 /* simple rectangle */
1032 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
1034 /* rectangle with rounded corners */
1035 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
1038 gnome_print_clip (pi->pc);
1041 case GL_TEMPLATE_STYLE_ROUND:
1042 r1 = template->label.round.r;
1043 create_ellipse_path (pi->pc, r1, r1, r1, r1);
1044 gnome_print_clip (pi->pc);
1047 case GL_TEMPLATE_STYLE_CD:
1048 r1 = template->label.cd.r1;
1049 create_ellipse_path (pi->pc, r1, r1, r1, r1);
1050 gnome_print_clip (pi->pc);
1054 g_warning ("Unknown template label style");
1058 gl_template_free (&template);
1060 gl_debug (DEBUG_PRINT, "END");
1063 /*---------------------------------------------------------------------------*/
1064 /* PRIVATE. Path creation utilities. */
1065 /*---------------------------------------------------------------------------*/
1067 create_rectangle_path (GnomePrintContext *pc,
1073 gl_debug (DEBUG_PRINT, "START");
1075 gnome_print_newpath (pc);
1076 gnome_print_moveto (pc, x0, y0);
1077 gnome_print_lineto (pc, x0 + w, y0);
1078 gnome_print_lineto (pc, x0 + w, y0 + h);
1079 gnome_print_lineto (pc, x0, y0 + h);
1080 gnome_print_lineto (pc, x0, y0);
1081 gnome_print_closepath (pc);
1083 gl_debug (DEBUG_PRINT, "END");
1087 create_ellipse_path (GnomePrintContext *pc,
1096 gl_debug (DEBUG_PRINT, "START");
1098 gnome_print_newpath (pc);
1099 gnome_print_moveto (pc, x0 + rx, y0);
1100 for (i_theta = 2; i_theta <= 360; i_theta += 2) {
1101 x = x0 + rx * cos (i_theta * G_PI / 180.0);
1102 y = y0 + ry * sin (i_theta * G_PI / 180.0);
1103 gnome_print_lineto (pc, x, y);
1105 gnome_print_closepath (pc);
1107 gl_debug (DEBUG_PRINT, "END");
1111 create_rounded_rectangle_path (GnomePrintContext *pc,
1121 gl_debug (DEBUG_PRINT, "START");
1123 gnome_print_newpath (pc);
1125 gnome_print_moveto (pc, x0 + r, y0);
1126 for (i_theta = 5; i_theta <= 90; i_theta += 5) {
1127 x = x0 + r - r * sin (i_theta * G_PI / 180.0);
1128 y = y0 + r - r * cos (i_theta * G_PI / 180.0);
1129 gnome_print_lineto (pc, x, y);
1131 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1132 x = x0 + r - r * cos (i_theta * G_PI / 180.0);
1133 y = y0 + (h - r) + r * sin (i_theta * G_PI / 180.0);
1134 gnome_print_lineto (pc, x, y);
1136 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1137 x = x0 + (w - r) + r * sin (i_theta * G_PI / 180.0);
1138 y = y0 + (h - r) + r * cos (i_theta * G_PI / 180.0);
1139 gnome_print_lineto (pc, x, y);
1141 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1142 x = x0 + (w - r) + r * cos (i_theta * G_PI / 180.0);
1143 y = y0 + r - r * sin (i_theta * G_PI / 180.0);
1144 gnome_print_lineto (pc, x, y);
1146 gnome_print_lineto (pc, x0 + r, y0);
1148 gnome_print_closepath (pc);
1150 gl_debug (DEBUG_PRINT, "END");