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.
29 #include "adg-dim-private.h"
34 #define PARENT_CLASS ((AdgEntityClass *) adg_dim_parent_class)
51 static void finalize (GObject
*object
);
52 static void get_property (GObject
*object
,
56 static void set_property (GObject
*object
,
60 static void paper_matrix_changed (AdgEntity
*entity
,
61 AdgMatrix
*parent_matrix
);
62 static void invalidate (AdgEntity
*entity
);
63 static void clear (AdgDim
*entity
);
64 static gchar
* default_quote (AdgDim
*dim
);
65 static void quote_layout (AdgDim
*dim
,
67 static void text_cache_init (AdgTextCache
*text_cache
);
68 static gboolean
text_cache_update (AdgTextCache
*text_cache
,
72 static void text_cache_clear (AdgTextCache
*text_cache
);
73 static void text_cache_move_to (AdgTextCache
*text_cache
,
75 static void text_cache_render (AdgTextCache
*text_cache
,
79 G_DEFINE_ABSTRACT_TYPE(AdgDim
, adg_dim
, ADG_TYPE_ENTITY
);
83 adg_dim_class_init(AdgDimClass
*klass
)
85 GObjectClass
*gobject_class
;
86 AdgEntityClass
*entity_class
;
89 gobject_class
= (GObjectClass
*) klass
;
90 entity_class
= (AdgEntityClass
*) klass
;
92 g_type_class_add_private(klass
, sizeof(AdgDimPrivate
));
94 gobject_class
->finalize
= finalize
;
95 gobject_class
->get_property
= get_property
;
96 gobject_class
->set_property
= set_property
;
98 entity_class
->paper_matrix_changed
= paper_matrix_changed
;
99 entity_class
->invalidate
= invalidate
;
101 klass
->default_quote
= default_quote
;
102 klass
->quote_layout
= quote_layout
;
104 param
= g_param_spec_boxed("ref1",
106 P_("First reference point of the dimension"),
108 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
109 g_object_class_install_property(gobject_class
, PROP_REF1
, param
);
111 param
= g_param_spec_boxed("ref2",
113 P_("Second reference point of the dimension"),
115 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
116 g_object_class_install_property(gobject_class
, PROP_REF2
, param
);
118 param
= g_param_spec_boxed("pos1",
120 P_("First position point: it will be computed with the level property to get the real dimension position"),
121 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
122 g_object_class_install_property(gobject_class
, PROP_POS1
, param
);
124 param
= g_param_spec_boxed("pos2",
126 P_("Second position point: it will be computed with the level property to get the real dimension position"),
127 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
128 g_object_class_install_property(gobject_class
, PROP_POS2
, param
);
130 param
= g_param_spec_double("level",
132 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"),
133 -G_MAXDOUBLE
, G_MAXDOUBLE
, 1.0,
134 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
135 g_object_class_install_property(gobject_class
, PROP_LEVEL
, param
);
137 param
= g_param_spec_string("quote",
139 P_("The quote to display: set to NULL to get the default quote"),
140 NULL
, G_PARAM_READWRITE
);
141 g_object_class_install_property(gobject_class
, PROP_QUOTE
, param
);
143 param
= g_param_spec_string("tolerance-up",
145 P_("The up tolerance of the quote: set to NULL to suppress"),
146 NULL
, G_PARAM_READWRITE
);
147 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_UP
, param
);
149 param
= g_param_spec_string("tolerance-down",
150 P_("Down Tolerance"),
151 P_("The down tolerance of the quote: set to NULL to suppress"),
152 NULL
, G_PARAM_READWRITE
);
153 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_DOWN
, param
);
155 param
= g_param_spec_string("note",
157 P_("A custom note appended to the dimension quote"),
158 NULL
, G_PARAM_READWRITE
);
159 g_object_class_install_property(gobject_class
, PROP_NOTE
, param
);
163 adg_dim_init(AdgDim
*dim
)
165 AdgDimPrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE(dim
, ADG_TYPE_DIM
,
168 priv
->ref1
.x
= priv
->ref1
.y
= 0;
169 priv
->ref2
.x
= priv
->ref2
.y
= 0;
170 priv
->pos1
.x
= priv
->pos1
.y
= 0;
171 priv
->pos2
.x
= priv
->pos2
.y
= 0;
174 priv
->tolerance_up
= NULL
;
175 priv
->tolerance_down
= NULL
;
178 priv
->org
.x
= priv
->org
.y
= 0;
180 text_cache_init(&priv
->quote_cache
);
181 text_cache_init(&priv
->tolerance_up_cache
);
182 text_cache_init(&priv
->tolerance_down_cache
);
183 text_cache_init(&priv
->note_cache
);
189 finalize(GObject
*object
)
191 AdgDim
*dim
= (AdgDim
*) object
;
193 g_free(dim
->priv
->quote
);
194 g_free(dim
->priv
->tolerance_up
);
195 g_free(dim
->priv
->tolerance_down
);
199 ((GObjectClass
*) PARENT_CLASS
)->finalize(object
);
203 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
205 AdgDim
*dim
= (AdgDim
*) object
;
209 g_value_set_boxed(value
, &dim
->priv
->ref1
);
212 g_value_set_boxed(value
, &dim
->priv
->ref2
);
215 g_value_set_boxed(value
, &dim
->priv
->pos1
);
218 g_value_set_boxed(value
, &dim
->priv
->pos1
);
221 g_value_set_double(value
, dim
->priv
->level
);
224 g_value_set_string(value
, dim
->priv
->quote
);
226 case PROP_TOLERANCE_UP
:
227 g_value_set_string(value
, dim
->priv
->tolerance_up
);
229 case PROP_TOLERANCE_DOWN
:
230 g_value_set_string(value
, dim
->priv
->tolerance_down
);
233 g_value_set_string(value
, dim
->priv
->note
);
236 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
242 set_property(GObject
*object
, guint prop_id
,
243 const GValue
*value
, GParamSpec
*pspec
)
248 entity
= (AdgEntity
*) object
;
249 dim
= (AdgDim
*) object
;
253 cpml_pair_copy(&dim
->priv
->ref1
, (AdgPair
*) g_value_get_boxed(value
));
257 cpml_pair_copy(&dim
->priv
->ref2
, (AdgPair
*) g_value_get_boxed(value
));
261 cpml_pair_copy(&dim
->priv
->pos1
, (AdgPair
*) g_value_get_boxed(value
));
265 cpml_pair_copy(&dim
->priv
->pos2
, (AdgPair
*) g_value_get_boxed(value
));
269 dim
->priv
->level
= g_value_get_double(value
);
273 g_free(dim
->priv
->quote
);
274 dim
->priv
->quote
= g_value_dup_string(value
);
275 text_cache_clear(&dim
->priv
->quote_cache
);
277 case PROP_TOLERANCE_UP
:
278 g_free(dim
->priv
->tolerance_up
);
279 dim
->priv
->tolerance_up
= g_value_dup_string(value
);
280 text_cache_clear(&dim
->priv
->tolerance_up_cache
);
282 case PROP_TOLERANCE_DOWN
:
283 g_free(dim
->priv
->tolerance_down
);
284 dim
->priv
->tolerance_down
= g_value_dup_string(value
);
285 text_cache_clear(&dim
->priv
->tolerance_down_cache
);
288 g_free(dim
->priv
->note
);
289 dim
->priv
->note
= g_value_dup_string(value
);
290 text_cache_clear(&dim
->priv
->note_cache
);
293 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
303 * Gets the origin (org) coordinates. The returned pair is internally
304 * owned and must not be freed or modified. This function is only
305 * useful in new dimension implementations.
307 * Return value: the org coordinates
310 adg_dim_get_org(AdgDim
*dim
)
312 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
314 return &dim
->priv
->org
;
320 * @org: the org coordinates
322 * Sets new org coordinates. This function is only useful
323 * in new dimension implementations.
326 adg_dim_set_org(AdgDim
*dim
, const AdgPair
*org
)
328 g_return_if_fail(ADG_IS_DIM(dim
));
329 g_return_if_fail(org
!= NULL
);
331 dim
->priv
->org
= *org
;
335 * adg_dim_set_org_explicit:
337 * @org_x: x component of org
338 * @org_y: y component of org
340 * Explicitely sets new org coordinates. This function is only useful
341 * in new dimension implementations.
344 adg_dim_set_org_explicit(AdgDim
*dim
, gdouble org_x
, gdouble org_y
)
346 g_return_if_fail(ADG_IS_DIM(dim
));
348 dim
->priv
->org
.x
= org_x
;
349 dim
->priv
->org
.y
= org_y
;
356 * Gets the dimension angle. This function is only useful
357 * in new dimension implementations.
359 * Return value: the angle (in radians)
362 adg_dim_get_angle(AdgDim
*dim
)
364 g_return_val_if_fail(ADG_IS_DIM(dim
), 0);
366 return dim
->priv
->angle
;
372 * @angle: the new angle (in radians)
374 * Sets a new dimension angle. This function is only useful
375 * in new dimension implementations.
378 adg_dim_set_angle(AdgDim
*dim
, gdouble angle
)
380 g_return_if_fail(ADG_IS_DIM(dim
));
382 dim
->priv
->angle
= angle
;
389 * Gets the ref1 coordinates. The returned pair is internally owned
390 * and must not be freed or modified.
392 * Return value: the ref1 coordinates
395 adg_dim_get_ref1(AdgDim
*dim
)
397 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
399 return &dim
->priv
->ref1
;
406 * Gets the ref2 coordinates. The returned pair is internally owned
407 * and must not be freed or modified.
409 * Return value: the ref2 coordinates
412 adg_dim_get_ref2(AdgDim
*dim
)
414 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
416 return &dim
->priv
->ref2
;
422 * @ref1: the ref1 coordinates
423 * @ref2: the ref2 coordinates
425 * Shortcut to set ref1 and ref2 points at once.
428 adg_dim_set_ref(AdgDim
*dim
, const AdgPair
*ref1
, const AdgPair
*ref2
)
430 g_return_if_fail(ADG_IS_DIM(dim
));
432 if (ref1
!= NULL
|| ref2
!= NULL
) {
433 GObject
*object
= (GObject
*) dim
;
435 g_object_freeze_notify(object
);
438 dim
->priv
->ref1
= *ref1
;
439 g_object_notify(object
, "ref1");
443 dim
->priv
->ref2
= *ref2
;
444 g_object_notify(object
, "ref2");
447 g_object_thaw_notify(object
);
453 * adg_dim_set_ref_explicit:
455 * @ref1_x: x component of pos1
456 * @ref1_y: y component of pos1
457 * @ref2_x: x component of pos2
458 * @ref2_y: y component of pos2
460 * Shortcut to set ref1 and ref2 points at once,
461 * using explicit coordinates.
464 adg_dim_set_ref_explicit(AdgDim
*dim
, gdouble ref1_x
, gdouble ref1_y
,
465 gdouble ref2_x
, gdouble ref2_y
)
475 adg_dim_set_ref(dim
, &ref1
, &ref2
);
482 * Gets the pos1 coordinates. The returned pair is internally owned
483 * and must not be freed or modified.
485 * Return value: the pos1 coordinates
488 adg_dim_get_pos1(AdgDim
*dim
)
490 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
492 return &dim
->priv
->pos1
;
499 * Gets the pos2 coordinates. The returned pair is internally owned
500 * and must not be freed or modified.
502 * Return value: the pos2 coordinates
505 adg_dim_get_pos2(AdgDim
*dim
)
507 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
509 return &dim
->priv
->pos2
;
515 * @pos1: the pos1 coordinates
516 * @pos2: the pos2 coordinates
518 * Shortcut to set pos1 and pos2 points at once.
521 adg_dim_set_pos(AdgDim
*dim
, AdgPair
*pos1
, AdgPair
*pos2
)
523 g_return_if_fail(ADG_IS_DIM(dim
));
525 if (pos1
!= NULL
|| pos2
!= NULL
) {
526 GObject
*object
= (GObject
*) dim
;
528 g_object_freeze_notify(object
);
531 dim
->priv
->pos1
= *pos1
;
532 g_object_notify(object
, "pos1");
535 dim
->priv
->pos2
= *pos2
;
536 g_object_notify(object
, "pos2");
539 g_object_thaw_notify(object
);
545 * adg_dim_set_pos_explicit:
547 * @pos1_x: x component of pos1
548 * @pos1_y: y component of pos1
549 * @pos2_x: x component of pos2
550 * @pos2_y: y component of pos2
552 * Shortcut to set pos1 and pos2 points at once,
553 * using explicit coordinates.
556 adg_dim_set_pos_explicit(AdgDim
*dim
, gdouble pos1_x
, gdouble pos1_y
,
557 gdouble pos2_x
, gdouble pos2_y
)
567 adg_dim_set_pos(dim
, &pos1
, &pos2
);
574 * Gets the level of this dimension.
576 * Return value: the level value
579 adg_dim_get_level(AdgDim
*dim
)
581 g_return_val_if_fail(ADG_IS_DIM(dim
), 0);
583 return dim
->priv
->level
;
589 * @level: the new level
591 * Sets a new level for this dimension. The level is used to
592 * stack the quotes using a spacing value from dim_style
593 * (specified in paper space).
596 adg_dim_set_level(AdgDim
*dim
, gdouble level
)
598 g_return_if_fail(ADG_IS_DIM(dim
));
600 dim
->priv
->level
= level
;
601 g_object_notify((GObject
*) dim
, "level");
609 * Gets the quote text. The string is internally owned and
610 * must not be freed or modified.
612 * Return value: the quote text
615 adg_dim_get_quote(AdgDim
*dim
)
617 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
619 return dim
->priv
->quote
;
625 * @quote: the quote text
627 * Explicitely sets the text to use as quote. If @quote is %NULL or
628 * was never set, an automatic text is calculated using the format as
629 * specified by the dim_style associated to this entity and getting
630 * the number from the construction points (ref1, ref2, pos1 and pos2).
633 adg_dim_set_quote(AdgDim
*dim
, const gchar
*quote
)
635 g_return_if_fail(ADG_IS_DIM(dim
));
637 g_free(dim
->priv
->quote
);
638 dim
->priv
->quote
= g_strdup(quote
);
639 g_object_notify((GObject
*) dim
, "quote");
641 text_cache_clear(&dim
->priv
->quote_cache
);
645 * adg_dim_get_tolerance_up:
648 * Gets the upper tolerance text or %NULL on upper tolerance disabled.
649 * The string is internally owned and must not be freed or modified.
651 * Return value: the tolerance text
654 adg_dim_get_tolerance_up(AdgDim
*dim
)
656 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
658 return dim
->priv
->tolerance_up
;
662 * adg_dim_set_tolerance_up:
664 * @tolerance_up: the upper tolerance
666 * Sets the upper tolerance. Use %NULL as @tolerance_up to disable it.
669 adg_dim_set_tolerance_up(AdgDim
*dim
, const gchar
*tolerance_up
)
671 g_return_if_fail(ADG_IS_DIM(dim
));
673 g_free(dim
->priv
->tolerance_up
);
674 dim
->priv
->tolerance_up
= g_strdup(tolerance_up
);
675 g_object_notify((GObject
*) dim
, "tolerance-up");
677 text_cache_clear(&dim
->priv
->tolerance_up_cache
);
681 * adg_dim_get_tolerance_down:
684 * Gets the lower tolerance text or %NULL on lower tolerance disabled.
685 * The string is internally owned and must not be freed or modified.
687 * Return value: the tolerance text
690 adg_dim_get_tolerance_down(AdgDim
*dim
)
692 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
694 return dim
->priv
->tolerance_down
;
698 * adg_dim_set_tolerance_down:
700 * @tolerance_down: the lower tolerance
702 * Sets the lower tolerance. Use %NULL as @tolerance_down to disable it.
705 adg_dim_set_tolerance_down(AdgDim
*dim
, const gchar
*tolerance_down
)
707 g_return_if_fail(ADG_IS_DIM(dim
));
709 g_free(dim
->priv
->tolerance_down
);
710 dim
->priv
->tolerance_down
= g_strdup(tolerance_down
);
711 g_object_notify((GObject
*) dim
, "tolerance-down");
713 text_cache_clear(&dim
->priv
->tolerance_down_cache
);
717 * adg_dim_set_tolerances:
719 * @tolerance_up: the upper tolerance text
720 * @tolerance_down: the lower tolerance text
722 * Shortcut to set both the tolerance at once.
725 adg_dim_set_tolerances(AdgDim
*dim
, const gchar
*tolerance_up
,
726 const gchar
*tolerance_down
)
728 g_return_if_fail(ADG_IS_DIM(dim
));
730 g_object_freeze_notify((GObject
*) dim
);
731 adg_dim_set_tolerance_up(dim
, tolerance_up
);
732 adg_dim_set_tolerance_down(dim
, tolerance_down
);
733 g_object_thaw_notify((GObject
*) dim
);
740 * Gets the note text or %NULL if the note is not used. The string is
741 * internally owned and must not be freed or modified.
743 * Return value: the note text
746 adg_dim_get_note(AdgDim
*dim
)
748 g_return_val_if_fail(ADG_IS_DIM(dim
), NULL
);
750 return dim
->priv
->note
;
756 * @note: the new note
758 * Sets a new note text, usually appended at the end of the dimension text.
761 adg_dim_set_note(AdgDim
*dim
, const gchar
*note
)
763 g_return_if_fail(ADG_IS_DIM(dim
));
765 g_free(dim
->priv
->note
);
766 dim
->priv
->note
= g_strdup(note
);
767 g_object_notify((GObject
*) dim
, "note");
769 text_cache_clear(&dim
->priv
->note_cache
);
773 * adg_dim_render_quote:
774 * @dim: an #AdgDim object
775 * @cr: a #cairo_t drawing context
777 * Renders the quote of @dim at the @org position. This function
778 * is only useful in new dimension implementations.
781 adg_dim_render_quote(AdgDim
*dim
, cairo_t
*cr
)
784 AdgDimStyle
*dim_style
;
786 g_return_if_fail(ADG_IS_DIM(dim
));
789 dim_style
= (AdgDimStyle
*) adg_entity_get_style((AdgEntity
*) dim
,
792 if (priv
->quote
== NULL
)
793 adg_dim_set_quote(dim
, ADG_DIM_GET_CLASS(dim
)->default_quote(dim
));
797 cairo_set_matrix(cr
, adg_entity_get_paper_matrix((AdgEntity
*) dim
));
798 ADG_DIM_GET_CLASS(dim
)->quote_layout(dim
, cr
);
799 cairo_set_matrix(cr
, adg_entity_get_model_matrix((AdgEntity
*) dim
));
801 cairo_translate(cr
, priv
->org
.x
, priv
->org
.y
);
802 adg_entity_scale_to_paper((AdgEntity
*) dim
, cr
);
803 cairo_rotate(cr
, -priv
->angle
);
805 /* Rendering quote */
806 adg_style_apply(adg_dim_style_get_quote_style(dim_style
), cr
);
807 text_cache_render(&priv
->quote_cache
, cr
);
809 /* Rendering tolerances */
810 if (priv
->tolerance_up
!= NULL
|| priv
->tolerance_down
!= NULL
) {
811 adg_style_apply(adg_dim_style_get_tolerance_style(dim_style
), cr
);
813 if (priv
->tolerance_up
!= NULL
)
814 text_cache_render(&priv
->tolerance_up_cache
, cr
);
816 if (priv
->tolerance_down
!= NULL
)
817 text_cache_render(&priv
->tolerance_down_cache
, cr
);
820 /* Rendering the note */
821 if (priv
->note
!= NULL
) {
822 adg_style_apply(adg_dim_style_get_note_style(dim_style
), cr
);
823 text_cache_render(&priv
->note_cache
, cr
);
831 paper_matrix_changed(AdgEntity
*entity
, AdgMatrix
*parent_matrix
)
833 clear((AdgDim
*) entity
);
834 PARENT_CLASS
->paper_matrix_changed(entity
, parent_matrix
);
838 invalidate(AdgEntity
*entity
)
840 clear((AdgDim
*) entity
);
841 PARENT_CLASS
->invalidate(entity
);
847 text_cache_clear(&dim
->priv
->quote_cache
);
848 text_cache_clear(&dim
->priv
->tolerance_up_cache
);
849 text_cache_clear(&dim
->priv
->tolerance_down_cache
);
850 text_cache_clear(&dim
->priv
->note_cache
);
854 default_quote(AdgDim
*dim
)
856 g_warning("AdgDim::default_quote not implemented for `%s'",
857 g_type_name(G_TYPE_FROM_INSTANCE(dim
)));
858 return g_strdup("undef");
862 quote_layout(AdgDim
*dim
, cairo_t
*cr
)
865 AdgDimStyle
*dim_style
;
868 CpmlPair tolerance_up_org
, tolerance_down_org
, note_org
;
871 dim_style
= (AdgDimStyle
*) adg_entity_get_style((AdgEntity
*) dim
,
874 /* Compute the quote */
875 if (text_cache_update(&priv
->quote_cache
, priv
->quote
, cr
,
876 adg_dim_style_get_quote_style(dim_style
))) {
877 cp
.x
= priv
->quote_cache
.extents
.width
;
878 cp
.y
= priv
->quote_cache
.extents
.height
/ -2.;
884 /* Compute the tolerances */
885 if (priv
->tolerance_up
!= NULL
|| priv
->tolerance_down
!= NULL
) {
889 adg_style_apply(adg_dim_style_get_tolerance_style(dim_style
), cr
);
892 midspacing
= adg_dim_style_get_tolerance_spacing(dim_style
) / 2.;
893 cpml_pair_copy(&shift
, adg_dim_style_get_tolerance_shift(dim_style
));
896 if (text_cache_update(&priv
->tolerance_up_cache
,
897 priv
->tolerance_up
, cr
, NULL
)) {
898 tolerance_up_org
.x
= cp
.x
;
899 tolerance_up_org
.y
= cp
.y
+ shift
.y
- midspacing
;
901 width
= priv
->tolerance_up_cache
.extents
.width
;
904 if (text_cache_update(&priv
->tolerance_down_cache
,
905 priv
->tolerance_down
, cr
, NULL
)) {
906 tolerance_down_org
.x
= cp
.x
;
907 tolerance_down_org
.y
= cp
.y
+ shift
.y
+ midspacing
+
908 priv
->tolerance_down_cache
.extents
.height
;
910 if (priv
->tolerance_down_cache
.extents
.width
> width
)
911 width
= priv
->tolerance_down_cache
.extents
.width
;
917 /* Compute the note */
918 if (text_cache_update(&priv
->note_cache
, priv
->note
, cr
,
919 adg_dim_style_get_note_style(dim_style
))) {
920 cpml_pair_copy(&shift
, adg_dim_style_get_note_shift(dim_style
));
924 note_org
.y
= cp
.y
+ shift
.y
+ priv
->note_cache
.extents
.height
/ 2.;
926 cp
.x
+= priv
->note_cache
.extents
.width
;
929 /* Centering and shifting the whole group */
930 cpml_pair_copy(&shift
, adg_dim_style_get_quote_shift(dim_style
));
931 shift
.x
-= cp
.x
/ 2.;
933 if (priv
->quote_cache
.glyphs
) {
934 text_cache_move_to(&priv
->quote_cache
, &shift
);
937 if (priv
->tolerance_up_cache
.glyphs
) {
938 tolerance_up_org
.x
+= shift
.x
;
939 tolerance_up_org
.y
+= shift
.y
;
940 text_cache_move_to(&priv
->tolerance_up_cache
, &tolerance_up_org
);
943 if (priv
->tolerance_down_cache
.glyphs
) {
944 tolerance_down_org
.x
+= shift
.x
;
945 tolerance_down_org
.y
+= shift
.y
;
946 text_cache_move_to(&priv
->tolerance_down_cache
, &tolerance_down_org
);
949 if (priv
->note_cache
.glyphs
) {
950 note_org
.x
+= shift
.x
;
951 note_org
.y
+= shift
.y
;
952 text_cache_move_to(&priv
->note_cache
, ¬e_org
);
957 text_cache_init(AdgTextCache
*text_cache
)
959 text_cache
->utf8
= NULL
;
960 text_cache
->utf8_len
= -1;
961 text_cache
->glyphs
= NULL
;
962 text_cache
->num_glyphs
= 0;
963 text_cache
->clusters
= NULL
;
964 text_cache
->num_clusters
= 0;
965 text_cache
->cluster_flags
= 0;
966 memset(&text_cache
->extents
, 0, sizeof(text_cache
->extents
));
970 text_cache_update(AdgTextCache
*text_cache
, const gchar
*text
,
971 cairo_t
*cr
, AdgStyle
*style
)
976 text_cache
->utf8
= text
;
977 text_cache
->utf8_len
= g_utf8_strlen(text
, -1);
980 adg_style_apply(style
, cr
);
982 if (!text_cache
->glyphs
) {
983 cairo_status_t status
;
985 status
= cairo_scaled_font_text_to_glyphs(cairo_get_scaled_font(cr
),
988 text_cache
->utf8_len
,
990 &text_cache
->num_glyphs
,
991 &text_cache
->clusters
,
992 &text_cache
->num_clusters
,
993 &text_cache
->cluster_flags
);
995 if (status
!= CAIRO_STATUS_SUCCESS
) {
996 g_error("Unable to build glyphs (cairo message: %s)",
997 cairo_status_to_string(status
));
1001 cairo_glyph_extents(cr
, text_cache
->glyphs
, text_cache
->num_glyphs
,
1002 &text_cache
->extents
);
1009 text_cache_clear(AdgTextCache
*text_cache
)
1011 text_cache
->utf8
= NULL
;
1012 text_cache
->utf8_len
= -1;
1014 if (text_cache
->glyphs
) {
1015 cairo_glyph_free(text_cache
->glyphs
);
1016 text_cache
->glyphs
= NULL
;
1017 text_cache
->num_glyphs
= 0;
1019 if (text_cache
->clusters
) {
1020 cairo_text_cluster_free(text_cache
->clusters
);
1021 text_cache
->clusters
= NULL
;
1022 text_cache
->num_clusters
= 0;
1023 text_cache
->cluster_flags
= 0;
1025 memset(&text_cache
->extents
, 0, sizeof(text_cache
->extents
));
1029 text_cache_move_to(AdgTextCache
*text_cache
, const CpmlPair
*to
)
1031 cairo_glyph_t
*glyph
;
1035 glyph
= text_cache
->glyphs
;
1036 cnt
= text_cache
->num_glyphs
;
1037 x
= to
->x
- glyph
->x
;
1038 y
= to
->y
- glyph
->y
;
1048 text_cache_render(AdgTextCache
*text_cache
, cairo_t
*cr
)
1050 cairo_show_text_glyphs(cr
, text_cache
->utf8
, text_cache
->utf8_len
,
1051 text_cache
->glyphs
, text_cache
->num_glyphs
,
1052 text_cache
->clusters
, text_cache
->num_clusters
,
1053 text_cache
->cluster_flags
);