1
/* gtkplotpc - gtkplot print context - a renderer for printing functions
2
* Copyright 1999-2001 Adrian E. Feiguin <feiguin@ifir.edu.ar>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
21
* SECTION: gtkplotcairo
22
* @short_description: Cairo drawing backend.
24
* Subclass of #GtkPlotPC used for screen drawing.
37
#include "gtkplotpc.h"
38
#include "gtkplotcairo.h"
40
#include "gtkpsfont.h"
41
#include "gtkplotcanvas.h"
42
#include <pango/pango.h>
44
static void gtk_plot_cairo_init (GtkPlotCairo *pc);
45
static void gtk_plot_cairo_class_init (GtkPlotCairoClass *klass);
46
static void gtk_plot_cairo_finalize (GObject *object);
47
static gboolean gtk_plot_cairo_real_init (GtkPlotPC *pc);
48
static void gtk_plot_cairo_set_viewport (GtkPlotPC *pc,
49
gdouble w, gdouble h);
50
static void gtk_plot_cairo_leave (GtkPlotPC *pc);
51
static void gtk_plot_cairo_gsave (GtkPlotPC *pc);
52
static void gtk_plot_cairo_grestore (GtkPlotPC *pc);
53
static void gtk_plot_cairo_clip (GtkPlotPC *pc,
54
const GdkRectangle *area);
55
static void gtk_plot_cairo_clip_mask (GtkPlotPC *pc,
58
const GdkBitmap *mask);
59
static void gtk_plot_cairo_set_color (GtkPlotPC *pc,
60
const GdkColor *color);
61
static void gtk_plot_cairo_set_lineattr (GtkPlotPC *pc,
63
GdkLineStyle line_style,
64
GdkCapStyle cap_style,
65
GdkJoinStyle join_style);
66
static void gtk_plot_cairo_set_dash (GtkPlotPC *pc,
70
static void gtk_plot_cairo_draw_point (GtkPlotPC *pc,
71
gdouble x, gdouble y);
72
static void gtk_plot_cairo_draw_line (GtkPlotPC *pc,
73
gdouble x1, gdouble y1,
74
gdouble x2, gdouble y2);
75
static void gtk_plot_cairo_draw_lines (GtkPlotPC *pc,
78
static void gtk_plot_cairo_draw_rectangle (GtkPlotPC *pc,
83
static void gtk_plot_cairo_draw_polygon (GtkPlotPC *pc,
87
static void gtk_plot_cairo_draw_circle (GtkPlotPC *pc,
91
static void gtk_plot_cairo_draw_ellipse (GtkPlotPC *pc,
96
static void gtk_plot_cairo_set_font (GtkPlotPC *pc,
99
static void gtk_plot_cairo_draw_string (GtkPlotPC *pc,
104
gboolean transparent,
111
GtkJustification just,
113
static void gtk_plot_cairo_draw_pixmap (GtkPlotPC *pc,
116
gint xsrc, gint ysrc,
117
gint xdest, gint ydest,
118
gint width, gint height,
122
extern inline gint roundint (gdouble x);
124
static GtkPlotPCClass *parent_class = NULL;
127
gtk_plot_cairo_get_type (void)
129
static GType pc_type = 0;
133
pc_type = g_type_register_static_simple (
134
gtk_plot_pc_get_type(),
136
sizeof (GtkPlotCairoClass),
137
(GClassInitFunc) gtk_plot_cairo_class_init,
138
sizeof (GtkPlotCairo),
139
(GInstanceInitFunc) gtk_plot_cairo_init,
147
gtk_plot_cairo_init (GtkPlotCairo *pc)
151
CairoWindowAttr attributes;
152
gint attributes_mask;
155
attributes.window_type = CAIRO_WINDOW_CHILD;
156
attributes.title = NULL;
157
attributes.wclass = CAIRO_INPUT_OUTPUT;
158
attributes.visual = cairo_visual_get_system ();
159
attributes.colormap = cairo_colormap_get_system ();
160
attributes.event_mask = 0;
161
attributes_mask = CAIRO_WA_VISUAL | CAIRO_WA_COLORMAP;
165
pc->window = cairo_window_new (NULL, &attributes, attributes_mask);
167
screen = cairo_screen_get_default ();
170
pc->context = cairo_pango_context_get ();
173
pango_context_set_base_dir (pc->context,
174
pc->text_direction == GTK_TEXT_DIR_LTR ?
175
PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
179
pango_context_set_language (pc->context, gtk_get_default_language ());
180
pc->layout = pango_layout_new(pc->context);
186
gtk_plot_cairo_class_init (GtkPlotCairoClass *klass)
188
GtkObjectClass *object_class;
189
GObjectClass *gobject_class;
190
GtkPlotPCClass *pc_class;
191
GtkPlotCairoClass *cairo_class;
193
parent_class = g_type_class_ref (gtk_plot_pc_get_type ());
195
object_class = (GtkObjectClass *) klass;
196
gobject_class = (GObjectClass *) klass;
198
pc_class = (GtkPlotPCClass *) klass;
199
cairo_class = (GtkPlotCairoClass *) klass;
201
gobject_class->finalize = gtk_plot_cairo_finalize;
203
pc_class->init = gtk_plot_cairo_real_init;
204
pc_class->leave = gtk_plot_cairo_leave;
205
pc_class->set_viewport = gtk_plot_cairo_set_viewport;
206
pc_class->gsave = gtk_plot_cairo_gsave;
207
pc_class->grestore = gtk_plot_cairo_grestore;
208
pc_class->clip = gtk_plot_cairo_clip;
209
pc_class->clip_mask = gtk_plot_cairo_clip_mask;
210
pc_class->set_color = gtk_plot_cairo_set_color;
211
pc_class->set_dash = gtk_plot_cairo_set_dash;
212
pc_class->set_lineattr = gtk_plot_cairo_set_lineattr;
213
pc_class->draw_point = gtk_plot_cairo_draw_point;
214
pc_class->draw_line = gtk_plot_cairo_draw_line;
215
pc_class->draw_lines = gtk_plot_cairo_draw_lines;
216
pc_class->draw_rectangle = gtk_plot_cairo_draw_rectangle;
217
pc_class->draw_polygon = gtk_plot_cairo_draw_polygon;
218
pc_class->draw_circle = gtk_plot_cairo_draw_circle;
219
pc_class->draw_ellipse = gtk_plot_cairo_draw_ellipse;
220
pc_class->set_font = gtk_plot_cairo_set_font;
221
pc_class->draw_string = gtk_plot_cairo_draw_string;
222
pc_class->draw_pixmap = gtk_plot_cairo_draw_pixmap;
226
* gtk_plot_cairo_new:
234
gtk_plot_cairo_new (cairo_t *cairo)
238
object = g_object_new(gtk_plot_cairo_get_type(), NULL);
239
gtk_plot_cairo_construct(GTK_PLOT_CAIRO(object), cairo, NULL);
240
GTK_PLOT_CAIRO(object)->destroy_cairo = FALSE;
246
* gtk_plot_cairo_new_with_drawable:
254
gtk_plot_cairo_new_with_drawable (GdkDrawable *drawable)
257
cairo_t *cairo = NULL;
259
object = g_object_new(gtk_plot_cairo_get_type(), NULL);
260
if(drawable) cairo = gdk_cairo_create(drawable);
261
gtk_plot_cairo_construct(GTK_PLOT_CAIRO(object), cairo, NULL);
262
GTK_PLOT_CAIRO(object)->destroy_cairo = TRUE;
268
* gtk_plot_cairo_construct:
269
* @pc: A #GtkPlotCairo.
276
gtk_plot_cairo_construct(GtkPlotCairo *pc,
278
PangoContext *context)
281
gtk_plot_cairo_set_cairo(pc, cairo);
283
pc->context = context;
287
g_object_ref(G_OBJECT(pc->context));
291
g_object_ref(G_OBJECT(pc->layout));
295
if(pc->cairo) pc->layout = pango_cairo_create_layout(cairo);
301
gtk_plot_cairo_finalize (GObject *object)
303
GtkPlotCairo *pc = GTK_PLOT_CAIRO(object);
305
if(pc->destroy_cairo && pc->cairo) cairo_destroy(pc->cairo);
306
GTK_PLOT_CAIRO(object)->cairo = NULL;
309
g_object_unref(G_OBJECT(pc->layout));
313
g_object_unref(G_OBJECT(pc->context));
318
gtk_plot_cairo_real_init (GtkPlotPC *pc)
324
gtk_plot_cairo_leave (GtkPlotPC *pc)
329
* gtk_plot_cairo_set_cairo:
330
* @pc: a #GtkPlotCairo
336
gtk_plot_cairo_set_cairo(GtkPlotCairo *pc,
339
if(pc->destroy_cairo && pc->cairo && cairo) cairo_destroy(pc->cairo);
344
gtk_plot_cairo_set_viewport (GtkPlotPC *pc, gdouble w, gdouble h)
349
gtk_plot_cairo_gsave (GtkPlotPC *pc)
351
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
358
gtk_plot_cairo_grestore (GtkPlotPC *pc)
360
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
363
cairo_restore(cairo);
367
gtk_plot_cairo_clip (GtkPlotPC *pc,
368
const GdkRectangle *area)
370
/* discard CairoRectangle* const:
371
* cairo_gc_set_clip_rectangle should have a const arg.
372
* I've checked the code and it doesn't change it or keep it. murrayc.
374
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
377
cairo_reset_clip(cairo);
378
cairo_new_path(cairo);
380
cairo_move_to(cairo, area->x, area->y);
381
cairo_line_to(cairo, area->x+area->width, area->y);
382
cairo_line_to(cairo, area->x+area->width, area->y+area->height);
383
cairo_line_to(cairo, area->x, area->y+area->height);
384
cairo_close_path(cairo);
390
gtk_plot_cairo_clip_mask (GtkPlotPC *pc,
393
const GdkBitmap *mask)
395
/* TBD: Currently no support for clip mask */
400
gtk_plot_cairo_set_color (GtkPlotPC *pc,
401
const GdkColor *color)
403
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
406
cairo_set_source_rgba(cairo,
407
1.0/65535 * color->red,
408
1.0/65535 * color->green,
409
1.0/65535 * color->blue,
410
1.0); // TBD fix alpha
414
gtk_plot_cairo_set_dash (GtkPlotPC *pc,
419
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
422
gchar list[] = {'\0','\1','\2','\3','\4','\5','\6','\7'};
431
for(i = 0; i < num_values; i++){
434
dash[i] = list[value];
437
cairo_set_dash(cairo, dash, num_values, 0);
440
static void gtk_plot_cairo_set_lineattr (GtkPlotPC *pc,
442
GdkLineStyle line_style,
443
GdkCapStyle cap_style,
444
GdkJoinStyle join_style)
446
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
450
if (line_style == GDK_LINE_SOLID)
451
cairo_set_dash(cairo,
455
line_width = 0.5; // What should be the minimum line width?
456
cairo_set_line_width(cairo,
459
if(cap_style == GDK_CAP_NOT_LAST || cap_style == GDK_CAP_PROJECTING)
460
cairo_set_line_cap(cairo, CAIRO_LINE_CAP_SQUARE);
461
if(cap_style == GDK_CAP_BUTT) cairo_set_line_cap(cairo, CAIRO_LINE_CAP_BUTT);
462
if(cap_style == GDK_CAP_ROUND) cairo_set_line_cap(cairo, CAIRO_LINE_CAP_ROUND);
464
cairo_set_line_join(cairo,
465
(cairo_line_join_t)join_style);
469
gtk_plot_cairo_draw_point (GtkPlotPC *pc,
470
gdouble x, gdouble y)
472
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
475
/* Move and draw to same point, like in the postscript backend */
476
cairo_move_to(cairo, x,y);
477
cairo_line_to(cairo, x,y);
482
gtk_plot_cairo_draw_line (GtkPlotPC *pc,
483
gdouble x1, gdouble y1,
484
gdouble x2, gdouble y2)
486
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
489
cairo_move_to(cairo, x1,y1);
490
cairo_line_to(cairo, x2,y2);
495
gtk_plot_cairo_draw_lines (GtkPlotPC *pc,
496
GtkPlotPoint *points,
500
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
504
cairo_move_to(cairo, points[0].x,points[0].y);
505
for(i = 1; i < numpoints; i++){
506
cairo_line_to(cairo, points[i].x, points[i].y);
512
gtk_plot_cairo_draw_rectangle (GtkPlotPC *pc,
514
gdouble x, gdouble y,
515
gdouble width, gdouble height)
517
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
521
cairo_move_to(cairo, x, y);
522
cairo_line_to(cairo, x+width, y);
523
cairo_line_to(cairo, x+width, y+height);
524
cairo_line_to(cairo, x, y+height);
525
cairo_close_path(cairo);
533
gtk_plot_cairo_draw_polygon (GtkPlotPC *pc,
535
GtkPlotPoint *points,
539
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
543
cairo_move_to(cairo, points[0].x,points[0].y);
544
for(i = 1; i < numpoints; i++)
545
cairo_line_to(cairo, points[i].x, points[i].y);
546
cairo_close_path(cairo);
554
gtk_plot_cairo_draw_circle (GtkPlotPC *pc,
556
gdouble x, gdouble y,
559
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
563
cairo_arc (cairo, x, y, size/2, 0., 2 * M_PI);
571
gtk_plot_cairo_draw_ellipse (GtkPlotPC *pc,
573
gdouble x, gdouble y,
574
gdouble width, gdouble height)
576
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
581
cairo_translate(cairo, x+width/2.0,y+height/2.0);
582
cairo_scale (cairo, 1. / (height / 2.), 1. / (width / 2.));
583
cairo_arc (cairo, 0., 0., 1., 0., 2 * M_PI);
584
cairo_restore(cairo);
593
gtk_plot_cairo_set_font (GtkPlotPC *pc,
599
/* subfunction of gtk_plot_cairo_draw_string(). */
601
drawstring(GtkPlotPC *pc,
604
GtkPSFont *psfont, gint height,
607
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
608
PangoLayout *layout = GTK_PLOT_CAIRO(pc)->layout;
609
PangoFontDescription *font;
613
gint dpi_cairo, dpi_screen;
614
GdkScreen *screen = gdk_screen_get_default();
616
if(!text || strlen(text) == 0) return 0;
619
map = pango_cairo_font_map_get_default();
620
dpi_cairo = pango_cairo_font_map_get_resolution(PANGO_CAIRO_FONT_MAP(map));
621
dpi_screen = gdk_screen_get_resolution(screen);
622
if (dpi_screen != -1)
623
height *= (double)dpi_screen/(double)dpi_cairo;
624
font = gtk_psfont_get_font_description(psfont, height);
625
pango_layout_set_font_description(GTK_PLOT_CAIRO(pc)->layout, font);
626
pango_layout_set_text(GTK_PLOT_CAIRO(pc)->layout, text, strlen(text));
627
pango_layout_get_extents(GTK_PLOT_CAIRO(pc)->layout, NULL, &rect);
629
if (psfont->i18n_latinfamily && psfont->vertical) {
630
/* vertical-writing CJK postscript fonts. */
635
/* horizontal writing */
637
// cairo_translate(cairo, dx, dy-PANGO_PIXELS(rect.width));
638
cairo_translate(cairo, dx, dy);
639
else if(angle == 270)
640
cairo_translate(cairo, dx+PANGO_PIXELS(rect.height), dy);
641
else if(angle == 180)
642
cairo_translate(cairo, dx-PANGO_PIXELS(rect.width), dy);
644
cairo_translate(cairo, dx, dy);
646
cairo_rotate(cairo, -angle * G_PI / 180);
647
pango_cairo_update_layout(cairo, layout);
648
pango_cairo_show_layout(cairo, layout);
649
cairo_restore(cairo);
650
pango_font_description_free(font);
651
ret_value = (angle == 0 || angle == 180) ? rect.width : rect.height;
652
return PANGO_PIXELS(rect.width);
656
gtk_plot_cairo_draw_string (GtkPlotPC *pc,
661
gboolean transparent,
666
const gchar *font_name,
668
GtkJustification just,
671
cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
672
GList *family = NULL;
674
gint old_width, old_height;
675
gboolean bold, italic;
677
gint ascent, descent;
682
PangoFontDescription *font = NULL, *latin_font = NULL;
683
GtkPSFont *psfont, *base_psfont, *latin_psfont;
684
gchar subs[2], insert_char;
685
const gchar *aux = text;
686
const gchar *lastchar = text;
687
const gchar *wtext = text;
688
const gchar *xaux = text;
689
gchar *new_text; /* Support Tiny C compiler : Original : gchar new_text[strlen(text)+1];*/
692
PangoLayout *layout = NULL;
693
gint real_x, real_y, real_width, real_height;
694
GdkColor real_fg = *fg;
695
GdkColor real_bg = *bg;
696
gint sign_x = 1, sign_y = 0;
697
gint old_tx = tx, old_ty = ty;
702
layout = GTK_PLOT_CAIRO(pc)->layout;
704
gtk_plot_cairo_set_color(pc, fg);
707
desc = pango_font_description_from_string(font_name);
709
// Since the name does not contain the size yet... Also there is some
710
// factor that I have to figure out...
711
pango_font_description_set_size (desc, font_height *0.9 * PANGO_SCALE);
713
pango_layout_set_font_description(layout, desc);
714
pango_layout_set_text(layout, text, -1);
716
cairo_translate(cairo, tx, ty);
717
cairo_rotate(cairo, angle * G_PI / 180);
718
gtk_plot_cairo_set_color(pc, fg);
719
pango_cairo_update_layout(cairo, layout);
720
PangoFontMetrics *metrics = NULL;
722
metrics = pango_context_get_metrics(pango_layout_get_context(layout), desc, gtk_get_default_language());
724
pango_layout_get_size (layout, &width, &height);
726
ascent = pango_font_metrics_get_ascent(metrics);
727
descent = pango_font_metrics_get_descent(metrics);
729
if (just == GTK_JUSTIFY_RIGHT)
730
cairo_move_to(cairo, -PANGO_PIXELS(width),
731
-PANGO_PIXELS(ascent)
733
else if (just == GTK_JUSTIFY_CENTER)
734
cairo_move_to(cairo, -PANGO_PIXELS(width)/2.0,
735
-PANGO_PIXELS(ascent)
737
else if (just == GTK_JUSTIFY_LEFT)
738
cairo_move_to(cairo, 0,
739
-PANGO_PIXELS(ascent)
742
pango_cairo_show_layout(cairo, layout);
743
cairo_restore(cairo);
747
gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent);
749
if(height == 0 || width == 0) return;
753
if(angle == 90 || angle == 270)
779
case GTK_JUSTIFY_LEFT:
799
case GTK_JUSTIFY_RIGHT:
824
case GTK_JUSTIFY_CENTER:
830
old_tx -= width / 2.;
837
old_ty -= height / 2.;
842
old_tx -= width / 2.;
849
old_ty -= height / 2.;
857
real_height = height;
860
gtk_plot_cairo_set_color(pc, &real_bg);
861
gtk_plot_cairo_draw_rectangle(pc, TRUE, old_tx, old_ty, old_width, old_height);
863
gtk_psfont_get_families(&family, &numf);
864
base_psfont = psfont = gtk_psfont_get_by_name(font_name);
865
font = gtk_psfont_get_font_description(psfont, font_height);
866
italic = psfont->italic;
868
fontsize = font_height;
872
if (psfont->i18n_latinfamily) {
873
latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic,
875
if(latin_font) pango_font_description_free(latin_font);
876
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
882
gtk_plot_cairo_set_color(pc, &real_fg);
884
while(aux && *aux != '\0' && *aux != '\n'){
886
aux = g_utf8_next_char(aux);
888
case '0': case '1': case '2': case '3':
889
case '4': case '5': case '6': case '7': case '9':
890
psfont = gtk_psfont_get_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold);
891
pango_font_description_free(font);
892
font = gtk_psfont_get_font_description(psfont, fontsize);
893
aux = g_utf8_next_char(aux);
896
psfont = gtk_psfont_get_by_family("Symbol", italic, bold);
897
pango_font_description_free(font);
898
font = gtk_psfont_get_font_description(psfont, fontsize);
899
aux = g_utf8_next_char(aux);
903
psfont = gtk_psfont_get_by_family(psfont->family, italic, bold);
904
pango_font_description_free(font);
905
font = gtk_psfont_get_font_description(psfont, fontsize);
909
if (psfont->i18n_latinfamily) {
910
latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
912
if(latin_font) pango_font_description_free(latin_font);
913
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
915
aux = g_utf8_next_char(aux);
920
if (xaux[i] >= '0' && xaux[i] <= '9')
926
aux = g_utf8_next_char(aux);
930
insert_char = (gchar)atoi(num);
931
subs[0] = insert_char;
933
pango_layout_set_font_description(layout, font);
934
pango_layout_set_text(layout, subs, 1);
935
pango_layout_get_extents(layout, NULL, &rect);
936
x += sign_x*PANGO_PIXELS(rect.width);
937
y += sign_y*PANGO_PIXELS(rect.width);
943
psfont = gtk_psfont_get_by_family(psfont->family, italic, bold);
944
pango_font_description_free(font);
945
font = gtk_psfont_get_font_description(psfont, fontsize);
946
if (psfont->i18n_latinfamily) {
947
latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
949
if(latin_font) pango_font_description_free(latin_font);
950
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
952
aux = g_utf8_next_char(aux);
955
fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
956
pango_font_description_free(font);
957
font = gtk_psfont_get_font_description(psfont, fontsize);
958
if (psfont->i18n_latinfamily) {
959
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
963
else if(angle == 270)
964
x = x0 + sign_y*fontsize;
965
aux = g_utf8_next_char(aux);
968
fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
969
pango_font_description_free(font);
970
font = gtk_psfont_get_font_description(psfont, fontsize);
974
x = x0 - sign_y*fontsize;
975
if (psfont->i18n_latinfamily) {
976
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
978
aux = g_utf8_next_char(aux);
984
pango_font_description_free(font);
985
font = gtk_psfont_get_font_description(psfont, fontsize);
986
if (psfont->i18n_latinfamily) {
987
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
989
aux = g_utf8_next_char(aux);
995
pango_font_description_free(font);
996
font = gtk_psfont_get_font_description(psfont, fontsize);
997
if (psfont->i18n_latinfamily) {
998
latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
1000
aux = g_utf8_next_char(aux);
1003
psfont = base_psfont;
1004
fontsize = font_height;
1005
pango_font_description_free(font);
1006
font = gtk_psfont_get_font_description(psfont, fontsize);
1007
if(angle == 0 || angle == 180)
1011
italic = psfont->italic;
1012
bold = psfont->bold;
1013
aux = g_utf8_next_char(aux);
1017
const gchar *aux2 = lastchar;
1018
gint i = aux2 - g_utf8_prev_char(lastchar);
1019
pango_layout_set_text(layout, lastchar, i);
1020
pango_layout_get_extents(layout, NULL, &rect);
1021
x -= sign_x*PANGO_PIXELS(rect.width);
1022
y -= sign_y*PANGO_PIXELS(rect.width);
1024
if (lastchar == wtext)
1027
lastchar = g_utf8_prev_char(lastchar);
1029
pango_layout_set_text(layout, "X", 1);
1030
pango_layout_get_extents(layout, NULL, &rect);
1031
x -= sign_x*PANGO_PIXELS(rect.width);
1032
y -= sign_y*PANGO_PIXELS(rect.width);
1034
aux = g_utf8_next_char(aux);
1037
if(aux && *aux != '\0' && *aux !='\n'){
1039
new_width = drawstring(pc, angle, tx+x, ty+y,
1040
psfont, fontsize, aux);
1041
x += sign_x * new_width;
1042
y += sign_y * new_width;
1044
aux = g_utf8_next_char(aux);
1052
while(aux && *aux != '\0' && *aux !='\n' && *aux != '\\'){
1054
new_len += g_utf8_next_char(aux) - xaux;
1056
aux = g_utf8_next_char(aux);
1060
new_text = (gchar *) g_new0(gchar , strlen(text)+1); /* Tiny C Compiler support */
1061
for(i = 0; i < new_len; i++) new_text[i] = *xaux++;
1062
new_text[new_len] = '\0';
1063
new_width = drawstring(pc, angle, tx+x, ty+y,
1064
psfont, fontsize, new_text);
1065
x += sign_x * new_width;
1066
y += sign_y * new_width;
1073
if(latin_font) pango_font_description_free(latin_font);
1077
gtk_plot_cairo_set_color(pc, &real_fg);
1078
gtk_plot_pc_set_dash(pc, 0, NULL, 0);
1079
gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0);
1081
case GTK_PLOT_BORDER_SHADOW:
1082
gtk_plot_pc_draw_rectangle(pc,
1084
old_tx - border_space + shadow_width,
1085
old_ty + height + border_space,
1086
width + 2 * border_space, shadow_width);
1087
gtk_plot_pc_draw_rectangle(pc,
1089
old_tx + width + border_space,
1090
old_ty - border_space + shadow_width,
1091
shadow_width, height + 2 * border_space);
1092
case GTK_PLOT_BORDER_LINE:
1093
gtk_plot_pc_draw_rectangle(pc,
1095
old_tx - border_space, old_ty - border_space,
1096
width + 2*border_space, height + 2*border_space);
1097
case GTK_PLOT_BORDER_NONE:
1102
cairo_restore(cairo);
1106
static void gtk_plot_cairo_draw_pixmap (GtkPlotPC *pc,
1109
gint xsrc, gint ysrc,
1110
gint xdest, gint ydest,
1111
gint width, gint height,
1115
if (!GTK_PLOT_CAIRO(pc)->cairo)
1118
cairo_surface_t *image_surface = NULL;
1119
cairo_surface_t *mask_surface = NULL;
1121
/* TODO: USE MASK */
1123
image_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
1124
cr = cairo_create(image_surface);
1125
cairo_scale(cr,scale_x,scale_y);
1126
gdk_cairo_set_source_pixmap(cr,pixmap,xsrc,ysrc);
1131
mask_surface = cairo_image_surface_create(CAIRO_CONTENT_COLOR_ALPHA, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
1132
cr = cairo_create(image_surface);
1133
cairo_scale(cr,scale_x,scale_y);
1134
gdk_cairo_set_source_pixmap(cr,mask,xsrc,ysrc);
1139
mask_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, (width-xsrc)*scale_x, (height-ysrc)*scale_y);
1140
cr = cairo_create(mask_surface);
1141
cairo_set_source_rgb(cr,0,0,0);
1142
cairo_scale(cr,scale_x,scale_y);
1143
gdk_cairo_set_source_pixmap(cr,pixmap,xsrc,ysrc);
1144
cairo_mask_surface(cr,mask_surface,0,0);
1149
cairo_save(GTK_PLOT_CAIRO(pc)->cairo);
1151
cairo_rectangle(GTK_PLOT_CAIRO(pc)->cairo,xdest,ydest,(width-xsrc)*scale_x,(height-ysrc)*scale_y);
1152
cairo_clip(GTK_PLOT_CAIRO(pc)->cairo);
1155
if(mask) cairo_mask_surface(GTK_PLOT_CAIRO(pc)->cairo,mask_surface,xdest,ydest);
1157
cairo_set_source_surface(GTK_PLOT_CAIRO(pc)->cairo,image_surface,xdest,ydest);
1158
cairo_paint(GTK_PLOT_CAIRO(pc)->cairo);
1160
cairo_restore(GTK_PLOT_CAIRO(pc)->cairo);
1161
cairo_surface_destroy(image_surface);
1162
cairo_surface_destroy(mask_surface);