~ubuntu-branches/debian/sid/genius/sid

« back to all changes in this revision

Viewing changes to gtkextra/gtkplotcairo.c

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2014-04-07 15:43:04 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20140407154304-21r03zdnfc571kz0
Tags: 1.0.17-1
* Take over package from pkg-gnome
* New upstream release. Closes: #716731
* Bump standards version.
* Update Vcs fields to Git.
* Move to single-debian-patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gtkplotpc - gtkplot print context - a renderer for printing functions
 
2
 * Copyright 1999-2001  Adrian E. Feiguin <feiguin@ifir.edu.ar>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
/**
 
21
 * SECTION: gtkplotcairo
 
22
 * @short_description: Cairo drawing backend.
 
23
 *
 
24
 * Subclass of #GtkPlotPC used for screen drawing.
 
25
 */
 
26
 
 
27
 
 
28
#include <stdio.h>
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <math.h>
 
32
#include <ctype.h>
 
33
#include <time.h>
 
34
#include <gtk/gtk.h>
 
35
#include <cairo.h>
 
36
 
 
37
#include "gtkplotpc.h"
 
38
#include "gtkplotcairo.h"
 
39
#include "gtkplot.h"
 
40
#include "gtkpsfont.h"
 
41
#include "gtkplotcanvas.h"
 
42
#include <pango/pango.h>
 
43
 
 
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,
 
56
                                                       gdouble x,
 
57
                                                       gdouble y,
 
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,
 
62
                                                   gfloat line_width,
 
63
                                                   GdkLineStyle line_style,
 
64
                                                   GdkCapStyle cap_style,
 
65
                                                   GdkJoinStyle join_style);
 
66
static void gtk_plot_cairo_set_dash                    (GtkPlotPC *pc,
 
67
                                                        gdouble offset_,
 
68
                                                        gdouble *values,
 
69
                                                        gint num_values);
 
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,
 
76
                                                        GtkPlotPoint *points,
 
77
                                                        gint numpoints);
 
78
static void gtk_plot_cairo_draw_rectangle              (GtkPlotPC *pc,
 
79
                                                        gint filled,
 
80
                                                        gdouble x, gdouble y,
 
81
                                                        gdouble width, 
 
82
                                                        gdouble height);
 
83
static void gtk_plot_cairo_draw_polygon                (GtkPlotPC *pc,
 
84
                                                        gint filled,
 
85
                                                        GtkPlotPoint *points,
 
86
                                                        gint numpoints);
 
87
static void gtk_plot_cairo_draw_circle                 (GtkPlotPC *pc,
 
88
                                                        gint filled,
 
89
                                                        gdouble x, gdouble y,
 
90
                                                        gdouble size);
 
91
static void gtk_plot_cairo_draw_ellipse                (GtkPlotPC *pc,
 
92
                                                        gint filled,
 
93
                                                        gdouble x, gdouble y,
 
94
                                                        gdouble width, 
 
95
                                                        gdouble height);
 
96
static void gtk_plot_cairo_set_font                    (GtkPlotPC *pc,
 
97
                                                        GtkPSFont *psfont,
 
98
                                                        gint height);
 
99
static void gtk_plot_cairo_draw_string                (GtkPlotPC *pc,
 
100
                                                       gint x, gint y,
 
101
                                                       gint angle,
 
102
                                                       const GdkColor *fg,
 
103
                                                       const GdkColor *bg,
 
104
                                                       gboolean transparent,
 
105
                                                       gint border,
 
106
                                                       gint border_space,
 
107
                                                       gint border_width,
 
108
                                                       gint shadow_width,
 
109
                                                       const gchar *font,
 
110
                                                       gint height,
 
111
                                                       GtkJustification just,
 
112
                                                       const gchar *text);
 
113
static void gtk_plot_cairo_draw_pixmap                (GtkPlotPC *pc,
 
114
                                                      GdkPixmap *pixmap,
 
115
                                                      GdkBitmap *mask,
 
116
                                                      gint xsrc, gint ysrc,
 
117
                                                      gint xdest, gint ydest,
 
118
                                                      gint width, gint height,
 
119
                                                      gdouble scale_x, 
 
120
                                                      gdouble scale_y);
 
121
 
 
122
extern inline gint roundint                         (gdouble x);
 
123
 
 
124
static GtkPlotPCClass *parent_class = NULL;
 
125
 
 
126
GType
 
127
gtk_plot_cairo_get_type (void)
 
128
{
 
129
  static GType pc_type = 0;
 
130
 
 
131
  if (!pc_type)
 
132
    {
 
133
      pc_type = g_type_register_static_simple (
 
134
                gtk_plot_pc_get_type(),
 
135
                "GtkPlotCairo",
 
136
                sizeof (GtkPlotCairoClass),
 
137
                (GClassInitFunc) gtk_plot_cairo_class_init,
 
138
                sizeof (GtkPlotCairo),
 
139
                (GInstanceInitFunc) gtk_plot_cairo_init,
 
140
                0);
 
141
 
 
142
    }
 
143
  return pc_type;
 
144
}
 
145
 
 
146
static void
 
147
gtk_plot_cairo_init (GtkPlotCairo *pc)
 
148
{
 
149
  pc->cairo = NULL;
 
150
  /*
 
151
    CairoWindowAttr attributes;
 
152
    gint attributes_mask;
 
153
    CairoScreen *screen;
 
154
 
 
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;
 
162
  */
 
163
 
 
164
  /*
 
165
    pc->window = cairo_window_new (NULL, &attributes, attributes_mask);
 
166
 
 
167
    screen = cairo_screen_get_default ();
 
168
  */
 
169
  /*
 
170
    pc->context = cairo_pango_context_get ();
 
171
  */
 
172
  /*
 
173
    pango_context_set_base_dir (pc->context,
 
174
    pc->text_direction == GTK_TEXT_DIR_LTR ?
 
175
    PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
 
176
  */
 
177
  
 
178
  /*
 
179
    pango_context_set_language (pc->context, gtk_get_default_language ());
 
180
    pc->layout = pango_layout_new(pc->context);
 
181
  */
 
182
}
 
183
 
 
184
 
 
185
static void
 
186
gtk_plot_cairo_class_init (GtkPlotCairoClass *klass)
 
187
{
 
188
  GtkObjectClass *object_class;
 
189
  GObjectClass *gobject_class;
 
190
  GtkPlotPCClass *pc_class;
 
191
  GtkPlotCairoClass *cairo_class;
 
192
 
 
193
  parent_class = g_type_class_ref (gtk_plot_pc_get_type ());
 
194
 
 
195
  object_class = (GtkObjectClass *) klass;
 
196
  gobject_class = (GObjectClass *) klass;
 
197
 
 
198
  pc_class = (GtkPlotPCClass *) klass;
 
199
  cairo_class = (GtkPlotCairoClass *) klass;
 
200
 
 
201
  gobject_class->finalize = gtk_plot_cairo_finalize;
 
202
 
 
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;
 
223
}
 
224
 
 
225
/**
 
226
 * gtk_plot_cairo_new:
 
227
 * @cairo:
 
228
 *
 
229
 *
 
230
 *
 
231
 * Return value:
 
232
 */
 
233
GtkObject *
 
234
gtk_plot_cairo_new (cairo_t *cairo)
 
235
{
 
236
  GtkObject *object;
 
237
 
 
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;
 
241
 
 
242
  return (object);
 
243
}
 
244
 
 
245
/**
 
246
 * gtk_plot_cairo_new_with_drawable:
 
247
 * @drawable:
 
248
 *
 
249
 *
 
250
 *
 
251
 * Return value:
 
252
 */
 
253
GtkObject *
 
254
gtk_plot_cairo_new_with_drawable (GdkDrawable *drawable)
 
255
{
 
256
  GtkObject *object;
 
257
  cairo_t *cairo = NULL;
 
258
 
 
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;
 
263
 
 
264
  return (object);
 
265
}
 
266
 
 
267
/**
 
268
 * gtk_plot_cairo_construct:
 
269
 * @pc: A #GtkPlotCairo.
 
270
 * @cairo:
 
271
 * @context:
 
272
 *
 
273
 *
 
274
 */
 
275
void
 
276
gtk_plot_cairo_construct(GtkPlotCairo *pc,
 
277
                         cairo_t *cairo,
 
278
                         PangoContext *context)
 
279
{
 
280
 
 
281
  gtk_plot_cairo_set_cairo(pc, cairo);
 
282
 
 
283
  pc->context = context;
 
284
 
 
285
  if (pc->context) 
 
286
    {
 
287
      g_object_ref(G_OBJECT(pc->context));
 
288
    }
 
289
  if (pc->layout) 
 
290
    {
 
291
      g_object_ref(G_OBJECT(pc->layout));
 
292
    }
 
293
  else 
 
294
    { 
 
295
      if(pc->cairo) pc->layout = pango_cairo_create_layout(cairo);
 
296
    }
 
297
}
 
298
 
 
299
 
 
300
static void
 
301
gtk_plot_cairo_finalize (GObject *object)
 
302
{
 
303
  GtkPlotCairo *pc = GTK_PLOT_CAIRO(object);
 
304
 
 
305
  if(pc->destroy_cairo && pc->cairo) cairo_destroy(pc->cairo);
 
306
  GTK_PLOT_CAIRO(object)->cairo = NULL;
 
307
 
 
308
  if(pc->layout)
 
309
    g_object_unref(G_OBJECT(pc->layout));
 
310
  pc->layout = NULL;
 
311
 
 
312
  if(pc->context)
 
313
    g_object_unref(G_OBJECT(pc->context));
 
314
  pc->context = NULL;
 
315
}
 
316
 
 
317
static gboolean 
 
318
gtk_plot_cairo_real_init (GtkPlotPC *pc)
 
319
{
 
320
  return TRUE;
 
321
}
 
322
 
 
323
static void
 
324
gtk_plot_cairo_leave (GtkPlotPC *pc)
 
325
{
 
326
}
 
327
 
 
328
/**
 
329
 * gtk_plot_cairo_set_cairo:
 
330
 * @pc: a #GtkPlotCairo
 
331
 * @cairo:
 
332
 *
 
333
 *
 
334
 */
 
335
void
 
336
gtk_plot_cairo_set_cairo(GtkPlotCairo *pc,
 
337
                         cairo_t *cairo)
 
338
{
 
339
  if(pc->destroy_cairo && pc->cairo && cairo) cairo_destroy(pc->cairo);
 
340
  pc->cairo = cairo;
 
341
}
 
342
 
 
343
static void 
 
344
gtk_plot_cairo_set_viewport               (GtkPlotPC *pc, gdouble w, gdouble h)
 
345
{
 
346
}
 
347
 
 
348
static void 
 
349
gtk_plot_cairo_gsave                                  (GtkPlotPC *pc)
 
350
{
 
351
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
352
  if (!cairo)
 
353
    return;
 
354
  cairo_save(cairo);
 
355
}
 
356
 
 
357
static void 
 
358
gtk_plot_cairo_grestore                                  (GtkPlotPC *pc)
 
359
{
 
360
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
361
  if (!cairo)
 
362
    return;
 
363
  cairo_restore(cairo);
 
364
}
 
365
 
 
366
static void 
 
367
gtk_plot_cairo_clip (GtkPlotPC *pc,
 
368
                     const GdkRectangle *area)
 
369
{
 
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.
 
373
   */
 
374
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
 
375
  if (!cairo)
 
376
    return;
 
377
  cairo_reset_clip(cairo);
 
378
  cairo_new_path(cairo);
 
379
  if (area) {
 
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);
 
385
      cairo_clip(cairo);
 
386
  }
 
387
}
 
388
 
 
389
static void 
 
390
gtk_plot_cairo_clip_mask                              (GtkPlotPC *pc,
 
391
                                                       gdouble x,
 
392
                                                       gdouble y,
 
393
                                                       const GdkBitmap *mask)
 
394
{
 
395
  /* TBD: Currently no support for clip mask */
 
396
  return;
 
397
}
 
398
 
 
399
static void 
 
400
gtk_plot_cairo_set_color                               (GtkPlotPC *pc,
 
401
                                                        const GdkColor *color)
 
402
{
 
403
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
 
404
  if (!cairo)
 
405
    return;
 
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
 
411
}
 
412
 
 
413
static void 
 
414
gtk_plot_cairo_set_dash                               (GtkPlotPC *pc,
 
415
                                                       gdouble offset,
 
416
                                                       gdouble *values,
 
417
                                                       gint num_values)
 
418
{
 
419
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
 
420
  if (!cairo)
 
421
    return;
 
422
  gchar list[] = {'\0','\1','\2','\3','\4','\5','\6','\7'};
 
423
  double dash[1000];
 
424
  gint i;
 
425
 
 
426
  if(num_values == 0){
 
427
    return;
 
428
  }
 
429
 
 
430
  /* TBD - Fix this */
 
431
  for(i = 0; i < num_values; i++){
 
432
    gint value;
 
433
    value = values[i];
 
434
    dash[i] = list[value];
 
435
  }  
 
436
 
 
437
  cairo_set_dash(cairo, dash, num_values, 0);
 
438
}
 
439
 
 
440
static void gtk_plot_cairo_set_lineattr           (GtkPlotPC *pc,
 
441
                                                   gfloat line_width,
 
442
                                                   GdkLineStyle line_style,
 
443
                                                   GdkCapStyle cap_style,
 
444
                                                   GdkJoinStyle join_style)
 
445
{
 
446
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
 
447
 
 
448
  if (!cairo)
 
449
    return;
 
450
  if (line_style == GDK_LINE_SOLID)
 
451
      cairo_set_dash(cairo,
 
452
                     NULL, 0, 0);
 
453
 
 
454
  if (line_width == 0)
 
455
      line_width = 0.5;   // What should be the minimum line width?
 
456
  cairo_set_line_width(cairo,
 
457
                       line_width);
 
458
 
 
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);
 
463
 
 
464
  cairo_set_line_join(cairo,
 
465
                     (cairo_line_join_t)join_style);
 
466
}
 
467
 
 
468
static void 
 
469
gtk_plot_cairo_draw_point                              (GtkPlotPC *pc,
 
470
                                                        gdouble x, gdouble y)
 
471
{
 
472
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; /* Shortcut */
 
473
  if (!cairo)
 
474
    return;
 
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);
 
478
  cairo_stroke(cairo);
 
479
}
 
480
 
 
481
static void 
 
482
gtk_plot_cairo_draw_line                               (GtkPlotPC *pc,
 
483
                                                        gdouble x1, gdouble y1,
 
484
                                                        gdouble x2, gdouble y2)
 
485
{
 
486
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
487
  if (!cairo)
 
488
    return;
 
489
  cairo_move_to(cairo, x1,y1);
 
490
  cairo_line_to(cairo, x2,y2);
 
491
  cairo_stroke(cairo);
 
492
}
 
493
 
 
494
static void 
 
495
gtk_plot_cairo_draw_lines                              (GtkPlotPC *pc,
 
496
                                                        GtkPlotPoint *points,
 
497
                                                        gint numpoints)
 
498
{
 
499
  gint i;
 
500
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
501
  if (!cairo)
 
502
    return;
 
503
 
 
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);
 
507
  }
 
508
  cairo_stroke(cairo);
 
509
}
 
510
 
 
511
static void 
 
512
gtk_plot_cairo_draw_rectangle                          (GtkPlotPC *pc,
 
513
                                                        gint filled,
 
514
                                                        gdouble x, gdouble y,
 
515
                                                        gdouble width, gdouble height)
 
516
{
 
517
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
518
  if(!cairo)
 
519
    return;
 
520
 
 
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);
 
526
  if (filled)
 
527
    cairo_fill(cairo);
 
528
  else
 
529
    cairo_stroke(cairo);
 
530
}
 
531
 
 
532
static void 
 
533
gtk_plot_cairo_draw_polygon                            (GtkPlotPC *pc,
 
534
                                                        gint filled,
 
535
                                                        GtkPlotPoint *points,
 
536
                                                        gint numpoints)
 
537
{
 
538
  gint i;
 
539
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
540
  if (!cairo)
 
541
    return;
 
542
 
 
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);
 
547
  if (filled)
 
548
    cairo_fill(cairo);
 
549
  else
 
550
    cairo_stroke(cairo);
 
551
}
 
552
 
 
553
static void 
 
554
gtk_plot_cairo_draw_circle                             (GtkPlotPC *pc,
 
555
                                                        gint filled,
 
556
                                                        gdouble x, gdouble y,
 
557
                                                        gdouble size)
 
558
{
 
559
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
560
  if (!cairo)
 
561
    return;
 
562
 
 
563
  cairo_arc (cairo, x, y, size/2, 0., 2 * M_PI);
 
564
  if (filled)
 
565
    cairo_fill(cairo);
 
566
  else
 
567
    cairo_stroke(cairo);
 
568
}
 
569
 
 
570
static void 
 
571
gtk_plot_cairo_draw_ellipse                            (GtkPlotPC *pc,
 
572
                                                        gint filled,
 
573
                                                        gdouble x, gdouble y,
 
574
                                                        gdouble width, gdouble height)
 
575
{
 
576
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
577
  if (!cairo)
 
578
    return;
 
579
 
 
580
  cairo_save(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);
 
585
 
 
586
  if (filled)
 
587
    cairo_fill(cairo);
 
588
  else
 
589
    cairo_stroke(cairo);
 
590
}
 
591
 
 
592
static void 
 
593
gtk_plot_cairo_set_font                                (GtkPlotPC *pc,
 
594
                                                        GtkPSFont *psfont,
 
595
                                                        gint height)
 
596
{
 
597
}
 
598
 
 
599
/* subfunction of gtk_plot_cairo_draw_string(). */
 
600
static gint
 
601
drawstring(GtkPlotPC *pc,
 
602
           gint angle,
 
603
           gint dx, gint dy,
 
604
           GtkPSFont *psfont, gint height,
 
605
           const gchar *text)
 
606
{
 
607
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
608
  PangoLayout *layout = GTK_PLOT_CAIRO(pc)->layout;
 
609
  PangoFontDescription *font;
 
610
  PangoRectangle rect;
 
611
  PangoFontMap *map;
 
612
  gint ret_value;
 
613
  gint dpi_cairo, dpi_screen;
 
614
  GdkScreen *screen = gdk_screen_get_default();
 
615
 
 
616
  if(!text || strlen(text) == 0) return 0;
 
617
  cairo_save(cairo);
 
618
 
 
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);
 
628
 
 
629
  if (psfont->i18n_latinfamily && psfont->vertical) {
 
630
    /* vertical-writing CJK postscript fonts. */
 
631
    return rect.height;
 
632
  } 
 
633
  else 
 
634
    {
 
635
      /* horizontal writing */
 
636
      if(angle == 90)
 
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);
 
643
      else
 
644
        cairo_translate(cairo, dx, dy);
 
645
    }
 
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);
 
653
}
 
654
 
 
655
static void 
 
656
gtk_plot_cairo_draw_string                        (GtkPlotPC *pc,
 
657
                                                   gint tx, gint ty,
 
658
                                                   gint angle,
 
659
                                                   const GdkColor *fg,
 
660
                                                   const GdkColor *bg,
 
661
                                                   gboolean transparent,
 
662
                                                   gint border,
 
663
                                                   gint border_space,
 
664
                                                   gint border_width,
 
665
                                                   gint shadow_width,
 
666
                                                   const gchar *font_name,
 
667
                                                   gint font_height,
 
668
                                                   GtkJustification just,
 
669
                                                   const gchar *text)
 
670
{
 
671
  cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo;
 
672
  GList *family = NULL;
 
673
  gint x0, y0;
 
674
  gint old_width, old_height;
 
675
  gboolean bold, italic;
 
676
  gint fontsize;
 
677
  gint ascent, descent;
 
678
  gint numf;
 
679
  gint width, height;
 
680
  gint x, y;
 
681
  gint i;
 
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];*/
 
690
  gchar num[4];
 
691
  PangoRectangle rect;
 
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;
 
698
 
 
699
  if (!cairo)
 
700
    return;
 
701
 
 
702
  layout = GTK_PLOT_CAIRO(pc)->layout;
 
703
  cairo_save(cairo);
 
704
  gtk_plot_cairo_set_color(pc, fg);
 
705
/*
 
706
  font_name = "sans";
 
707
  desc = pango_font_description_from_string(font_name);
 
708
 
 
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);
 
712
 
 
713
  pango_layout_set_font_description(layout, desc);
 
714
  pango_layout_set_text(layout, text, -1);
 
715
  cairo_save(cairo);
 
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;
 
721
 
 
722
  metrics = pango_context_get_metrics(pango_layout_get_context(layout), desc, gtk_get_default_language());
 
723
 
 
724
  pango_layout_get_size (layout, &width, &height);
 
725
 
 
726
  ascent = pango_font_metrics_get_ascent(metrics);
 
727
  descent = pango_font_metrics_get_descent(metrics);
 
728
 
 
729
  if (just == GTK_JUSTIFY_RIGHT) 
 
730
    cairo_move_to(cairo, -PANGO_PIXELS(width),
 
731
                  -PANGO_PIXELS(ascent)
 
732
                  );
 
733
  else if (just == GTK_JUSTIFY_CENTER) 
 
734
    cairo_move_to(cairo, -PANGO_PIXELS(width)/2.0,
 
735
                  -PANGO_PIXELS(ascent)
 
736
                  );
 
737
  else if (just == GTK_JUSTIFY_LEFT)
 
738
    cairo_move_to(cairo, 0,
 
739
                  -PANGO_PIXELS(ascent)
 
740
                  );
 
741
  
 
742
  pango_cairo_show_layout(cairo, layout);
 
743
  cairo_restore(cairo);
 
744
*/
 
745
 
 
746
 
 
747
  gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent);
 
748
 
 
749
  if(height == 0 || width == 0) return;
 
750
 
 
751
  old_width = width;
 
752
  old_height = height;
 
753
  if(angle == 90 || angle == 270)
 
754
    {
 
755
      old_width = height;
 
756
      old_height = width;
 
757
    }
 
758
  switch(angle){
 
759
    case 90:
 
760
      sign_x = 0;
 
761
      sign_y = -1;
 
762
      break;
 
763
    case 180:
 
764
      sign_x = -1;
 
765
      sign_y = 0;
 
766
      break;
 
767
    case 270:
 
768
      sign_x = 0;
 
769
      sign_y = 1;
 
770
      break;
 
771
    case 0:
 
772
    default:
 
773
      sign_x = 1;
 
774
      sign_y = 0;
 
775
      break;
 
776
  }
 
777
 
 
778
  switch(just){
 
779
    case GTK_JUSTIFY_LEFT:
 
780
      switch(angle){
 
781
        case 0:
 
782
            ty -= ascent;
 
783
            break;
 
784
        case 90:
 
785
            ty -= height;
 
786
            tx -= ascent;
 
787
            break;
 
788
        case 180:
 
789
            tx -= width;
 
790
            ty -= descent;
 
791
            break;
 
792
        case 270:
 
793
            tx -= descent;
 
794
            break;
 
795
      }
 
796
      old_tx = tx;
 
797
      old_ty = ty;
 
798
      break;
 
799
    case GTK_JUSTIFY_RIGHT:
 
800
      switch(angle){
 
801
        case 0:
 
802
            tx -= width;
 
803
            ty -= ascent;
 
804
            old_tx -= width;
 
805
            old_ty -= ascent;
 
806
            break;
 
807
        case 90:
 
808
            tx -= ascent;
 
809
            ty += height;
 
810
            old_tx -= ascent;
 
811
            break;
 
812
        case 180:
 
813
            tx += width;
 
814
            ty -= descent;
 
815
            old_ty -= descent;
 
816
            break;
 
817
        case 270:
 
818
            tx -= descent;
 
819
            old_tx -= descent;
 
820
            old_ty -= height;
 
821
            break;
 
822
      }
 
823
      break;
 
824
    case GTK_JUSTIFY_CENTER:
 
825
    default:
 
826
      switch(angle){
 
827
        case 0:
 
828
            tx -= width / 2.;
 
829
            ty -= ascent;
 
830
            old_tx -= width / 2.;
 
831
            old_ty -= ascent;
 
832
            break;
 
833
        case 90:
 
834
            tx -= ascent;
 
835
            ty += height / 2.;
 
836
            old_tx -= ascent;
 
837
            old_ty -= height / 2.;
 
838
            break;
 
839
        case 180:
 
840
            tx += width / 2.;
 
841
            ty -= descent;
 
842
            old_tx -= width / 2.;
 
843
            old_ty -= descent;
 
844
            break;
 
845
        case 270:
 
846
            tx -= descent;
 
847
            ty -= height / 2.;
 
848
            old_tx -= descent;
 
849
            old_ty -= height / 2.;
 
850
            break;
 
851
      }
 
852
  }
 
853
 
 
854
  real_x = tx;
 
855
  real_y = ty;
 
856
  real_width = width;
 
857
  real_height = height;
 
858
 
 
859
  if(!transparent){
 
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);
 
862
  }
 
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;
 
867
  bold = psfont->bold;
 
868
  fontsize = font_height;
 
869
  x0 = x = 0;
 
870
  y0 = y = 0;
 
871
 
 
872
  if (psfont->i18n_latinfamily) {
 
873
    latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic,
 
874
                                             bold);
 
875
    if(latin_font) pango_font_description_free(latin_font);
 
876
    latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
 
877
  } else {
 
878
    latin_psfont = NULL;
 
879
    latin_font = NULL;
 
880
  }
 
881
 
 
882
  gtk_plot_cairo_set_color(pc, &real_fg);
 
883
  aux = text;
 
884
  while(aux && *aux != '\0' && *aux != '\n'){
 
885
   if(*aux == '\\'){
 
886
     aux = g_utf8_next_char(aux);
 
887
     switch(*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);
 
894
           break;
 
895
       case '8': case 'g':
 
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);
 
900
           break;
 
901
       case 'B':
 
902
           bold = TRUE;
 
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);
 
906
           if(latin_font){
 
907
             latin_font = NULL;
 
908
           }
 
909
           if (psfont->i18n_latinfamily) {
 
910
             latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily,
 
911
                                                      italic, bold);
 
912
             if(latin_font) pango_font_description_free(latin_font);
 
913
             latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
 
914
           }
 
915
           aux = g_utf8_next_char(aux);
 
916
           break;
 
917
       case 'x':
 
918
           xaux = aux + 1;
 
919
           for (i=0; i<3; i++){
 
920
            if (xaux[i] >= '0' && xaux[i] <= '9')
 
921
              num[i] = xaux[i];
 
922
            else
 
923
              break;
 
924
           }
 
925
           if (i < 3){
 
926
              aux = g_utf8_next_char(aux);
 
927
              break;
 
928
           }
 
929
           num[3] = '\0';
 
930
           insert_char = (gchar)atoi(num);
 
931
           subs[0] = insert_char;
 
932
           subs[1] = '\0';
 
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);
 
938
           aux += 4;
 
939
           lastchar = aux - 1;
 
940
           break;
 
941
       case 'i':
 
942
           italic = TRUE;
 
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,
 
948
                                                      italic, bold);
 
949
             if(latin_font) pango_font_description_free(latin_font);
 
950
             latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
 
951
           }
 
952
           aux = g_utf8_next_char(aux);
 
953
           break;
 
954
       case 'S': case '^':
 
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);
 
960
           }
 
961
           if(angle == 180)
 
962
             y = y0 + fontsize;
 
963
           else if(angle == 270)
 
964
             x = x0 + sign_y*fontsize;
 
965
           aux = g_utf8_next_char(aux);
 
966
           break;
 
967
       case 's': case '_':
 
968
           fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
 
969
           pango_font_description_free(font);
 
970
           font = gtk_psfont_get_font_description(psfont, fontsize);
 
971
           if(angle == 0)
 
972
             y = y0 + fontsize;
 
973
           else if(angle == 90)
 
974
             x = x0 - sign_y*fontsize;
 
975
           if (psfont->i18n_latinfamily) {
 
976
             latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize);
 
977
           }
 
978
           aux = g_utf8_next_char(aux);
 
979
           break;
 
980
       case '+':
 
981
           fontsize += 3;
 
982
           y -= sign_x*3;
 
983
           x += sign_y*3;
 
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);
 
988
           }
 
989
           aux = g_utf8_next_char(aux);
 
990
           break;
 
991
       case '-':
 
992
           fontsize -= 3;
 
993
           y += sign_x*3;
 
994
           x -= sign_y*3;
 
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);
 
999
           }
 
1000
           aux = g_utf8_next_char(aux);
 
1001
           break;
 
1002
       case 'N':
 
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)
 
1008
             y = y0;
 
1009
           else
 
1010
             x = x0;
 
1011
           italic = psfont->italic;
 
1012
           bold = psfont->bold;
 
1013
           aux = g_utf8_next_char(aux);
 
1014
           break;
 
1015
       case 'b':
 
1016
           if (lastchar) {
 
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);
 
1023
 
 
1024
             if (lastchar == wtext)
 
1025
               lastchar = NULL;
 
1026
             else
 
1027
               lastchar = g_utf8_prev_char(lastchar);
 
1028
           } else {
 
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);
 
1033
           }
 
1034
           aux = g_utf8_next_char(aux);
 
1035
           break;
 
1036
       default:
 
1037
           if(aux && *aux != '\0' && *aux !='\n'){
 
1038
             gint new_width = 0;
 
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;
 
1043
             lastchar = aux;
 
1044
             aux = g_utf8_next_char(aux);
 
1045
           }
 
1046
           break;
 
1047
     }
 
1048
   } else {
 
1049
     gint new_len = 0;
 
1050
     gint new_width = 0;
 
1051
     lastchar = aux;
 
1052
     while(aux && *aux != '\0' && *aux !='\n' && *aux != '\\'){
 
1053
       xaux = aux;
 
1054
       new_len += g_utf8_next_char(aux) - xaux;
 
1055
       xaux++;
 
1056
       aux = g_utf8_next_char(aux);
 
1057
     }
 
1058
     xaux = lastchar;
 
1059
 
 
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;
 
1067
     lastchar = aux;
 
1068
 
 
1069
     g_free (new_text);
 
1070
   }
 
1071
  }
 
1072
 
 
1073
  if(latin_font) pango_font_description_free(latin_font);
 
1074
 
 
1075
/* border */
 
1076
 
 
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);
 
1080
  switch(border){
 
1081
    case GTK_PLOT_BORDER_SHADOW:
 
1082
      gtk_plot_pc_draw_rectangle(pc,
 
1083
                         TRUE,
 
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,
 
1088
                         TRUE,
 
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,
 
1094
                         FALSE,
 
1095
                         old_tx - border_space, old_ty - border_space,
 
1096
                         width + 2*border_space, height + 2*border_space);
 
1097
    case GTK_PLOT_BORDER_NONE:
 
1098
    default:
 
1099
        break;
 
1100
  }
 
1101
 
 
1102
  cairo_restore(cairo);
 
1103
  return;
 
1104
}
 
1105
 
 
1106
static void gtk_plot_cairo_draw_pixmap                (GtkPlotPC *pc,
 
1107
                                                      GdkPixmap *pixmap,
 
1108
                                                      GdkBitmap *mask,
 
1109
                                                      gint xsrc, gint ysrc,
 
1110
                                                      gint xdest, gint ydest,
 
1111
                                                      gint width, gint height,
 
1112
                                                      gdouble scale_x, 
 
1113
                                                      gdouble scale_y)
 
1114
{
 
1115
  if (!GTK_PLOT_CAIRO(pc)->cairo)
 
1116
    return;
 
1117
 
 
1118
  cairo_surface_t *image_surface = NULL;
 
1119
  cairo_surface_t *mask_surface = NULL;
 
1120
  cairo_t *cr;
 
1121
/* TODO: USE MASK */
 
1122
 
 
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);
 
1127
  cairo_paint(cr);
 
1128
  cairo_destroy(cr);
 
1129
 
 
1130
/*
 
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);
 
1135
  cairo_paint(cr);
 
1136
  cairo_destroy(cr);
 
1137
*/
 
1138
  if(mask){
 
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);
 
1145
    cairo_fill(cr);
 
1146
    cairo_destroy(cr);
 
1147
  }
 
1148
 
 
1149
  cairo_save(GTK_PLOT_CAIRO(pc)->cairo);
 
1150
/*
 
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);
 
1153
*/
 
1154
/*
 
1155
  if(mask) cairo_mask_surface(GTK_PLOT_CAIRO(pc)->cairo,mask_surface,xdest,ydest);
 
1156
*/
 
1157
  cairo_set_source_surface(GTK_PLOT_CAIRO(pc)->cairo,image_surface,xdest,ydest);
 
1158
  cairo_paint(GTK_PLOT_CAIRO(pc)->cairo);
 
1159
  
 
1160
  cairo_restore(GTK_PLOT_CAIRO(pc)->cairo);
 
1161
  cairo_surface_destroy(image_surface);
 
1162
  cairo_surface_destroy(mask_surface);
 
1163
}