1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012 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.
22 * SECTION:adg-dim-style
23 * @short_description: Dimension style related stuff
25 * Contains parameters on how to build dimensions such as the different font
26 * styles (for value and limits), line style, offsets of the various
27 * dimension components etc...
35 * All fields are private and should not be used directly.
36 * Use its public methods instead.
42 #include "adg-internal.h"
43 #include "adg-style.h"
44 #include "adg-font-style.h"
46 #include "adg-line-style.h"
47 #include "adg-dress.h"
48 #include "adg-dress-builtins.h"
49 #include "adg-model.h"
50 #include "adg-trail.h"
51 #include "adg-marker.h"
53 #include "adg-dim-style.h"
54 #include "adg-dim-style-private.h"
57 G_DEFINE_TYPE(AdgDimStyle
, adg_dim_style
, ADG_TYPE_STYLE
)
71 PROP_BASELINE_SPACING
,
80 static void _adg_finalize (GObject
*object
);
81 static void _adg_get_property (GObject
*object
,
85 static void _adg_set_property (GObject
*object
,
89 static void _adg_apply (AdgStyle
*style
,
92 static AdgMarker
* _adg_marker_new (const AdgMarkerData
94 static void _adg_set_marker (AdgMarkerData
*marker_data
,
96 static void _adg_free_marker (AdgMarkerData
*marker_data
);
100 adg_dim_style_class_init(AdgDimStyleClass
*klass
)
102 GObjectClass
*gobject_class
;
103 AdgStyleClass
*style_class
;
106 gobject_class
= (GObjectClass
*) klass
;
107 style_class
= (AdgStyleClass
*) klass
;
109 g_type_class_add_private(klass
, sizeof(AdgDimStylePrivate
));
111 gobject_class
->finalize
= _adg_finalize
;
112 gobject_class
->get_property
= _adg_get_property
;
113 gobject_class
->set_property
= _adg_set_property
;
115 style_class
->apply
= _adg_apply
;
117 param
= g_param_spec_object("marker1",
119 P_("The template entity to use as first marker"),
122 g_object_class_install_property(gobject_class
, PROP_MARKER1
, param
);
124 param
= g_param_spec_object("marker2",
126 P_("The template entity to use as second marker"),
129 g_object_class_install_property(gobject_class
, PROP_MARKER2
, param
);
131 param
= adg_param_spec_dress("color-dress",
133 P_("Color dress for the whole dimension"),
134 ADG_DRESS_COLOR_DIMENSION
,
136 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
138 param
= adg_param_spec_dress("value-dress",
140 P_("Font dress for the nominal value of the dimension"),
141 ADG_DRESS_FONT_QUOTE_TEXT
,
143 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
145 param
= adg_param_spec_dress("min-dress",
146 P_("Minimum Limit Dress"),
147 P_("Font dress for the lower limit value"),
148 ADG_DRESS_FONT_QUOTE_ANNOTATION
,
150 g_object_class_install_property(gobject_class
, PROP_MIN_DRESS
, param
);
152 param
= adg_param_spec_dress("max-dress",
153 P_("Maximum Limit Dress"),
154 P_("Font dress for the upper limit value"),
155 ADG_DRESS_FONT_QUOTE_ANNOTATION
,
157 g_object_class_install_property(gobject_class
, PROP_MAX_DRESS
, param
);
159 param
= adg_param_spec_dress("line-dress",
161 P_("Line dress for the baseline and the extension lines"),
162 ADG_DRESS_LINE_DIMENSION
,
164 g_object_class_install_property(gobject_class
, PROP_LINE_DRESS
, param
);
166 param
= g_param_spec_double("from-offset",
168 P_("Offset (in global space) of the extension lines from the path to the quote"),
171 g_object_class_install_property(gobject_class
, PROP_FROM_OFFSET
, param
);
173 param
= g_param_spec_double("to-offset",
175 P_("How many extend (in global space) the extension lines after hitting the baseline"),
178 g_object_class_install_property(gobject_class
, PROP_TO_OFFSET
, param
);
180 param
= g_param_spec_double("beyond",
182 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside markers"),
185 g_object_class_install_property(gobject_class
, PROP_BEYOND
, param
);
187 param
= g_param_spec_double("baseline-spacing",
188 P_("Baseline Spacing"),
189 P_("Distance between two consecutive baselines while stacking dimensions"),
192 g_object_class_install_property(gobject_class
, PROP_BASELINE_SPACING
, param
);
194 param
= g_param_spec_double("limits-spacing",
195 P_("Limits Spacing"),
196 P_("Distance between limits/tolerances"),
199 g_object_class_install_property(gobject_class
, PROP_LIMITS_SPACING
, param
);
201 param
= g_param_spec_boxed("quote-shift",
203 P_("Used to specify a smooth displacement (in global space) of the quote by taking as reference the perfect compact position (the middle of the baseline on common linear dimension, for instance)"),
206 g_object_class_install_property(gobject_class
, PROP_QUOTE_SHIFT
, param
);
208 param
= g_param_spec_boxed("limits-shift",
210 P_("Used to specify a smooth displacement (in global space) for the limits/tolerances by taking as reference the perfect compact position"),
213 g_object_class_install_property(gobject_class
, PROP_LIMITS_SHIFT
, param
);
215 param
= g_param_spec_string("number-format",
217 P_("The format (in printf style) of the numeric component of the basic value"),
220 g_object_class_install_property(gobject_class
, PROP_NUMBER_FORMAT
, param
);
222 param
= g_param_spec_string("number-tag",
224 P_("The tag to substitute inside the value template string"),
227 g_object_class_install_property(gobject_class
, PROP_NUMBER_TAG
, param
);
231 adg_dim_style_init(AdgDimStyle
*dim_style
)
233 AdgDimStylePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim_style
,
237 data
->marker1
.type
= 0;
238 data
->marker1
.n_parameters
= 0;
239 data
->marker1
.parameters
= NULL
;
240 data
->marker2
.type
= 0;
241 data
->marker2
.n_parameters
= 0;
242 data
->marker2
.parameters
= NULL
;
243 data
->color_dress
= ADG_DRESS_COLOR_DIMENSION
;
244 data
->value_dress
= ADG_DRESS_FONT_QUOTE_TEXT
;
245 data
->min_dress
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
246 data
->max_dress
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
247 data
->line_dress
= ADG_DRESS_LINE_DIMENSION
;
248 data
->marker_dress
= ADG_DRESS_UNDEFINED
;
249 data
->from_offset
= 6;
252 data
->baseline_spacing
= 32;
253 data
->limits_spacing
= 0;
254 data
->quote_shift
.x
= 4;
255 data
->quote_shift
.y
= -1;
256 data
->limits_shift
.x
= +2;
257 data
->limits_shift
.y
= +2;
258 data
->number_format
= g_strdup("%-.7g");
259 data
->number_tag
= g_strdup("<>");
261 dim_style
->data
= data
;
265 _adg_finalize(GObject
*object
)
267 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) object
)->data
;
269 _adg_free_marker(&data
->marker1
);
270 _adg_free_marker(&data
->marker2
);
272 g_free(data
->number_format
);
273 data
->number_format
= NULL
;
275 g_free(data
->number_tag
);
276 data
->number_tag
= NULL
;
280 _adg_get_property(GObject
*object
, guint prop_id
,
281 GValue
*value
, GParamSpec
*pspec
)
283 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) object
)->data
;
286 case PROP_COLOR_DRESS
:
287 g_value_set_int(value
, data
->color_dress
);
289 case PROP_VALUE_DRESS
:
290 g_value_set_int(value
, data
->value_dress
);
293 g_value_set_int(value
, data
->min_dress
);
296 g_value_set_int(value
, data
->max_dress
);
298 case PROP_LINE_DRESS
:
299 g_value_set_int(value
, data
->line_dress
);
301 case PROP_FROM_OFFSET
:
302 g_value_set_double(value
, data
->from_offset
);
305 g_value_set_double(value
, data
->to_offset
);
308 g_value_set_double(value
, data
->beyond
);
310 case PROP_BASELINE_SPACING
:
311 g_value_set_double(value
, data
->baseline_spacing
);
313 case PROP_LIMITS_SPACING
:
314 g_value_set_double(value
, data
->limits_spacing
);
316 case PROP_QUOTE_SHIFT
:
317 g_value_set_boxed(value
, &data
->quote_shift
);
319 case PROP_LIMITS_SHIFT
:
320 g_value_set_boxed(value
, &data
->limits_shift
);
322 case PROP_NUMBER_FORMAT
:
323 g_value_set_string(value
, data
->number_format
);
325 case PROP_NUMBER_TAG
:
326 g_value_set_string(value
, data
->number_tag
);
329 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
335 _adg_set_property(GObject
*object
, guint prop_id
,
336 const GValue
*value
, GParamSpec
*pspec
)
338 AdgDimStyle
*dim_style
;
339 AdgDimStylePrivate
*data
;
341 dim_style
= (AdgDimStyle
*) object
;
342 data
= dim_style
->data
;
346 _adg_set_marker(&data
->marker1
, g_value_get_object(value
));
349 _adg_set_marker(&data
->marker2
, g_value_get_object(value
));
351 case PROP_COLOR_DRESS
:
352 data
->color_dress
= g_value_get_int(value
);
354 case PROP_VALUE_DRESS
:
355 data
->value_dress
= g_value_get_int(value
);
358 data
->min_dress
= g_value_get_int(value
);
361 data
->max_dress
= g_value_get_int(value
);
363 case PROP_LINE_DRESS
:
364 data
->line_dress
= g_value_get_int(value
);
366 case PROP_FROM_OFFSET
:
367 data
->from_offset
= g_value_get_double(value
);
370 data
->to_offset
= g_value_get_double(value
);
373 data
->beyond
= g_value_get_double(value
);
375 case PROP_BASELINE_SPACING
:
376 data
->baseline_spacing
= g_value_get_double(value
);
378 case PROP_LIMITS_SPACING
:
379 data
->limits_spacing
= g_value_get_double(value
);
381 case PROP_QUOTE_SHIFT
:
382 adg_pair_copy(&data
->quote_shift
, g_value_get_boxed(value
));
384 case PROP_LIMITS_SHIFT
:
385 adg_pair_copy(&data
->limits_shift
, g_value_get_boxed(value
));
387 case PROP_NUMBER_FORMAT
:
388 g_free(data
->number_format
);
389 data
->number_format
= g_value_dup_string(value
);
391 case PROP_NUMBER_TAG
:
392 g_free(data
->number_tag
);
393 data
->number_tag
= g_value_dup_string(value
);
396 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
405 * Constructs a new empty dimension style initialized with default params.
407 * Returns: (transfer full): a newly created dimension style.
412 adg_dim_style_new(void)
414 return g_object_new(ADG_TYPE_DIM_STYLE
, NULL
);
418 * adg_dim_style_set_marker1:
419 * @dim_style: an #AdgStyle
420 * @marker: an #AdgMarker derived entity
422 * Uses @marker as entity template to generate a new marker entity
423 * when a call to adg_dim_style_marker1_new() is made. It is allowed
424 * to pass %NULL as @marker, in which case the template data of the
425 * first marker are unset.
427 * This method duplicates internally the property values of @marker,
428 * so any further change to @marker does not affect @dim_style anymore.
429 * This also means @marker could be destroyed without problems after
430 * this call because @dim_style uses only its property values and does
431 * not add any references to @marker.
436 adg_dim_style_set_marker1(AdgDimStyle
*dim_style
, AdgMarker
*marker
)
438 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
439 g_object_set(dim_style
, "marker1", marker
, NULL
);
443 * adg_dim_style_marker1_new:
444 * @dim_style: an #AdgDimStyle
446 * Creates a new marker entity by cloning the #AdgMarker:marker1
447 * object. The returned entity should be unreferenced with
448 * g_object_unref() when no longer needed.
450 * Returns: (transfer full): a newly created marker or %NULL
451 * if the #AdgDimStyle:marker1 property
452 * is not set or on errors.
457 adg_dim_style_marker1_new(AdgDimStyle
*dim_style
)
459 AdgDimStylePrivate
*data
;
461 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
463 data
= dim_style
->data
;
465 return _adg_marker_new(&data
->marker1
);
469 * adg_dim_style_set_marker2:
470 * @dim_style: an #AdgStyle
471 * @marker: an #AdgMarker derived entity
473 * Uses @marker as entity template to generate a new marker entity
474 * when a call to adg_dim_style_marker2_new() is made. It is allowed
475 * to pass %NULL as @marker, in which case the template data of the
476 * second marker are unset.
478 * This method duplicates internally the property values of @marker,
479 * so any further change to @marker does not affect @dim_style anymore.
480 * This also means @marker could be destroyed without problems after
481 * this call because @dim_style uses only its property values and does
482 * not add any references to @marker.
487 adg_dim_style_set_marker2(AdgDimStyle
*dim_style
, AdgMarker
*marker
)
489 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
490 g_object_set(dim_style
, "marker2", marker
, NULL
);
494 * adg_dim_style_marker2_new:
495 * @dim_style: an #AdgDimStyle
497 * Creates a new marker entity by cloning the #AdgMarker:marker2
498 * object. The returned entity should be unreferenced with
499 * g_object_unref() when no longer needed.
501 * Returns: (transfer full): a newly created marker or %NULL
502 * if the #AdgDimStyle:marker2 property
503 * is not set or on errors.
508 adg_dim_style_marker2_new(AdgDimStyle
*dim_style
)
510 AdgDimStylePrivate
*data
;
512 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
514 data
= dim_style
->data
;
516 return _adg_marker_new(&data
->marker2
);
520 * adg_dim_style_set_color_dress:
521 * @dim_style: an #AdgDimStyle object
522 * @dress: the new color dress
524 * Sets a new color dress on @dim_style.
529 adg_dim_style_set_color_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
531 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
532 g_object_set(dim_style
, "color-dress", dress
, NULL
);
536 * adg_dim_style_get_color_dress:
537 * @dim_style: an #AdgDimStyle object
539 * Gets the @dim_style color dress to be used. This dress should be
540 * intended as a fallback color as it could be overriden by more
541 * specific dresses, such as a color explicitely specified on the
542 * #AdgDimStyle:value-dress.
544 * Returns: (transfer none): the color dress.
549 adg_dim_style_get_color_dress(AdgDimStyle
*dim_style
)
551 AdgDimStylePrivate
*data
;
553 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
555 data
= dim_style
->data
;
557 return data
->color_dress
;
561 * adg_dim_style_set_value_dress:
562 * @dim_style: an #AdgDimStyle object
563 * @dress: the new basic value font style
565 * Sets a new dress on @dim_style for the basic value.
570 adg_dim_style_set_value_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
572 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
573 g_object_set(dim_style
, "value-dress", dress
, NULL
);
577 * adg_dim_style_get_value_dress:
578 * @dim_style: an #AdgDimStyle object
580 * Gets the font dress to be used for the basic value of dimensions
583 * Returns: (transfer none): the font dress.
588 adg_dim_style_get_value_dress(AdgDimStyle
*dim_style
)
590 AdgDimStylePrivate
*data
;
592 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
594 data
= dim_style
->data
;
596 return data
->value_dress
;
600 * adg_dim_style_set_min_dress:
601 * @dim_style: an #AdgDimStyle object
602 * @dress: the new lower limit dress
604 * Sets a new dress on @dim_style for the lower limit value.
609 adg_dim_style_set_min_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
611 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
612 g_object_set(dim_style
, "min-dress", dress
, NULL
);
616 * adg_dim_style_get_min_dress:
617 * @dim_style: an #AdgDimStyle object
619 * Gets the @dim_style dress to be used for the lower limit.
621 * Returns: (transfer none): the lower limit dress.
626 adg_dim_style_get_min_dress(AdgDimStyle
*dim_style
)
628 AdgDimStylePrivate
*data
;
630 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
632 data
= dim_style
->data
;
634 return data
->min_dress
;
638 * adg_dim_style_set_max_dress:
639 * @dim_style: an #AdgDimStyle object
640 * @dress: the new upper limit dress
642 * Sets a new dress on @dim_style for the upper limit value.
647 adg_dim_style_set_max_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
649 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
650 g_object_set(dim_style
, "max-dress", dress
, NULL
);
654 * adg_dim_style_get_max_dress:
655 * @dim_style: an #AdgDimStyle object
657 * Gets the @dim_style dress to be used for the upper limit.
659 * Returns: (transfer none): the upper limit dress.
664 adg_dim_style_get_max_dress(AdgDimStyle
*dim_style
)
666 AdgDimStylePrivate
*data
;
668 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
670 data
= dim_style
->data
;
672 return data
->max_dress
;
676 * adg_dim_style_set_line_dress:
677 * @dim_style: an #AdgDimStyle object
678 * @dress: the new line dress
680 * Sets a new line dress on @dim_style.
685 adg_dim_style_set_line_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
687 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
688 g_object_set(dim_style
, "line-dress", dress
, NULL
);
692 * adg_dim_style_get_line_dress:
693 * @dim_style: an #AdgDimStyle object
695 * Gets the line dress to be used for rendering the base and
696 * the extension lines with @dim_style.
698 * Returns: (transfer none): the line dress.
703 adg_dim_style_get_line_dress(AdgDimStyle
*dim_style
)
705 AdgDimStylePrivate
*data
;
707 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
709 data
= dim_style
->data
;
711 return data
->line_dress
;
715 * adg_dim_style_set_from_offset:
716 * @dim_style: an #AdgDimStyle object
717 * @offset: the new offset
719 * Sets a new value in the #AdgDimStyle:from-offset property.
724 adg_dim_style_set_from_offset(AdgDimStyle
*dim_style
, gdouble offset
)
726 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
727 g_object_set(dim_style
, "from-offset", offset
, NULL
);
731 * adg_dim_style_get_from_offset:
732 * @dim_style: an #AdgDimStyle object
734 * Gets the distance (in global space) the extension lines must keep from the
737 * Returns: the requested distance.
742 adg_dim_style_get_from_offset(AdgDimStyle
*dim_style
)
744 AdgDimStylePrivate
*data
;
746 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
748 data
= dim_style
->data
;
750 return data
->from_offset
;
754 * adg_dim_style_set_to_offset:
755 * @dim_style: an #AdgDimStyle object
756 * @offset: the new offset
758 * Sets a new value in the #AdgDimStyle:to-offset property.
763 adg_dim_style_set_to_offset(AdgDimStyle
*dim_style
, gdouble offset
)
765 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
766 g_object_set(dim_style
, "to-offset", offset
, NULL
);
770 * adg_dim_style_get_to_offset:
771 * @dim_style: an #AdgDimStyle object
773 * Gets how much (in global space) the extension lines must extend after
774 * crossing the baseline.
776 * Returns: the requested distance.
781 adg_dim_style_get_to_offset(AdgDimStyle
*dim_style
)
783 AdgDimStylePrivate
*data
;
785 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
787 data
= dim_style
->data
;
789 return data
->to_offset
;
793 * adg_dim_style_set_beyond:
794 * @dim_style: an #AdgDimStyle object
795 * @beyond: the new length
797 * Sets a new value in the #AdgDimStyle:beyond property.
802 adg_dim_style_set_beyond(AdgDimStyle
*dim_style
, gdouble beyond
)
804 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
805 g_object_set(dim_style
, "beyond", beyond
, NULL
);
809 * adg_dim_style_get_beyond:
810 * @dim_style: an #AdgDimStyle object
812 * Gets how much (in global space) the baseline should extend beyond
813 * the extension lines on dimension with outside markers.
815 * Returns: the requested beyond length.
820 adg_dim_style_get_beyond(AdgDimStyle
*dim_style
)
822 AdgDimStylePrivate
*data
;
824 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
826 data
= dim_style
->data
;
832 * adg_dim_style_set_baseline_spacing:
833 * @dim_style: an #AdgDimStyle object
834 * @spacing: the new spacing
836 * Sets a new value in the #AdgDimStyle:baseline-spacing value.
841 adg_dim_style_set_baseline_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
843 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
844 g_object_set(dim_style
, "baseline-spacing", spacing
, NULL
);
848 * adg_dim_style_get_baseline_spacing:
849 * @dim_style: an #AdgDimStyle object
851 * Gets the distance between two consecutive baselines
852 * while stacking dimensions.
854 * Returns: the requested spacing.
859 adg_dim_style_get_baseline_spacing(AdgDimStyle
*dim_style
)
861 AdgDimStylePrivate
*data
;
863 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
865 data
= dim_style
->data
;
867 return data
->baseline_spacing
;
871 * adg_dim_style_set_limits_spacing:
872 * @dim_style: an #AdgDimStyle object
873 * @spacing: the new spacing
875 * Sets a new #AdgDimStyle:limits-spacing value.
880 adg_dim_style_set_limits_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
882 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
883 g_object_set(dim_style
, "limits-spacing", spacing
, NULL
);
887 * adg_dim_style_get_limits_spacing:
888 * @dim_style: an #AdgDimStyle object
890 * Gets the distance (in global space) between the limits/tolerances.
892 * Returns: the requested spacing.
897 adg_dim_style_get_limits_spacing(AdgDimStyle
*dim_style
)
899 AdgDimStylePrivate
*data
;
901 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
903 data
= dim_style
->data
;
905 return data
->limits_spacing
;
909 * adg_dim_style_set_quote_shift:
910 * @dim_style: an #AdgDimStyle object
911 * @shift: the new displacement
913 * Sets a new #AdgDimStyle:quote-shift value.
918 adg_dim_style_set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
920 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
921 g_object_set(dim_style
, "quote-shift", shift
, NULL
);
925 * adg_dim_style_get_quote_shift:
926 * @dim_style: an #AdgDimStyle object
928 * Gets the smooth displacement of the quote. The returned pointer refers
929 * to an internal allocated struct and must not be modified or freed.
931 * Returns: (transfer none): the requested shift.
936 adg_dim_style_get_quote_shift(AdgDimStyle
*dim_style
)
938 AdgDimStylePrivate
*data
;
940 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
942 data
= dim_style
->data
;
944 return &data
->quote_shift
;
948 * adg_dim_style_set_limits_shift:
949 * @dim_style: an #AdgDimStyle object
950 * @shift: the new displacement
952 * Sets a new #AdgDimStyle:limits-shift value.
957 adg_dim_style_set_limits_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
959 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
960 g_object_set(dim_style
, "limits-shift", shift
, NULL
);
964 * adg_dim_style_get_limits_shift:
965 * @dim_style: an #AdgDimStyle object
967 * Gets the smooth displacement for the limits. The returned pointer
968 * refers to an internal allocated struct and must not be modified or freed.
970 * Returns: (transfer none): the requested shift.
975 adg_dim_style_get_limits_shift(AdgDimStyle
*dim_style
)
977 AdgDimStylePrivate
*data
;
979 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
981 data
= dim_style
->data
;
983 return &data
->limits_shift
;
987 * adg_dim_style_set_number_format:
988 * @dim_style: an #AdgDimStyle object
989 * @format: the new format to adopt
991 * Sets a new value in the #AdgDimStyle:number-format property.
996 adg_dim_style_set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
998 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
999 g_object_set(dim_style
, "number-format", format
, NULL
);
1003 * adg_dim_style_get_number_format:
1004 * @dim_style: an #AdgDimStyle object
1006 * Gets the number format (in printf style) of this quoting style. The
1007 * returned pointer refers to internally managed text that must not be
1008 * modified or freed.
1010 * Returns: (transfer none): the requested format.
1015 adg_dim_style_get_number_format(AdgDimStyle
*dim_style
)
1017 AdgDimStylePrivate
*data
;
1019 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
1021 data
= dim_style
->data
;
1023 return data
->number_format
;
1027 * adg_dim_style_set_number_tag:
1028 * @dim_style: an #AdgDimStyle object
1031 * Sets a new tag in the #AdgDimStyle:number-tag property.
1036 adg_dim_style_set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
1038 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
1039 g_object_set(dim_style
, "number-tag", tag
, NULL
);
1043 * adg_dim_style_get_number_tag:
1044 * @dim_style: an #AdgDimStyle object
1046 * Gets the number tag of @dim_style. This tag will be used while
1047 * generating the set values of the dimensions bound to this style:
1048 * check the #AdgDim:value documentation for further details.
1050 * The returned pointer refers to internally managed text that
1051 * must not be modified or freed.
1053 * Returns: (transfer none): the requested tag.
1058 adg_dim_style_get_number_tag(AdgDimStyle
*dim_style
)
1060 AdgDimStylePrivate
*data
;
1062 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
1064 data
= dim_style
->data
;
1066 return data
->number_tag
;
1071 _adg_apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
1073 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) style
)->data
;
1074 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);
1078 _adg_marker_new(const AdgMarkerData
*marker_data
)
1080 if (marker_data
->type
== 0)
1083 return g_object_newv(marker_data
->type
,
1084 marker_data
->n_parameters
,
1085 marker_data
->parameters
);
1089 _adg_set_marker(AdgMarkerData
*marker_data
, AdgMarker
*marker
)
1091 g_return_if_fail(marker
== NULL
|| ADG_IS_MARKER(marker
));
1093 /* Free the previous marker data, if any */
1094 _adg_free_marker(marker_data
);
1100 GParameter
*parameter
;
1103 object
= (GObject
*) marker
;
1104 specs
= g_object_class_list_properties(G_OBJECT_GET_CLASS(marker
),
1105 &marker_data
->n_parameters
);
1107 marker_data
->type
= G_TYPE_FROM_INSTANCE(marker
);
1108 marker_data
->parameters
= g_new0(GParameter
, marker_data
->n_parameters
);
1110 for (n
= 0; n
< marker_data
->n_parameters
; ++n
) {
1112 parameter
= &marker_data
->parameters
[n
];
1114 /* Using intern strings because GParameter:name is const.
1115 * GObject properties are internally managed using non-static
1116 * GQuark, so g_intern_string() is the way to go */
1117 parameter
->name
= g_intern_string(spec
->name
);
1119 g_value_init(¶meter
->value
, spec
->value_type
);
1120 g_object_get_property(object
, spec
->name
, ¶meter
->value
);
1128 _adg_free_marker(AdgMarkerData
*marker_data
)
1132 for (n
= 0; n
< marker_data
->n_parameters
; ++n
)
1133 g_value_unset(&marker_data
->parameters
[n
].value
);
1135 marker_data
->type
= 0;
1136 marker_data
->n_parameters
= 0;
1137 marker_data
->parameters
= NULL
;