1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* plplotcanvas-hacktext.c: Hacktext CanvasItem, cloned from the
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public License
8
* as published by the Free Software Foundation; either version 2 of
9
* the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public
17
* License along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
* Federico Mena <federico@nuclecu.unam.mx>
22
* Raph Levien <raph@acm.org>
23
* Lauris Kaplinski <lauris@helixcode.com>
25
* Copyright (C) 1998-1999 The Free Software Foundation
26
* Copyright (C) 2000-2002 Ximian Inc.
31
* FIXME: TODO: Clipping
39
#include <libgnomeprint/gnome-pgl.h>
40
#include <libgnomeprint/gnome-font.h>
41
#include <libgnomeprint/gnome-rfont.h>
43
#include "plplotcanvas-hacktext.h"
47
* Macros from gnome-print-i18n.h in gnome-print
50
#ifndef __GNOME_PRINT_I18N_H__
51
#define __GNOME_PRINT_I18N_H__
52
# define textdomain(String) (String)
53
# define gettext(String) (String)
54
# define dgettext(Domain,Message) (Message)
55
# define dcgettext(Domain,Message,Type) (Message)
56
# define bindtextdomain(Domain,Directory) (Domain)
57
# define _(String) (String)
58
# define N_(String) (String)
59
#endif /* __GNOME_PRINT_I18N_H__ */
63
* Continue with hacktext code
78
static void plplot_canvas_hacktext_class_init (PlplotCanvasHacktextClass *class);
79
static void plplot_canvas_hacktext_init (PlplotCanvasHacktext *hacktext);
80
static void plplot_canvas_hacktext_destroy (GtkObject *object);
81
static void plplot_canvas_hacktext_set_property (GObject *object,
85
static void plplot_canvas_hacktext_get_property (GObject *object,
89
static void plplot_canvas_hacktext_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags);
90
static void plplot_canvas_hacktext_realize (GnomeCanvasItem *item);
91
static void plplot_canvas_hacktext_unrealize (GnomeCanvasItem *item);
92
static double plplot_canvas_hacktext_point (GnomeCanvasItem *item, double x, double y,
93
int cx, int cy, GnomeCanvasItem **actual_item);
94
static void plplot_canvas_hacktext_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2);
95
static void plplot_canvas_hacktext_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
96
static void plplot_canvas_hacktext_req_repaint (PlplotCanvasHacktext *hacktext, ArtIRect *bbox);
99
static GnomeCanvasItemClass *parent_class;
101
struct _PlplotCanvasHacktextPriv {
104
GnomeGlyphList * glyphlist;
105
GnomePosGlyphList * pgl;
106
double affine[6]; /* the text to world transform (NB! mirrored Y) */
110
plplot_canvas_hacktext_get_type (void)
112
static GType type = 0;
115
sizeof (PlplotCanvasHacktextClass),
117
(GClassInitFunc) plplot_canvas_hacktext_class_init,
119
sizeof (PlplotCanvasHacktext),
121
(GInstanceInitFunc) plplot_canvas_hacktext_init,
124
type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM, "PlplotCanvasHacktext", &info, 0);
130
plplot_canvas_hacktext_class_init (PlplotCanvasHacktextClass *class)
132
GObjectClass *gobject_class;
133
GtkObjectClass *object_class;
134
GnomeCanvasItemClass *item_class;
136
object_class = (GtkObjectClass *) class;
137
gobject_class = (GObjectClass *) class;
138
item_class = (GnomeCanvasItemClass *) class;
140
parent_class = g_type_class_peek_parent (class);
142
gobject_class->set_property = plplot_canvas_hacktext_set_property;
143
gobject_class->get_property = plplot_canvas_hacktext_get_property;
145
g_object_class_install_property
148
g_param_spec_string ("text",
152
G_PARAM_READABLE | G_PARAM_WRITABLE));
153
g_object_class_install_property
156
g_param_spec_double ("x", NULL, NULL,
157
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
158
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
159
g_object_class_install_property
162
g_param_spec_double ("y", NULL, NULL,
163
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
164
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
165
g_object_class_install_property
168
g_param_spec_pointer ("glyphlist",
171
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
172
g_object_class_install_property
175
g_param_spec_string ("fill_color",
177
_("Text color, as string"),
180
g_object_class_install_property
182
PROP_FILL_COLOR_RGBA,
183
g_param_spec_uint ("fill_color_rgba",
185
_("Text color, as an R/G/B/A combined integer"),
187
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
188
g_object_class_install_property
191
g_param_spec_object ("font",
193
_("Font as a GnomeFont struct"),
195
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
197
object_class->destroy = plplot_canvas_hacktext_destroy;
199
item_class->update = plplot_canvas_hacktext_update;
200
item_class->realize = plplot_canvas_hacktext_realize;
201
item_class->unrealize = plplot_canvas_hacktext_unrealize;
202
item_class->point = plplot_canvas_hacktext_point;
203
item_class->bounds = plplot_canvas_hacktext_bounds;
204
item_class->render = plplot_canvas_hacktext_render;
208
plplot_canvas_hacktext_init (PlplotCanvasHacktext *hacktext)
210
hacktext->text = NULL;
211
hacktext->priv = g_new (PlplotCanvasHacktextPriv, 1);
212
hacktext->priv->pgl = NULL;
213
hacktext->priv->font = NULL;
214
hacktext->priv->glyphlist = NULL;
216
art_affine_identity (hacktext->priv->affine);
220
plplot_canvas_hacktext_destroy (GtkObject *object)
222
PlplotCanvasHacktext *hacktext;
224
g_return_if_fail (object != NULL);
225
g_return_if_fail (PLPLOT_IS_CANVAS_HACKTEXT (object));
227
hacktext = PLPLOT_CANVAS_HACKTEXT (object);
229
if (hacktext->text) {
230
g_free (hacktext->text);
231
hacktext->text = NULL;
234
if (hacktext->priv) {
235
if (hacktext->priv->font)
236
gnome_font_unref (hacktext->priv->font);
237
if (hacktext->priv->glyphlist)
238
gnome_glyphlist_unref (hacktext->priv->glyphlist);
239
if (hacktext->priv->pgl)
240
gnome_pgl_destroy (hacktext->priv->pgl);
241
g_free (hacktext->priv);
242
hacktext->priv = NULL;
245
if (GTK_OBJECT_CLASS (parent_class)->destroy)
246
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
250
art_drect_hacktext (ArtDRect *bbox, PlplotCanvasHacktext *hacktext)
252
g_assert (bbox != NULL);
253
g_assert (hacktext != NULL);
255
g_return_if_fail (hacktext->priv);
257
if (GTK_OBJECT_FLAGS (hacktext) & GNOME_CANVAS_UPDATE_REQUESTED) {
258
gnome_canvas_update_now (GNOME_CANVAS_ITEM (hacktext)->canvas);
261
if (!hacktext->priv->pgl)
264
gnome_pgl_bbox (hacktext->priv->pgl, bbox);
267
/* Computes the bounding box of the hacktext. Assumes that the number of points in the hacktext is
271
get_bounds (PlplotCanvasHacktext *hacktext, double *bx1, double *by1, double *bx2, double *by2)
275
/* Compute bounds of hacktext */
276
art_drect_hacktext (&bbox, hacktext);
287
plplot_canvas_hacktext_set_property (GObject *object,
292
GnomeCanvasItem *item;
293
PlplotCanvasHacktext *bp;
298
item = GNOME_CANVAS_ITEM (object);
299
bp = PLPLOT_CANVAS_HACKTEXT (object);
308
if (bp->priv->glyphlist) {
309
gnome_glyphlist_unref (bp->priv->glyphlist);
310
bp->priv->glyphlist = NULL;
313
bp->text = g_value_dup_string (value);
315
gnome_canvas_item_request_update (item);
319
gl = g_value_get_pointer (value);
326
if (bp->priv->glyphlist) {
327
gnome_glyphlist_unref (bp->priv->glyphlist);
328
bp->priv->glyphlist = NULL;
331
/* FIXME: should be duplicate() (Lauris) */
333
gnome_glyphlist_ref (gl);
335
bp->priv->glyphlist = gl;
337
gnome_canvas_item_request_update (item);
341
case PROP_FILL_COLOR:
342
if (gnome_canvas_get_color (item->canvas, g_value_get_string (value), &color)) {
344
bp->fill_pixel = color.pixel;
346
((color.red & 0xff00) << 16) |
347
((color.green & 0xff00) << 8) |
348
(color.blue & 0xff00) |
351
bp->fill_set = FALSE;
355
gnome_canvas_item_request_update (item);
358
case PROP_FILL_COLOR_RGBA:
360
bp->fill_rgba = g_value_get_uint (value);
362
/* should probably request repaint on the fill_svp */
363
gnome_canvas_item_request_update (item);
368
font = g_value_get_object (value);
370
gnome_font_ref (font);
372
gnome_font_unref (bp->priv->font);
373
bp->priv->font = font;
374
bp->size = gnome_font_get_size (bp->priv->font);
375
gnome_canvas_item_request_update (item);
379
bp->x = g_value_get_double (value);
380
gnome_canvas_item_request_update (item);
384
bp->y = g_value_get_double (value);
385
gnome_canvas_item_request_update (item);
394
plplot_canvas_hacktext_get_property (GObject *object,
399
PlplotCanvasHacktextPriv *priv;
400
PlplotCanvasHacktext *bp;
402
bp = PLPLOT_CANVAS_HACKTEXT (object);
403
priv = (PlplotCanvasHacktextPriv *) bp->priv;
407
g_value_set_string (value, bp->text);
410
g_value_set_pointer (value, priv->glyphlist);
412
case PROP_FILL_COLOR_RGBA:
413
g_value_set_uint (value, bp->fill_color);
416
g_value_set_object (value, bp->priv->font);
419
g_value_set_double (value, bp->x);
422
g_value_set_double (value, bp->y);
425
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
431
plplot_canvas_hacktext_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
433
PlplotCanvasHacktext *hacktext;
434
ArtIRect ibbox = {0, 0, 0, 0};
436
hacktext = (PlplotCanvasHacktext *) item;
438
if (parent_class->update)
439
(* parent_class->update) (item, affine, clip_path, flags);
441
if (hacktext->priv->pgl)
442
plplot_canvas_hacktext_req_repaint (hacktext, NULL);
444
gnome_canvas_item_reset_bounds (item);
446
hacktext->priv->affine[0] = affine[0];
447
hacktext->priv->affine[1] = affine[1];
448
hacktext->priv->affine[2] = -affine[2];
449
hacktext->priv->affine[3] = -affine[3];
450
hacktext->priv->affine[4] = affine[4] + hacktext->x * affine[0] + hacktext->y * affine[2];
451
hacktext->priv->affine[5] = affine[5] + hacktext->x * affine[1] + hacktext->y * affine[3];
453
if (hacktext->text) {
454
if (hacktext->priv->glyphlist) {
455
gnome_glyphlist_unref (hacktext->priv->glyphlist);
456
hacktext->priv->glyphlist = NULL;
459
if (!hacktext->priv->font)
462
hacktext->priv->glyphlist = gnome_glyphlist_from_text_dumb (hacktext->priv->font, hacktext->fill_rgba,
467
if (hacktext->priv->glyphlist) {
468
GnomePosGlyphList * pgl;
470
pgl = gnome_pgl_from_gl (hacktext->priv->glyphlist, hacktext->priv->affine, GNOME_PGL_RENDER_DEFAULT);
472
if (hacktext->priv->pgl)
473
gnome_pgl_destroy (hacktext->priv->pgl);
475
hacktext->priv->pgl = pgl;
478
plplot_canvas_hacktext_req_repaint (hacktext, &ibbox);
480
hacktext->item.x1 = ibbox.x0;
481
hacktext->item.y1 = ibbox.y0;
482
hacktext->item.x2 = ibbox.x1;
483
hacktext->item.y2 = ibbox.y1;
487
plplot_canvas_hacktext_realize (GnomeCanvasItem *item)
489
PlplotCanvasHacktext *hacktext;
491
hacktext = (PlplotCanvasHacktext *) item;
493
if (parent_class->realize)
494
(* parent_class->realize) (item);
498
plplot_canvas_hacktext_unrealize (GnomeCanvasItem *item)
500
PlplotCanvasHacktext *hacktext;
502
hacktext = (PlplotCanvasHacktext *) item;
504
if (parent_class->unrealize)
505
(* parent_class->unrealize) (item);
509
plplot_canvas_hacktext_point (GnomeCanvasItem *item, double mx, double my,
510
int cx, int cy, GnomeCanvasItem **actual_item)
512
PlplotCanvasHacktext * hacktext;
514
hacktext = (PlplotCanvasHacktext *) item;
516
if (!hacktext->priv->pgl)
521
if (gnome_pgl_test_point (hacktext->priv->pgl, cx, cy))
528
plplot_canvas_hacktext_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
530
PlplotCanvasHacktext *hacktext;
532
g_return_if_fail (item != NULL);
533
g_return_if_fail (PLPLOT_IS_CANVAS_HACKTEXT (item));
535
hacktext = PLPLOT_CANVAS_HACKTEXT (item);
537
if (hacktext->text == NULL) {
538
*x1 = *y1 = *x2 = *y2 = 0.0;
542
get_bounds (hacktext, x1, y1, x2, y2);
546
plplot_canvas_hacktext_req_repaint (PlplotCanvasHacktext *hacktext,
551
g_return_if_fail (hacktext->priv);
553
if (!hacktext->priv->pgl)
556
if (gnome_pgl_bbox (hacktext->priv->pgl, &gbbox)) {
558
art_drect_to_irect (&ibox, &gbbox);
559
gnome_canvas_request_redraw (hacktext->item.canvas, ibox.x0, ibox.y0, ibox.x1, ibox.y1);
560
if (bbox) art_irect_union (bbox, bbox, &ibox);
565
plplot_canvas_hacktext_render (GnomeCanvasItem *item,
568
PlplotCanvasHacktext * hacktext;
570
hacktext = (PlplotCanvasHacktext *) item;
572
g_return_if_fail (hacktext->priv);
574
if (!hacktext->priv->pgl)
577
gnome_canvas_buf_ensure_buf (buf);
581
gnome_rfont_render_pgl_rgb8 (hacktext->priv->pgl,
582
-buf->rect.x0, -buf->rect.y0,
584
buf->rect.x1 - buf->rect.x0,
585
buf->rect.y1 - buf->rect.y0,
587
GNOME_RFONT_RENDER_DEFAULT);