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
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
)
35 swfdec_text_mouse_in (SwfdecGraphic
*graphic
, double x
, double y
)
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
;
46 glyph
= &g_array_index (text
->glyphs
, SwfdecTextGlyph
, i
);
47 draw
= swfdec_font_get_glyph (glyph
->font
, glyph
->glyph
);
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
))
61 swfdec_text_render (SwfdecGraphic
*graphic
, cairo_t
*cr
,
62 const SwfdecColorTransform
*trans
, const SwfdecRect
*inval
)
66 SwfdecText
*text
= SWFDEC_TEXT (graphic
);
67 SwfdecColorTransform force_color
;
68 SwfdecRect rect
, inval_moved
;
70 cairo_transform (cr
, &text
->transform
);
72 swfdec_rect_transform (&inval_moved
, inval
, &text
->transform_inverse
);
73 for (i
= 0; i
< text
->glyphs
->len
; i
++) {
74 SwfdecTextGlyph
*glyph
;
78 glyph
= &g_array_index (text
->glyphs
, SwfdecTextGlyph
, i
);
80 draw
= swfdec_font_get_glyph (glyph
->font
, glyph
->glyph
);
82 SWFDEC_INFO ("failed getting glyph %d, maybe an empty glyph?", glyph
->glyph
);
86 cairo_matrix_init_translate (&pos
,
88 cairo_matrix_scale (&pos
,
89 (double) glyph
->height
/ glyph
->font
->scale_factor
,
90 (double) glyph
->height
/ glyph
->font
->scale_factor
);
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
);
99 SWFDEC_ERROR ("non-invertible matrix!");
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
);
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
;
128 swfdec_text_init (SwfdecText
* text
)
130 text
->glyphs
= g_array_new (FALSE
, TRUE
, sizeof (SwfdecTextGlyph
));
131 cairo_matrix_init_identity (&text
->transform
);