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 */
58 const glTemplate *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);
373 /* gnome_print_config_dump (pi->config); */
376 GnomePrintPaper *paper;
379 list = gnome_print_paper_get_list();
380 for ( p=list; p != NULL; p=p->next ) {
381 paper = (GnomePrintPaper *)p->data;
382 gl_debug (DEBUG_PRINT, " \"%s\"", paper->name);
384 gl_debug (DEBUG_PRINT,
385 "template->page_size = \"%s\"", template->page_size);
387 name = gnome_print_config_get (pi->config,
388 GNOME_PRINT_KEY_PAPER_SIZE);
389 gl_debug (DEBUG_PRINT, "config = \"%s\"", name);
393 pi->template = template;
394 pi->label_rotate_flag = gl_label_get_rotate_flag (label);
396 gl_template_free (&template);
398 gl_debug (DEBUG_PRINT, "END");
403 /*---------------------------------------------------------------------------*/
404 /* PRIVATE. free print info structure */
405 /*---------------------------------------------------------------------------*/
407 print_info_free (PrintInfo ** pi)
409 gl_debug (DEBUG_PRINT, "START");
411 gnome_print_context_close ((*pi)->pc);
416 gl_debug (DEBUG_PRINT, "END");
419 /*---------------------------------------------------------------------------*/
420 /* PRIVATE. Print i'th label. */
421 /*---------------------------------------------------------------------------*/
423 print_label (PrintInfo *pi,
427 glMergeRecord *record,
428 gboolean outline_flag,
429 gboolean reverse_flag)
432 gdouble width, height;
433 glTemplate *template;
435 gl_debug (DEBUG_PRINT, "START");
437 template = gl_label_get_template (label);
439 gl_label_get_size (label, &width, &height);
441 gnome_print_gsave (pi->pc);
443 /* Transform coordinate system to be relative to upper corner */
444 /* of the current label */
445 gnome_print_translate (pi->pc, x, y);
446 if (gl_label_get_rotate_flag (label)) {
447 gl_debug (DEBUG_PRINT, "Rotate flag set");
448 gnome_print_rotate (pi->pc, 90.0);
449 gnome_print_scale (pi->pc, 1.0, -1.0);
451 gl_debug (DEBUG_PRINT, "Rotate flag NOT set");
452 art_affine_scale (a, 1.0, -1.0);
454 gnome_print_concat (pi->pc, a);
456 if ( reverse_flag ) {
457 gnome_print_translate (pi->pc, width, 0.0);
458 art_affine_scale (a, -1.0, 1.0);
459 gnome_print_concat (pi->pc, a);
462 draw_outline (pi, label);
464 clip_to_outline (pi, label);
465 draw_label (pi, label, record);
467 gnome_print_grestore (pi->pc);
469 gl_template_free (&template);
471 gl_debug (DEBUG_PRINT, "END");
474 /*---------------------------------------------------------------------------*/
475 /* PRIVATE. Draw label. */
476 /*---------------------------------------------------------------------------*/
478 draw_label (PrintInfo * pi,
480 glMergeRecord * record)
483 glLabelObject *object;
485 gl_debug (DEBUG_PRINT, "START");
487 for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
488 object = (glLabelObject *) p_obj->data;
490 if (GL_IS_LABEL_TEXT(object)) {
491 draw_text_object (pi, GL_LABEL_TEXT(object), record);
492 } else if (GL_IS_LABEL_BOX(object)) {
493 draw_box_object (pi, GL_LABEL_BOX(object));
494 } else if (GL_IS_LABEL_LINE(object)) {
495 draw_line_object (pi, GL_LABEL_LINE(object));
496 } else if (GL_IS_LABEL_ELLIPSE(object)) {
497 draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object));
498 } else if (GL_IS_LABEL_IMAGE(object)) {
499 draw_image_object (pi, GL_LABEL_IMAGE(object));
500 } else if (GL_IS_LABEL_BARCODE(object)) {
501 draw_barcode_object (pi, GL_LABEL_BARCODE(object),
507 gl_debug (DEBUG_PRINT, "END");
510 /*---------------------------------------------------------------------------*/
511 /* PRIVATE. Draw text object. */
512 /*---------------------------------------------------------------------------*/
514 draw_text_object (PrintInfo * pi,
515 glLabelText * object,
516 glMergeRecord * record)
521 gdouble x_offset, y_offset, w, object_w, object_h;
528 GnomeFontWeight font_weight;
529 gboolean font_italic_flag;
531 GtkJustification just;
532 GnomeGlyphList *glyphlist;
537 gl_debug (DEBUG_PRINT, "START");
539 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x0, &y0);
540 gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
541 lines = gl_label_text_get_lines (object);
542 gl_label_text_get_props (object,
543 &font_family, &font_size, &font_weight,
547 font = gnome_font_find_closest_from_weight_slant (
552 gnome_print_setfont (pi->pc, font);
554 gnome_print_setrgbcolor (pi->pc,
555 GL_COLOR_F_RED (color),
556 GL_COLOR_F_GREEN (color),
557 GL_COLOR_F_BLUE (color));
558 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color));
560 text = gl_text_node_lines_expand (lines, record);
561 line = g_strsplit (text, "\n", -1);
564 art_affine_identity (affine);
566 for (i = 0; line[i] != NULL; i++) {
568 glyphlist = gnome_glyphlist_from_text_dumb (font, color,
572 gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
576 case GTK_JUSTIFY_LEFT:
579 case GTK_JUSTIFY_CENTER:
580 x_offset = (object_w - w) / 2.0;
582 case GTK_JUSTIFY_RIGHT:
583 x_offset = object_w - w;
587 break; /* shouldn't happen */
590 y_offset = (i + 1) * font_size
591 + gnome_font_get_descender (font);
595 gnome_print_moveto (pi->pc, x, y);
597 gnome_print_gsave (pi->pc);
598 gnome_print_scale (pi->pc, 1.0, -1.0);
599 gnome_print_show (pi->pc, line[i]);
600 gnome_print_grestore (pi->pc);
605 gl_text_node_lines_free (&lines);
606 g_free (font_family);
608 gl_debug (DEBUG_PRINT, "END");
611 /*---------------------------------------------------------------------------*/
612 /* PRIVATE. Draw box object. */
613 /*---------------------------------------------------------------------------*/
615 draw_box_object (PrintInfo * pi,
620 guint line_color, fill_color;
622 gl_debug (DEBUG_PRINT, "START");
624 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
625 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
626 line_width = gl_label_box_get_line_width (object);
627 line_color = gl_label_box_get_line_color (object);
628 fill_color = gl_label_box_get_fill_color (object);
630 /* Paint fill color */
631 create_rectangle_path (pi->pc, x, y, w, h);
632 gnome_print_setrgbcolor (pi->pc,
633 GL_COLOR_F_RED (fill_color),
634 GL_COLOR_F_GREEN (fill_color),
635 GL_COLOR_F_BLUE (fill_color));
636 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
637 gnome_print_fill (pi->pc);
640 create_rectangle_path (pi->pc, x, y, w, h);
641 gnome_print_setrgbcolor (pi->pc,
642 GL_COLOR_F_RED (line_color),
643 GL_COLOR_F_GREEN (line_color),
644 GL_COLOR_F_BLUE (line_color));
645 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
646 gnome_print_setlinewidth (pi->pc, line_width);
647 gnome_print_stroke (pi->pc);
649 gl_debug (DEBUG_PRINT, "END");
652 /*---------------------------------------------------------------------------*/
653 /* PRIVATE. Draw line object. */
654 /*---------------------------------------------------------------------------*/
656 draw_line_object (PrintInfo * pi,
657 glLabelLine * object)
663 gl_debug (DEBUG_PRINT, "START");
665 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
666 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
667 line_width = gl_label_line_get_line_width (object);
668 line_color = gl_label_line_get_line_color (object);
670 gnome_print_moveto (pi->pc, x, y);
671 gnome_print_lineto (pi->pc, x + w, y + h);
672 gnome_print_setrgbcolor (pi->pc,
673 GL_COLOR_F_RED (line_color),
674 GL_COLOR_F_GREEN (line_color),
675 GL_COLOR_F_BLUE (line_color));
676 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
677 gnome_print_setlinewidth (pi->pc, line_width);
678 gnome_print_stroke (pi->pc);
680 gl_debug (DEBUG_PRINT, "END");
683 /*---------------------------------------------------------------------------*/
684 /* PRIVATE. Draw ellipse object. */
685 /*---------------------------------------------------------------------------*/
687 draw_ellipse_object (PrintInfo * pi,
688 glLabelEllipse * object)
690 gdouble x, y, x0, y0, rx, ry, w, h;
692 guint line_color, fill_color;
694 gl_debug (DEBUG_PRINT, "START");
696 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
697 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
698 line_width = gl_label_ellipse_get_line_width (object);
699 line_color = gl_label_ellipse_get_line_color (object);
700 fill_color = gl_label_ellipse_get_fill_color (object);
707 /* Paint fill color */
708 create_ellipse_path (pi->pc, x0, y0, rx, ry);
709 gnome_print_setrgbcolor (pi->pc,
710 GL_COLOR_F_RED (fill_color),
711 GL_COLOR_F_GREEN (fill_color),
712 GL_COLOR_F_BLUE (fill_color));
713 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
714 gnome_print_fill (pi->pc);
717 create_ellipse_path (pi->pc, x0, y0, rx, ry);
718 gnome_print_setrgbcolor (pi->pc,
719 GL_COLOR_F_RED (line_color),
720 GL_COLOR_F_GREEN (line_color),
721 GL_COLOR_F_BLUE (line_color));
722 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
723 gnome_print_setlinewidth (pi->pc, line_width);
724 gnome_print_stroke (pi->pc);
726 gl_debug (DEBUG_PRINT, "END");
729 /*---------------------------------------------------------------------------*/
730 /* PRIVATE. Draw image object. */
731 /*---------------------------------------------------------------------------*/
733 draw_image_object (PrintInfo * pi,
734 glLabelImage * object)
737 const GdkPixbuf *pixbuf;
739 gint image_w, image_h, image_stride;
740 gboolean image_alpha_flag;
743 gl_debug (DEBUG_PRINT, "START");
745 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
746 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
748 pixbuf = gl_label_image_get_pixbuf (object);
749 image_data = gdk_pixbuf_get_pixels (pixbuf);
750 image_w = gdk_pixbuf_get_width (pixbuf);
751 image_h = gdk_pixbuf_get_height (pixbuf);
752 image_stride = gdk_pixbuf_get_rowstride(pixbuf);
753 image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf);
755 gnome_print_gsave (pi->pc);
756 gnome_print_translate (pi->pc, x, y+h);
757 gnome_print_scale (pi->pc, w, -h);
758 if (image_alpha_flag) {
759 ret = gnome_print_rgbaimage (pi->pc, image_data,
760 image_w, image_h, image_stride);
761 gl_debug (DEBUG_PRINT, "Ret a = %d", ret);
763 ret = gnome_print_rgbimage (pi->pc, image_data,
764 image_w, image_h, image_stride);
765 gl_debug (DEBUG_PRINT, "Ret = %d", ret);
767 gnome_print_grestore (pi->pc);
769 gl_debug (DEBUG_PRINT, "END");
772 /*---------------------------------------------------------------------------*/
773 /* PRIVATE. Draw box object. */
774 /*---------------------------------------------------------------------------*/
776 draw_barcode_object (PrintInfo * pi,
777 glLabelBarcode * object,
778 glMergeRecord * record)
782 glBarcodeChar *bchar;
784 gdouble x, y, y_offset;
786 gchar *text, *cstring;
787 glTextNode *text_node;
788 glBarcodeStyle style;
793 gl_debug (DEBUG_PRINT, "START");
795 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
796 text_node = gl_label_barcode_get_data (object);
797 gl_label_barcode_get_props (object,
798 &style, &text_flag, &color, &scale);
800 text = gl_text_node_expand (text_node, record);
801 gbc = gl_barcode_new (style, text_flag, scale, text);
803 gl_text_node_free (&text_node);
807 font = gnome_font_find_closest_from_weight_slant (
808 GL_BARCODE_FONT_FAMILY,
809 GL_BARCODE_FONT_WEIGHT,
811 gnome_print_setfont (pi->pc, font);
813 gnome_print_setrgbcolor (pi->pc,
814 GL_COLOR_F_RED (color),
815 GL_COLOR_F_GREEN (color),
816 GL_COLOR_F_BLUE (color));
817 gnome_print_setopacity (pi->pc,
818 GL_COLOR_F_ALPHA (color));
820 y_offset = 12.0 - gnome_font_get_descender (font);
821 gnome_print_moveto (pi->pc, x, y + y_offset);
823 gnome_print_gsave (pi->pc);
824 gnome_print_scale (pi->pc, 1.0, -1.0);
825 gnome_print_show (pi->pc, _("Invalid barcode"));
826 gnome_print_grestore (pi->pc);
830 for (li = gbc->lines; li != NULL; li = li->next) {
831 line = (glBarcodeLine *) li->data;
833 gnome_print_moveto (pi->pc, x + line->x, y + line->y);
834 gnome_print_lineto (pi->pc, x + line->x,
835 y + line->y + line->length);
836 gnome_print_setrgbcolor (pi->pc,
837 GL_COLOR_F_RED (color),
838 GL_COLOR_F_GREEN (color),
839 GL_COLOR_F_BLUE (color));
840 gnome_print_setopacity (pi->pc,
841 GL_COLOR_F_ALPHA (color));
842 gnome_print_setlinewidth (pi->pc, line->width);
843 gnome_print_stroke (pi->pc);
846 for (li = gbc->chars; li != NULL; li = li->next) {
847 bchar = (glBarcodeChar *) li->data;
849 font = gnome_font_find_closest_from_weight_slant (
850 GL_BARCODE_FONT_FAMILY,
851 GL_BARCODE_FONT_WEIGHT,
852 FALSE, bchar->fsize);
853 gnome_print_setfont (pi->pc, font);
855 gnome_print_setrgbcolor (pi->pc,
856 GL_COLOR_F_RED (color),
857 GL_COLOR_F_GREEN (color),
858 GL_COLOR_F_BLUE (color));
859 gnome_print_setopacity (pi->pc,
860 GL_COLOR_F_ALPHA (color));
863 bchar->y + bchar->fsize -
864 gnome_font_get_descender (font);
865 gnome_print_moveto (pi->pc, x + bchar->x, y + y_offset);
867 cstring = g_strdup_printf ("%c", bchar->c);
868 gnome_print_gsave (pi->pc);
869 gnome_print_scale (pi->pc, 1.0, -1.0);
870 gnome_print_show (pi->pc, cstring);
871 gnome_print_grestore (pi->pc);
876 gl_barcode_free (&gbc);
880 gl_debug (DEBUG_PRINT, "END");
883 /*---------------------------------------------------------------------------*/
884 /* PRIVATE. Draw outline. */
885 /*---------------------------------------------------------------------------*/
887 draw_outline (PrintInfo * pi,
892 glTemplate *template;
894 gl_debug (DEBUG_PRINT, "START");
896 template = gl_label_get_template (label);
898 gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
899 gnome_print_setopacity (pi->pc, 1.0);
900 gnome_print_setlinewidth (pi->pc, 0.25);
902 switch (template->label.style) {
904 case GL_TEMPLATE_STYLE_RECT:
905 gl_label_get_size (label, &w, &h);
906 r = template->label.rect.r;
908 /* simple rectangle */
909 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
911 /* rectangle with rounded corners */
912 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
915 gnome_print_stroke (pi->pc);
918 case GL_TEMPLATE_STYLE_ROUND:
920 r1 = template->label.round.r;
921 create_ellipse_path (pi->pc, r1, r1, r1, r1);
922 gnome_print_stroke (pi->pc);
925 case GL_TEMPLATE_STYLE_CD:
926 /* CD style, round label w/ concentric round hole */
927 r1 = template->label.cd.r1;
928 r2 = template->label.cd.r2;
929 create_ellipse_path (pi->pc, r1, r1, r1, r1);
930 gnome_print_stroke (pi->pc);
931 create_ellipse_path (pi->pc, r1, r1, r2, r2);
932 gnome_print_stroke (pi->pc);
936 g_warning ("Unknown template label style");
940 gl_template_free (&template);
942 gl_debug (DEBUG_PRINT, "END");
945 /*---------------------------------------------------------------------------*/
946 /* PRIVATE. Clip to outline. */
947 /*---------------------------------------------------------------------------*/
949 clip_to_outline (PrintInfo * pi,
954 glTemplate *template;
956 gl_debug (DEBUG_PRINT, "START");
958 template = gl_label_get_template (label);
960 switch (template->label.style) {
962 case GL_TEMPLATE_STYLE_RECT:
963 gl_label_get_size (label, &w, &h);
964 r = template->label.rect.r;
966 /* simple rectangle */
967 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
969 /* rectangle with rounded corners */
970 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
973 gnome_print_clip (pi->pc);
976 case GL_TEMPLATE_STYLE_ROUND:
977 r1 = template->label.round.r;
978 create_ellipse_path (pi->pc, r1, r1, r1, r1);
979 gnome_print_clip (pi->pc);
982 case GL_TEMPLATE_STYLE_CD:
983 r1 = template->label.cd.r1;
984 create_ellipse_path (pi->pc, r1, r1, r1, r1);
985 gnome_print_clip (pi->pc);
989 g_warning ("Unknown template label style");
993 gl_template_free (&template);
995 gl_debug (DEBUG_PRINT, "END");
998 /*---------------------------------------------------------------------------*/
999 /* PRIVATE. Path creation utilities. */
1000 /*---------------------------------------------------------------------------*/
1002 create_rectangle_path (GnomePrintContext * pc,
1008 gl_debug (DEBUG_PRINT, "START");
1010 gnome_print_newpath (pc);
1011 gnome_print_moveto (pc, x0, y0);
1012 gnome_print_lineto (pc, x0 + w, y0);
1013 gnome_print_lineto (pc, x0 + w, y0 + h);
1014 gnome_print_lineto (pc, x0, y0 + h);
1015 gnome_print_lineto (pc, x0, y0);
1016 gnome_print_closepath (pc);
1018 gl_debug (DEBUG_PRINT, "END");
1022 create_ellipse_path (GnomePrintContext * pc,
1031 gl_debug (DEBUG_PRINT, "START");
1033 gnome_print_newpath (pc);
1034 gnome_print_moveto (pc, x0 + rx, y0);
1035 for (i_theta = 2; i_theta <= 360; i_theta += 2) {
1036 x = x0 + rx * cos (i_theta * M_PI / 180.0);
1037 y = y0 + ry * sin (i_theta * M_PI / 180.0);
1038 gnome_print_lineto (pc, x, y);
1040 gnome_print_closepath (pc);
1042 gl_debug (DEBUG_PRINT, "END");
1046 create_rounded_rectangle_path (GnomePrintContext * pc,
1056 gl_debug (DEBUG_PRINT, "START");
1058 gnome_print_newpath (pc);
1060 gnome_print_moveto (pc, x0 + r, y0);
1061 for (i_theta = 5; i_theta <= 90; i_theta += 5) {
1062 x = x0 + r - r * sin (i_theta * M_PI / 180.0);
1063 y = y0 + r - r * cos (i_theta * M_PI / 180.0);
1064 gnome_print_lineto (pc, x, y);
1066 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1067 x = x0 + r - r * cos (i_theta * M_PI / 180.0);
1068 y = y0 + (h - r) + r * sin (i_theta * M_PI / 180.0);
1069 gnome_print_lineto (pc, x, y);
1071 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1072 x = x0 + (w - r) + r * sin (i_theta * M_PI / 180.0);
1073 y = y0 + (h - r) + r * cos (i_theta * M_PI / 180.0);
1074 gnome_print_lineto (pc, x, y);
1076 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1077 x = x0 + (w - r) + r * cos (i_theta * M_PI / 180.0);
1078 y = y0 + r - r * sin (i_theta * M_PI / 180.0);
1079 gnome_print_lineto (pc, x, y);
1081 gnome_print_lineto (pc, x0 + r, y0);
1083 gnome_print_closepath (pc);
1085 gl_debug (DEBUG_PRINT, "END");