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: Linear dimensions
25 * The #AdgLDim entity represents a linear dimension.
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
37 #include "adg-ldim-private.h"
38 #include "adg-dim-private.h"
39 #include "adg-dim-style.h"
42 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_ldim_parent_class)
43 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_ldim_parent_class)
54 static void dispose (GObject
*object
);
55 static void get_property (GObject
*object
,
59 static void set_property (GObject
*object
,
63 static void local_changed (AdgEntity
*entity
);
64 static void invalidate (AdgEntity
*entity
);
65 static void arrange (AdgEntity
*entity
);
66 static void render (AdgEntity
*entity
,
68 static gchar
* default_value (AdgDim
*dim
);
69 static void update_geometry (AdgLDim
*ldim
);
70 static void update_shift (AdgLDim
*ldim
);
71 static void update_entities (AdgLDim
*ldim
);
72 static gboolean
choose_outside (AdgLDim
*ldim
);
73 static void unset_trail (AdgLDim
*ldim
);
74 static void dispose_markers (AdgLDim
*ldim
);
75 static CpmlPath
* trail_callback (AdgTrail
*trail
,
79 G_DEFINE_TYPE(AdgLDim
, adg_ldim
, ADG_TYPE_DIM
);
83 adg_ldim_class_init(AdgLDimClass
*klass
)
85 GObjectClass
*gobject_class
;
86 AdgEntityClass
*entity_class
;
87 AdgDimClass
*dim_class
;
90 gobject_class
= (GObjectClass
*) klass
;
91 entity_class
= (AdgEntityClass
*) klass
;
92 dim_class
= (AdgDimClass
*) klass
;
94 g_type_class_add_private(klass
, sizeof(AdgLDimPrivate
));
96 gobject_class
->dispose
= dispose
;
97 gobject_class
->get_property
= get_property
;
98 gobject_class
->set_property
= set_property
;
100 entity_class
->local_changed
= local_changed
;
101 entity_class
->invalidate
= invalidate
;
102 entity_class
->arrange
= arrange
;
103 entity_class
->render
= render
;
105 dim_class
->default_value
= default_value
;
107 param
= g_param_spec_double("direction",
109 P_("The inclination angle of the extension lines"),
110 -G_MAXDOUBLE
, G_MAXDOUBLE
, ADG_DIR_RIGHT
,
111 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
112 g_object_class_install_property(gobject_class
, PROP_DIRECTION
, param
);
114 param
= g_param_spec_boolean("has-extension1",
115 P_("Has First Extension Line flag"),
116 P_("Show (TRUE) or hide (FALSE) the first extension line"),
117 TRUE
, G_PARAM_READWRITE
);
118 g_object_class_install_property(gobject_class
, PROP_HAS_EXTENSION1
, param
);
120 param
= g_param_spec_boolean("has-extension2",
121 P_("Has Second Extension Line flag"),
122 P_("Show (TRUE) or hide (FALSE) the second extension line"),
123 TRUE
, G_PARAM_READWRITE
);
124 g_object_class_install_property(gobject_class
, PROP_HAS_EXTENSION2
, param
);
128 adg_ldim_init(AdgLDim
*ldim
)
130 AdgLDimPrivate
*data
;
131 cairo_path_data_t move_to
, line_to
;
133 data
= G_TYPE_INSTANCE_GET_PRIVATE(ldim
, ADG_TYPE_LDIM
, AdgLDimPrivate
);
134 move_to
.header
.type
= CAIRO_PATH_MOVE_TO
;
135 move_to
.header
.length
= 2;
136 line_to
.header
.type
= CAIRO_PATH_LINE_TO
;
137 line_to
.header
.length
= 2;
140 data
->has_extension1
= TRUE
;
141 data
->has_extension2
= TRUE
;
143 data
->cpml
.path
.status
= CAIRO_STATUS_INVALID_PATH_DATA
;
144 data
->cpml
.path
.data
= data
->cpml
.data
;
145 data
->cpml
.path
.num_data
= G_N_ELEMENTS(data
->cpml
.data
);
146 data
->cpml
.path
.data
[0] = move_to
;
147 data
->cpml
.path
.data
[2] = line_to
;
148 data
->cpml
.path
.data
[4] = move_to
;
149 data
->cpml
.path
.data
[6] = line_to
;
150 data
->cpml
.path
.data
[8] = move_to
;
151 data
->cpml
.path
.data
[10] = line_to
;
152 data
->cpml
.path
.data
[12] = move_to
;
153 data
->cpml
.path
.data
[14] = line_to
;
154 data
->cpml
.path
.data
[16] = move_to
;
155 data
->cpml
.path
.data
[18] = line_to
;
158 data
->marker1
= NULL
;
159 data
->marker2
= NULL
;
161 data
->geometry
.is_arranged
= FALSE
;
162 data
->shift
.is_arranged
= FALSE
;
168 dispose(GObject
*object
)
170 dispose_markers((AdgLDim
*) object
);
172 if (PARENT_OBJECT_CLASS
->dispose
)
173 PARENT_OBJECT_CLASS
->dispose(object
);
177 get_property(GObject
*object
,
178 guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
180 AdgLDimPrivate
*data
= ((AdgLDim
*) object
)->data
;
184 g_value_set_double(value
, data
->direction
);
186 case PROP_HAS_EXTENSION1
:
187 g_value_set_boolean(value
, data
->has_extension1
);
189 case PROP_HAS_EXTENSION2
:
190 g_value_set_boolean(value
, data
->has_extension2
);
193 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
199 set_property(GObject
*object
,
200 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
202 AdgLDimPrivate
*data
= ((AdgLDim
*) object
)->data
;
206 data
->direction
= g_value_get_double(value
);
208 case PROP_HAS_EXTENSION1
:
209 data
->has_extension1
= g_value_get_boolean(value
);
211 case PROP_HAS_EXTENSION2
:
212 data
->has_extension2
= g_value_get_boolean(value
);
215 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
224 * Creates a new - undefined - linear dimension. You must, at least,
225 * define the reference points with adg_dim_set_ref(), the dimension
226 * direction with adg_ldim_set_direction() and the position reference
227 * using adg_dim_set_pos().
229 * Returns: the newly created linear dimension entity
234 return g_object_new(ADG_TYPE_LDIM
, NULL
);
239 * @ref1: the first reference point
240 * @ref2: the second reference point
241 * @pos: the position reference
242 * @direction: angle where to extend the dimension
244 * Creates a new linear dimension, specifing all the needed properties in
247 * Returns: the newly created linear dimension entity
250 adg_ldim_new_full(const AdgPair
*ref1
, const AdgPair
*ref2
,
251 const AdgPair
*pos
, gdouble direction
)
256 ldim
= g_object_new(ADG_TYPE_LDIM
, "direction", direction
, NULL
);
257 dim
= (AdgDim
*) ldim
;
259 adg_dim_set_ref(dim
, ref1
, ref2
);
260 adg_dim_set_pos(dim
, pos
);
266 * adg_ldim_new_full_explicit:
267 * @ref1_x: the x coordinate of the first reference point
268 * @ref1_y: the y coordinate of the first reference point
269 * @ref2_x: the x coordinate of the second reference point
270 * @ref2_y: the y coordinate of the second reference point
271 * @pos_x: the x coordinate of the position reference
272 * @pos_y: the y coordinate of the position reference
273 * @direction: angle where to extend the dimension
275 * Wrappes adg_ldim_new_full() with explicit values.
277 * Returns: the newly created linear dimension entity
280 adg_ldim_new_full_explicit(gdouble ref1_x
, gdouble ref1_y
,
281 gdouble ref2_x
, gdouble ref2_y
,
282 gdouble pos_x
, gdouble pos_y
, gdouble direction
)
295 return adg_ldim_new_full(&ref1
, &ref2
, &pos
, direction
);
299 * adg_ldim_new_full_from_model:
300 * @model: the model from which the named pairs are taken
301 * @ref1: the first reference point
302 * @ref2: the second reference point
303 * @pos: the position reference
304 * @direction: angle where to extend the dimension
306 * Creates a new linear dimension, specifing all the needed properties in
307 * one shot and using named pairs from @model.
309 * Returns: the newly created linear dimension entity
312 adg_ldim_new_full_from_model(AdgModel
*model
,
313 const gchar
*ref1
, const gchar
*ref2
,
314 const gchar
*pos
, gdouble direction
)
319 ldim
= g_object_new(ADG_TYPE_LDIM
, "direction", direction
, NULL
);
320 dim
= (AdgDim
*) ldim
;
322 adg_dim_set_ref_from_model(dim
, model
, ref1
, ref2
);
323 adg_dim_set_pos_from_model(dim
, model
, pos
);
329 * adg_ldim_get_direction:
330 * @ldim: an #AdgLDim entity
332 * Gets the direction where @ldim will extend.
334 * Returns: the direction angle in radians
337 adg_ldim_get_direction(AdgLDim
*ldim
)
339 AdgLDimPrivate
*data
;
341 g_return_val_if_fail(ADG_IS_LDIM(ldim
), 0);
345 return data
->direction
;
349 * adg_ldim_set_direction:
350 * @ldim: an #AdgLDim entity
351 * @direction: an angle value, in radians
353 * Sets the direction angle where to extend @ldim.
356 adg_ldim_set_direction(AdgLDim
*ldim
, gdouble direction
)
358 AdgLDimPrivate
*data
;
360 g_return_if_fail(ADG_IS_LDIM(ldim
));
363 data
->direction
= direction
;
365 g_object_notify((GObject
*) ldim
, "direction");
369 * adg_ldim_has_extension1:
370 * @ldim: an #AdgLDim entity
372 * Checks if @ldim should render also the first extension line.
374 * Returns: %TRUE on first extension line presents, %FALSE otherwise
377 adg_ldim_has_extension1(AdgLDim
*ldim
)
379 AdgLDimPrivate
*data
;
381 g_return_val_if_fail(ADG_IS_LDIM(ldim
), FALSE
);
385 return data
->has_extension1
;
389 * adg_ldim_switch_extension1:
390 * @ldim: an #AdgLDim entity
391 * @new_state: the new state
393 * Shows (if @new_state is %TRUE) or hide (if @new_state is %FALSE)
394 * the first extension line of @ldim.
397 adg_ldim_switch_extension1(AdgLDim
*ldim
, gboolean new_state
)
399 AdgLDimPrivate
*data
;
401 g_return_if_fail(ADG_IS_LDIM(ldim
));
405 if (data
->has_extension1
!= new_state
) {
406 data
->has_extension1
= new_state
;
407 g_object_notify((GObject
*) ldim
, "has-extension1");
412 * adg_ldim_has_extension2:
413 * @ldim: an #AdgLDim entity
415 * Checks if @ldim should render also the second extension line.
417 * Returns: %TRUE on first extension line presents, %FALSE otherwise
420 adg_ldim_has_extension2(AdgLDim
*ldim
)
422 AdgLDimPrivate
*data
;
424 g_return_val_if_fail(ADG_IS_LDIM(ldim
), FALSE
);
428 return data
->has_extension2
;
432 * adg_ldim_switch_extension2:
433 * @ldim: an #AdgLDim entity
434 * @new_state: the new new_state
436 * Shows (if @new_state is %TRUE) or hide (if @new_state is %FALSE)
437 * the second extension line of @ldim.
440 adg_ldim_switch_extension2(AdgLDim
*ldim
, gboolean new_state
)
442 AdgLDimPrivate
*data
;
444 g_return_if_fail(ADG_IS_LDIM(ldim
));
448 if (data
->has_extension2
!= new_state
) {
449 data
->has_extension2
= new_state
;
450 g_object_notify((GObject
*) ldim
, "has-extension2");
456 local_changed(AdgEntity
*entity
)
458 unset_trail((AdgLDim
*) entity
);
460 if (PARENT_ENTITY_CLASS
->local_changed
)
461 PARENT_ENTITY_CLASS
->local_changed(entity
);
465 invalidate(AdgEntity
*entity
)
468 AdgLDimPrivate
*data
;
470 ldim
= (AdgLDim
*) entity
;
473 dispose_markers(ldim
);
474 data
->geometry
.is_arranged
= FALSE
;
475 data
->shift
.is_arranged
= FALSE
;
478 if (PARENT_ENTITY_CLASS
->invalidate
)
479 PARENT_ENTITY_CLASS
->invalidate(entity
);
483 arrange(AdgEntity
*entity
)
487 AdgLDimPrivate
*data
;
489 AdgDimStyle
*dim_style
;
491 const AdgMatrix
*local
;
492 AdgPair ref1
, ref2
, base1
, base2
;
497 if (PARENT_ENTITY_CLASS
->arrange
)
498 PARENT_ENTITY_CLASS
->arrange(entity
);
500 ldim
= (AdgLDim
*) entity
;
501 dim
= (AdgDim
*) ldim
;
503 quote
= adg_dim_get_quote(dim
);
505 update_geometry(ldim
);
507 update_entities(ldim
);
509 /* Check for cached result */
510 if (data
->cpml
.path
.status
== CAIRO_STATUS_SUCCESS
) {
511 AdgEntity
*quote_entity
= (AdgEntity
*) quote
;
512 adg_entity_set_global_map(quote_entity
, &data
->quote
.global_map
);
513 adg_entity_set_local_map(quote_entity
, &data
->quote
.local_map
);
517 dim_style
= GET_DIM_STYLE(dim
);
519 switch (adg_dim_get_outside(dim
)) {
520 case ADG_THREE_STATE_OFF
:
523 case ADG_THREE_STATE_ON
:
526 case ADG_THREE_STATE_UNKNOWN
:
528 outside
= choose_outside(ldim
);
532 local
= adg_entity_get_local_matrix(entity
);
533 cpml_pair_copy(&ref1
, adg_dim_get_ref1(dim
));
534 cpml_pair_copy(&ref2
, adg_dim_get_ref2(dim
));
535 cpml_pair_copy(&base1
, &data
->geometry
.base1
);
536 cpml_pair_copy(&base2
, &data
->geometry
.base2
);
538 cpml_pair_transform(&ref1
, local
);
539 cpml_pair_transform(&ref2
, local
);
540 cpml_pair_transform(&base1
, local
);
541 cpml_pair_transform(&base2
, local
);
543 cpml_pair_add(cpml_pair_copy(&pair
, &ref1
), &data
->shift
.from
);
544 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[13]);
546 cpml_pair_copy(&pair
, &base1
);
547 cpml_pair_add(&pair
, &data
->shift
.base
);
548 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[1]);
550 cpml_pair_add(&pair
, &data
->shift
.to
);
551 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[15]);
553 cpml_pair_add(cpml_pair_copy(&pair
, &ref2
), &data
->shift
.from
);
554 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[17]);
556 cpml_pair_copy(&pair
, &base2
);
557 cpml_pair_add(&pair
, &data
->shift
.base
);
558 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[3]);
560 cpml_pair_add(&pair
, &data
->shift
.to
);
561 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[19]);
563 /* Calculate the outside segments */
568 beyond
= adg_dim_style_get_beyond(dim_style
);
569 cpml_pair_from_cairo(&pair
, &data
->cpml
.data
[1]);
571 cpml_pair_from_cairo(&vector
, &data
->cpml
.data
[3]);
572 cpml_pair_sub(&vector
, &pair
);
573 cpml_vector_set_length(&vector
, beyond
);
575 cpml_pair_from_cairo(&pair
, &data
->cpml
.data
[1]);
576 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[5]);
578 cpml_pair_sub(&pair
, &vector
);
579 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[7]);
581 cpml_pair_from_cairo(&pair
, &data
->cpml
.data
[3]);
582 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[11]);
584 cpml_pair_add(&pair
, &vector
);
585 cpml_pair_to_cairo(&pair
, &data
->cpml
.data
[9]);
587 data
->cpml
.data
[2].header
.length
= 2;
588 data
->cpml
.data
[10].header
.length
= 2;
591 data
->cpml
.data
[2].header
.length
= 10;
595 /* Play with header lengths to show or hide the extension lines */
596 if (data
->has_extension1
) {
597 data
->cpml
.data
[14].header
.length
= data
->has_extension2
? 2 : 6;
599 data
->cpml
.data
[n
].header
.length
+= 4;
600 if (!data
->has_extension2
)
601 data
->cpml
.data
[n
].header
.length
+= 4;
604 data
->cpml
.path
.status
= CAIRO_STATUS_SUCCESS
;
605 cpml_extents_copy(&extents
, adg_trail_extents(data
->trail
));
608 /* Update global and local map of the quote container */
609 AdgEntity
*quote_entity
;
612 CpmlExtents quote_extents
;
614 quote_entity
= (AdgEntity
*) quote
;
615 angle
= adg_dim_quote_angle(dim
, data
->direction
+ G_PI_2
);
617 pair
.x
= (data
->cpml
.data
[1].point
.x
+ data
->cpml
.data
[3].point
.x
) / 2;
618 pair
.y
= (data
->cpml
.data
[1].point
.y
+ data
->cpml
.data
[3].point
.y
) / 2;
620 cairo_matrix_init_translate(&map
, pair
.x
, pair
.y
);
621 cairo_matrix_rotate(&map
, angle
);
622 adg_entity_set_global_map(quote_entity
, &map
);
624 adg_matrix_copy(&data
->quote
.global_map
,
625 adg_entity_get_global_map(quote_entity
));
626 adg_matrix_copy(&data
->quote
.local_map
,
627 adg_entity_get_local_map(quote_entity
));
629 cpml_extents_copy("e_extents
, adg_entity_get_extents(quote_entity
));
630 cpml_extents_transform("e_extents
, &map
);
631 cpml_extents_add(&extents
, "e_extents
);
634 if (data
->marker1
!= NULL
) {
635 AdgEntity
*marker1_entity
;
636 CpmlExtents marker1_extents
;
638 marker1_entity
= (AdgEntity
*) data
->marker1
;
640 adg_marker_set_segment(data
->marker1
, data
->trail
, outside
? 2 : 1);
641 adg_entity_local_changed(marker1_entity
);
643 cpml_extents_copy(&marker1_extents
, adg_entity_get_extents(marker1_entity
));
644 cpml_extents_transform(&marker1_extents
,
645 adg_entity_get_global_map(marker1_entity
));
646 cpml_extents_add(&extents
, &marker1_extents
);
649 if (data
->marker2
!= NULL
) {
650 AdgEntity
*marker2_entity
;
651 CpmlExtents marker2_extents
;
653 marker2_entity
= (AdgEntity
*) data
->marker2
;
655 adg_marker_set_segment(data
->marker2
, data
->trail
, outside
? 3 : 1);
656 adg_entity_local_changed(marker2_entity
);
658 cpml_extents_copy(&marker2_extents
, adg_entity_get_extents(marker2_entity
));
659 cpml_extents_transform(&marker2_extents
,
660 adg_entity_get_global_map(marker2_entity
));
661 cpml_extents_add(&extents
, &marker2_extents
);
664 adg_entity_set_extents(entity
, &extents
);
668 render(AdgEntity
*entity
, cairo_t
*cr
)
672 AdgLDimPrivate
*data
;
673 AdgDimStyle
*dim_style
;
675 const cairo_path_t
*cairo_path
;
677 ldim
= (AdgLDim
*) entity
;
678 dim
= (AdgDim
*) entity
;
680 dim_style
= GET_DIM_STYLE(dim
);
682 adg_style_apply((AdgStyle
*) dim_style
, entity
, cr
);
684 if (data
->marker1
!= NULL
)
685 adg_entity_render((AdgEntity
*) data
->marker1
, cr
);
687 if (data
->marker2
!= NULL
)
688 adg_entity_render((AdgEntity
*) data
->marker2
, cr
);
690 adg_entity_render((AdgEntity
*) adg_dim_get_quote(dim
), cr
);
692 dress
= adg_dim_style_get_line_dress(dim_style
);
693 adg_entity_apply_dress(entity
, dress
, cr
);
695 cairo_path
= adg_trail_get_cairo_path(data
->trail
);
696 cairo_append_path(cr
, cairo_path
);
701 default_value(AdgDim
*dim
)
704 AdgLDimPrivate
*data
;
705 AdgDimStyle
*dim_style
;
708 ldim
= (AdgLDim
*) dim
;
710 dim_style
= GET_DIM_STYLE(dim
);
711 format
= adg_dim_style_get_number_format(dim_style
);
713 update_geometry(ldim
);
715 return g_strdup_printf(format
, data
->geometry
.distance
);
719 update_geometry(AdgLDim
*ldim
)
721 AdgLDimPrivate
*data
;
723 const AdgPair
*ref1
, *ref2
;
725 CpmlVector baseline
, extension
;
730 if (data
->geometry
.is_arranged
)
733 dim
= (AdgDim
*) ldim
;
734 ref1
= adg_dim_get_ref1(dim
);
735 ref2
= adg_dim_get_ref2(dim
);
736 pos
= adg_dim_get_pos(dim
);
737 cpml_vector_from_angle(&extension
, data
->direction
);
738 cpml_pair_copy(&baseline
, &extension
);
739 cpml_vector_normal(&baseline
);
741 d
= extension
.y
* baseline
.x
-
742 extension
.x
* baseline
.y
;
743 g_return_if_fail(d
!= 0);
745 k
= ((pos
->y
- ref1
->y
) * baseline
.x
-
746 (pos
->x
- ref1
->x
) * baseline
.y
) / d
;
747 data
->geometry
.base1
.x
= ref1
->x
+ k
* extension
.x
;
748 data
->geometry
.base1
.y
= ref1
->y
+ k
* extension
.y
;
750 k
= ((pos
->y
- ref2
->y
) * baseline
.x
-
751 (pos
->x
- ref2
->x
) * baseline
.y
) / d
;
752 data
->geometry
.base2
.x
= ref2
->x
+ k
* extension
.x
;
753 data
->geometry
.base2
.y
= ref2
->y
+ k
* extension
.y
;
755 data
->geometry
.distance
= cpml_pair_distance(&data
->geometry
.base1
,
756 &data
->geometry
.base2
);
758 data
->geometry
.is_arranged
= TRUE
;
762 update_shift(AdgLDim
*ldim
)
764 AdgLDimPrivate
*data
;
765 AdgDimStyle
*dim_style
;
766 gdouble from_offset
, to_offset
;
767 gdouble baseline_spacing
, level
;
772 if (data
->shift
.is_arranged
)
775 dim_style
= GET_DIM_STYLE(ldim
);
776 from_offset
= adg_dim_style_get_from_offset(dim_style
);
777 to_offset
= adg_dim_style_get_to_offset(dim_style
);
778 baseline_spacing
= adg_dim_style_get_baseline_spacing(dim_style
);
779 level
= adg_dim_get_level((AdgDim
*) ldim
);
781 cpml_vector_from_angle(&vector
, data
->direction
);
783 cpml_vector_set_length(&vector
, from_offset
);
784 cpml_pair_copy(&data
->shift
.from
, &vector
);
786 cpml_vector_set_length(&vector
, to_offset
);
787 cpml_pair_copy(&data
->shift
.to
, &vector
);
789 cpml_vector_set_length(&vector
, level
* baseline_spacing
);
790 cpml_pair_copy(&data
->shift
.base
, &vector
);
792 data
->shift
.is_arranged
= TRUE
;
796 update_entities(AdgLDim
*ldim
)
798 AdgLDimPrivate
*data
;
799 AdgDimStyle
*dim_style
;
802 dim_style
= GET_DIM_STYLE(ldim
);
804 if (data
->trail
== NULL
)
805 data
->trail
= adg_trail_new(trail_callback
, ldim
);
807 if (data
->marker1
== NULL
)
808 data
->marker1
= adg_dim_style_marker1_new(dim_style
);
810 if (data
->marker2
== NULL
)
811 data
->marker2
= adg_dim_style_marker2_new(dim_style
);
815 choose_outside(AdgLDim
*ldim
)
817 AdgLDimPrivate
*data
;
819 const AdgMatrix
*local
;
820 gdouble marker1
, marker2
;
821 gdouble needed
, available
;
824 quote
= (AdgEntity
*) adg_dim_get_quote((AdgDim
*) ldim
);
825 local
= adg_entity_get_local_matrix((AdgEntity
*) ldim
);
826 marker1
= data
->marker1
== NULL
? 0 : adg_marker_get_size(data
->marker1
);
827 marker2
= data
->marker2
== NULL
? 0 : adg_marker_get_size(data
->marker2
);
829 needed
= adg_entity_get_extents(quote
)->size
.x
+ marker1
+ marker2
;
830 available
= data
->geometry
.distance
* local
->xx
;
832 return needed
> available
;
836 unset_trail(AdgLDim
*ldim
)
838 AdgLDimPrivate
*data
= ldim
->data
;
840 if (data
->trail
!= NULL
)
841 adg_model_clear((AdgModel
*) data
->trail
);
843 data
->cpml
.path
.status
= CAIRO_STATUS_INVALID_PATH_DATA
;
847 dispose_markers(AdgLDim
*ldim
)
849 AdgLDimPrivate
*data
= ldim
->data
;
851 if (data
->trail
!= NULL
) {
852 g_object_unref(data
->trail
);
856 if (data
->marker1
!= NULL
) {
857 g_object_unref(data
->marker1
);
858 data
->marker1
= NULL
;
861 if (data
->marker2
!= NULL
) {
862 g_object_unref(data
->marker2
);
863 data
->marker2
= NULL
;
868 trail_callback(AdgTrail
*trail
, gpointer user_data
)
871 AdgLDimPrivate
*data
;
873 ldim
= (AdgLDim
*) user_data
;
876 return &data
->cpml
.path
;