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.
29
#include "gtkplotpc.h"
30
#include "gtkplotgdk.h"
32
#include "gtkpsfont.h"
33
#include "gtkplotcanvas.h"
35
static void gtk_plot_gdk_init (GtkPlotGdk *pc);
36
static void gtk_plot_gdk_class_init (GtkPlotGdkClass *klass);
37
static void gtk_plot_gdk_finalize (GObject *object);
38
static void gtk_plot_gdk_real_set_drawable (GtkPlotGdk *gdk,
39
GdkDrawable *drawable);
40
static gboolean gtk_plot_gdk_real_init (GtkPlotPC *pc);
41
static void gtk_plot_gdk_set_viewport (GtkPlotPC *pc,
42
gdouble w, gdouble h);
43
static void gtk_plot_gdk_leave (GtkPlotPC *pc);
44
static void gtk_plot_gdk_gsave (GtkPlotPC *pc);
45
static void gtk_plot_gdk_grestore (GtkPlotPC *pc);
46
static void gtk_plot_gdk_clip (GtkPlotPC *pc,
47
const GdkRectangle *area);
48
static void gtk_plot_gdk_clip_mask (GtkPlotPC *pc,
51
const GdkBitmap *mask);
52
static void gtk_plot_gdk_set_color (GtkPlotPC *pc,
53
const GdkColor *color);
54
static void gtk_plot_gdk_set_lineattr (GtkPlotPC *pc,
56
GdkLineStyle line_style,
57
GdkCapStyle cap_style,
58
GdkJoinStyle join_style);
59
static void gtk_plot_gdk_set_dash (GtkPlotPC *pc,
63
static void gtk_plot_gdk_draw_point (GtkPlotPC *pc,
64
gdouble x, gdouble y);
65
static void gtk_plot_gdk_draw_line (GtkPlotPC *pc,
66
gdouble x1, gdouble y1,
67
gdouble x2, gdouble y2);
68
static void gtk_plot_gdk_draw_lines (GtkPlotPC *pc,
71
static void gtk_plot_gdk_draw_rectangle (GtkPlotPC *pc,
76
static void gtk_plot_gdk_draw_polygon (GtkPlotPC *pc,
80
static void gtk_plot_gdk_draw_circle (GtkPlotPC *pc,
84
static void gtk_plot_gdk_draw_ellipse (GtkPlotPC *pc,
89
static void gtk_plot_gdk_set_font (GtkPlotPC *pc,
92
static void gtk_plot_gdk_draw_string (GtkPlotPC *pc,
104
GtkJustification just,
106
static void gtk_plot_gdk_draw_pixmap (GtkPlotPC *pc,
109
gint xsrc, gint ysrc,
110
gint xdest, gint ydest,
111
gint width, gint height,
115
static GdkPixmap * scale_pixmap (GdkWindow *window,
119
static GdkBitmap * scale_bitmap (GdkWindow *window,
124
static gint roundint (gdouble x);
126
static GtkPlotPCClass *parent_class = NULL;
129
gtk_plot_gdk_get_type (void)
131
static GtkType pc_type = 0;
135
GtkTypeInfo pc_info =
139
sizeof (GtkPlotGdkClass),
140
(GtkClassInitFunc) gtk_plot_gdk_class_init,
141
(GtkObjectInitFunc) gtk_plot_gdk_init,
142
/* reserved 1*/ NULL,
143
/* reserved 2 */ NULL,
144
(GtkClassInitFunc) NULL,
147
pc_type = gtk_type_unique (GTK_TYPE_PLOT_PC, &pc_info);
153
gtk_plot_gdk_init (GtkPlotGdk *pc)
155
GdkWindowAttr attributes;
156
gint attributes_mask;
158
attributes.window_type = GDK_WINDOW_CHILD;
159
attributes.title = NULL;
160
attributes.wclass = GDK_INPUT_OUTPUT;
161
attributes.visual = gdk_visual_get_system ();
162
attributes.colormap = gdk_colormap_get_system ();
163
attributes.event_mask = 0;
164
attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
170
pc->window = gdk_window_new (NULL, &attributes, attributes_mask);
175
gtk_plot_gdk_class_init (GtkPlotGdkClass *klass)
177
GtkObjectClass *object_class;
178
GObjectClass *gobject_class;
179
GtkPlotPCClass *pc_class;
180
GtkPlotGdkClass *gdk_class;
182
parent_class = gtk_type_class (gtk_plot_pc_get_type ());
184
object_class = (GtkObjectClass *) klass;
185
gobject_class = (GObjectClass *) klass;
187
pc_class = (GtkPlotPCClass *) klass;
188
gdk_class = (GtkPlotGdkClass *) klass;
190
gobject_class->finalize = gtk_plot_gdk_finalize;
192
gdk_class->set_drawable = gtk_plot_gdk_real_set_drawable;
194
pc_class->init = gtk_plot_gdk_real_init;
195
pc_class->leave = gtk_plot_gdk_leave;
196
pc_class->set_viewport = gtk_plot_gdk_set_viewport;
197
pc_class->gsave = gtk_plot_gdk_gsave;
198
pc_class->grestore = gtk_plot_gdk_grestore;
199
pc_class->clip = gtk_plot_gdk_clip;
200
pc_class->clip_mask = gtk_plot_gdk_clip_mask;
201
pc_class->set_color = gtk_plot_gdk_set_color;
202
pc_class->set_dash = gtk_plot_gdk_set_dash;
203
pc_class->set_lineattr = gtk_plot_gdk_set_lineattr;
204
pc_class->draw_point = gtk_plot_gdk_draw_point;
205
pc_class->draw_line = gtk_plot_gdk_draw_line;
206
pc_class->draw_lines = gtk_plot_gdk_draw_lines;
207
pc_class->draw_rectangle = gtk_plot_gdk_draw_rectangle;
208
pc_class->draw_polygon = gtk_plot_gdk_draw_polygon;
209
pc_class->draw_circle = gtk_plot_gdk_draw_circle;
210
pc_class->draw_ellipse = gtk_plot_gdk_draw_ellipse;
211
pc_class->set_font = gtk_plot_gdk_set_font;
212
pc_class->draw_string = gtk_plot_gdk_draw_string;
213
pc_class->draw_pixmap = gtk_plot_gdk_draw_pixmap;
218
gtk_plot_gdk_new (GdkDrawable *drawable)
222
object = gtk_type_new(gtk_plot_gdk_get_type());
224
gtk_plot_gdk_construct(GTK_PLOT_GDK(object), drawable);
230
gtk_plot_gdk_construct(GtkPlotGdk *pc, GdkDrawable *drawable)
233
gtk_plot_gdk_set_drawable(GTK_PLOT_GDK(pc), drawable);
234
gtk_plot_pc_gsave(GTK_PLOT_PC(pc));
240
gtk_plot_gdk_finalize (GObject *object)
242
gdk_window_destroy(GTK_PLOT_GDK(object)->window);
243
GTK_PLOT_GDK(object)->window = NULL;
245
if(GTK_PLOT_GDK(object)->ref_count > 0 && GTK_PLOT_GDK(object)->gc){
246
gdk_gc_destroy(GTK_PLOT_GDK(object)->gc);
247
GTK_PLOT_GDK(object)->gc = NULL;
250
// G_OBJECT_CLASS(parent_class)->finalize(object);
254
gtk_plot_gdk_real_set_drawable(GtkPlotGdk *pc, GdkDrawable *drawable)
256
pc->drawable = drawable;
260
gtk_plot_gdk_real_init (GtkPlotPC *pc)
266
gtk_plot_gdk_leave (GtkPlotPC *pc)
271
gtk_plot_gdk_set_drawable (GtkPlotGdk *gdk, GdkDrawable *drawable)
273
GTK_PLOT_GDK_CLASS(GTK_OBJECT_GET_CLASS(GTK_OBJECT(gdk)))->set_drawable(gdk, drawable);
277
gtk_plot_gdk_set_viewport (GtkPlotPC *pc, gdouble w, gdouble h)
282
gtk_plot_gdk_gsave (GtkPlotPC *pc)
284
if(GTK_PLOT_GDK(pc)->gc)
285
gdk_gc_ref(GTK_PLOT_GDK(pc)->gc);
287
GTK_PLOT_GDK(pc)->gc = gdk_gc_new(GTK_PLOT_GDK(pc)->window);
290
GTK_PLOT_GDK(pc)->ref_count++;
294
gtk_plot_gdk_grestore (GtkPlotPC *pc)
296
if(GTK_PLOT_GDK(pc)->gc) gdk_gc_unref(GTK_PLOT_GDK(pc)->gc);
298
GTK_PLOT_GDK(pc)->ref_count--;
299
if(GTK_PLOT_GDK(pc)->ref_count == 0) GTK_PLOT_GDK(pc)->gc = NULL;
303
gtk_plot_gdk_clip (GtkPlotPC *pc,
304
const GdkRectangle *area)
306
if(!GTK_PLOT_GDK(pc)->gc) return;
308
/* discard GdkRectangle* const:
309
* gdk_gc_set_clip_rectangle should have a const arg.
310
* I've checked the code and it doesn't change it or keep it. murrayc.
313
gdk_gc_set_clip_rectangle(GTK_PLOT_GDK(pc)->gc, (GdkRectangle*)area);
317
gtk_plot_gdk_clip_mask (GtkPlotPC *pc,
320
const GdkBitmap *mask)
322
if(!GTK_PLOT_GDK(pc)->gc) return;
325
gdk_gc_set_clip_origin(GTK_PLOT_GDK(pc)->gc, x, y);
327
gdk_gc_set_clip_mask(GTK_PLOT_GDK(pc)->gc, (GdkBitmap*)mask);
331
gtk_plot_gdk_set_color (GtkPlotPC *pc,
332
const GdkColor *color)
336
if(!GTK_PLOT_GDK(pc)->gc) return;
339
gdk_color_alloc(gdk_colormap_get_system(), &new_color);
340
gdk_gc_set_foreground(GTK_PLOT_GDK(pc)->gc, &new_color);
344
gtk_plot_gdk_set_dash (GtkPlotPC *pc,
349
gchar list[] = {'\0','\1','\2','\3','\4','\5','\6','\7'};
350
gchar dash[1000] = "";
353
if(!GTK_PLOT_GDK(pc)->gc) return;
359
for(i = 0; i < num_values; i++){
362
dash[i] = list[value];
365
gdk_gc_set_dashes(GTK_PLOT_GDK(pc)->gc, 0, dash, num_values);
368
static void gtk_plot_gdk_set_lineattr (GtkPlotPC *pc,
370
GdkLineStyle line_style,
371
GdkCapStyle cap_style,
372
GdkJoinStyle join_style)
374
if(!GTK_PLOT_GDK(pc)->gc) return;
376
gdk_gc_set_line_attributes(GTK_PLOT_GDK(pc)->gc,
377
roundint(line_width),
384
gtk_plot_gdk_draw_point (GtkPlotPC *pc,
385
gdouble x, gdouble y)
387
if(!GTK_PLOT_GDK(pc)->gc) return;
388
if(!GTK_PLOT_GDK(pc)->drawable) return;
390
gdk_draw_point(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
391
roundint(x), roundint(y));
395
gtk_plot_gdk_draw_line (GtkPlotPC *pc,
396
gdouble x1, gdouble y1,
397
gdouble x2, gdouble y2)
399
if(!GTK_PLOT_GDK(pc)->gc) return;
400
if(!GTK_PLOT_GDK(pc)->drawable) return;
402
gdk_draw_line(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
403
roundint(x1), roundint(y1), roundint(x2), roundint(y2));
407
gtk_plot_gdk_draw_lines (GtkPlotPC *pc,
408
GtkPlotPoint *points,
414
if(!GTK_PLOT_GDK(pc)->gc) return;
415
if(!GTK_PLOT_GDK(pc)->drawable) return;
417
p = (GdkPoint *)g_malloc(numpoints * sizeof(GdkPoint));
418
for(i = 0; i < numpoints; i++){
419
p[i].x = roundint(points[i].x);
420
p[i].y = roundint(points[i].y);
423
gdk_draw_lines(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc, p, numpoints);
429
gtk_plot_gdk_draw_rectangle (GtkPlotPC *pc,
431
gdouble x, gdouble y,
432
gdouble width, gdouble height)
434
if(!GTK_PLOT_GDK(pc)->gc) return;
435
if(!GTK_PLOT_GDK(pc)->drawable) return;
437
gdk_draw_rectangle (GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
439
roundint(x), roundint(y),
440
roundint(width), roundint(height));
445
gtk_plot_gdk_draw_polygon (GtkPlotPC *pc,
447
GtkPlotPoint *points,
453
if(!GTK_PLOT_GDK(pc)->gc) return;
454
if(!GTK_PLOT_GDK(pc)->drawable) return;
456
p = (GdkPoint *)g_malloc(numpoints * sizeof(GdkPoint));
457
for(i = 0; i < numpoints; i++){
458
p[i].x = roundint(points[i].x);
459
p[i].y = roundint(points[i].y);
462
gdk_draw_polygon(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
463
filled, p, numpoints);
469
gtk_plot_gdk_draw_circle (GtkPlotPC *pc,
471
gdouble x, gdouble y,
474
if(!GTK_PLOT_GDK(pc)->gc) return;
475
if(!GTK_PLOT_GDK(pc)->drawable) return;
477
gdk_draw_arc (GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
479
roundint(x-size/2.0), roundint(y-size/2.0),
480
roundint(size), roundint(size), 0, 25000);
485
gtk_plot_gdk_draw_ellipse (GtkPlotPC *pc,
487
gdouble x, gdouble y,
488
gdouble width, gdouble height)
490
if(!GTK_PLOT_GDK(pc)->gc) return;
491
if(!GTK_PLOT_GDK(pc)->drawable) return;
493
gdk_draw_arc (GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
495
roundint(x), roundint(y),
496
roundint(width), roundint(height), 0, 25000);
500
gtk_plot_gdk_set_font (GtkPlotPC *pc,
507
/* subfunction of gtk_plot_gdk_draw_string(). */
509
drawstring(GtkPlotPC *pc,
513
GtkPSFont *psfont, gint height,
520
gint w, h, a, d, x, y, d2;
523
font = gtk_psfont_get_gdkfont(psfont, height);
525
if (psfont->i18n_latinfamily && psfont->vertical && (0 > wc || wc > 0x7f)) {
526
/* vertical-writing CJK postscript fonts. */
528
w = gdk_char_width_wc(font, wc);
534
tmp = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, w, h, 1);
536
mask_color.pixel = 0;
537
gdk_gc_set_foreground(gc, &mask_color);
538
gdk_draw_rectangle(tmp, gc, TRUE, 0, 0, -1, -1);
539
mask_color.pixel = 1;
540
gdk_gc_set_foreground(gc, &mask_color);
542
gdk_draw_text_wc(tmp, font, gc, 0, a, &wc, 1);
544
image = gdk_image_get(tmp, 0, 0, w, h);
546
for (y = 0; y < h; y++) {
547
for (x = 0; x < w; x++) {
548
pixel = gdk_image_get_pixel(image, x, y);
550
gdk_draw_point(dest, gc, dx + y, dy + d2 - x);
554
gdk_image_destroy(image);
555
gdk_pixmap_unref(tmp);
556
gdk_font_unref(font);
560
/* horizontal writing */
562
gdk_draw_text_wc(dest, font, gc, dx, dy, &wc, 1);
563
w = gdk_char_width_wc(font, wc);
564
gdk_font_unref(font);
571
gtk_plot_gdk_draw_string (GtkPlotPC *pc,
576
gboolean transparent,
581
const gchar *font_name,
583
GtkJustification just,
586
GdkBitmap *text_bitmap;
587
GdkPixmap *text_pixmap;
588
GdkBitmap *text_mask;
590
GdkGC *gc, *bitmap_gc;
591
GdkColormap *colormap;
593
GList *family = NULL;
595
gint old_width, old_height;
596
gboolean bold, italic;
598
gint ascent, descent, w;
604
GdkFont *font = NULL, *latin_font = NULL;
605
GtkPSFont *psfont, *base_psfont, *latin_psfont;
606
gchar subs[2], insert_char;
607
GdkWChar *aux, *wtext, *lastchar = NULL, *xaux;
610
if(!GTK_PLOT_GDK(pc)->drawable) return;
611
if(!GTK_PLOT_GDK(pc)->window) return;
612
if(!GTK_PLOT_GDK(pc)->gc) return;
613
if(!text || strlen(text) == 0) return;
615
colormap = gdk_colormap_get_system ();
616
gc = GTK_PLOT_GDK(pc)->gc;
620
gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent);
622
if(height == 0 || width == 0) return;
626
if(angle == 90 || angle == 270)
632
gtk_psfont_get_families(&family, &numf);
633
base_psfont = psfont = gtk_psfont_get_by_name(font_name);
634
font = gtk_psfont_get_gdkfont(psfont, font_height);
635
italic = psfont->italic;
637
fontsize = font_height;
641
if (psfont->i18n_latinfamily) {
642
latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic,
644
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
650
i = strlen(text) + 2;
651
aux = wtext = g_malloc0(sizeof(GdkWChar) * i);
652
gdk_mbstowcs(wtext, text, i - 1);
654
/* initializing text bitmap - ajd */
655
text_bitmap = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window,
656
old_width, old_height, 1);
657
bitmap_gc = gdk_gc_new(text_bitmap);
658
mask_color.pixel = 0;
659
gdk_gc_set_foreground(bitmap_gc, &mask_color);
660
gdk_draw_rectangle(text_bitmap, bitmap_gc, TRUE,
662
mask_color.pixel = 1;
663
gdk_gc_set_foreground(bitmap_gc, &mask_color);
665
while(aux && *aux != '\0' && *aux != '\n'){
669
case '0': case '1': case '2': case '3':
670
case '4': case '5': case '6': case '7': case '9':
671
psfont = gtk_psfont_get_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold);
672
gdk_font_unref(font);
673
font = gtk_psfont_get_gdkfont(psfont, fontsize);
677
psfont = gtk_psfont_get_by_family("Symbol", italic, bold);
678
gdk_font_unref(font);
679
font = gtk_psfont_get_gdkfont(psfont, fontsize);
684
gdk_font_unref(font);
685
psfont = gtk_psfont_get_by_family(psfont->family, italic, bold);
686
font = gtk_psfont_get_gdkfont(psfont, fontsize);
688
gdk_font_unref(latin_font);
691
if (psfont->i18n_latinfamily) {
692
latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
694
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
701
if (xaux[i] >= '0' && xaux[i] <= '9')
711
insert_char = (gchar)atoi(num);
712
subs[0] = insert_char;
714
x += gdk_char_width(font, insert_char);
720
psfont = gtk_psfont_get_by_family(psfont->family, italic, bold);
721
gdk_font_unref(font);
722
font = gtk_psfont_get_gdkfont(psfont, fontsize);
724
gdk_font_unref(latin_font);
727
if (psfont->i18n_latinfamily) {
728
latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
730
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
735
fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
736
gdk_font_unref(font);
737
font = gtk_psfont_get_gdkfont(psfont, fontsize);
740
gdk_font_unref(latin_font);
743
if (psfont->i18n_latinfamily) {
744
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
749
fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
750
gdk_font_unref(font);
751
font = gtk_psfont_get_gdkfont(psfont, fontsize);
754
gdk_font_unref(latin_font);
757
if (psfont->i18n_latinfamily) {
758
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
764
gdk_font_unref(font);
765
font = gtk_psfont_get_gdkfont(psfont, fontsize);
767
gdk_font_unref(latin_font);
770
if (psfont->i18n_latinfamily) {
771
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
777
gdk_font_unref(font);
778
font = gtk_psfont_get_gdkfont(psfont, fontsize);
780
gdk_font_unref(latin_font);
783
if (psfont->i18n_latinfamily) {
784
latin_font = gtk_psfont_get_gdkfont(latin_psfont, fontsize);
789
psfont = base_psfont;
790
gdk_font_unref(font);
791
fontsize = font_height;
792
font = gtk_psfont_get_gdkfont(psfont, fontsize);
794
italic = psfont->italic;
800
gtk_psfont_get_char_size(psfont, font, latin_font, *lastchar, &w,
804
if (lastchar == wtext)
809
gtk_psfont_get_char_size(psfont, font, latin_font, 'X', &w, NULL,
816
if(aux && *aux != '\0' && *aux !='\n'){
817
x += drawstring(pc, text_bitmap, bitmap_gc, x, y,
818
psfont, fontsize, *aux);
825
if(aux && *aux != '\0' && *aux !='\n'){
826
x += drawstring(pc, text_bitmap, bitmap_gc, x, y,
827
psfont, fontsize, *aux);
836
/* initializing clip mask bitmap - ajd */
837
text_mask = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, width, height, 1);
838
mask_color.pixel = 0;
839
gdk_gc_set_foreground(bitmap_gc, &mask_color);
840
gdk_draw_rectangle(text_mask, bitmap_gc, TRUE, 0, 0, -1, -1);
841
mask_color.pixel = 1;
842
gdk_gc_set_foreground(bitmap_gc, &mask_color);
844
/* performing text rotation and saving it onto clip mask bitmap - ajd */
845
image = gdk_image_get(text_bitmap, 0, 0, old_width, old_height);
846
for(y = 0; y < old_height; y++)
847
for(x = 0; x < old_width; x++)
849
if( gdk_image_get_pixel(image, x, y) == 1 ){
868
gdk_draw_point(text_mask, bitmap_gc, xp, yp);
871
gdk_image_destroy(image);
874
/* initializing text pixmap - ajd */
875
text_pixmap = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, width, height, -1);
876
gdk_gc_set_foreground(gc, (GdkColor *) bg);
877
gdk_draw_rectangle(text_pixmap, gc, TRUE, 0, 0, -1, -1);
878
gdk_gc_set_foreground(gc, (GdkColor *) fg);
880
/* copying clip mask bitmap onto text pixmap - ajd */
881
gdk_gc_set_clip_mask(gc, text_mask);
882
gdk_gc_set_clip_origin(gc, 0, 0);
883
gdk_draw_rectangle(text_pixmap, gc, TRUE, 0, 0, -1, -1);
884
gdk_gc_set_clip_mask(gc, NULL);
886
gtk_plot_text_get_area(text, angle, just, font_name, font_height,
887
&x, &y, &width, &height);
892
gdk_gc_set_clip_mask (gc, text_mask);
893
gdk_gc_set_clip_origin (gc, tx, ty);
895
gdk_gc_set_foreground(gc, (GdkColor *) bg);
896
gtk_plot_pc_draw_rectangle(pc,
898
tx - border_space, ty - border_space,
899
width + 2*border_space, height + 2*border_space);
902
gdk_draw_pixmap(GTK_PLOT_GDK(pc)->drawable, gc,
905
gdk_gc_set_clip_mask(gc, NULL);
907
gdk_pixmap_unref(text_pixmap);
908
gdk_bitmap_unref(text_mask);
909
gdk_font_unref(font);
911
gdk_font_unref(latin_font);
912
gdk_gc_unref(bitmap_gc);
913
gdk_pixmap_unref(text_bitmap);
918
gdk_gc_set_foreground(gc, (GdkColor *) fg);
919
gtk_plot_pc_set_dash(pc, 0, NULL, 0);
920
gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0);
922
case GTK_PLOT_BORDER_SHADOW:
923
gtk_plot_pc_draw_rectangle(pc,
925
tx - border_space + shadow_width,
926
ty + height + border_space,
927
width + 2 * border_space, shadow_width);
928
gtk_plot_pc_draw_rectangle(pc,
930
tx + width + border_space,
931
ty - border_space + shadow_width,
932
shadow_width, height + 2 * border_space);
933
case GTK_PLOT_BORDER_LINE:
934
gtk_plot_pc_draw_rectangle(pc,
936
tx - border_space, ty - border_space,
937
width + 2*border_space, height + 2*border_space);
938
case GTK_PLOT_BORDER_NONE:
946
static void gtk_plot_gdk_draw_pixmap (GtkPlotPC *pc,
949
gint xsrc, gint ysrc,
950
gint xdest, gint ydest,
957
GdkPixmap *new_pixmap;
958
GdkBitmap *new_mask = NULL;
960
if(!GTK_PLOT_GDK(pc)->drawable) return;
961
if(!GTK_PLOT_GDK(pc)->window) return;
962
if(!GTK_PLOT_GDK(pc)->gc) return;
964
gc = GTK_PLOT_GDK(pc)->gc;
968
new_pixmap = scale_pixmap(GTK_PLOT_GDK(pc)->window, pixmap, scale_x, scale_y);
971
new_mask = scale_bitmap(GTK_PLOT_GDK(pc)->window, mask, scale_x, scale_y);
973
gtk_plot_pc_clip_mask(pc, xdest, ydest, new_mask);
974
gdk_draw_pixmap(GTK_PLOT_GDK(pc)->drawable, gc, new_pixmap,
975
xsrc, ysrc, xdest, ydest, width*scale_x, height*scale_y);
976
gtk_plot_pc_clip_mask(pc, xdest, ydest, NULL);
978
if(new_mask) gdk_bitmap_unref(new_mask);
979
gdk_pixmap_unref(new_pixmap);
983
scale_pixmap (GdkWindow *window, GdkPixmap *pixmap, gdouble scale_x, gdouble scale_y)
987
GdkImage *image, *new_image;
988
GdkPixmap *new_pixmap;
989
gint x, y, width, height, new_width, new_height;
992
if(!pixmap) return NULL;
993
if(!window) return NULL;
995
gc = gdk_gc_new(pixmap);
996
visual = gdk_visual_get_system ();
998
gdk_window_get_size(pixmap, &width, &height);
1000
if(scale_x == 1.0 && scale_y == 1.0){
1001
new_pixmap = gdk_pixmap_new(window, width, height, -1);
1002
gdk_draw_pixmap(new_pixmap,
1011
new_width = roundint(width * scale_x);
1012
new_height = roundint(height * scale_y);
1014
/* make a client side image of the pixmap, and
1015
* scale the data into a another client side image */
1016
new_image = gdk_image_new(GDK_IMAGE_FASTEST,visual,new_width,new_height);
1017
image = gdk_drawable_get_image(pixmap,
1021
for(x = 0; x < new_width; x++){
1022
for(y = 0; y < new_height; y++){
1025
px = MIN(roundint(x / scale_x), width - 1);
1026
py = MIN(roundint(y / scale_y), height - 1);
1028
pixel = gdk_image_get_pixel(image, px, py);
1029
gdk_image_put_pixel(new_image, x, y, pixel);
1033
/* draw the image into a new pixmap */
1034
new_pixmap = gdk_pixmap_new(window, new_width, new_height, -1);
1035
gdk_draw_image(new_pixmap,gc,new_image,0,0,0,0,new_width,new_height);
1037
gdk_image_destroy(image);
1038
gdk_image_destroy(new_image);
1044
scale_bitmap (GdkWindow *window, GdkBitmap *bitmap, gdouble scale_x, gdouble scale_y)
1048
GdkImage *image, *new_image;
1049
GdkBitmap *new_bitmap;
1050
gint x, y, width, height, new_width, new_height;
1053
if(!bitmap) return NULL;
1054
if(!window) return NULL;
1056
gc = gdk_gc_new(bitmap);
1057
visual = gdk_visual_get_system ();
1059
gdk_window_get_size(bitmap, &width, &height);
1061
if(scale_x == 1.0 && scale_y == 1.0){
1062
new_bitmap = gdk_pixmap_new(window, width, height, 1);
1064
gdk_gc_set_foreground(gc, &color);
1065
gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height);
1067
gdk_gc_set_foreground(gc, &color);
1069
gdk_draw_pixmap(new_bitmap,
1078
new_width = roundint(width * scale_x);
1079
new_height = roundint(height * scale_y);
1081
/* make a client side image of the bitmap, and
1082
* scale the data into a another client side image */
1083
image = gdk_drawable_get_image(bitmap,
1087
new_image = gdk_image_new(GDK_IMAGE_FASTEST,visual,new_width,new_height);
1088
new_bitmap = gdk_pixmap_new(window, new_width, new_height, 1);
1091
gdk_gc_set_foreground(gc, &color);
1092
gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height);
1094
gdk_gc_set_foreground(gc, &color);
1096
for(x = 0; x < new_width; x++){
1097
for(y = 0; y < new_height; y++){
1101
px = MIN(roundint(x / scale_x), width - 1);
1102
py = MIN(roundint(y / scale_y), height - 1);
1104
pixel = gdk_image_get_pixel(image, px, py);
1105
gdk_image_put_pixel(new_image, x, y, pixel);
1110
/* draw the image into a new pixmap */
1111
gdk_draw_image(new_bitmap,gc,new_image,0,0,0,0,new_width,new_height);
1113
gdk_image_destroy(image);
1114
gdk_image_destroy(new_image);
1121
return (x+.50999999471);