1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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.
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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 * @short_description: Root abstract class for all dimension entities
25 * The #AdgDim class is the base stub of all the dimension entities.
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
37 #include "adg-dim-private.h"
57 static void finalize (GObject
*object
);
58 static void get_property (GObject
*object
,
62 static void set_property (GObject
*object
,
66 static void invalidate (AdgEntity
*entity
);
67 static void clear (AdgDim
*entity
);
68 static gchar
* default_quote (AdgDim
*dim
);
69 static void quote_layout (AdgDim
*dim
,
71 static void text_cache_init (AdgTextCache
*text_cache
);
72 static gboolean
text_cache_update (AdgTextCache
*text_cache
,
76 static void text_cache_clear (AdgTextCache
*text_cache
);
77 static void text_cache_move_to (AdgTextCache
*text_cache
,
79 static void text_cache_render (AdgTextCache
*text_cache
,
83 G_DEFINE_ABSTRACT_TYPE(AdgDim
, adg_dim
, ADG_TYPE_ENTITY
);
87 adg_dim_class_init(AdgDimClass
*klass
)
89 GObjectClass
*gobject_class
;
90 AdgEntityClass
*entity_class
;
93 gobject_class
= (GObjectClass
*) klass
;
94 entity_class
= (AdgEntityClass
*) klass
;
96 g_type_class_add_private(klass
, sizeof(AdgDimPrivate
));
98 gobject_class
->finalize
= finalize
;
99 gobject_class
->get_property
= get_property
;
100 gobject_class
->set_property
= set_property
;
102 entity_class
->invalidate
= invalidate
;
104 klass
->default_quote
= default_quote
;
105 klass
->quote_layout
= quote_layout
;
107 param
= g_param_spec_boxed("ref1",
109 P_("First reference point of the dimension"),
111 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
112 g_object_class_install_property(gobject_class
, PROP_REF1
, param
);
114 param
= g_param_spec_boxed("ref2",
116 P_("Second reference point of the dimension"),
118 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
119 g_object_class_install_property(gobject_class
, PROP_REF2
, param
);
121 param
= g_param_spec_boxed("pos1",
123 P_("First position point: it will be computed with the level property to get the real dimension position"),
124 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
125 g_object_class_install_property(gobject_class
, PROP_POS1
, param
);
127 param
= g_param_spec_boxed("pos2",
129 P_("Second position point: it will be computed with the level property to get the real dimension position"),
130 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
131 g_object_class_install_property(gobject_class
, PROP_POS2
, param
);
133 param
= g_param_spec_double("level",
135 P_("The dimension level, that is the factor to multiply dim_style->baseline_spacing to get the offset (in device units) from pos1..pos2 where render the dimension baseline"),
136 -G_MAXDOUBLE
, G_MAXDOUBLE
, 1.0,
137 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
138 g_object_class_install_property(gobject_class
, PROP_LEVEL
, param
);
140 param
= g_param_spec_string("quote",
142 P_("The quote to display: set to NULL to get the default quote"),
143 NULL
, G_PARAM_READWRITE
);
144 g_object_class_install_property(gobject_class
, PROP_QUOTE
, param
);
146 param
= g_param_spec_string("tolerance-up",
148 P_("The up tolerance of the quote: set to NULL to suppress"),
149 NULL
, G_PARAM_READWRITE
);
150 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_UP
, param
);
152 param
= g_param_spec_string("tolerance-down",
153 P_("Down Tolerance"),
154 P_("The down tolerance of the quote: set to NULL to suppress"),
155 NULL
, G_PARAM_READWRITE
);
156 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_DOWN
, param
);
158 param
= g_param_spec_string("note",
160 P_("A custom note appended to the dimension quote"),
161 NULL
, G_PARAM_READWRITE
);
162 g_object_class_install_property(gobject_class
, PROP_NOTE
, param
);
166 adg_dim_init(AdgDim
*dim
)
168 AdgDimPrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim
, ADG_TYPE_DIM
,
171 data
->ref1
.x
= data
->ref1
.y
= 0;
172 data
->ref2
.x
= data
->ref2
.y
= 0;
173 data
->pos1
.x
= data
->pos1
.y
= 0;
174 data
->pos2
.x
= data
->pos2
.y
= 0;
177 data
->tolerance_up
= NULL
;
178 data
->tolerance_down
= NULL
;
181 data
->org
.x
= data
->org
.y
= 0;
183 text_cache_init(&data
->quote_cache
);
184 text_cache_init(&data
->tolerance_up_cache
);
185 text_cache_init(&data
->tolerance_down_cache
);
186 text_cache_init(&data
->note_cache
);
192 finalize(GObject
*object
)
196 GObjectClass
*object_class
;
198 dim
= (AdgDim
*) object
;
200 object_class
= (GObjectClass
*) adg_dim_parent_class
;
203 g_free(data
->tolerance_up
);
204 g_free(data
->tolerance_down
);
208 if (object_class
->finalize
!= NULL
)
209 object_class
->finalize(object
);
213 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
215 AdgDimPrivate
*data
= ((AdgDim
*) object
)->data
;
219 g_value_set_boxed(value
, &data
->ref1
);
222 g_value_set_boxed(value
, &data
->ref2
);
225 g_value_set_boxed(value
, &data
->pos1
);
228 g_value_set_boxed(value
, &data
->pos1
);
231 g_value_set_double(value
, data
->level
);
234 g_value_set_string(value
, data
->quote
);
236 case PROP_TOLERANCE_UP
:
237 g_value_set_string(value
, data
->tolerance_up
);
239 case PROP_TOLERANCE_DOWN
:
240 g_value_set_string(value
, data
->tolerance_down
);
243 g_value_set_string(value
, data
->note
);
246 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
252 set_property(GObject
*object
, guint prop_id
,
253 const GValue
*value
, GParamSpec
*pspec
)
258 dim
= (AdgDim
*) object
;
263 cpml_pair_copy(&data
->ref1
, (AdgPair
*) g_value_get_boxed(value
));
267 cpml_pair_copy(&data
->ref2
, (AdgPair
*) g_value_get_boxed(value
));
271 cpml_pair_copy(&data
->pos1
, (AdgPair
*) g_value_get_boxed(value
));
275 cpml_pair_copy(&data
->pos2
, (AdgPair
*) g_value_get_boxed(value
));
279 data
->level
= g_value_get_double(value
);
284 data
->quote
= g_value_dup_string(value
);
285 text_cache_clear(&data
->quote_cache
);
287 case PROP_TOLERANCE_UP
:
288 g_free(data
->tolerance_up
);
289 data
->tolerance_up
= g_value_dup_string(value
);
290 text_cache_clear(&data
->tolerance_up_cache
);
292 case PROP_TOLERANCE_DOWN
:
293 g_free(data
->tolerance_down
);
294 data
->tolerance_down
= g_value_dup_string(value
);
295 text_cache_clear(&data
->tolerance_down_cache
);
299 data
->note
= g_value_dup_string(value
);
300 text_cache_clear(&data
->note_cache
);
303 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
313 * Gets the origin (org) coordinates. The returned pair is internally
314 * owned and must not be freed or modified. This function is only
315 * useful in new dimension implementations.
317 * Return value: the org coordinates
320 adg_dim_get_org(AdgDim
*dim
)
324 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
334 * @org: the org coordinates
336 * Sets new org coordinates. This function is only useful
337 * in new dimension implementations.
340 adg_dim_set_org(AdgDim
*dim
, const AdgPair
*org
)
344 g_return_if_fail(ADG_IS_DIM(dim
));
345 g_return_if_fail(org
!= NULL
);
352 * adg_dim_set_org_explicit:
354 * @org_x: x component of org
355 * @org_y: y component of org
357 * Explicitely sets new org coordinates. This function is only useful
358 * in new dimension implementations.
361 adg_dim_set_org_explicit(AdgDim
*dim
, gdouble org_x
, gdouble org_y
)
365 g_return_if_fail(ADG_IS_DIM(dim
));
376 * Gets the dimension angle. This function is only useful
377 * in new dimension implementations.
379 * Return value: the angle (in radians)
382 adg_dim_get_angle(AdgDim
*dim
)
386 g_return_val_if_fail(ADG_IS_DIM(dim
), 0);
396 * @angle: the new angle (in radians)
398 * Sets a new dimension angle. This function is only useful
399 * in new dimension implementations.
402 adg_dim_set_angle(AdgDim
*dim
, gdouble angle
)
406 g_return_if_fail(ADG_IS_DIM(dim
));
416 * Gets the ref1 coordinates. The returned pair is internally owned
417 * and must not be freed or modified.
419 * Return value: the ref1 coordinates
422 adg_dim_get_ref1(AdgDim
*dim
)
426 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
437 * Gets the ref2 coordinates. The returned pair is internally owned
438 * and must not be freed or modified.
440 * Return value: the ref2 coordinates
443 adg_dim_get_ref2(AdgDim
*dim
)
447 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
457 * @ref1: the ref1 coordinates
458 * @ref2: the ref2 coordinates
460 * Shortcut to set ref1 and ref2 points at once.
463 adg_dim_set_ref(AdgDim
*dim
, const AdgPair
*ref1
, const AdgPair
*ref2
)
465 g_return_if_fail(ADG_IS_DIM(dim
));
467 if (ref1
!= NULL
|| ref2
!= NULL
) {
472 object
= (GObject
*) dim
;
474 g_object_freeze_notify(object
);
478 g_object_notify(object
, "ref1");
483 g_object_notify(object
, "ref2");
486 g_object_thaw_notify(object
);
492 * adg_dim_set_ref_explicit:
494 * @ref1_x: x component of pos1
495 * @ref1_y: y component of pos1
496 * @ref2_x: x component of pos2
497 * @ref2_y: y component of pos2
499 * Shortcut to set ref1 and ref2 points at once,
500 * using explicit coordinates.
503 adg_dim_set_ref_explicit(AdgDim
*dim
, gdouble ref1_x
, gdouble ref1_y
,
504 gdouble ref2_x
, gdouble ref2_y
)
514 adg_dim_set_ref(dim
, &ref1
, &ref2
);
521 * Gets the pos1 coordinates. The returned pair is internally owned
522 * and must not be freed or modified.
524 * Return value: the pos1 coordinates
527 adg_dim_get_pos1(AdgDim
*dim
)
531 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
542 * Gets the pos2 coordinates. The returned pair is internally owned
543 * and must not be freed or modified.
545 * Return value: the pos2 coordinates
548 adg_dim_get_pos2(AdgDim
*dim
)
552 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
562 * @pos1: the pos1 coordinates
563 * @pos2: the pos2 coordinates
565 * Shortcut to set pos1 and pos2 points at once.
568 adg_dim_set_pos(AdgDim
*dim
, AdgPair
*pos1
, AdgPair
*pos2
)
570 g_return_if_fail(ADG_IS_DIM(dim
));
572 if (pos1
!= NULL
|| pos2
!= NULL
) {
577 object
= (GObject
*) dim
;
579 g_object_freeze_notify(object
);
583 g_object_notify(object
, "pos1");
587 g_object_notify(object
, "pos2");
590 g_object_thaw_notify(object
);
596 * adg_dim_set_pos_explicit:
598 * @pos1_x: x component of pos1
599 * @pos1_y: y component of pos1
600 * @pos2_x: x component of pos2
601 * @pos2_y: y component of pos2
603 * Shortcut to set pos1 and pos2 points at once,
604 * using explicit coordinates.
607 adg_dim_set_pos_explicit(AdgDim
*dim
, gdouble pos1_x
, gdouble pos1_y
,
608 gdouble pos2_x
, gdouble pos2_y
)
618 adg_dim_set_pos(dim
, &pos1
, &pos2
);
625 * Gets the level of this dimension.
627 * Return value: the level value
630 adg_dim_get_level(AdgDim
*dim
)
634 g_return_val_if_fail(ADG_IS_DIM(dim
), 0);
644 * @level: the new level
646 * Sets a new level for this dimension. The level is used to
647 * stack the quotes using a spacing value from dim_style
648 * (specified in global space).
651 adg_dim_set_level(AdgDim
*dim
, gdouble level
)
655 g_return_if_fail(ADG_IS_DIM(dim
));
660 g_object_notify((GObject
*) dim
, "level");
668 * Gets the quote text. The string is internally owned and
669 * must not be freed or modified.
671 * Return value: the quote text
674 adg_dim_get_quote(AdgDim
*dim
)
678 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
688 * @quote: the quote text
690 * Explicitely sets the text to use as quote. If @quote is %NULL or
691 * was never set, an automatic text is calculated using the format as
692 * specified by the dim_style associated to this entity and getting
693 * the number from the construction points (ref1, ref2, pos1 and pos2).
696 adg_dim_set_quote(AdgDim
*dim
, const gchar
*quote
)
700 g_return_if_fail(ADG_IS_DIM(dim
));
705 data
->quote
= g_strdup(quote
);
706 g_object_notify((GObject
*) dim
, "quote");
708 text_cache_clear(&data
->quote_cache
);
712 * adg_dim_get_tolerance_up:
715 * Gets the upper tolerance text or %NULL on upper tolerance disabled.
716 * The string is internally owned and must not be freed or modified.
718 * Return value: the tolerance text
721 adg_dim_get_tolerance_up(AdgDim
*dim
)
725 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
729 return data
->tolerance_up
;
733 * adg_dim_set_tolerance_up:
735 * @tolerance_up: the upper tolerance
737 * Sets the upper tolerance. Use %NULL as @tolerance_up to disable it.
740 adg_dim_set_tolerance_up(AdgDim
*dim
, const gchar
*tolerance_up
)
744 g_return_if_fail(ADG_IS_DIM(dim
));
748 g_free(data
->tolerance_up
);
749 data
->tolerance_up
= g_strdup(tolerance_up
);
750 g_object_notify((GObject
*) dim
, "tolerance-up");
752 text_cache_clear(&data
->tolerance_up_cache
);
756 * adg_dim_get_tolerance_down:
759 * Gets the lower tolerance text or %NULL on lower tolerance disabled.
760 * The string is internally owned and must not be freed or modified.
762 * Return value: the tolerance text
765 adg_dim_get_tolerance_down(AdgDim
*dim
)
769 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
773 return data
->tolerance_down
;
777 * adg_dim_set_tolerance_down:
779 * @tolerance_down: the lower tolerance
781 * Sets the lower tolerance. Use %NULL as @tolerance_down to disable it.
784 adg_dim_set_tolerance_down(AdgDim
*dim
, const gchar
*tolerance_down
)
788 g_return_if_fail(ADG_IS_DIM(dim
));
792 g_free(data
->tolerance_down
);
793 data
->tolerance_down
= g_strdup(tolerance_down
);
794 g_object_notify((GObject
*) dim
, "tolerance-down");
796 text_cache_clear(&data
->tolerance_down_cache
);
800 * adg_dim_set_tolerances:
802 * @tolerance_up: the upper tolerance text
803 * @tolerance_down: the lower tolerance text
805 * Shortcut to set both the tolerance at once.
808 adg_dim_set_tolerances(AdgDim
*dim
, const gchar
*tolerance_up
,
809 const gchar
*tolerance_down
)
811 g_return_if_fail(ADG_IS_DIM(dim
));
813 g_object_freeze_notify((GObject
*) dim
);
814 adg_dim_set_tolerance_up(dim
, tolerance_up
);
815 adg_dim_set_tolerance_down(dim
, tolerance_down
);
816 g_object_thaw_notify((GObject
*) dim
);
823 * Gets the note text or %NULL if the note is not used. The string is
824 * internally owned and must not be freed or modified.
826 * Return value: the note text
829 adg_dim_get_note(AdgDim
*dim
)
833 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
843 * @note: the new note
845 * Sets a new note text, usually appended at the end of the dimension text.
848 adg_dim_set_note(AdgDim
*dim
, const gchar
*note
)
852 g_return_if_fail(ADG_IS_DIM(dim
));
857 data
->note
= g_strdup(note
);
858 g_object_notify((GObject
*) dim
, "note");
860 text_cache_clear(&data
->note_cache
);
864 * adg_dim_render_quote:
865 * @dim: an #AdgDim object
866 * @cr: a #cairo_t drawing context
868 * Renders the quote of @dim at the @org position. This function
869 * is only useful in new dimension implementations.
872 adg_dim_render_quote(AdgDim
*dim
, cairo_t
*cr
)
876 AdgDimStyle
*dim_style
;
877 AdgMatrix global
, local
;
878 cairo_matrix_t matrix
;
880 g_return_if_fail(ADG_IS_DIM(dim
));
883 entity
= (AdgEntity
*) dim
;
884 dim_style
= (AdgDimStyle
*) adg_entity_get_style(entity
, ADG_SLOT_DIM_STYLE
);
885 adg_entity_get_global_matrix(entity
, &global
);
886 adg_entity_get_local_matrix(entity
, &local
);
888 if (data
->quote
== NULL
)
889 adg_dim_set_quote(dim
, ADG_DIM_GET_CLASS(dim
)->default_quote(dim
));
893 cairo_set_matrix(cr
, &global
);
894 ADG_DIM_GET_CLASS(dim
)->quote_layout(dim
, cr
);
895 adg_style_apply(adg_dim_style_get_quote_style(dim_style
), cr
);
897 cairo_set_matrix(cr
, &local
);
898 cairo_translate(cr
, data
->org
.x
, data
->org
.y
);
899 cairo_get_matrix(cr
, &matrix
);
900 matrix
.xx
= global
.xx
;
901 matrix
.yy
= global
.yy
;
902 cairo_set_matrix(cr
, &matrix
);
903 cairo_rotate(cr
, -data
->angle
);
905 /* Rendering quote */
906 text_cache_render(&data
->quote_cache
, cr
);
908 /* Rendering tolerances */
909 if (data
->tolerance_up
!= NULL
|| data
->tolerance_down
!= NULL
) {
910 adg_style_apply(adg_dim_style_get_tolerance_style(dim_style
), cr
);
912 if (data
->tolerance_up
!= NULL
)
913 text_cache_render(&data
->tolerance_up_cache
, cr
);
915 if (data
->tolerance_down
!= NULL
)
916 text_cache_render(&data
->tolerance_down_cache
, cr
);
919 /* Rendering the note */
920 if (data
->note
!= NULL
) {
921 adg_style_apply(adg_dim_style_get_note_style(dim_style
), cr
);
922 text_cache_render(&data
->note_cache
, cr
);
930 invalidate(AdgEntity
*entity
)
932 AdgEntityClass
*entity_class
= (AdgEntityClass
*) adg_dim_parent_class
;
934 clear((AdgDim
*) entity
);
936 if (entity_class
->invalidate
!= NULL
)
937 entity_class
->invalidate(entity
);
943 AdgDimPrivate
*data
= dim
->data
;
945 text_cache_clear(&data
->quote_cache
);
946 text_cache_clear(&data
->tolerance_up_cache
);
947 text_cache_clear(&data
->tolerance_down_cache
);
948 text_cache_clear(&data
->note_cache
);
952 default_quote(AdgDim
*dim
)
954 g_warning("AdgDim::default_quote not implemented for `%s'",
955 g_type_name(G_TYPE_FROM_INSTANCE(dim
)));
956 return g_strdup("undef");
960 quote_layout(AdgDim
*dim
, cairo_t
*cr
)
963 AdgDimStyle
*dim_style
;
966 CpmlPair tolerance_up_org
, tolerance_down_org
, note_org
;
969 dim_style
= (AdgDimStyle
*) adg_entity_get_style((AdgEntity
*) dim
,
971 tolerance_up_org
.x
= tolerance_up_org
.y
= 0;
972 tolerance_down_org
.x
= tolerance_down_org
.y
= 0;
973 note_org
.x
= note_org
.y
= 0;
975 /* Compute the quote */
976 if (text_cache_update(&data
->quote_cache
, data
->quote
, cr
,
977 adg_dim_style_get_quote_style(dim_style
))) {
978 cp
.x
= data
->quote_cache
.extents
.width
;
979 cp
.y
= data
->quote_cache
.extents
.height
/ -2.;
985 /* Compute the tolerances */
986 if (data
->tolerance_up
!= NULL
|| data
->tolerance_down
!= NULL
) {
990 adg_style_apply(adg_dim_style_get_tolerance_style(dim_style
), cr
);
993 midspacing
= adg_dim_style_get_tolerance_spacing(dim_style
) / 2.;
994 cpml_pair_copy(&shift
, adg_dim_style_get_tolerance_shift(dim_style
));
997 if (text_cache_update(&data
->tolerance_up_cache
,
998 data
->tolerance_up
, cr
, NULL
)) {
999 tolerance_up_org
.x
= cp
.x
;
1000 tolerance_up_org
.y
= cp
.y
+ shift
.y
- midspacing
;
1002 width
= data
->tolerance_up_cache
.extents
.width
;
1005 if (text_cache_update(&data
->tolerance_down_cache
,
1006 data
->tolerance_down
, cr
, NULL
)) {
1007 tolerance_down_org
.x
= cp
.x
;
1008 tolerance_down_org
.y
= cp
.y
+ shift
.y
+ midspacing
+
1009 data
->tolerance_down_cache
.extents
.height
;
1011 if (data
->tolerance_down_cache
.extents
.width
> width
)
1012 width
= data
->tolerance_down_cache
.extents
.width
;
1018 /* Compute the note */
1019 if (text_cache_update(&data
->note_cache
, data
->note
, cr
,
1020 adg_dim_style_get_note_style(dim_style
))) {
1021 cpml_pair_copy(&shift
, adg_dim_style_get_note_shift(dim_style
));
1025 note_org
.y
= cp
.y
+ shift
.y
+ data
->note_cache
.extents
.height
/ 2.;
1027 cp
.x
+= data
->note_cache
.extents
.width
;
1030 /* Centering and shifting the whole group */
1031 cpml_pair_copy(&shift
, adg_dim_style_get_quote_shift(dim_style
));
1032 shift
.x
-= cp
.x
/ 2.;
1034 if (data
->quote_cache
.glyphs
) {
1035 text_cache_move_to(&data
->quote_cache
, &shift
);
1038 if (data
->tolerance_up_cache
.glyphs
) {
1039 tolerance_up_org
.x
+= shift
.x
;
1040 tolerance_up_org
.y
+= shift
.y
;
1041 text_cache_move_to(&data
->tolerance_up_cache
, &tolerance_up_org
);
1044 if (data
->tolerance_down_cache
.glyphs
) {
1045 tolerance_down_org
.x
+= shift
.x
;
1046 tolerance_down_org
.y
+= shift
.y
;
1047 text_cache_move_to(&data
->tolerance_down_cache
, &tolerance_down_org
);
1050 if (data
->note_cache
.glyphs
) {
1051 note_org
.x
+= shift
.x
;
1052 note_org
.y
+= shift
.y
;
1053 text_cache_move_to(&data
->note_cache
, ¬e_org
);
1058 text_cache_init(AdgTextCache
*text_cache
)
1060 text_cache
->utf8
= NULL
;
1061 text_cache
->utf8_len
= -1;
1062 text_cache
->glyphs
= NULL
;
1063 text_cache
->num_glyphs
= 0;
1064 text_cache
->clusters
= NULL
;
1065 text_cache
->num_clusters
= 0;
1066 text_cache
->cluster_flags
= 0;
1067 memset(&text_cache
->extents
, 0, sizeof(text_cache
->extents
));
1071 text_cache_update(AdgTextCache
*text_cache
, const gchar
*text
,
1072 cairo_t
*cr
, AdgStyle
*style
)
1077 text_cache
->utf8
= text
;
1078 text_cache
->utf8_len
= g_utf8_strlen(text
, -1);
1081 adg_style_apply(style
, cr
);
1083 if (!text_cache
->glyphs
) {
1084 cairo_status_t status
;
1086 status
= cairo_scaled_font_text_to_glyphs(cairo_get_scaled_font(cr
),
1089 text_cache
->utf8_len
,
1090 &text_cache
->glyphs
,
1091 &text_cache
->num_glyphs
,
1092 &text_cache
->clusters
,
1093 &text_cache
->num_clusters
,
1094 &text_cache
->cluster_flags
);
1096 if (status
!= CAIRO_STATUS_SUCCESS
) {
1097 g_error("Unable to build glyphs (cairo message: %s)",
1098 cairo_status_to_string(status
));
1102 cairo_glyph_extents(cr
, text_cache
->glyphs
, text_cache
->num_glyphs
,
1103 &text_cache
->extents
);
1110 text_cache_clear(AdgTextCache
*text_cache
)
1112 text_cache
->utf8
= NULL
;
1113 text_cache
->utf8_len
= -1;
1115 if (text_cache
->glyphs
) {
1116 cairo_glyph_free(text_cache
->glyphs
);
1117 text_cache
->glyphs
= NULL
;
1118 text_cache
->num_glyphs
= 0;
1120 if (text_cache
->clusters
) {
1121 cairo_text_cluster_free(text_cache
->clusters
);
1122 text_cache
->clusters
= NULL
;
1123 text_cache
->num_clusters
= 0;
1124 text_cache
->cluster_flags
= 0;
1126 memset(&text_cache
->extents
, 0, sizeof(text_cache
->extents
));
1130 text_cache_move_to(AdgTextCache
*text_cache
, const CpmlPair
*to
)
1132 cairo_glyph_t
*glyph
;
1136 glyph
= text_cache
->glyphs
;
1137 cnt
= text_cache
->num_glyphs
;
1138 x
= to
->x
- glyph
->x
;
1139 y
= to
->y
- glyph
->y
;
1149 text_cache_render(AdgTextCache
*text_cache
, cairo_t
*cr
)
1151 cairo_show_text_glyphs(cr
, text_cache
->utf8
, text_cache
->utf8_len
,
1152 text_cache
->glyphs
, text_cache
->num_glyphs
,
1153 text_cache
->clusters
, text_cache
->num_clusters
,
1154 text_cache
->cluster_flags
);