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, gint i,
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;
114 gl_debug (DEBUG_PRINT, "START");
116 pi = print_info_new (master, label);
118 for (i_sheet = 0; i_sheet < n_sheets; i_sheet++) {
120 page_str = g_strdup_printf ("sheet %d", i_sheet + 1);
121 gnome_print_beginpage (pi->pc, page_str);
124 for (i_label = first - 1; i_label < last; i_label++) {
126 print_label (pi, label, i_label, NULL,
127 outline_flag, reverse_flag);
131 gnome_print_showpage (pi->pc);
134 print_info_free (&pi);
136 gl_debug (DEBUG_PRINT, "END");
139 /*****************************************************************************/
140 /* Merge print command (collated copies) */
141 /*****************************************************************************/
143 gl_print_merge_collated (GnomePrintMaster * master,
148 gboolean outline_flag,
149 gboolean reverse_flag)
152 gint i_sheet, i_label, n_labels_per_page, i_copy;
154 glMergeRecord *record;
157 gl_debug (DEBUG_PRINT, "START");
159 pi = print_info_new (master, label);
161 n_labels_per_page = (pi->template->nx) * (pi->template->ny);
166 for ( p=record_list; p!=NULL; p=p->next ) {
167 record = (glMergeRecord *)p->data;
169 if ( record->select_flag ) {
170 for (i_copy = 0; i_copy < n_copies; i_copy++) {
172 if ((i_label == 0) || (i_sheet == 0)) {
173 str = g_strdup_printf ("sheet %d",
175 gnome_print_beginpage (pi->pc, str);
179 print_label (pi, label, i_label, record,
180 outline_flag, reverse_flag);
182 i_label = (i_label + 1) % n_labels_per_page;
184 gnome_print_showpage (pi->pc);
191 gnome_print_showpage (pi->pc);
194 print_info_free (&pi);
196 gl_debug (DEBUG_PRINT, "END");
199 /*****************************************************************************/
200 /* Merge print command (uncollated copies) */
201 /*****************************************************************************/
203 gl_print_merge_uncollated (GnomePrintMaster * master,
208 gboolean outline_flag,
209 gboolean reverse_flag)
212 gint i_sheet, i_label, n_labels_per_page, i_copy;
214 glMergeRecord *record;
217 gl_debug (DEBUG_PRINT, "START");
219 pi = print_info_new (master, label);
221 n_labels_per_page = (pi->template->nx) * (pi->template->ny);
226 for (i_copy = 0; i_copy < n_copies; i_copy++) {
228 for ( p=record_list; p!=NULL; p=p->next ) {
229 record = (glMergeRecord *)p->data;
231 if ( record->select_flag ) {
234 if ((i_label == 0) || (i_sheet == 0)) {
235 str = g_strdup_printf ("sheet %d",
237 gnome_print_beginpage (pi->pc, str);
241 print_label (pi, label, i_label, record,
242 outline_flag, reverse_flag);
244 i_label = (i_label + 1) % n_labels_per_page;
246 gnome_print_showpage (pi->pc);
253 gnome_print_showpage (pi->pc);
256 print_info_free (&pi);
258 gl_debug (DEBUG_PRINT, "END");
261 /*****************************************************************************/
262 /* Batch print. Call appropriate function above. */
263 /*****************************************************************************/
265 gl_print_batch (GnomePrintMaster * master, glLabel * label,
266 gint n_sheets, gint n_copies,
267 gboolean outline_flag, gboolean reverse_flag)
270 GList *record_list = NULL;
272 glTemplate *template;
274 gl_debug (DEBUG_PRINT, "START");
276 merge = gl_label_get_merge (label);
277 template = gl_label_get_template (label);
279 if ( merge->type == GL_MERGE_NONE ) {
280 n_per_page = (template->nx)*(template->ny);
282 gl_print_simple (master, label, n_sheets, 1, n_per_page,
283 outline_flag, reverse_flag);
285 record_list = gl_merge_read_data (merge->type,
289 gl_print_merge_collated (master, label, record_list,
291 outline_flag, reverse_flag);
293 gl_merge_free (&merge);
294 gl_template_free (&template);
296 gl_debug (DEBUG_PRINT, "END");
299 /*---------------------------------------------------------------------------*/
300 /* PRIVATE. new print info structure */
301 /*---------------------------------------------------------------------------*/
303 print_info_new (GnomePrintMaster * master,
306 PrintInfo *pi = g_new0 (PrintInfo, 1);
307 glTemplate *template;
309 gl_debug (DEBUG_PRINT, "START");
311 template = gl_label_get_template (label);
313 if (template == NULL) {
314 g_warning ("Label has no template");
318 pi->pc = gnome_print_master_get_context (master);
319 pi->config = gnome_print_master_get_config (master);
321 if ((template != NULL) && (template->page_size != NULL)) {
322 const GnomePrintPaper *paper = NULL;
324 gl_debug (DEBUG_PRINT,
325 "setting page size = \"%s\"", template->page_size);
328 /* Currently cannot set page size directly from name, */
329 /* since we must set Ids not Names and there is no */
330 /* way to do the reverse lookup of Id from Name. */
331 /* Sometimes they are the same, but not always */
332 /* (e.g. for the name "US Letter" id="USLetter" */
333 /* So we use the "Custom" Id. */
334 paper = gnome_print_paper_get_by_name (template->page_size);
335 gnome_print_config_set (pi->config,
336 GNOME_PRINT_KEY_PAPER_SIZE,
338 gnome_print_config_set_length (pi->config,
339 GNOME_PRINT_KEY_PAPER_WIDTH,
341 GNOME_PRINT_PS_UNIT);
342 gnome_print_config_set_length (pi->config,
343 GNOME_PRINT_KEY_PAPER_HEIGHT,
345 GNOME_PRINT_PS_UNIT);
347 gnome_print_config_set (pi->config,
348 GNOME_PRINT_KEY_PAPER_SIZE,
349 GL_PRINT_DEFAULT_PAPER);
353 /* gnome_print_config_dump (pi->config); */
356 GnomePrintPaper *paper;
359 list = gnome_print_paper_get_list();
360 for ( p=list; p != NULL; p=p->next ) {
361 paper = (GnomePrintPaper *)p->data;
362 gl_debug (DEBUG_PRINT, " \"%s\"", paper->name);
364 gl_debug (DEBUG_PRINT,
365 "template->page_size = \"%s\"", template->page_size);
367 name = gnome_print_config_get (pi->config,
368 GNOME_PRINT_KEY_PAPER_SIZE);
369 gl_debug (DEBUG_PRINT, "config = \"%s\"", name);
373 pi->template = template;
374 pi->label_rotate_flag = gl_label_get_rotate_flag (label);
376 gl_template_free (&template);
378 gl_debug (DEBUG_PRINT, "END");
383 /*---------------------------------------------------------------------------*/
384 /* PRIVATE. free print info structure */
385 /*---------------------------------------------------------------------------*/
387 print_info_free (PrintInfo ** pi)
389 gl_debug (DEBUG_PRINT, "START");
391 gnome_print_context_close ((*pi)->pc);
396 gl_debug (DEBUG_PRINT, "END");
399 /*---------------------------------------------------------------------------*/
400 /* PRIVATE. Print i'th label. */
401 /*---------------------------------------------------------------------------*/
403 print_label (PrintInfo * pi,
406 glMergeRecord * record,
407 gboolean outline_flag,
408 gboolean reverse_flag)
412 gdouble width, height;
413 glTemplate *template;
415 gl_debug (DEBUG_PRINT, "START");
417 template = gl_label_get_template (label);
419 gl_label_get_size (label, &width, &height);
421 ix = i_label % (template->nx);
422 iy = ((template->ny) - 1) - (i_label / (template->nx));
424 gnome_print_gsave (pi->pc);
426 /* Transform coordinate system to be relative to upper corner */
427 /* of the current label */
428 gnome_print_translate (pi->pc,
429 ix * (template->dx) + template->x0,
430 iy * (template->dy) + template->y0);
431 if (gl_label_get_rotate_flag (label)) {
432 gl_debug (DEBUG_PRINT, "Rotate flag set");
433 gnome_print_rotate (pi->pc, 90.0);
434 gnome_print_scale (pi->pc, 1.0, -1.0);
436 gl_debug (DEBUG_PRINT, "Rotate flag NOT set");
437 art_affine_scale (a, 1.0, -1.0);
439 gnome_print_concat (pi->pc, a);
441 if ( reverse_flag ) {
442 gnome_print_translate (pi->pc, width, 0.0);
443 art_affine_scale (a, -1.0, 1.0);
444 gnome_print_concat (pi->pc, a);
447 draw_outline (pi, label);
449 clip_to_outline (pi, label);
450 draw_label (pi, label, record);
452 gnome_print_grestore (pi->pc);
454 gl_template_free (&template);
456 gl_debug (DEBUG_PRINT, "END");
459 /*---------------------------------------------------------------------------*/
460 /* PRIVATE. Draw label. */
461 /*---------------------------------------------------------------------------*/
463 draw_label (PrintInfo * pi,
465 glMergeRecord * record)
468 glLabelObject *object;
470 gl_debug (DEBUG_PRINT, "START");
472 for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
473 object = (glLabelObject *) p_obj->data;
475 if (GL_IS_LABEL_TEXT(object)) {
476 draw_text_object (pi, GL_LABEL_TEXT(object), record);
477 } else if (GL_IS_LABEL_BOX(object)) {
478 draw_box_object (pi, GL_LABEL_BOX(object));
479 } else if (GL_IS_LABEL_LINE(object)) {
480 draw_line_object (pi, GL_LABEL_LINE(object));
481 } else if (GL_IS_LABEL_ELLIPSE(object)) {
482 draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object));
483 } else if (GL_IS_LABEL_IMAGE(object)) {
484 draw_image_object (pi, GL_LABEL_IMAGE(object));
485 } else if (GL_IS_LABEL_BARCODE(object)) {
486 draw_barcode_object (pi, GL_LABEL_BARCODE(object),
492 gl_debug (DEBUG_PRINT, "END");
495 /*---------------------------------------------------------------------------*/
496 /* PRIVATE. Draw text object. */
497 /*---------------------------------------------------------------------------*/
499 draw_text_object (PrintInfo * pi,
500 glLabelText * object,
501 glMergeRecord * record)
506 gdouble x_offset, y_offset, w, object_w, object_h;
513 GnomeFontWeight font_weight;
514 gboolean font_italic_flag;
516 GtkJustification just;
517 GnomeGlyphList *glyphlist;
522 gl_debug (DEBUG_PRINT, "START");
524 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x0, &y0);
525 gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
526 lines = gl_label_text_get_lines (object);
527 gl_label_text_get_props (object,
528 &font_family, &font_size, &font_weight,
532 font = gnome_font_find_closest_from_weight_slant (
537 gnome_print_setfont (pi->pc, font);
539 gnome_print_setrgbcolor (pi->pc,
540 GL_COLOR_F_RED (color),
541 GL_COLOR_F_GREEN (color),
542 GL_COLOR_F_BLUE (color));
543 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color));
545 text = gl_text_node_lines_expand (lines, record);
546 line = g_strsplit (text, "\n", -1);
549 art_affine_identity (affine);
551 for (i = 0; line[i] != NULL; i++) {
553 glyphlist = gnome_glyphlist_from_text_dumb (font, color,
557 gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
561 case GTK_JUSTIFY_LEFT:
564 case GTK_JUSTIFY_CENTER:
565 x_offset = (object_w - w) / 2.0;
567 case GTK_JUSTIFY_RIGHT:
568 x_offset = object_w - w;
572 break; /* shouldn't happen */
575 y_offset = (i + 1) * font_size
576 + gnome_font_get_descender (font);
580 gnome_print_moveto (pi->pc, x, y);
582 gnome_print_gsave (pi->pc);
583 gnome_print_scale (pi->pc, 1.0, -1.0);
584 gnome_print_show (pi->pc, line[i]);
585 gnome_print_grestore (pi->pc);
590 gl_text_node_lines_free (&lines);
591 g_free (font_family);
593 gl_debug (DEBUG_PRINT, "END");
596 /*---------------------------------------------------------------------------*/
597 /* PRIVATE. Draw box object. */
598 /*---------------------------------------------------------------------------*/
600 draw_box_object (PrintInfo * pi,
605 guint line_color, fill_color;
607 gl_debug (DEBUG_PRINT, "START");
609 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
610 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
611 line_width = gl_label_box_get_line_width (object);
612 line_color = gl_label_box_get_line_color (object);
613 fill_color = gl_label_box_get_fill_color (object);
615 /* Paint fill color */
616 create_rectangle_path (pi->pc, x, y, w, h);
617 gnome_print_setrgbcolor (pi->pc,
618 GL_COLOR_F_RED (fill_color),
619 GL_COLOR_F_GREEN (fill_color),
620 GL_COLOR_F_BLUE (fill_color));
621 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
622 gnome_print_fill (pi->pc);
625 create_rectangle_path (pi->pc, x, y, w, h);
626 gnome_print_setrgbcolor (pi->pc,
627 GL_COLOR_F_RED (line_color),
628 GL_COLOR_F_GREEN (line_color),
629 GL_COLOR_F_BLUE (line_color));
630 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
631 gnome_print_setlinewidth (pi->pc, line_width);
632 gnome_print_stroke (pi->pc);
634 gl_debug (DEBUG_PRINT, "END");
637 /*---------------------------------------------------------------------------*/
638 /* PRIVATE. Draw line object. */
639 /*---------------------------------------------------------------------------*/
641 draw_line_object (PrintInfo * pi,
642 glLabelLine * object)
648 gl_debug (DEBUG_PRINT, "START");
650 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
651 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
652 line_width = gl_label_line_get_line_width (object);
653 line_color = gl_label_line_get_line_color (object);
655 gnome_print_moveto (pi->pc, x, y);
656 gnome_print_lineto (pi->pc, x + w, y + h);
657 gnome_print_setrgbcolor (pi->pc,
658 GL_COLOR_F_RED (line_color),
659 GL_COLOR_F_GREEN (line_color),
660 GL_COLOR_F_BLUE (line_color));
661 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
662 gnome_print_setlinewidth (pi->pc, line_width);
663 gnome_print_stroke (pi->pc);
665 gl_debug (DEBUG_PRINT, "END");
668 /*---------------------------------------------------------------------------*/
669 /* PRIVATE. Draw ellipse object. */
670 /*---------------------------------------------------------------------------*/
672 draw_ellipse_object (PrintInfo * pi,
673 glLabelEllipse * object)
675 gdouble x, y, x0, y0, rx, ry, w, h;
677 guint line_color, fill_color;
679 gl_debug (DEBUG_PRINT, "START");
681 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
682 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
683 line_width = gl_label_ellipse_get_line_width (object);
684 line_color = gl_label_ellipse_get_line_color (object);
685 fill_color = gl_label_ellipse_get_fill_color (object);
692 /* Paint fill color */
693 create_ellipse_path (pi->pc, x0, y0, rx, ry);
694 gnome_print_setrgbcolor (pi->pc,
695 GL_COLOR_F_RED (fill_color),
696 GL_COLOR_F_GREEN (fill_color),
697 GL_COLOR_F_BLUE (fill_color));
698 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color));
699 gnome_print_fill (pi->pc);
702 create_ellipse_path (pi->pc, x0, y0, rx, ry);
703 gnome_print_setrgbcolor (pi->pc,
704 GL_COLOR_F_RED (line_color),
705 GL_COLOR_F_GREEN (line_color),
706 GL_COLOR_F_BLUE (line_color));
707 gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color));
708 gnome_print_setlinewidth (pi->pc, line_width);
709 gnome_print_stroke (pi->pc);
711 gl_debug (DEBUG_PRINT, "END");
714 /*---------------------------------------------------------------------------*/
715 /* PRIVATE. Draw image object. */
716 /*---------------------------------------------------------------------------*/
718 draw_image_object (PrintInfo * pi,
719 glLabelImage * object)
722 const GdkPixbuf *pixbuf;
724 gint image_w, image_h, image_stride;
725 gboolean image_alpha_flag;
728 gl_debug (DEBUG_PRINT, "START");
730 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
731 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
733 pixbuf = gl_label_image_get_pixbuf (object);
734 image_data = gdk_pixbuf_get_pixels (pixbuf);
735 image_w = gdk_pixbuf_get_width (pixbuf);
736 image_h = gdk_pixbuf_get_height (pixbuf);
737 image_stride = gdk_pixbuf_get_rowstride(pixbuf);
738 image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf);
740 gnome_print_gsave (pi->pc);
741 gnome_print_translate (pi->pc, x, y+h);
742 gnome_print_scale (pi->pc, w, -h);
743 if (image_alpha_flag) {
744 ret = gnome_print_rgbaimage (pi->pc, image_data,
745 image_w, image_h, image_stride);
746 gl_debug (DEBUG_PRINT, "Ret a = %d", ret);
748 ret = gnome_print_rgbimage (pi->pc, image_data,
749 image_w, image_h, image_stride);
750 gl_debug (DEBUG_PRINT, "Ret = %d", ret);
752 gnome_print_grestore (pi->pc);
754 gl_debug (DEBUG_PRINT, "END");
757 /*---------------------------------------------------------------------------*/
758 /* PRIVATE. Draw box object. */
759 /*---------------------------------------------------------------------------*/
761 draw_barcode_object (PrintInfo * pi,
762 glLabelBarcode * object,
763 glMergeRecord * record)
767 glBarcodeChar *bchar;
769 gdouble x, y, y_offset;
771 gchar *text, *cstring;
772 glTextNode *text_node;
773 glBarcodeStyle style;
778 gl_debug (DEBUG_PRINT, "START");
780 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
781 text_node = gl_label_barcode_get_data (object);
782 gl_label_barcode_get_props (object,
783 &style, &text_flag, &color, &scale);
785 text = gl_text_node_expand (text_node, record);
786 gbc = gl_barcode_new (style, text_flag, scale, text);
788 gl_text_node_free (&text_node);
792 font = gnome_font_find_closest_from_weight_slant (
793 GL_BARCODE_FONT_FAMILY,
794 GL_BARCODE_FONT_WEIGHT,
796 gnome_print_setfont (pi->pc, font);
798 gnome_print_setrgbcolor (pi->pc,
799 GL_COLOR_F_RED (color),
800 GL_COLOR_F_GREEN (color),
801 GL_COLOR_F_BLUE (color));
802 gnome_print_setopacity (pi->pc,
803 GL_COLOR_F_ALPHA (color));
805 y_offset = 12.0 - gnome_font_get_descender (font);
806 gnome_print_moveto (pi->pc, x, y + y_offset);
808 gnome_print_gsave (pi->pc);
809 gnome_print_scale (pi->pc, 1.0, -1.0);
810 gnome_print_show (pi->pc, _("Invalid barcode"));
811 gnome_print_grestore (pi->pc);
815 for (li = gbc->lines; li != NULL; li = li->next) {
816 line = (glBarcodeLine *) li->data;
818 gnome_print_moveto (pi->pc, x + line->x, y + line->y);
819 gnome_print_lineto (pi->pc, x + line->x,
820 y + line->y + line->length);
821 gnome_print_setrgbcolor (pi->pc,
822 GL_COLOR_F_RED (color),
823 GL_COLOR_F_GREEN (color),
824 GL_COLOR_F_BLUE (color));
825 gnome_print_setopacity (pi->pc,
826 GL_COLOR_F_ALPHA (color));
827 gnome_print_setlinewidth (pi->pc, line->width);
828 gnome_print_stroke (pi->pc);
831 for (li = gbc->chars; li != NULL; li = li->next) {
832 bchar = (glBarcodeChar *) li->data;
834 font = gnome_font_find_closest_from_weight_slant (
835 GL_BARCODE_FONT_FAMILY,
836 GL_BARCODE_FONT_WEIGHT,
837 FALSE, bchar->fsize);
838 gnome_print_setfont (pi->pc, font);
840 gnome_print_setrgbcolor (pi->pc,
841 GL_COLOR_F_RED (color),
842 GL_COLOR_F_GREEN (color),
843 GL_COLOR_F_BLUE (color));
844 gnome_print_setopacity (pi->pc,
845 GL_COLOR_F_ALPHA (color));
848 bchar->y + bchar->fsize -
849 gnome_font_get_descender (font);
850 gnome_print_moveto (pi->pc, x + bchar->x, y + y_offset);
852 cstring = g_strdup_printf ("%c", bchar->c);
853 gnome_print_gsave (pi->pc);
854 gnome_print_scale (pi->pc, 1.0, -1.0);
855 gnome_print_show (pi->pc, cstring);
856 gnome_print_grestore (pi->pc);
861 gl_barcode_free (&gbc);
865 gl_debug (DEBUG_PRINT, "END");
868 /*---------------------------------------------------------------------------*/
869 /* PRIVATE. Draw outline. */
870 /*---------------------------------------------------------------------------*/
872 draw_outline (PrintInfo * pi,
877 glTemplate *template;
879 gl_debug (DEBUG_PRINT, "START");
881 template = gl_label_get_template (label);
883 gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
884 gnome_print_setopacity (pi->pc, 1.0);
885 gnome_print_setlinewidth (pi->pc, 0.25);
887 switch (template->style) {
889 case GL_TEMPLATE_STYLE_RECT:
890 gl_label_get_size (label, &w, &h);
891 r = template->label_round;
893 /* simple rectangle */
894 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
896 /* rectangle with rounded corners */
897 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
900 gnome_print_stroke (pi->pc);
903 case GL_TEMPLATE_STYLE_ROUND:
905 r1 = template->label_radius;
906 create_ellipse_path (pi->pc, r1, r1, r1, r1);
907 gnome_print_stroke (pi->pc);
910 case GL_TEMPLATE_STYLE_CD:
911 /* CD style, round label w/ concentric round hole */
912 r1 = template->label_radius;
913 r2 = template->label_hole;
914 create_ellipse_path (pi->pc, r1, r1, r1, r1);
915 gnome_print_stroke (pi->pc);
916 create_ellipse_path (pi->pc, r1, r1, r2, r2);
917 gnome_print_stroke (pi->pc);
921 g_warning ("Unknown template label style");
925 gl_template_free (&template);
927 gl_debug (DEBUG_PRINT, "END");
930 /*---------------------------------------------------------------------------*/
931 /* PRIVATE. Clip to outline. */
932 /*---------------------------------------------------------------------------*/
934 clip_to_outline (PrintInfo * pi,
939 glTemplate *template;
941 gl_debug (DEBUG_PRINT, "START");
943 template = gl_label_get_template (label);
945 switch (template->style) {
947 case GL_TEMPLATE_STYLE_RECT:
948 gl_label_get_size (label, &w, &h);
949 r = template->label_round;
951 /* simple rectangle */
952 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
954 /* rectangle with rounded corners */
955 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
958 gnome_print_clip (pi->pc);
961 case GL_TEMPLATE_STYLE_ROUND:
962 case GL_TEMPLATE_STYLE_CD:
963 r1 = template->label_radius;
964 create_ellipse_path (pi->pc, r1, r1, r1, r1);
965 gnome_print_clip (pi->pc);
969 g_warning ("Unknown template label style");
973 gl_template_free (&template);
975 gl_debug (DEBUG_PRINT, "END");
978 /*---------------------------------------------------------------------------*/
979 /* PRIVATE. Path creation utilities. */
980 /*---------------------------------------------------------------------------*/
982 create_rectangle_path (GnomePrintContext * pc,
988 gl_debug (DEBUG_PRINT, "START");
990 gnome_print_newpath (pc);
991 gnome_print_moveto (pc, x0, y0);
992 gnome_print_lineto (pc, x0 + w, y0);
993 gnome_print_lineto (pc, x0 + w, y0 + h);
994 gnome_print_lineto (pc, x0, y0 + h);
995 gnome_print_lineto (pc, x0, y0);
996 gnome_print_closepath (pc);
998 gl_debug (DEBUG_PRINT, "END");
1002 create_ellipse_path (GnomePrintContext * pc,
1011 gl_debug (DEBUG_PRINT, "START");
1013 gnome_print_newpath (pc);
1014 gnome_print_moveto (pc, x0 + rx, y0);
1015 for (i_theta = 2; i_theta <= 360; i_theta += 2) {
1016 x = x0 + rx * cos (i_theta * M_PI / 180.0);
1017 y = y0 + ry * sin (i_theta * M_PI / 180.0);
1018 gnome_print_lineto (pc, x, y);
1020 gnome_print_closepath (pc);
1022 gl_debug (DEBUG_PRINT, "END");
1026 create_rounded_rectangle_path (GnomePrintContext * pc,
1036 gl_debug (DEBUG_PRINT, "START");
1038 gnome_print_newpath (pc);
1040 gnome_print_moveto (pc, x0 + r, y0);
1041 for (i_theta = 5; i_theta <= 90; i_theta += 5) {
1042 x = x0 + r - r * sin (i_theta * M_PI / 180.0);
1043 y = y0 + r - r * cos (i_theta * M_PI / 180.0);
1044 gnome_print_lineto (pc, x, y);
1046 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1047 x = x0 + r - r * cos (i_theta * M_PI / 180.0);
1048 y = y0 + (h - r) + r * sin (i_theta * M_PI / 180.0);
1049 gnome_print_lineto (pc, x, y);
1051 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1052 x = x0 + (w - r) + r * sin (i_theta * M_PI / 180.0);
1053 y = y0 + (h - r) + r * cos (i_theta * M_PI / 180.0);
1054 gnome_print_lineto (pc, x, y);
1056 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1057 x = x0 + (w - r) + r * cos (i_theta * M_PI / 180.0);
1058 y = y0 + r - r * sin (i_theta * M_PI / 180.0);
1059 gnome_print_lineto (pc, x, y);
1061 gnome_print_lineto (pc, x0 + r, y0);
1063 gnome_print_closepath (pc);
1065 gl_debug (DEBUG_PRINT, "END");