1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010 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...
33 * All fields are private and should not be used directly.
34 * Use its public methods instead.
38 #include "adg-internal.h"
39 #include "adg-dim-style.h"
40 #include "adg-dim-style-private.h"
41 #include "adg-dress-builtins.h"
42 #include "adg-font-style.h"
43 #include "adg-line-style.h"
58 PROP_BASELINE_SPACING
,
67 static void finalize (GObject
*object
);
68 static void get_property (GObject
*object
,
72 static void set_property (GObject
*object
,
76 static void apply (AdgStyle
*style
,
79 static gboolean
set_from_offset (AdgDimStyle
*dim_style
,
81 static gboolean
set_to_offset (AdgDimStyle
*dim_style
,
83 static gboolean
set_baseline_spacing (AdgDimStyle
*dim_style
,
85 static gboolean
set_limits_spacing (AdgDimStyle
*dim_style
,
87 static gboolean
set_beyond (AdgDimStyle
*dim_style
,
89 static gboolean
set_quote_shift (AdgDimStyle
*dim_style
,
90 const AdgPair
*shift
);
91 static gboolean
set_limits_shift (AdgDimStyle
*dim_style
,
92 const AdgPair
*shift
);
93 static void set_number_format (AdgDimStyle
*dim_style
,
95 static void set_number_tag (AdgDimStyle
*dim_style
,
97 static AdgMarker
* marker_new (const AdgMarkerData
99 static gboolean
set_marker (AdgMarkerData
*marker_data
,
101 static void free_marker (AdgMarkerData
*marker_data
);
104 G_DEFINE_TYPE(AdgDimStyle
, adg_dim_style
, ADG_TYPE_STYLE
);
108 adg_dim_style_class_init(AdgDimStyleClass
*klass
)
110 GObjectClass
*gobject_class
;
111 AdgStyleClass
*style_class
;
114 gobject_class
= (GObjectClass
*) klass
;
115 style_class
= (AdgStyleClass
*) klass
;
117 g_type_class_add_private(klass
, sizeof(AdgDimStylePrivate
));
119 gobject_class
->finalize
= finalize
;
120 gobject_class
->get_property
= get_property
;
121 gobject_class
->set_property
= set_property
;
123 style_class
->apply
= apply
;
125 param
= g_param_spec_object("marker1",
127 P_("The template entity to use as first marker"),
130 g_object_class_install_property(gobject_class
, PROP_MARKER1
, param
);
132 param
= g_param_spec_object("marker2",
134 P_("The template entity to use as second marker"),
137 g_object_class_install_property(gobject_class
, PROP_MARKER2
, param
);
139 param
= adg_param_spec_dress("color-dress",
141 P_("Color dress for the whole dimension"),
142 ADG_DRESS_COLOR_DIMENSION
,
144 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
146 param
= adg_param_spec_dress("value-dress",
148 P_("Font dress for the nominal value of the dimension"),
149 ADG_DRESS_FONT_QUOTE_TEXT
,
151 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
153 param
= adg_param_spec_dress("min-dress",
154 P_("Minimum Limit Dress"),
155 P_("Font dress for the lower limit value"),
156 ADG_DRESS_FONT_QUOTE_ANNOTATION
,
158 g_object_class_install_property(gobject_class
, PROP_MIN_DRESS
, param
);
160 param
= adg_param_spec_dress("max-dress",
161 P_("Maximum Limit Dress"),
162 P_("Font dress for the upper limit value"),
163 ADG_DRESS_FONT_QUOTE_ANNOTATION
,
165 g_object_class_install_property(gobject_class
, PROP_MAX_DRESS
, param
);
167 param
= adg_param_spec_dress("line-dress",
169 P_("Line dress for the baseline and the extension lines"),
170 ADG_DRESS_LINE_DIMENSION
,
172 g_object_class_install_property(gobject_class
, PROP_LINE_DRESS
, param
);
174 param
= g_param_spec_double("from-offset",
176 P_("Offset (in global space) of the extension lines from the path to the quote"),
179 g_object_class_install_property(gobject_class
, PROP_FROM_OFFSET
, param
);
181 param
= g_param_spec_double("to-offset",
183 P_("How many extend (in global space) the extension lines after hitting the baseline"),
186 g_object_class_install_property(gobject_class
, PROP_TO_OFFSET
, param
);
188 param
= g_param_spec_double("beyond",
190 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside markers"),
193 g_object_class_install_property(gobject_class
, PROP_BEYOND
, param
);
195 param
= g_param_spec_double("baseline-spacing",
196 P_("Baseline Spacing"),
197 P_("Distance between two consecutive baselines while stacking dimensions"),
200 g_object_class_install_property(gobject_class
, PROP_BASELINE_SPACING
, param
);
202 param
= g_param_spec_double("limits-spacing",
203 P_("Limits Spacing"),
204 P_("Distance between limits/tolerances"),
207 g_object_class_install_property(gobject_class
, PROP_LIMITS_SPACING
, param
);
209 param
= g_param_spec_boxed("quote-shift",
211 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)"),
214 g_object_class_install_property(gobject_class
, PROP_QUOTE_SHIFT
, param
);
216 param
= g_param_spec_boxed("limits-shift",
218 P_("Used to specify a smooth displacement (in global space) for the limits/tolerances by taking as reference the perfect compact position"),
221 g_object_class_install_property(gobject_class
, PROP_LIMITS_SHIFT
, param
);
223 param
= g_param_spec_string("number-format",
225 P_("The format (in printf style) of the numeric component of the basic value"),
228 g_object_class_install_property(gobject_class
, PROP_NUMBER_FORMAT
, param
);
230 param
= g_param_spec_string("number-tag",
232 P_("The tag to substitute inside the value template string"),
235 g_object_class_install_property(gobject_class
, PROP_NUMBER_TAG
, param
);
239 adg_dim_style_init(AdgDimStyle
*dim_style
)
241 AdgDimStylePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim_style
,
245 data
->marker1
.type
= 0;
246 data
->marker1
.n_parameters
= 0;
247 data
->marker1
.parameters
= NULL
;
248 data
->marker2
.type
= 0;
249 data
->marker2
.n_parameters
= 0;
250 data
->marker2
.parameters
= NULL
;
251 data
->color_dress
= ADG_DRESS_COLOR_DIMENSION
;
252 data
->value_dress
= ADG_DRESS_FONT_QUOTE_TEXT
;
253 data
->min_dress
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
254 data
->max_dress
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
255 data
->line_dress
= ADG_DRESS_LINE_DIMENSION
;
256 data
->marker_dress
= ADG_DRESS_UNDEFINED
;
257 data
->from_offset
= 6;
260 data
->baseline_spacing
= 30;
261 data
->limits_spacing
= 1;
262 data
->quote_shift
.x
= 0;
263 data
->quote_shift
.y
= -4;
264 data
->limits_shift
.x
= +2;
265 data
->limits_shift
.y
= -2;
266 data
->number_format
= g_strdup("%-.7g");
267 data
->number_tag
= g_strdup("<>");
269 dim_style
->data
= data
;
273 finalize(GObject
*object
)
275 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) object
)->data
;
277 free_marker(&data
->marker1
);
278 free_marker(&data
->marker2
);
280 g_free(data
->number_format
);
281 data
->number_format
= NULL
;
283 g_free(data
->number_tag
);
284 data
->number_tag
= NULL
;
288 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
290 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) object
)->data
;
293 case PROP_COLOR_DRESS
:
294 g_value_set_int(value
, data
->color_dress
);
296 case PROP_VALUE_DRESS
:
297 g_value_set_int(value
, data
->value_dress
);
300 g_value_set_int(value
, data
->min_dress
);
303 g_value_set_int(value
, data
->max_dress
);
305 case PROP_LINE_DRESS
:
306 g_value_set_int(value
, data
->line_dress
);
308 case PROP_FROM_OFFSET
:
309 g_value_set_double(value
, data
->from_offset
);
312 g_value_set_double(value
, data
->to_offset
);
315 g_value_set_double(value
, data
->beyond
);
317 case PROP_BASELINE_SPACING
:
318 g_value_set_double(value
, data
->baseline_spacing
);
320 case PROP_LIMITS_SPACING
:
321 g_value_set_double(value
, data
->limits_spacing
);
323 case PROP_QUOTE_SHIFT
:
324 g_value_set_boxed(value
, &data
->quote_shift
);
326 case PROP_LIMITS_SHIFT
:
327 g_value_set_boxed(value
, &data
->limits_shift
);
329 case PROP_NUMBER_FORMAT
:
330 g_value_set_string(value
, data
->number_format
);
332 case PROP_NUMBER_TAG
:
333 g_value_set_string(value
, data
->number_tag
);
336 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
342 set_property(GObject
*object
,
343 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
345 AdgDimStyle
*dim_style
;
346 AdgDimStylePrivate
*data
;
348 dim_style
= (AdgDimStyle
*) object
;
349 data
= dim_style
->data
;
353 set_marker(&data
->marker1
, g_value_get_object(value
));
356 set_marker(&data
->marker2
, g_value_get_object(value
));
358 case PROP_COLOR_DRESS
:
359 data
->color_dress
= g_value_get_int(value
);
361 case PROP_VALUE_DRESS
:
362 data
->value_dress
= g_value_get_int(value
);
365 data
->min_dress
= g_value_get_int(value
);
368 data
->max_dress
= g_value_get_int(value
);
370 case PROP_LINE_DRESS
:
371 data
->line_dress
= g_value_get_int(value
);
373 case PROP_FROM_OFFSET
:
374 set_from_offset(dim_style
, g_value_get_double(value
));
377 set_to_offset(dim_style
, g_value_get_double(value
));
380 set_beyond(dim_style
, g_value_get_double(value
));
382 case PROP_BASELINE_SPACING
:
383 set_baseline_spacing(dim_style
, g_value_get_double(value
));
385 case PROP_LIMITS_SPACING
:
386 set_limits_spacing(dim_style
, g_value_get_double(value
));
388 case PROP_QUOTE_SHIFT
:
389 set_quote_shift(dim_style
, g_value_get_boxed(value
));
391 case PROP_LIMITS_SHIFT
:
392 set_limits_shift(dim_style
, g_value_get_boxed(value
));
394 case PROP_NUMBER_FORMAT
:
395 set_number_format(dim_style
, g_value_get_string(value
));
397 case PROP_NUMBER_TAG
:
398 set_number_tag(dim_style
, g_value_get_string(value
));
401 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
410 * Constructs a new empty dimension style initialized with default params.
412 * Returns: a newly created dimension style
415 adg_dim_style_new(void)
417 return g_object_new(ADG_TYPE_DIM_STYLE
, NULL
);
421 * adg_dim_style_set_marker1:
422 * @dim_style: an #AdgStyle
423 * @marker: an #AdgMarker derived entity
425 * Uses @marker as entity template to generate a new marker entity
426 * when a call to adg_dim_style_marker1_new() is made. It is allowed
427 * to pass %NULL as @marker, in which case the template data of the
428 * first marker are unset.
430 * This method duplicates internally the property values of @marker,
431 * so any further change to @marker does not affect @dim_style anymore.
432 * This also means @marker could be destroyed without problems after
433 * this call because @dim_style uses only its property values and does
434 * not add any references to @marker.
437 adg_dim_style_set_marker1(AdgDimStyle
*dim_style
, AdgMarker
*marker
)
439 AdgDimStylePrivate
*data
;
441 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
443 data
= dim_style
->data
;
445 if (set_marker(&data
->marker1
, marker
))
446 g_object_notify((GObject
*) dim_style
, "marker1");
450 * adg_dim_style_marker1_new:
451 * @dim_style: an #AdgDimStyle
453 * Creates a new marker entity by cloning the #AdgMarker:marker1
454 * object. The returned entity should be unreferenced with
455 * g_object_unref() when no longer needed.
457 * Returns: a newly created marker or %NULL if the #AdgDimStyle:marker1
458 * property is not set or on errors
461 adg_dim_style_marker1_new(AdgDimStyle
*dim_style
)
463 AdgDimStylePrivate
*data
;
465 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
467 data
= dim_style
->data
;
469 return marker_new(&data
->marker1
);
473 * adg_dim_style_set_marker2:
474 * @dim_style: an #AdgStyle
475 * @marker: an #AdgMarker derived entity
477 * Uses @marker as entity template to generate a new marker entity
478 * when a call to adg_dim_style_marker2_new() is made. It is allowed
479 * to pass %NULL as @marker, in which case the template data of the
480 * second marker are unset.
482 * This method duplicates internally the property values of @marker,
483 * so any further change to @marker does not affect @dim_style anymore.
484 * This also means @marker could be destroyed without problems after
485 * this call because @dim_style uses only its property values and does
486 * not add any references to @marker.
489 adg_dim_style_set_marker2(AdgDimStyle
*dim_style
, AdgMarker
*marker
)
491 AdgDimStylePrivate
*data
;
493 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
494 g_return_if_fail(marker
== NULL
|| ADG_IS_MARKER(marker
));
496 data
= dim_style
->data
;
498 if (set_marker(&data
->marker2
, marker
))
499 g_object_notify((GObject
*) dim_style
, "marker2");
503 * adg_dim_style_marker2_new:
504 * @dim_style: an #AdgDimStyle
506 * Creates a new marker entity by cloning the #AdgMarker:marker2
507 * object. The returned entity should be unreferenced with
508 * g_object_unref() when no longer needed.
510 * Returns: a newly created marker or %NULL if the #AdgDimStyle:marker2
511 * property is not set or on errors
514 adg_dim_style_marker2_new(AdgDimStyle
*dim_style
)
516 AdgDimStylePrivate
*data
;
518 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
520 data
= dim_style
->data
;
522 return marker_new(&data
->marker2
);
526 * adg_dim_style_set_color_dress:
527 * @dim_style: an #AdgDimStyle object
528 * @dress: the new color dress
530 * Sets a new color dress on @dim_style.
533 adg_dim_style_set_color_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
535 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
536 g_object_set((GObject
*) dim_style
, "color-dress", dress
, NULL
);
540 * adg_dim_style_get_color_dress:
541 * @dim_style: an #AdgDimStyle object
543 * Gets the @dim_style color dress to be used. This dress should be
544 * intended as a fallback color as it could be overriden by more
545 * specific dresses, such as a color explicitely specified on the
546 * #AdgDimStyle:value-dress.
548 * Returns: the color dress
551 adg_dim_style_get_color_dress(AdgDimStyle
*dim_style
)
553 AdgDimStylePrivate
*data
;
555 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
557 data
= dim_style
->data
;
559 return data
->color_dress
;
563 * adg_dim_style_set_value_dress:
564 * @dim_style: an #AdgDimStyle object
565 * @dress: the new basic value font style
567 * 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((GObject
*) 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: the font dress
586 adg_dim_style_get_value_dress(AdgDimStyle
*dim_style
)
588 AdgDimStylePrivate
*data
;
590 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
592 data
= dim_style
->data
;
594 return data
->value_dress
;
598 * adg_dim_style_set_min_dress:
599 * @dim_style: an #AdgDimStyle object
600 * @dress: the new lower limit dress
602 * Sets a new dress on @dim_style for the lower limit value.
605 adg_dim_style_set_min_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
607 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
608 g_object_set((GObject
*) dim_style
, "min-dress", dress
, NULL
);
612 * adg_dim_style_get_min_dress:
613 * @dim_style: an #AdgDimStyle object
615 * Gets the @dim_style dress to be used for the lower limit.
617 * Returns: the lower limit dress
620 adg_dim_style_get_min_dress(AdgDimStyle
*dim_style
)
622 AdgDimStylePrivate
*data
;
624 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
626 data
= dim_style
->data
;
628 return data
->min_dress
;
632 * adg_dim_style_set_max_dress:
633 * @dim_style: an #AdgDimStyle object
634 * @dress: the new upper limit dress
636 * Sets a new dress on @dim_style for the upper limit value.
639 adg_dim_style_set_max_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
641 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
642 g_object_set((GObject
*) dim_style
, "max-dress", dress
, NULL
);
646 * adg_dim_style_get_max_dress:
647 * @dim_style: an #AdgDimStyle object
649 * Gets the @dim_style dress to be used for the upper limit.
651 * Returns: the upper limit dress
654 adg_dim_style_get_max_dress(AdgDimStyle
*dim_style
)
656 AdgDimStylePrivate
*data
;
658 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
660 data
= dim_style
->data
;
662 return data
->max_dress
;
666 * adg_dim_style_set_line_dress:
667 * @dim_style: an #AdgDimStyle object
668 * @dress: the new line dress
670 * Sets a new line dress on @dim_style.
673 adg_dim_style_set_line_dress(AdgDimStyle
*dim_style
, AdgDress dress
)
675 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
676 g_object_set((GObject
*) dim_style
, "line-dress", dress
, NULL
);
680 * adg_dim_style_get_line_dress:
681 * @dim_style: an #AdgDimStyle object
683 * Gets the line dress to be used for rendering the base and
684 * the extension lines with @dim_style.
686 * Returns: the line dress
689 adg_dim_style_get_line_dress(AdgDimStyle
*dim_style
)
691 AdgDimStylePrivate
*data
;
693 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), ADG_DRESS_UNDEFINED
);
695 data
= dim_style
->data
;
697 return data
->line_dress
;
701 * adg_dim_style_set_from_offset:
702 * @dim_style: an #AdgDimStyle object
703 * @offset: the new offset
705 * Sets a new value in the #AdgDimStyle:from-offset property.
708 adg_dim_style_set_from_offset(AdgDimStyle
*dim_style
, gdouble offset
)
710 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
712 if (set_from_offset(dim_style
, offset
))
713 g_object_notify((GObject
*) dim_style
, "from-offset");
717 * adg_dim_style_get_from_offset:
718 * @dim_style: an #AdgDimStyle object
720 * Gets the distance (in global space) the extension lines must keep from the
723 * Returns: the requested distance
726 adg_dim_style_get_from_offset(AdgDimStyle
*dim_style
)
728 AdgDimStylePrivate
*data
;
730 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
732 data
= dim_style
->data
;
734 return data
->from_offset
;
738 * adg_dim_style_set_to_offset:
739 * @dim_style: an #AdgDimStyle object
740 * @offset: the new offset
742 * Sets a new value in the #AdgDimStyle:to-offset property.
745 adg_dim_style_set_to_offset(AdgDimStyle
*dim_style
, gdouble offset
)
747 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
749 if (set_to_offset(dim_style
, offset
))
750 g_object_notify((GObject
*) dim_style
, "to-offset");
754 * adg_dim_style_get_to_offset:
755 * @dim_style: an #AdgDimStyle object
757 * Gets how much (in global space) the extension lines must extend after
758 * crossing the baseline.
760 * Returns: the requested distance
763 adg_dim_style_get_to_offset(AdgDimStyle
*dim_style
)
765 AdgDimStylePrivate
*data
;
767 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
769 data
= dim_style
->data
;
771 return data
->to_offset
;
775 * adg_dim_style_set_beyond:
776 * @dim_style: an #AdgDimStyle object
777 * @beyond: the new length
779 * Sets a new value in the #AdgDimStyle:beyond property.
782 adg_dim_style_set_beyond(AdgDimStyle
*dim_style
, gdouble beyond
)
784 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
786 if (set_beyond(dim_style
, beyond
))
787 g_object_notify((GObject
*) dim_style
, "beyond");
791 * adg_dim_style_get_beyond:
792 * @dim_style: an #AdgDimStyle object
794 * Gets how much (in global space) the baseline should extend beyond
795 * the extension lines on dimension with outside markers.
797 * Returns: the requested beyond length
800 adg_dim_style_get_beyond(AdgDimStyle
*dim_style
)
802 AdgDimStylePrivate
*data
;
804 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
806 data
= dim_style
->data
;
812 * adg_dim_style_set_baseline_spacing:
813 * @dim_style: an #AdgDimStyle object
814 * @spacing: the new spacing
816 * Sets a new value in the #AdgDimStyle:baseline-spacing value.
819 adg_dim_style_set_baseline_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
821 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
823 if (set_baseline_spacing(dim_style
, spacing
))
824 g_object_notify((GObject
*) dim_style
, "baseline-spacing");
828 * adg_dim_style_get_baseline_spacing:
829 * @dim_style: an #AdgDimStyle object
831 * Gets the distance between two consecutive baselines
832 * while stacking dimensions.
834 * Returns: the requested spacing
837 adg_dim_style_get_baseline_spacing(AdgDimStyle
*dim_style
)
839 AdgDimStylePrivate
*data
;
841 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
843 data
= dim_style
->data
;
845 return data
->baseline_spacing
;
849 * adg_dim_style_set_limits_spacing:
850 * @dim_style: an #AdgDimStyle object
851 * @spacing: the new spacing
853 * Sets a new #AdgDimStyle:limits-spacing value.
856 adg_dim_style_set_limits_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
858 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
860 if (set_limits_spacing(dim_style
, spacing
))
861 g_object_notify((GObject
*) dim_style
, "limits-spacing");
865 * adg_dim_style_get_limits_spacing:
866 * @dim_style: an #AdgDimStyle object
868 * Gets the distance (in global space) between the limits/tolerances.
870 * Returns: the requested spacing
873 adg_dim_style_get_limits_spacing(AdgDimStyle
*dim_style
)
875 AdgDimStylePrivate
*data
;
877 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
879 data
= dim_style
->data
;
881 return data
->limits_spacing
;
885 * adg_dim_style_set_quote_shift:
886 * @dim_style: an #AdgDimStyle object
887 * @shift: the new displacement
889 * Sets a new #AdgDimStyle:quote-shift value.
892 adg_dim_style_set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
894 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
896 if (set_quote_shift(dim_style
, shift
))
897 g_object_notify((GObject
*) dim_style
, "quote-shift");
901 * adg_dim_style_get_quote_shift:
902 * @dim_style: an #AdgDimStyle object
904 * Gets the smooth displacement of the quote. The returned pointer refers
905 * to an internal allocated struct and must not be modified or freed.
907 * Returns: the requested shift
910 adg_dim_style_get_quote_shift(AdgDimStyle
*dim_style
)
912 AdgDimStylePrivate
*data
;
914 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
916 data
= dim_style
->data
;
918 return &data
->quote_shift
;
922 * adg_dim_style_set_limits_shift:
923 * @dim_style: an #AdgDimStyle object
924 * @shift: the new displacement
926 * Sets a new #AdgDimStyle:limits-shift value.
929 adg_dim_style_set_limits_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
931 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
933 if (set_limits_shift(dim_style
, shift
))
934 g_object_notify((GObject
*) dim_style
, "limits-shift");
938 * adg_dim_style_get_limits_shift:
939 * @dim_style: an #AdgDimStyle object
941 * Gets the smooth displacement for the limits. The returned pointer
942 * refers to an internal allocated struct and must not be modified or freed.
944 * Returns: the requested shift
947 adg_dim_style_get_limits_shift(AdgDimStyle
*dim_style
)
949 AdgDimStylePrivate
*data
;
951 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
953 data
= dim_style
->data
;
955 return &data
->limits_shift
;
959 * adg_dim_style_set_number_format:
960 * @dim_style: an #AdgDimStyle object
961 * @format: the new format to adopt
963 * Sets a new value in the #AdgDimStyle:number-format property.
966 adg_dim_style_set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
968 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
970 set_number_format(dim_style
, format
);
971 g_object_notify((GObject
*) dim_style
, "number-format");
975 * adg_dim_style_get_number_format:
976 * @dim_style: an #AdgDimStyle object
978 * Gets the number format (in printf style) of this quoting style. The
979 * returned pointer refers to internally managed text that must not be
982 * Returns: the requested format
985 adg_dim_style_get_number_format(AdgDimStyle
*dim_style
)
987 AdgDimStylePrivate
*data
;
989 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
991 data
= dim_style
->data
;
993 return data
->number_format
;
997 * adg_dim_style_set_number_tag:
998 * @dim_style: an #AdgDimStyle object
1001 * Sets a new tag in the #AdgDimStyle:number-tag property.
1004 adg_dim_style_set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
1006 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
1008 set_number_tag(dim_style
, tag
);
1009 g_object_notify((GObject
*) dim_style
, "number-tag");
1013 * adg_dim_style_get_number_tag:
1014 * @dim_style: an #AdgDimStyle object
1016 * Gets the number tag of @dim_style. This tag will be used while
1017 * generating the set values of the dimensions bound to this style:
1018 * check the #AdgDim:value documentation for further details.
1020 * The returned pointer refers to internally managed text that
1021 * must not be modified or freed.
1023 * Returns: the requested tag
1026 adg_dim_style_get_number_tag(AdgDimStyle
*dim_style
)
1028 AdgDimStylePrivate
*data
;
1030 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
1032 data
= dim_style
->data
;
1034 return data
->number_tag
;
1039 apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
1041 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) style
)->data
;
1042 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);
1046 set_from_offset(AdgDimStyle
*dim_style
, gdouble offset
)
1048 AdgDimStylePrivate
*data
= dim_style
->data
;
1050 /* A better approach would be to use the GParamSpec of this property */
1051 g_return_val_if_fail(offset
>= 0, FALSE
);
1053 if (data
->from_offset
== offset
)
1056 data
->from_offset
= offset
;
1061 set_to_offset(AdgDimStyle
*dim_style
, gdouble offset
)
1063 AdgDimStylePrivate
*data
= dim_style
->data
;
1065 /* A better approach would be to use the GParamSpec of this property */
1066 g_return_val_if_fail(offset
>= 0, FALSE
);
1068 if (data
->to_offset
== offset
)
1071 data
->to_offset
= offset
;
1076 set_baseline_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
1078 AdgDimStylePrivate
*data
= dim_style
->data
;
1080 /* A better approach would be to use the GParamSpec of this property */
1081 g_return_val_if_fail(spacing
>= 0, FALSE
);
1083 if (data
->baseline_spacing
== spacing
)
1086 data
->baseline_spacing
= spacing
;
1091 set_limits_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
1093 AdgDimStylePrivate
*data
= dim_style
->data
;
1095 /* A better approach would be to use the GParamSpec of this property */
1096 g_return_val_if_fail(spacing
>= 0, FALSE
);
1098 if (data
->limits_spacing
== spacing
)
1101 data
->limits_spacing
= spacing
;
1106 set_beyond(AdgDimStyle
*dim_style
, gdouble beyond
)
1108 AdgDimStylePrivate
*data
= dim_style
->data
;
1110 /* A better approach would be to use the GParamSpec of this property */
1111 g_return_val_if_fail(beyond
>= 0, FALSE
);
1113 if (data
->beyond
== beyond
)
1116 data
->beyond
= beyond
;
1121 set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1123 AdgDimStylePrivate
*data
;
1125 g_return_val_if_fail(shift
!= NULL
, FALSE
);
1127 data
= dim_style
->data
;
1129 if (adg_pair_equal(&data
->quote_shift
, shift
))
1132 data
->quote_shift
= *shift
;
1138 set_limits_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1140 AdgDimStylePrivate
*data
;
1142 g_return_val_if_fail(shift
!= NULL
, FALSE
);
1144 data
= dim_style
->data
;
1146 if (adg_pair_equal(&data
->limits_shift
, shift
))
1149 data
->limits_shift
= *shift
;
1155 set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
1157 AdgDimStylePrivate
*data
= dim_style
->data
;
1159 g_free(data
->number_format
);
1160 data
->number_format
= g_strdup(format
);
1164 set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
1166 AdgDimStylePrivate
*data
= dim_style
->data
;
1168 g_free(data
->number_tag
);
1169 data
->number_tag
= g_strdup(tag
);
1173 marker_new(const AdgMarkerData
*marker_data
)
1175 if (marker_data
->type
== 0)
1178 return g_object_newv(marker_data
->type
,
1179 marker_data
->n_parameters
,
1180 marker_data
->parameters
);
1184 set_marker(AdgMarkerData
*marker_data
, AdgMarker
*marker
)
1186 g_return_val_if_fail(marker
== NULL
|| ADG_IS_MARKER(marker
), FALSE
);
1188 /* Free the previous marker data, if any */
1189 free_marker(marker_data
);
1195 GParameter
*parameter
;
1198 object
= (GObject
*) marker
;
1199 specs
= g_object_class_list_properties(G_OBJECT_GET_CLASS(marker
),
1200 &marker_data
->n_parameters
);
1202 marker_data
->type
= G_TYPE_FROM_INSTANCE(marker
);
1203 marker_data
->parameters
= g_new0(GParameter
, marker_data
->n_parameters
);
1205 for (n
= 0; n
< marker_data
->n_parameters
; ++n
) {
1207 parameter
= &marker_data
->parameters
[n
];
1209 /* Using intern strings because GParameter:name is const.
1210 * GObject properties are internally managed using non-static
1211 * GQuark, so g_intern_string() is the way to go */
1212 parameter
->name
= g_intern_string(spec
->name
);
1214 g_value_init(¶meter
->value
, spec
->value_type
);
1215 g_object_get_property(object
, spec
->name
, ¶meter
->value
);
1225 free_marker(AdgMarkerData
*marker_data
)
1229 for (n
= 0; n
< marker_data
->n_parameters
; ++n
)
1230 g_value_unset(&marker_data
->parameters
[n
].value
);
1232 marker_data
->type
= 0;
1233 marker_data
->n_parameters
= 0;
1234 marker_data
->parameters
= NULL
;