1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
7 * This file is part of the Gnome Library.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * published by the Free Software Foundation; either the
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * You should have received a copy of the GNU Lesser General Public License
19 * License along with the Gnome Library; see the file COPYING.LIB. If not,
24 /* Text item type for GnomeCanvas widget
26 * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas
27 * widget. Tk is copyrighted by the Regents of the University of California,
28 * Sun Microsystems, and other parties.
31 * Author: Federico Mena <federico@nuclecu.unam.mx>
32 * Port to Pango co-done by Gergõ Érdi <cactus@cactus.rulez.org>
35 #include "evolution-config.h"
39 #include "gnome-canvas-text.h"
41 #include "gnome-canvas-util.h"
42 #include "gnome-canvas-i18n.h"
44 /* Object argument IDs */
59 PROP_FAMILY
, PROP_FAMILY_SET
,
63 PROP_STYLE
, PROP_STYLE_SET
,
64 PROP_VARIANT
, PROP_VARIANT_SET
,
65 PROP_WEIGHT
, PROP_WEIGHT_SET
,
66 PROP_STRETCH
, PROP_STRETCH_SET
,
67 PROP_SIZE
, PROP_SIZE_SET
,
69 PROP_STRIKETHROUGH
, PROP_STRIKETHROUGH_SET
,
70 PROP_UNDERLINE
, PROP_UNDERLINE_SET
,
71 PROP_RISE
, PROP_RISE_SET
,
72 PROP_SCALE
, PROP_SCALE_SET
,
87 /* Rendered size accessors */
92 static void gnome_canvas_text_dispose (GnomeCanvasItem
*object
);
93 static void gnome_canvas_text_set_property (GObject
*object
,
97 static void gnome_canvas_text_get_property (GObject
*object
,
102 static void gnome_canvas_text_update (GnomeCanvasItem
*item
,
103 const cairo_matrix_t
*matrix
,
105 static void gnome_canvas_text_draw (GnomeCanvasItem
*item
, cairo_t
*cr
,
106 gint x
, gint y
, gint width
, gint height
);
107 static GnomeCanvasItem
*gnome_canvas_text_point (GnomeCanvasItem
*item
,
112 static void gnome_canvas_text_bounds (GnomeCanvasItem
*item
,
113 gdouble
*x1
, gdouble
*y1
, gdouble
*x2
, gdouble
*y2
);
115 static void gnome_canvas_text_set_markup (GnomeCanvasText
*textitem
,
116 const gchar
*markup
);
118 static void gnome_canvas_text_set_font_desc (GnomeCanvasText
*textitem
,
119 PangoFontDescription
*font_desc
);
121 static void gnome_canvas_text_apply_font_desc (GnomeCanvasText
*textitem
);
122 static void gnome_canvas_text_apply_attributes (GnomeCanvasText
*textitem
);
124 static void add_attr (PangoAttrList
*attr_list
,
125 PangoAttribute
*attr
);
130 GNOME_TYPE_CANVAS_ITEM
)
132 /* Class initialization function for the text item */
134 gnome_canvas_text_class_init (GnomeCanvasTextClass
*class)
136 GObjectClass
*gobject_class
;
137 GnomeCanvasItemClass
*item_class
;
139 gobject_class
= (GObjectClass
*) class;
140 item_class
= (GnomeCanvasItemClass
*) class;
142 gobject_class
->set_property
= gnome_canvas_text_set_property
;
143 gobject_class
->get_property
= gnome_canvas_text_get_property
;
146 g_object_class_install_property (
149 g_param_spec_string (
157 g_object_class_install_property (
160 g_param_spec_string (
163 "Marked up text to render",
168 g_object_class_install_property (
171 g_param_spec_double (
181 g_object_class_install_property (
184 g_param_spec_double (
195 g_object_class_install_property (
198 g_param_spec_string (
201 "Font description as a string",
206 g_object_class_install_property (
212 "Font description as a PangoFontDescription struct",
213 PANGO_TYPE_FONT_DESCRIPTION
,
217 g_object_class_install_property (
220 g_param_spec_string (
223 "Name of the font family, e.g. "
224 "Sans, Helvetica, Times, Monospace",
230 g_object_class_install_property (
237 PANGO_TYPE_ATTR_LIST
,
241 g_object_class_install_property (
253 g_object_class_install_property (
261 PANGO_VARIANT_NORMAL
,
265 g_object_class_install_property (
278 g_object_class_install_property (
286 PANGO_STRETCH_NORMAL
,
290 g_object_class_install_property (
296 "Font size (as a multiple of PANGO_SCALE, "
297 "eg. 12*PANGO_SCALE for a 12pt font size)",
304 g_object_class_install_property (
307 g_param_spec_double (
310 "Font size in points (eg. 12 for a 12pt font size)",
317 g_object_class_install_property (
323 "Offset of text above the baseline "
324 "(below the baseline if rise is negative)",
331 g_object_class_install_property (
334 g_param_spec_boolean (
337 "Whether to strike through the text",
342 g_object_class_install_property (
348 "Style of underline for this text",
349 PANGO_TYPE_UNDERLINE
,
350 PANGO_UNDERLINE_NONE
,
354 g_object_class_install_property (
357 g_param_spec_double (
360 "Size of font, relative to default size",
367 g_object_class_install_property (
374 GTK_TYPE_JUSTIFICATION
,
379 g_object_class_install_property (
382 g_param_spec_double (
392 g_object_class_install_property (
395 g_param_spec_double (
405 g_object_class_install_property (
408 g_param_spec_boolean (
416 g_object_class_install_property (
419 g_param_spec_double (
429 g_object_class_install_property (
432 g_param_spec_double (
442 g_object_class_install_property (
445 g_param_spec_string (
448 "Text color, as string",
452 g_object_class_install_property (
458 "Text color, as a GdkColor",
462 g_object_class_install_property (
464 PROP_FILL_COLOR_RGBA
,
468 "Text color, as an R/G/B/A combined integer",
473 g_object_class_install_property (
476 g_param_spec_double (
479 "Width of the rendered text",
480 0.0, G_MAXDOUBLE
, 0.0,
483 g_object_class_install_property (
486 g_param_spec_double (
489 "Height of the rendered text",
490 0.0, G_MAXDOUBLE
, 0.0,
493 /* Style props are set (explicitly applied) or not */
494 #define ADD_SET_PROP(propname, propval, nick, blurb) \
495 g_object_class_install_property ( \
496 gobject_class, propval, \
497 g_param_spec_boolean ( \
498 propname, nick, blurb, FALSE, \
499 G_PARAM_READABLE | G_PARAM_WRITABLE))
505 "Whether this tag affects the font family");
511 "Whether this tag affects the font style");
517 "Whether this tag affects the font variant");
523 "Whether this tag affects the font weight");
529 "Whether this tag affects the font stretch");
535 "Whether this tag affects the font size");
541 "Whether this tag affects the rise");
545 PROP_STRIKETHROUGH_SET
,
547 "Whether this tag affects strikethrough");
553 "Whether this tag affects underlining");
559 "Whether this tag affects font scaling");
562 item_class
->dispose
= gnome_canvas_text_dispose
;
563 item_class
->update
= gnome_canvas_text_update
;
564 item_class
->draw
= gnome_canvas_text_draw
;
565 item_class
->point
= gnome_canvas_text_point
;
566 item_class
->bounds
= gnome_canvas_text_bounds
;
569 /* Object initialization function for the text item */
571 gnome_canvas_text_init (GnomeCanvasText
*text
)
575 text
->justification
= GTK_JUSTIFY_LEFT
;
576 text
->clip_width
= 0.0;
577 text
->clip_height
= 0.0;
582 text
->font_desc
= NULL
;
584 text
->underline
= PANGO_UNDERLINE_NONE
;
585 text
->strikethrough
= FALSE
;
588 text
->underline_set
= FALSE
;
589 text
->strike_set
= FALSE
;
590 text
->rise_set
= FALSE
;
593 /* Dispose handler for the text item */
595 gnome_canvas_text_dispose (GnomeCanvasItem
*object
)
597 GnomeCanvasText
*text
;
599 g_return_if_fail (GNOME_IS_CANVAS_TEXT (object
));
601 text
= GNOME_CANVAS_TEXT (object
);
606 if (text
->layout
!= NULL
) {
607 g_object_unref (text
->layout
);
611 if (text
->font_desc
!= NULL
) {
612 pango_font_description_free (text
->font_desc
);
613 text
->font_desc
= NULL
;
616 if (text
->attr_list
!= NULL
) {
617 pango_attr_list_unref (text
->attr_list
);
618 text
->attr_list
= NULL
;
621 GNOME_CANVAS_ITEM_CLASS (gnome_canvas_text_parent_class
)->
626 get_bounds (GnomeCanvasText
*text
,
632 GnomeCanvasItem
*item
;
635 item
= GNOME_CANVAS_ITEM (text
);
637 /* Get canvas pixel coordinates for text position */
641 gnome_canvas_item_i2w (item
, &wx
, &wy
);
643 item
->canvas
, wx
+ text
->xofs
, wy
+ text
->yofs
,
644 &text
->cx
, &text
->cy
);
646 /* Get canvas pixel coordinates for clip rectangle position */
648 gnome_canvas_w2c (item
->canvas
, wx
, wy
, &text
->clip_cx
, &text
->clip_cy
);
649 text
->clip_cwidth
= text
->clip_width
;
650 text
->clip_cheight
= text
->clip_height
;
655 *px1
= text
->clip_cx
;
656 *py1
= text
->clip_cy
;
657 *px2
= text
->clip_cx
+ text
->clip_cwidth
;
658 *py2
= text
->clip_cy
+ text
->clip_cheight
;
662 *px2
= text
->cx
+ text
->max_width
;
663 *py2
= text
->cy
+ text
->height
;
668 get_property_font_set_mask (guint property_id
)
670 switch (property_id
) {
671 case PROP_FAMILY_SET
:
672 return PANGO_FONT_MASK_FAMILY
;
674 return PANGO_FONT_MASK_STYLE
;
675 case PROP_VARIANT_SET
:
676 return PANGO_FONT_MASK_VARIANT
;
677 case PROP_WEIGHT_SET
:
678 return PANGO_FONT_MASK_WEIGHT
;
679 case PROP_STRETCH_SET
:
680 return PANGO_FONT_MASK_STRETCH
;
682 return PANGO_FONT_MASK_SIZE
;
689 ensure_font (GnomeCanvasText
*text
)
691 if (!text
->font_desc
)
692 text
->font_desc
= pango_font_description_new ();
695 /* Set_arg handler for the text item */
697 gnome_canvas_text_set_property (GObject
*object
,
702 GnomeCanvasItem
*item
;
703 GnomeCanvasText
*text
;
705 PangoAlignment align
;
707 g_return_if_fail (object
!= NULL
);
708 g_return_if_fail (GNOME_IS_CANVAS_TEXT (object
));
710 item
= GNOME_CANVAS_ITEM (object
);
711 text
= GNOME_CANVAS_TEXT (object
);
714 text
->layout
= pango_layout_new (
715 gtk_widget_get_pango_context (
716 GTK_WIDGET (item
->canvas
)));
722 text
->text
= g_value_dup_string (value
);
723 pango_layout_set_text (text
->layout
, text
->text
, -1);
728 gnome_canvas_text_set_markup (
729 text
, g_value_get_string (value
));
733 text
->x
= g_value_get_double (value
);
737 text
->y
= g_value_get_double (value
);
741 const gchar
*font_name
;
742 PangoFontDescription
*font_desc
;
744 font_name
= g_value_get_string (value
);
746 font_desc
= pango_font_description_from_string (font_name
);
750 gnome_canvas_text_set_font_desc (text
, font_desc
);
752 pango_font_description_free (font_desc
);
758 gnome_canvas_text_set_font_desc (text
, g_value_peek_pointer (value
));
767 case PROP_SIZE_POINTS
:
772 pango_font_description_set_family (
774 g_value_get_string (value
));
777 pango_font_description_set_style (
779 g_value_get_enum (value
));
782 pango_font_description_set_variant (
784 g_value_get_enum (value
));
787 pango_font_description_set_weight (
789 g_value_get_int (value
));
792 pango_font_description_set_stretch (
794 g_value_get_enum (value
));
797 /* FIXME: This is bogus! It should be pixels, not points/PANGO_SCALE! */
798 pango_font_description_set_size (
800 g_value_get_int (value
));
802 case PROP_SIZE_POINTS
:
803 pango_font_description_set_size (
805 g_value_get_double (value
) * PANGO_SCALE
);
809 gnome_canvas_text_apply_font_desc (text
);
812 case PROP_FAMILY_SET
:
814 case PROP_VARIANT_SET
:
815 case PROP_WEIGHT_SET
:
816 case PROP_STRETCH_SET
:
818 if (!g_value_get_boolean (value
) && text
->font_desc
)
819 pango_font_description_unset_fields (
821 get_property_font_set_mask (param_id
));
825 text
->scale
= g_value_get_double (value
);
826 text
->scale_set
= TRUE
;
828 gnome_canvas_text_apply_font_desc (text
);
832 text
->scale_set
= g_value_get_boolean (value
);
834 gnome_canvas_text_apply_font_desc (text
);
838 text
->underline
= g_value_get_enum (value
);
839 text
->underline_set
= TRUE
;
841 gnome_canvas_text_apply_attributes (text
);
844 case PROP_UNDERLINE_SET
:
845 text
->underline_set
= g_value_get_boolean (value
);
847 gnome_canvas_text_apply_attributes (text
);
850 case PROP_STRIKETHROUGH
:
851 text
->strikethrough
= g_value_get_boolean (value
);
852 text
->strike_set
= TRUE
;
854 gnome_canvas_text_apply_attributes (text
);
857 case PROP_STRIKETHROUGH_SET
:
858 text
->strike_set
= g_value_get_boolean (value
);
860 gnome_canvas_text_apply_attributes (text
);
864 text
->rise
= g_value_get_int (value
);
865 text
->rise_set
= TRUE
;
867 gnome_canvas_text_apply_attributes (text
);
871 text
->rise_set
= TRUE
;
873 gnome_canvas_text_apply_attributes (text
);
876 case PROP_ATTRIBUTES
:
878 pango_attr_list_unref (text
->attr_list
);
880 text
->attr_list
= g_value_peek_pointer (value
);
881 pango_attr_list_ref (text
->attr_list
);
883 gnome_canvas_text_apply_attributes (text
);
886 case PROP_JUSTIFICATION
:
887 text
->justification
= g_value_get_enum (value
);
889 switch (text
->justification
) {
890 case GTK_JUSTIFY_LEFT
:
891 align
= PANGO_ALIGN_LEFT
;
893 case GTK_JUSTIFY_CENTER
:
894 align
= PANGO_ALIGN_CENTER
;
896 case GTK_JUSTIFY_RIGHT
:
897 align
= PANGO_ALIGN_RIGHT
;
900 /* GTK_JUSTIFY_FILL isn't supported yet. */
901 align
= PANGO_ALIGN_LEFT
;
904 pango_layout_set_alignment (text
->layout
, align
);
907 case PROP_CLIP_WIDTH
:
908 text
->clip_width
= fabs (g_value_get_double (value
));
911 case PROP_CLIP_HEIGHT
:
912 text
->clip_height
= fabs (g_value_get_double (value
));
916 text
->clip
= g_value_get_boolean (value
);
920 text
->xofs
= g_value_get_double (value
);
924 text
->yofs
= g_value_get_double (value
);
927 case PROP_FILL_COLOR
: {
928 const gchar
*color_name
;
930 color_name
= g_value_get_string (value
);
933 if (gdk_color_parse (color_name
, &color
)) {
934 text
->rgba
= ((color
.red
& 0xff00) << 16 |
935 (color
.green
& 0xff00) << 8 |
936 (color
.blue
& 0xff00) |
940 "%s: Failed to parse color form string '%s'",
941 G_STRFUNC
, color_name
);
947 case PROP_FILL_COLOR_GDK
:
948 pcolor
= g_value_get_boxed (value
);
950 text
->rgba
= ((pcolor
->red
& 0xff00) << 16 |
951 (pcolor
->green
& 0xff00) << 8|
952 (pcolor
->blue
& 0xff00) |
959 case PROP_FILL_COLOR_RGBA
:
960 text
->rgba
= g_value_get_uint (value
);
964 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
968 /* Calculate text dimensions */
971 pango_layout_get_pixel_size (
980 gnome_canvas_item_request_update (item
);
983 /* Get_arg handler for the text item */
985 gnome_canvas_text_get_property (GObject
*object
,
990 GnomeCanvasText
*text
;
992 g_return_if_fail (object
!= NULL
);
993 g_return_if_fail (GNOME_IS_CANVAS_TEXT (object
));
995 text
= GNOME_CANVAS_TEXT (object
);
999 g_value_set_string (value
, text
->text
);
1003 g_value_set_double (value
, text
->x
);
1007 g_value_set_double (value
, text
->y
);
1011 case PROP_FONT_DESC
:
1018 case PROP_SIZE_POINTS
:
1024 /* FIXME GValue imposes a totally gratuitous string
1025 * copy here, we could just hand off string
1029 str
= pango_font_description_to_string (text
->font_desc
);
1030 g_value_set_string (value
, str
);
1036 case PROP_FONT_DESC
:
1037 g_value_set_boxed (value
, text
->font_desc
);
1041 g_value_set_string (
1043 pango_font_description_get_family (
1050 pango_font_description_get_style (
1057 pango_font_description_get_variant (
1064 pango_font_description_get_weight (
1071 pango_font_description_get_stretch (
1078 pango_font_description_get_size (
1082 case PROP_SIZE_POINTS
:
1083 g_value_set_double (
1085 pango_font_description_get_size (
1086 text
->font_desc
)) / (gdouble
) PANGO_SCALE
);
1091 case PROP_FAMILY_SET
:
1092 case PROP_STYLE_SET
:
1093 case PROP_VARIANT_SET
:
1094 case PROP_WEIGHT_SET
:
1095 case PROP_STRETCH_SET
:
1098 PangoFontMask set_mask
= text
->font_desc
?
1099 pango_font_description_get_set_fields (text
->font_desc
) : 0;
1100 PangoFontMask test_mask
= get_property_font_set_mask (param_id
);
1101 g_value_set_boolean (value
, (set_mask
& test_mask
) != 0);
1107 g_value_set_double (value
, text
->scale
);
1109 case PROP_SCALE_SET
:
1110 g_value_set_boolean (value
, text
->scale_set
);
1113 case PROP_UNDERLINE
:
1114 g_value_set_enum (value
, text
->underline
);
1116 case PROP_UNDERLINE_SET
:
1117 g_value_set_boolean (value
, text
->underline_set
);
1120 case PROP_STRIKETHROUGH
:
1121 g_value_set_boolean (value
, text
->strikethrough
);
1123 case PROP_STRIKETHROUGH_SET
:
1124 g_value_set_boolean (value
, text
->strike_set
);
1128 g_value_set_int (value
, text
->rise
);
1131 g_value_set_boolean (value
, text
->rise_set
);
1134 case PROP_ATTRIBUTES
:
1135 g_value_set_boxed (value
, text
->attr_list
);
1138 case PROP_JUSTIFICATION
:
1139 g_value_set_enum (value
, text
->justification
);
1142 case PROP_CLIP_WIDTH
:
1143 g_value_set_double (value
, text
->clip_width
);
1146 case PROP_CLIP_HEIGHT
:
1147 g_value_set_double (value
, text
->clip_height
);
1151 g_value_set_boolean (value
, text
->clip
);
1155 g_value_set_double (value
, text
->xofs
);
1159 g_value_set_double (value
, text
->yofs
);
1162 case PROP_FILL_COLOR_RGBA
:
1163 g_value_set_uint (value
, text
->rgba
);
1166 case PROP_TEXT_WIDTH
:
1167 g_value_set_double (value
, text
->max_width
);
1170 case PROP_TEXT_HEIGHT
:
1171 g_value_set_double (value
, text
->height
);
1175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
1182 gnome_canvas_text_apply_font_desc (GnomeCanvasText
*text
)
1184 PangoFontDescription
*font_desc
;
1185 PangoContext
*pango_context
;
1188 widget
= GTK_WIDGET (GNOME_CANVAS_ITEM (text
)->canvas
);
1189 pango_context
= gtk_widget_create_pango_context (widget
);
1190 font_desc
= pango_font_description_copy (pango_context_get_font_description (pango_context
));
1191 g_object_unref (pango_context
);
1193 if (text
->font_desc
)
1194 pango_font_description_merge (font_desc
, text
->font_desc
, TRUE
);
1196 pango_layout_set_font_description (text
->layout
, font_desc
);
1197 pango_font_description_free (font_desc
);
1201 add_attr (PangoAttrList
*attr_list
,
1202 PangoAttribute
*attr
)
1204 attr
->start_index
= 0;
1205 attr
->end_index
= G_MAXINT
;
1207 pango_attr_list_insert (attr_list
, attr
);
1212 gnome_canvas_text_apply_attributes (GnomeCanvasText
*text
)
1214 PangoAttrList
*attr_list
;
1216 if (text
->attr_list
)
1217 attr_list
= pango_attr_list_copy (text
->attr_list
);
1219 attr_list
= pango_attr_list_new ();
1221 if (text
->underline_set
)
1222 add_attr (attr_list
, pango_attr_underline_new (text
->underline
));
1223 if (text
->strike_set
)
1224 add_attr (attr_list
, pango_attr_strikethrough_new (text
->strikethrough
));
1226 add_attr (attr_list
, pango_attr_rise_new (text
->rise
));
1228 pango_layout_set_attributes (text
->layout
, attr_list
);
1229 pango_attr_list_unref (attr_list
);
1233 gnome_canvas_text_set_font_desc (GnomeCanvasText
*text
,
1234 PangoFontDescription
*font_desc
)
1236 if (text
->font_desc
)
1237 pango_font_description_free (text
->font_desc
);
1240 text
->font_desc
= pango_font_description_copy (font_desc
);
1242 text
->font_desc
= NULL
;
1244 gnome_canvas_text_apply_font_desc (text
);
1247 /* Setting the text from a Pango markup string */
1249 gnome_canvas_text_set_markup (GnomeCanvasText
*textitem
,
1250 const gchar
*markup
)
1252 PangoAttrList
*attr_list
= NULL
;
1254 GError
*error
= NULL
;
1256 if (markup
&& !pango_parse_markup (markup
, -1,
1258 &attr_list
, &text
, NULL
,
1262 "Failed to set cell text from markup due to "
1263 "error parsing markup: %s", error
->message
);
1264 g_error_free (error
);
1268 g_free (textitem
->text
);
1269 if (textitem
->attr_list
)
1270 pango_attr_list_unref (textitem
->attr_list
);
1272 textitem
->text
= text
;
1273 textitem
->attr_list
= attr_list
;
1275 pango_layout_set_text (textitem
->layout
, text
, -1);
1277 gnome_canvas_text_apply_attributes (textitem
);
1280 /* Update handler for the text item */
1282 gnome_canvas_text_update (GnomeCanvasItem
*item
,
1283 const cairo_matrix_t
*matrix
,
1286 GnomeCanvasText
*text
;
1287 gdouble x1
, y1
, x2
, y2
;
1289 text
= GNOME_CANVAS_TEXT (item
);
1291 GNOME_CANVAS_ITEM_CLASS (gnome_canvas_text_parent_class
)->
1292 update (item
, matrix
, flags
);
1294 get_bounds (text
, &x1
, &y1
, &x2
, &y2
);
1296 gnome_canvas_update_bbox (
1298 floor (x1
), floor (y1
),
1299 ceil (x2
), ceil (y2
));
1302 /* Draw handler for the text item */
1304 gnome_canvas_text_draw (GnomeCanvasItem
*item
,
1311 GnomeCanvasText
*text
= GNOME_CANVAS_TEXT (item
);
1324 text
->clip_cheight
);
1328 cairo_set_source_rgba (
1330 ((text
->rgba
>> 24) & 0xff) / 255.0,
1331 ((text
->rgba
>> 16) & 0xff) / 255.0,
1332 ((text
->rgba
>> 8) & 0xff) / 255.0,
1333 ( text
->rgba
& 0xff) / 255.0);
1335 cairo_move_to (cr
, text
->cx
- x
, text
->cy
- y
);
1336 pango_cairo_show_layout (cr
, text
->layout
);
1341 /* Point handler for the text item */
1342 static GnomeCanvasItem
*
1343 gnome_canvas_text_point (GnomeCanvasItem
*item
,
1349 GnomeCanvasText
*text
;
1350 PangoLayoutIter
*iter
;
1351 gint x1
, y1
, x2
, y2
;
1353 text
= GNOME_CANVAS_TEXT (item
);
1355 /* The idea is to build bounding rectangles for each of the lines of
1356 * text (clipped by the clipping rectangle, if it is activated) and see
1357 * whether the point is inside any of these. If it is, we are done.
1358 * Otherwise, calculate the distance to the nearest rectangle.
1361 iter
= pango_layout_get_iter (text
->layout
);
1363 PangoRectangle log_rect
;
1365 pango_layout_iter_get_line_extents (iter
, NULL
, &log_rect
);
1367 x1
= text
->cx
+ PANGO_PIXELS (log_rect
.x
);
1368 y1
= text
->cy
+ PANGO_PIXELS (log_rect
.y
);
1369 x2
= x1
+ PANGO_PIXELS (log_rect
.width
);
1370 y2
= y1
+ PANGO_PIXELS (log_rect
.height
);
1373 if (x1
< text
->clip_cx
)
1376 if (y1
< text
->clip_cy
)
1379 if (x2
> (text
->clip_cx
+ text
->clip_width
))
1380 x2
= text
->clip_cx
+ text
->clip_width
;
1382 if (y2
> (text
->clip_cy
+ text
->clip_height
))
1383 y2
= text
->clip_cy
+ text
->clip_height
;
1385 if ((x1
>= x2
) || (y1
>= y2
))
1389 /* Calculate distance from point to rectangle */
1391 if (cx
>= x1
&& cx
< x2
&& cy
>= y1
&& cy
< y2
) {
1392 pango_layout_iter_free (iter
);
1396 } while (pango_layout_iter_next_line (iter
));
1398 pango_layout_iter_free (iter
);
1403 /* Bounds handler for the text item */
1405 gnome_canvas_text_bounds (GnomeCanvasItem
*item
,
1411 GnomeCanvasText
*text
;
1412 gdouble width
, height
;
1414 text
= GNOME_CANVAS_TEXT (item
);
1420 width
= text
->clip_width
;
1421 height
= text
->clip_height
;
1423 width
= text
->max_width
;
1424 height
= text
->height
;