make the g_print a debug message
[swfdec.git] / libswfdec / swfdec_text.c
blob9205ea8b7d119a707efbef77378f578ba56f14d2
1 /* Swfdec
2 * Copyright (C) 2003-2006 David Schleef <ds@schleef.org>
3 * 2005-2006 Eric Anholt <eric@anholt.net>
4 * 2006 Benjamin Otte <otte@gnome.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include "swfdec_text.h"
27 #include "swfdec_debug.h"
28 #include "swfdec_draw.h"
29 #include "swfdec_font.h"
30 #include "swfdec_swf_decoder.h"
32 G_DEFINE_TYPE (SwfdecText, swfdec_text, SWFDEC_TYPE_GRAPHIC)
34 static gboolean
35 swfdec_text_mouse_in (SwfdecGraphic *graphic, double x, double y)
37 guint i;
38 SwfdecText *text = SWFDEC_TEXT (graphic);
40 cairo_matrix_transform_point (&text->transform_inverse, &x, &y);
41 for (i = 0; i < text->glyphs->len; i++) {
42 SwfdecTextGlyph *glyph;
43 SwfdecDraw *draw;
44 double tmpx, tmpy;
46 glyph = &g_array_index (text->glyphs, SwfdecTextGlyph, i);
47 draw = swfdec_font_get_glyph (glyph->font, glyph->glyph);
48 if (draw == NULL)
49 continue;
50 tmpx = x - glyph->x;
51 tmpy = y - glyph->y;
52 tmpx = tmpx * glyph->font->scale_factor / glyph->height;
53 tmpy = tmpy * glyph->font->scale_factor / glyph->height;
54 if (swfdec_draw_contains (draw, tmpx, tmpy))
55 return TRUE;
57 return FALSE;
60 static void
61 swfdec_text_render (SwfdecGraphic *graphic, cairo_t *cr,
62 const SwfdecColorTransform *trans, const SwfdecRect *inval)
64 guint i;
65 SwfdecColor color;
66 SwfdecText *text = SWFDEC_TEXT (graphic);
67 SwfdecColorTransform force_color;
68 SwfdecRect rect, inval_moved;
70 cairo_transform (cr, &text->transform);
71 /* scale by bounds */
72 swfdec_rect_transform (&inval_moved, inval, &text->transform_inverse);
73 for (i = 0; i < text->glyphs->len; i++) {
74 SwfdecTextGlyph *glyph;
75 SwfdecDraw *draw;
76 cairo_matrix_t pos;
78 glyph = &g_array_index (text->glyphs, SwfdecTextGlyph, i);
80 draw = swfdec_font_get_glyph (glyph->font, glyph->glyph);
81 if (draw == NULL) {
82 SWFDEC_INFO ("failed getting glyph %d, maybe an empty glyph?", glyph->glyph);
83 continue;
86 cairo_matrix_init_translate (&pos,
87 glyph->x, glyph->y);
88 cairo_matrix_scale (&pos,
89 (double) glyph->height / glyph->font->scale_factor,
90 (double) glyph->height / glyph->font->scale_factor);
91 cairo_save (cr);
92 cairo_transform (cr, &pos);
93 if (!cairo_matrix_invert (&pos)) {
94 swfdec_rect_transform (&rect, &inval_moved, &pos);
95 color = swfdec_color_apply_transform (glyph->color, trans);
96 swfdec_color_transform_init_color (&force_color, color);
97 swfdec_draw_paint (draw, cr, &force_color);
98 } else {
99 SWFDEC_ERROR ("non-invertible matrix!");
101 cairo_restore (cr);
105 static void
106 swfdec_text_dispose (GObject *object)
108 SwfdecText * text = SWFDEC_TEXT (object);
110 g_array_free (text->glyphs, TRUE);
112 G_OBJECT_CLASS (swfdec_text_parent_class)->dispose (object);
115 static void
116 swfdec_text_class_init (SwfdecTextClass * g_class)
118 GObjectClass *object_class = G_OBJECT_CLASS (g_class);
119 SwfdecGraphicClass *graphic_class = SWFDEC_GRAPHIC_CLASS (g_class);
121 object_class->dispose = swfdec_text_dispose;
123 graphic_class->render = swfdec_text_render;
124 graphic_class->mouse_in = swfdec_text_mouse_in;
127 static void
128 swfdec_text_init (SwfdecText * text)
130 text->glyphs = g_array_new (FALSE, TRUE, sizeof (SwfdecTextGlyph));
131 cairo_matrix_init_identity (&text->transform);