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"
44 #define GL_PRINT_DEFAULT_PAPER "US Letter"
46 #define RED(x) ( (((x)>>24) & 0xff) / 255.0 )
47 #define GREEN(x) ( (((x)>>16) & 0xff) / 255.0 )
48 #define BLUE(x) ( (((x)>>8) & 0xff) / 255.0 )
49 #define ALPHA(x) ( ( (x) & 0xff) / 255.0 )
51 /*===========================================*/
53 /*===========================================*/
54 typedef struct _PrintInfo {
55 /* gnome print context */
56 GnomePrintContext *pc;
58 /* gnome print configuration */
59 GnomePrintConfig *config;
61 /* gLabels Template */
62 const glTemplate *template;
63 gboolean label_rotate_flag;
67 /*===========================================*/
68 /* Private function prototypes. */
69 /*===========================================*/
70 static PrintInfo *print_info_new (GnomePrintMaster * master, glLabel * label);
71 static void print_info_free (PrintInfo ** pi);
73 static void print_label (PrintInfo * pi, glLabel * label, gint i,
74 glMergeRecord * record, gboolean outline_flag,
75 gboolean reverse_flag);
77 static void draw_label (PrintInfo * pi, glLabel * label,
78 glMergeRecord * record);
80 static void draw_text_object (PrintInfo * pi, glLabelText * object,
81 glMergeRecord * record);
82 static void draw_box_object (PrintInfo * pi, glLabelBox * object);
83 static void draw_line_object (PrintInfo * pi, glLabelLine * object);
84 static void draw_ellipse_object (PrintInfo * pi, glLabelEllipse * object);
85 static void draw_image_object (PrintInfo * pi, glLabelImage * object);
86 static void draw_barcode_object (PrintInfo * pi, glLabelBarcode * object,
87 glMergeRecord * record);
89 static void draw_outline (PrintInfo * pi, glLabel * label);
90 static void clip_to_outline (PrintInfo * pi, glLabel * label);
92 static void create_rectangle_path (GnomePrintContext * pc,
93 gdouble x0, gdouble y0,
94 gdouble w, gdouble h);
95 static void create_ellipse_path (GnomePrintContext * pc,
96 gdouble x0, gdouble y0,
97 gdouble rx, gdouble ry);
98 static void create_rounded_rectangle_path (GnomePrintContext * pc,
99 gdouble x0, gdouble y0,
100 gdouble w, gdouble h, gdouble r);
102 /*****************************************************************************/
103 /* Simple (no merge data) print command. */
104 /*****************************************************************************/
106 gl_print_simple (GnomePrintMaster * master,
111 gboolean outline_flag,
112 gboolean reverse_flag)
115 gint i_sheet, i_label;
116 gchar *page_str = NULL;
118 gl_debug (DEBUG_PRINT, "START");
120 pi = print_info_new (master, label);
122 for (i_sheet = 0; i_sheet < n_sheets; i_sheet++) {
124 page_str = g_strdup_printf ("sheet %d", i_sheet + 1);
125 gnome_print_beginpage (pi->pc, page_str);
128 for (i_label = first - 1; i_label < last; i_label++) {
130 print_label (pi, label, i_label, NULL,
131 outline_flag, reverse_flag);
135 gnome_print_showpage (pi->pc);
138 print_info_free (&pi);
140 gl_debug (DEBUG_PRINT, "END");
143 /*****************************************************************************/
144 /* Merge print command (collated copies) */
145 /*****************************************************************************/
147 gl_print_merge_collated (GnomePrintMaster * master,
152 gboolean outline_flag,
153 gboolean reverse_flag)
156 gint i_sheet, i_label, n_labels_per_page, i_copy;
158 glMergeRecord *record;
161 gl_debug (DEBUG_PRINT, "START");
163 pi = print_info_new (master, label);
165 n_labels_per_page = (pi->template->nx) * (pi->template->ny);
170 for ( p=record_list; p!=NULL; p=p->next ) {
171 record = (glMergeRecord *)p->data;
173 if ( record->select_flag ) {
174 for (i_copy = 0; i_copy < n_copies; i_copy++) {
176 if ((i_label == 0) || (i_sheet == 0)) {
177 str = g_strdup_printf ("sheet %d",
179 gnome_print_beginpage (pi->pc, str);
183 print_label (pi, label, i_label, record,
184 outline_flag, reverse_flag);
186 i_label = (i_label + 1) % n_labels_per_page;
188 gnome_print_showpage (pi->pc);
195 gnome_print_showpage (pi->pc);
198 print_info_free (&pi);
200 gl_debug (DEBUG_PRINT, "END");
203 /*****************************************************************************/
204 /* Merge print command (uncollated copies) */
205 /*****************************************************************************/
207 gl_print_merge_uncollated (GnomePrintMaster * master,
212 gboolean outline_flag,
213 gboolean reverse_flag)
216 gint i_sheet, i_label, n_labels_per_page, i_copy;
218 glMergeRecord *record;
221 gl_debug (DEBUG_PRINT, "START");
223 pi = print_info_new (master, label);
225 n_labels_per_page = (pi->template->nx) * (pi->template->ny);
230 for (i_copy = 0; i_copy < n_copies; i_copy++) {
232 for ( p=record_list; p!=NULL; p=p->next ) {
233 record = (glMergeRecord *)p->data;
235 if ( record->select_flag ) {
238 if ((i_label == 0) || (i_sheet == 0)) {
239 str = g_strdup_printf ("sheet %d",
241 gnome_print_beginpage (pi->pc, str);
245 print_label (pi, label, i_label, record,
246 outline_flag, reverse_flag);
248 i_label = (i_label + 1) % n_labels_per_page;
250 gnome_print_showpage (pi->pc);
257 gnome_print_showpage (pi->pc);
260 print_info_free (&pi);
262 gl_debug (DEBUG_PRINT, "END");
265 /*****************************************************************************/
266 /* Batch print. Call appropriate function above. */
267 /*****************************************************************************/
269 gl_print_batch (GnomePrintMaster * master, glLabel * label,
270 gint n_sheets, gint n_copies,
271 gboolean outline_flag, gboolean reverse_flag)
274 GList *record_list = NULL;
276 glTemplate *template;
278 gl_debug (DEBUG_PRINT, "START");
280 merge = gl_label_get_merge (label);
281 template = gl_label_get_template (label);
283 if ( merge->type == GL_MERGE_NONE ) {
284 n_per_page = (template->nx)*(template->ny);
286 gl_print_simple (master, label, n_sheets, 1, n_per_page,
287 outline_flag, reverse_flag);
289 record_list = gl_merge_read_data (merge->type,
293 gl_print_merge_collated (master, label, record_list,
295 outline_flag, reverse_flag);
297 gl_merge_free (&merge);
298 gl_template_free (&template);
300 gl_debug (DEBUG_PRINT, "END");
303 /*---------------------------------------------------------------------------*/
304 /* PRIVATE. new print info structure */
305 /*---------------------------------------------------------------------------*/
307 print_info_new (GnomePrintMaster * master,
310 PrintInfo *pi = g_new0 (PrintInfo, 1);
311 glTemplate *template;
313 gl_debug (DEBUG_PRINT, "START");
315 template = gl_label_get_template (label);
317 if (template == NULL) {
318 g_warning ("Label has no template");
322 pi->pc = gnome_print_master_get_context (master);
323 pi->config = gnome_print_master_get_config (master);
325 if ((template != NULL) && (template->page_size != NULL)) {
326 const GnomePrintPaper *paper = NULL;
328 gl_debug (DEBUG_PRINT,
329 "setting page size = \"%s\"", template->page_size);
332 /* Currently cannot set page size directly from name, */
333 /* since we must set Ids not Names and there is no */
334 /* way to do the reverse lookup of Id from Name. */
335 /* Sometimes they are the same, but not always */
336 /* (e.g. for the name "US Letter" id="USLetter" */
337 /* So we use the "Custom" Id. */
338 paper = gnome_print_paper_get_by_name (template->page_size);
339 gnome_print_config_set (pi->config,
340 GNOME_PRINT_KEY_PAPER_SIZE,
342 gnome_print_config_set_length (pi->config,
343 GNOME_PRINT_KEY_PAPER_WIDTH,
345 GNOME_PRINT_PS_UNIT);
346 gnome_print_config_set_length (pi->config,
347 GNOME_PRINT_KEY_PAPER_HEIGHT,
349 GNOME_PRINT_PS_UNIT);
351 gnome_print_config_set (pi->config,
352 GNOME_PRINT_KEY_PAPER_SIZE,
353 GL_PRINT_DEFAULT_PAPER);
357 /* gnome_print_config_dump (pi->config); */
360 GnomePrintPaper *paper;
363 list = gnome_print_paper_get_list();
364 for ( p=list; p != NULL; p=p->next ) {
365 paper = (GnomePrintPaper *)p->data;
366 gl_debug (DEBUG_PRINT, " \"%s\"", paper->name);
368 gl_debug (DEBUG_PRINT,
369 "template->page_size = \"%s\"", template->page_size);
371 name = gnome_print_config_get (pi->config,
372 GNOME_PRINT_KEY_PAPER_SIZE);
373 gl_debug (DEBUG_PRINT, "config = \"%s\"", name);
377 pi->template = template;
378 pi->label_rotate_flag = gl_label_get_rotate_flag (label);
380 gl_template_free (&template);
382 gl_debug (DEBUG_PRINT, "END");
387 /*---------------------------------------------------------------------------*/
388 /* PRIVATE. free print info structure */
389 /*---------------------------------------------------------------------------*/
391 print_info_free (PrintInfo ** pi)
393 gl_debug (DEBUG_PRINT, "START");
395 gnome_print_context_close ((*pi)->pc);
400 gl_debug (DEBUG_PRINT, "END");
403 /*---------------------------------------------------------------------------*/
404 /* PRIVATE. Print i'th label. */
405 /*---------------------------------------------------------------------------*/
407 print_label (PrintInfo * pi,
410 glMergeRecord * record,
411 gboolean outline_flag,
412 gboolean reverse_flag)
416 gdouble width, height;
417 glTemplate *template;
419 gl_debug (DEBUG_PRINT, "START");
421 template = gl_label_get_template (label);
423 gl_label_get_size (label, &width, &height);
425 ix = i_label % (template->nx);
426 iy = ((template->ny) - 1) - (i_label / (template->nx));
428 gnome_print_gsave (pi->pc);
430 /* Transform coordinate system to be relative to upper corner */
431 /* of the current label */
432 gnome_print_translate (pi->pc,
433 ix * (template->dx) + template->x0,
434 iy * (template->dy) + template->y0);
435 if (gl_label_get_rotate_flag (label)) {
436 gl_debug (DEBUG_PRINT, "Rotate flag set");
437 gnome_print_rotate (pi->pc, 90.0);
438 gnome_print_scale (pi->pc, 1.0, -1.0);
440 gl_debug (DEBUG_PRINT, "Rotate flag NOT set");
441 art_affine_scale (a, 1.0, -1.0);
443 gnome_print_concat (pi->pc, a);
445 if ( reverse_flag ) {
446 gnome_print_translate (pi->pc, width, 0.0);
447 art_affine_scale (a, -1.0, 1.0);
448 gnome_print_concat (pi->pc, a);
451 draw_outline (pi, label);
453 clip_to_outline (pi, label);
454 draw_label (pi, label, record);
456 gnome_print_grestore (pi->pc);
458 gl_template_free (&template);
460 gl_debug (DEBUG_PRINT, "END");
463 /*---------------------------------------------------------------------------*/
464 /* PRIVATE. Draw label. */
465 /*---------------------------------------------------------------------------*/
467 draw_label (PrintInfo * pi,
469 glMergeRecord * record)
472 glLabelObject *object;
474 gl_debug (DEBUG_PRINT, "START");
476 for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
477 object = (glLabelObject *) p_obj->data;
479 if (GL_IS_LABEL_TEXT(object)) {
480 draw_text_object (pi, GL_LABEL_TEXT(object), record);
481 } else if (GL_IS_LABEL_BOX(object)) {
482 draw_box_object (pi, GL_LABEL_BOX(object));
483 } else if (GL_IS_LABEL_LINE(object)) {
484 draw_line_object (pi, GL_LABEL_LINE(object));
485 } else if (GL_IS_LABEL_ELLIPSE(object)) {
486 draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object));
487 } else if (GL_IS_LABEL_IMAGE(object)) {
488 draw_image_object (pi, GL_LABEL_IMAGE(object));
489 } else if (GL_IS_LABEL_BARCODE(object)) {
490 draw_barcode_object (pi, GL_LABEL_BARCODE(object),
496 gl_debug (DEBUG_PRINT, "END");
499 /*---------------------------------------------------------------------------*/
500 /* PRIVATE. Draw text object. */
501 /*---------------------------------------------------------------------------*/
503 draw_text_object (PrintInfo * pi,
504 glLabelText * object,
505 glMergeRecord * record)
510 gdouble x_offset, y_offset, w, object_w, object_h;
517 GnomeFontWeight font_weight;
518 gboolean font_italic_flag;
520 GtkJustification just;
521 GnomeGlyphList *glyphlist;
526 gl_debug (DEBUG_PRINT, "START");
528 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x0, &y0);
529 gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
530 lines = gl_label_text_get_lines (object);
531 gl_label_text_get_props (object,
532 &font_family, &font_size, &font_weight,
536 font = gnome_font_find_closest_from_weight_slant (
541 gnome_print_setfont (pi->pc, font);
543 gnome_print_setrgbcolor (pi->pc,
547 gnome_print_setopacity (pi->pc, ALPHA (color));
549 text = gl_text_node_lines_expand (lines, record);
550 line = g_strsplit (text, "\n", -1);
553 art_affine_identity (affine);
555 for (i = 0; line[i] != NULL; i++) {
557 glyphlist = gnome_glyphlist_from_text_dumb (font, color,
561 gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
565 case GTK_JUSTIFY_LEFT:
568 case GTK_JUSTIFY_CENTER:
569 x_offset = (object_w - w) / 2.0;
571 case GTK_JUSTIFY_RIGHT:
572 x_offset = object_w - w;
576 break; /* shouldn't happen */
579 y_offset = (i + 1) * font_size
580 + gnome_font_get_descender (font);
584 gnome_print_moveto (pi->pc, x, y);
586 gnome_print_gsave (pi->pc);
587 gnome_print_scale (pi->pc, 1.0, -1.0);
588 gnome_print_show (pi->pc, line[i]);
589 gnome_print_grestore (pi->pc);
594 gl_text_node_lines_free (&lines);
595 g_free (font_family);
597 gl_debug (DEBUG_PRINT, "END");
600 /*---------------------------------------------------------------------------*/
601 /* PRIVATE. Draw box object. */
602 /*---------------------------------------------------------------------------*/
604 draw_box_object (PrintInfo * pi,
609 guint line_color, fill_color;
611 gl_debug (DEBUG_PRINT, "START");
613 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
614 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
615 line_width = gl_label_box_get_line_width (object);
616 line_color = gl_label_box_get_line_color (object);
617 fill_color = gl_label_box_get_fill_color (object);
619 /* Paint fill color */
620 create_rectangle_path (pi->pc, x, y, w, h);
621 gnome_print_setrgbcolor (pi->pc,
625 gnome_print_setopacity (pi->pc, ALPHA (fill_color));
626 gnome_print_fill (pi->pc);
629 create_rectangle_path (pi->pc, x, y, w, h);
630 gnome_print_setrgbcolor (pi->pc,
634 gnome_print_setopacity (pi->pc, ALPHA (line_color));
635 gnome_print_setlinewidth (pi->pc, line_width);
636 gnome_print_stroke (pi->pc);
638 gl_debug (DEBUG_PRINT, "END");
641 /*---------------------------------------------------------------------------*/
642 /* PRIVATE. Draw line object. */
643 /*---------------------------------------------------------------------------*/
645 draw_line_object (PrintInfo * pi,
646 glLabelLine * object)
652 gl_debug (DEBUG_PRINT, "START");
654 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
655 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
656 line_width = gl_label_line_get_line_width (object);
657 line_color = gl_label_line_get_line_color (object);
659 gnome_print_moveto (pi->pc, x, y);
660 gnome_print_lineto (pi->pc, x + w, y + h);
661 gnome_print_setrgbcolor (pi->pc,
665 gnome_print_setopacity (pi->pc, ALPHA (line_color));
666 gnome_print_setlinewidth (pi->pc, line_width);
667 gnome_print_stroke (pi->pc);
669 gl_debug (DEBUG_PRINT, "END");
672 /*---------------------------------------------------------------------------*/
673 /* PRIVATE. Draw ellipse object. */
674 /*---------------------------------------------------------------------------*/
676 draw_ellipse_object (PrintInfo * pi,
677 glLabelEllipse * object)
679 gdouble x, y, x0, y0, rx, ry, w, h;
681 guint line_color, fill_color;
683 gl_debug (DEBUG_PRINT, "START");
685 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
686 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
687 line_width = gl_label_ellipse_get_line_width (object);
688 line_color = gl_label_ellipse_get_line_color (object);
689 fill_color = gl_label_ellipse_get_fill_color (object);
696 /* Paint fill color */
697 create_ellipse_path (pi->pc, x0, y0, rx, ry);
698 gnome_print_setrgbcolor (pi->pc,
702 gnome_print_setopacity (pi->pc, ALPHA (fill_color));
703 gnome_print_fill (pi->pc);
706 create_ellipse_path (pi->pc, x0, y0, rx, ry);
707 gnome_print_setrgbcolor (pi->pc,
711 gnome_print_setopacity (pi->pc, ALPHA (line_color));
712 gnome_print_setlinewidth (pi->pc, line_width);
713 gnome_print_stroke (pi->pc);
715 gl_debug (DEBUG_PRINT, "END");
718 /*---------------------------------------------------------------------------*/
719 /* PRIVATE. Draw image object. */
720 /*---------------------------------------------------------------------------*/
722 draw_image_object (PrintInfo * pi,
723 glLabelImage * object)
726 const GdkPixbuf *pixbuf;
728 gint image_w, image_h, image_stride;
729 gboolean image_alpha_flag;
732 gl_debug (DEBUG_PRINT, "START");
734 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
735 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
737 pixbuf = gl_label_image_get_pixbuf (object);
738 image_data = gdk_pixbuf_get_pixels (pixbuf);
739 image_w = gdk_pixbuf_get_width (pixbuf);
740 image_h = gdk_pixbuf_get_height (pixbuf);
741 image_stride = gdk_pixbuf_get_rowstride(pixbuf);
742 image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf);
744 gnome_print_gsave (pi->pc);
745 gnome_print_translate (pi->pc, x, y+h);
746 gnome_print_scale (pi->pc, w, -h);
747 if (image_alpha_flag) {
748 ret = gnome_print_rgbaimage (pi->pc, image_data,
749 image_w, image_h, image_stride);
750 gl_debug (DEBUG_PRINT, "Ret a = %d", ret);
752 ret = gnome_print_rgbimage (pi->pc, image_data,
753 image_w, image_h, image_stride);
754 gl_debug (DEBUG_PRINT, "Ret = %d", ret);
756 gnome_print_grestore (pi->pc);
758 gl_debug (DEBUG_PRINT, "END");
761 /*---------------------------------------------------------------------------*/
762 /* PRIVATE. Draw box object. */
763 /*---------------------------------------------------------------------------*/
765 draw_barcode_object (PrintInfo * pi,
766 glLabelBarcode * object,
767 glMergeRecord * record)
771 glBarcodeChar *bchar;
773 gdouble x, y, y_offset;
775 gchar *text, *cstring;
776 glTextNode *text_node;
777 glBarcodeStyle style;
782 gl_debug (DEBUG_PRINT, "START");
784 gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
785 text_node = gl_label_barcode_get_data (object);
786 gl_label_barcode_get_props (object,
787 &style, &text_flag, &color, &scale);
789 text = gl_text_node_expand (text_node, record);
790 gbc = gl_barcode_new (style, text_flag, scale, text);
792 gl_text_node_free (&text_node);
796 font = gnome_font_find_closest_from_weight_slant (
797 GL_BARCODE_FONT_FAMILY,
798 GL_BARCODE_FONT_WEIGHT,
800 gnome_print_setfont (pi->pc, font);
802 gnome_print_setrgbcolor (pi->pc,
806 gnome_print_setopacity (pi->pc,
809 y_offset = 12.0 - gnome_font_get_descender (font);
810 gnome_print_moveto (pi->pc, x, y + y_offset);
812 gnome_print_gsave (pi->pc);
813 gnome_print_scale (pi->pc, 1.0, -1.0);
814 gnome_print_show (pi->pc, _("Invalid barcode"));
815 gnome_print_grestore (pi->pc);
819 for (li = gbc->lines; li != NULL; li = li->next) {
820 line = (glBarcodeLine *) li->data;
822 gnome_print_moveto (pi->pc, x + line->x, y + line->y);
823 gnome_print_lineto (pi->pc, x + line->x,
824 y + line->y + line->length);
825 gnome_print_setrgbcolor (pi->pc,
829 gnome_print_setopacity (pi->pc,
831 gnome_print_setlinewidth (pi->pc, line->width);
832 gnome_print_stroke (pi->pc);
835 for (li = gbc->chars; li != NULL; li = li->next) {
836 bchar = (glBarcodeChar *) li->data;
838 font = gnome_font_find_closest_from_weight_slant (
839 GL_BARCODE_FONT_FAMILY,
840 GL_BARCODE_FONT_WEIGHT,
841 FALSE, bchar->fsize);
842 gnome_print_setfont (pi->pc, font);
844 gnome_print_setrgbcolor (pi->pc,
848 gnome_print_setopacity (pi->pc,
852 bchar->y + bchar->fsize -
853 gnome_font_get_descender (font);
854 gnome_print_moveto (pi->pc, x + bchar->x, y + y_offset);
856 cstring = g_strdup_printf ("%c", bchar->c);
857 gnome_print_gsave (pi->pc);
858 gnome_print_scale (pi->pc, 1.0, -1.0);
859 gnome_print_show (pi->pc, cstring);
860 gnome_print_grestore (pi->pc);
865 gl_barcode_free (&gbc);
869 gl_debug (DEBUG_PRINT, "END");
872 /*---------------------------------------------------------------------------*/
873 /* PRIVATE. Draw outline. */
874 /*---------------------------------------------------------------------------*/
876 draw_outline (PrintInfo * pi,
881 glTemplate *template;
883 gl_debug (DEBUG_PRINT, "START");
885 template = gl_label_get_template (label);
887 gnome_print_setrgbcolor (pi->pc, 0.25, 0.25, 0.25);
888 gnome_print_setopacity (pi->pc, 1.0);
889 gnome_print_setlinewidth (pi->pc, 0.25);
891 switch (template->style) {
893 case GL_TEMPLATE_STYLE_RECT:
894 gl_label_get_size (label, &w, &h);
895 r = template->label_round;
897 /* simple rectangle */
898 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
900 /* rectangle with rounded corners */
901 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
904 gnome_print_stroke (pi->pc);
907 case GL_TEMPLATE_STYLE_ROUND:
909 r1 = template->label_radius;
910 create_ellipse_path (pi->pc, r1, r1, r1, r1);
911 gnome_print_stroke (pi->pc);
914 case GL_TEMPLATE_STYLE_CD:
915 /* CD style, round label w/ concentric round hole */
916 r1 = template->label_radius;
917 r2 = template->label_hole;
918 create_ellipse_path (pi->pc, r1, r1, r1, r1);
919 gnome_print_stroke (pi->pc);
920 create_ellipse_path (pi->pc, r1, r1, r2, r2);
921 gnome_print_stroke (pi->pc);
925 g_warning ("Unknown template label style");
929 gl_template_free (&template);
931 gl_debug (DEBUG_PRINT, "END");
934 /*---------------------------------------------------------------------------*/
935 /* PRIVATE. Clip to outline. */
936 /*---------------------------------------------------------------------------*/
938 clip_to_outline (PrintInfo * pi,
943 glTemplate *template;
945 gl_debug (DEBUG_PRINT, "START");
947 template = gl_label_get_template (label);
949 switch (template->style) {
951 case GL_TEMPLATE_STYLE_RECT:
952 gl_label_get_size (label, &w, &h);
953 r = template->label_round;
955 /* simple rectangle */
956 create_rectangle_path (pi->pc, 0.0, 0.0, w, h);
958 /* rectangle with rounded corners */
959 create_rounded_rectangle_path (pi->pc, 0.0, 0.0,
962 gnome_print_clip (pi->pc);
965 case GL_TEMPLATE_STYLE_ROUND:
966 case GL_TEMPLATE_STYLE_CD:
967 r1 = template->label_radius;
968 create_ellipse_path (pi->pc, r1, r1, r1, r1);
969 gnome_print_clip (pi->pc);
973 g_warning ("Unknown template label style");
977 gl_template_free (&template);
979 gl_debug (DEBUG_PRINT, "END");
982 /*---------------------------------------------------------------------------*/
983 /* PRIVATE. Path creation utilities. */
984 /*---------------------------------------------------------------------------*/
986 create_rectangle_path (GnomePrintContext * pc,
992 gl_debug (DEBUG_PRINT, "START");
994 gnome_print_newpath (pc);
995 gnome_print_moveto (pc, x0, y0);
996 gnome_print_lineto (pc, x0 + w, y0);
997 gnome_print_lineto (pc, x0 + w, y0 + h);
998 gnome_print_lineto (pc, x0, y0 + h);
999 gnome_print_lineto (pc, x0, y0);
1000 gnome_print_closepath (pc);
1002 gl_debug (DEBUG_PRINT, "END");
1006 create_ellipse_path (GnomePrintContext * pc,
1015 gl_debug (DEBUG_PRINT, "START");
1017 gnome_print_newpath (pc);
1018 gnome_print_moveto (pc, x0 + rx, y0);
1019 for (i_theta = 2; i_theta <= 360; i_theta += 2) {
1020 x = x0 + rx * cos (i_theta * M_PI / 180.0);
1021 y = y0 + ry * sin (i_theta * M_PI / 180.0);
1022 gnome_print_lineto (pc, x, y);
1024 gnome_print_closepath (pc);
1026 gl_debug (DEBUG_PRINT, "END");
1030 create_rounded_rectangle_path (GnomePrintContext * pc,
1040 gl_debug (DEBUG_PRINT, "START");
1042 gnome_print_newpath (pc);
1044 gnome_print_moveto (pc, x0 + r, y0);
1045 for (i_theta = 5; i_theta <= 90; i_theta += 5) {
1046 x = x0 + r - r * sin (i_theta * M_PI / 180.0);
1047 y = y0 + r - r * cos (i_theta * M_PI / 180.0);
1048 gnome_print_lineto (pc, x, y);
1050 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1051 x = x0 + r - r * cos (i_theta * M_PI / 180.0);
1052 y = y0 + (h - r) + r * sin (i_theta * M_PI / 180.0);
1053 gnome_print_lineto (pc, x, y);
1055 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1056 x = x0 + (w - r) + r * sin (i_theta * M_PI / 180.0);
1057 y = y0 + (h - r) + r * cos (i_theta * M_PI / 180.0);
1058 gnome_print_lineto (pc, x, y);
1060 for (i_theta = 0; i_theta <= 90; i_theta += 5) {
1061 x = x0 + (w - r) + r * cos (i_theta * M_PI / 180.0);
1062 y = y0 + r - r * sin (i_theta * M_PI / 180.0);
1063 gnome_print_lineto (pc, x, y);
1065 gnome_print_lineto (pc, x0 + r, y0);
1067 gnome_print_closepath (pc);
1069 gl_debug (DEBUG_PRINT, "END");