build: depends on cairo-gobject if introspection is enabled
[adg.git] / src / adg / adg-dim-style.c
blobce06a2e328fa56506cd11c78493c46737e104881
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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.
21 /**
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...
29 * Since: 1.0
32 /**
33 * AdgDimStyle:
35 * All fields are private and should not be used directly.
36 * Use its public methods instead.
38 * Since: 1.0
39 **/
42 #include "adg-internal.h"
43 #include "adg-style.h"
44 #include "adg-font-style.h"
45 #include "adg-dash.h"
46 #include "adg-line-style.h"
47 #include "adg-model.h"
48 #include "adg-trail.h"
49 #include "adg-marker.h"
50 #include "adg-dress.h"
51 #include "adg-param-dress.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)
59 enum {
60 PROP_0,
61 PROP_MARKER1,
62 PROP_MARKER2,
63 PROP_COLOR_DRESS,
64 PROP_VALUE_DRESS,
65 PROP_MIN_DRESS,
66 PROP_MAX_DRESS,
67 PROP_LINE_DRESS,
68 PROP_FROM_OFFSET,
69 PROP_TO_OFFSET,
70 PROP_BEYOND,
71 PROP_BASELINE_SPACING,
72 PROP_LIMITS_SPACING,
73 PROP_QUOTE_SHIFT,
74 PROP_LIMITS_SHIFT,
75 PROP_NUMBER_FORMAT,
76 PROP_NUMBER_TAG
80 static void _adg_finalize (GObject *object);
81 static void _adg_get_property (GObject *object,
82 guint prop_id,
83 GValue *value,
84 GParamSpec *pspec);
85 static void _adg_set_property (GObject *object,
86 guint prop_id,
87 const GValue *value,
88 GParamSpec *pspec);
89 static void _adg_apply (AdgStyle *style,
90 AdgEntity *entity,
91 cairo_t *cr);
92 static AdgMarker * _adg_marker_new (const AdgMarkerData
93 *marker_data);
94 static void _adg_set_marker (AdgMarkerData *marker_data,
95 AdgMarker *marker);
96 static void _adg_free_marker (AdgMarkerData *marker_data);
99 static void
100 adg_dim_style_class_init(AdgDimStyleClass *klass)
102 GObjectClass *gobject_class;
103 AdgStyleClass *style_class;
104 GParamSpec *param;
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",
118 P_("First Marker"),
119 P_("The template entity to use as first marker"),
120 ADG_TYPE_MARKER,
121 G_PARAM_WRITABLE);
122 g_object_class_install_property(gobject_class, PROP_MARKER1, param);
124 param = g_param_spec_object("marker2",
125 P_("Second Marker"),
126 P_("The template entity to use as second marker"),
127 ADG_TYPE_MARKER,
128 G_PARAM_WRITABLE);
129 g_object_class_install_property(gobject_class, PROP_MARKER2, param);
131 param = adg_param_spec_dress("color-dress",
132 P_("Color Dress"),
133 P_("Color dress for the whole dimension"),
134 ADG_DRESS_COLOR_DIMENSION,
135 G_PARAM_READWRITE);
136 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
138 param = adg_param_spec_dress("value-dress",
139 P_("Value Dress"),
140 P_("Font dress for the nominal value of the dimension"),
141 ADG_DRESS_FONT_QUOTE_TEXT,
142 G_PARAM_READWRITE);
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,
149 G_PARAM_READWRITE);
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,
156 G_PARAM_READWRITE);
157 g_object_class_install_property(gobject_class, PROP_MAX_DRESS, param);
159 param = adg_param_spec_dress("line-dress",
160 P_("Line Dress"),
161 P_("Line dress for the baseline and the extension lines"),
162 ADG_DRESS_LINE_DIMENSION,
163 G_PARAM_READWRITE);
164 g_object_class_install_property(gobject_class, PROP_LINE_DRESS, param);
166 param = g_param_spec_double("from-offset",
167 P_("From Offset"),
168 P_("Offset (in global space) of the extension lines from the path to the quote"),
169 0, G_MAXDOUBLE, 5,
170 G_PARAM_READWRITE);
171 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET, param);
173 param = g_param_spec_double("to-offset",
174 P_("To Offset"),
175 P_("How many extend (in global space) the extension lines after hitting the baseline"),
176 0, G_MAXDOUBLE, 5,
177 G_PARAM_READWRITE);
178 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
180 param = g_param_spec_double("beyond",
181 P_("Beyond Length"),
182 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside markers"),
183 0, G_MAXDOUBLE, 20,
184 G_PARAM_READWRITE);
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"),
190 0, G_MAXDOUBLE, 32,
191 G_PARAM_READWRITE);
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"),
197 0, G_MAXDOUBLE, 2,
198 G_PARAM_READWRITE);
199 g_object_class_install_property(gobject_class, PROP_LIMITS_SPACING, param);
201 param = g_param_spec_boxed("quote-shift",
202 P_("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)"),
204 CPML_TYPE_PAIR,
205 G_PARAM_READWRITE);
206 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT, param);
208 param = g_param_spec_boxed("limits-shift",
209 P_("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"),
211 CPML_TYPE_PAIR,
212 G_PARAM_READWRITE);
213 g_object_class_install_property(gobject_class, PROP_LIMITS_SHIFT, param);
215 param = g_param_spec_string("number-format",
216 P_("Number Format"),
217 P_("The format (in printf style) of the numeric component of the basic value"),
218 "%-.7g",
219 G_PARAM_READWRITE);
220 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT, param);
222 param = g_param_spec_string("number-tag",
223 P_("Number Tag"),
224 P_("The tag to substitute inside the value template string"),
225 "<>",
226 G_PARAM_READWRITE);
227 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
230 static void
231 adg_dim_style_init(AdgDimStyle *dim_style)
233 AdgDimStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
234 ADG_TYPE_DIM_STYLE,
235 AdgDimStylePrivate);
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;
250 data->to_offset = 6;
251 data->beyond = 20;
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;
264 static void
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;
279 static void
280 _adg_get_property(GObject *object, guint prop_id,
281 GValue *value, GParamSpec *pspec)
283 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
285 switch (prop_id) {
286 case PROP_COLOR_DRESS:
287 g_value_set_enum(value, data->color_dress);
288 break;
289 case PROP_VALUE_DRESS:
290 g_value_set_enum(value, data->value_dress);
291 break;
292 case PROP_MIN_DRESS:
293 g_value_set_enum(value, data->min_dress);
294 break;
295 case PROP_MAX_DRESS:
296 g_value_set_enum(value, data->max_dress);
297 break;
298 case PROP_LINE_DRESS:
299 g_value_set_enum(value, data->line_dress);
300 break;
301 case PROP_FROM_OFFSET:
302 g_value_set_double(value, data->from_offset);
303 break;
304 case PROP_TO_OFFSET:
305 g_value_set_double(value, data->to_offset);
306 break;
307 case PROP_BEYOND:
308 g_value_set_double(value, data->beyond);
309 break;
310 case PROP_BASELINE_SPACING:
311 g_value_set_double(value, data->baseline_spacing);
312 break;
313 case PROP_LIMITS_SPACING:
314 g_value_set_double(value, data->limits_spacing);
315 break;
316 case PROP_QUOTE_SHIFT:
317 g_value_set_boxed(value, &data->quote_shift);
318 break;
319 case PROP_LIMITS_SHIFT:
320 g_value_set_boxed(value, &data->limits_shift);
321 break;
322 case PROP_NUMBER_FORMAT:
323 g_value_set_string(value, data->number_format);
324 break;
325 case PROP_NUMBER_TAG:
326 g_value_set_string(value, data->number_tag);
327 break;
328 default:
329 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
330 break;
334 static void
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;
344 switch (prop_id) {
345 case PROP_MARKER1:
346 _adg_set_marker(&data->marker1, g_value_get_object(value));
347 break;
348 case PROP_MARKER2:
349 _adg_set_marker(&data->marker2, g_value_get_object(value));
350 break;
351 case PROP_COLOR_DRESS:
352 data->color_dress = g_value_get_enum(value);
353 break;
354 case PROP_VALUE_DRESS:
355 data->value_dress = g_value_get_enum(value);
356 break;
357 case PROP_MIN_DRESS:
358 data->min_dress = g_value_get_enum(value);
359 break;
360 case PROP_MAX_DRESS:
361 data->max_dress = g_value_get_enum(value);
362 break;
363 case PROP_LINE_DRESS:
364 data->line_dress = g_value_get_enum(value);
365 break;
366 case PROP_FROM_OFFSET:
367 data->from_offset = g_value_get_double(value);
368 break;
369 case PROP_TO_OFFSET:
370 data->to_offset = g_value_get_double(value);
371 break;
372 case PROP_BEYOND:
373 data->beyond = g_value_get_double(value);
374 break;
375 case PROP_BASELINE_SPACING:
376 data->baseline_spacing = g_value_get_double(value);
377 break;
378 case PROP_LIMITS_SPACING:
379 data->limits_spacing = g_value_get_double(value);
380 break;
381 case PROP_QUOTE_SHIFT:
382 cpml_pair_copy(&data->quote_shift, g_value_get_boxed(value));
383 break;
384 case PROP_LIMITS_SHIFT:
385 cpml_pair_copy(&data->limits_shift, g_value_get_boxed(value));
386 break;
387 case PROP_NUMBER_FORMAT:
388 g_free(data->number_format);
389 data->number_format = g_value_dup_string(value);
390 break;
391 case PROP_NUMBER_TAG:
392 g_free(data->number_tag);
393 data->number_tag = g_value_dup_string(value);
394 break;
395 default:
396 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
397 break;
403 * adg_dim_style_new:
405 * Constructs a new empty dimension style initialized with default params.
407 * Returns: (transfer full): a newly created dimension style.
409 * Since: 1.0
411 AdgDimStyle *
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.
433 * Since: 1.0
435 void
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.
454 * Since: 1.0
456 AdgMarker *
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.
484 * Since: 1.0
486 void
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.
505 * Since: 1.0
507 AdgMarker *
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.
526 * Since: 1.0
528 void
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.
546 * Since: 1.0
548 AdgDress
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.
567 * Since: 1.0
569 void
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
581 * with @dim_style.
583 * Returns: (transfer none): the font dress.
585 * Since: 1.0
587 AdgDress
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.
606 * Since: 1.0
608 void
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.
623 * Since: 1.0
625 AdgDress
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.
644 * Since: 1.0
646 void
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.
661 * Since: 1.0
663 AdgDress
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.
682 * Since: 1.0
684 void
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.
700 * Since: 1.0
702 AdgDress
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.
721 * Since: 1.0
723 void
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
735 * sensed points.
737 * Returns: the requested distance.
739 * Since: 1.0
741 gdouble
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.
760 * Since: 1.0
762 void
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.
778 * Since: 1.0
780 gdouble
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.
799 * Since: 1.0
801 void
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.
817 * Since: 1.0
819 gdouble
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;
828 return data->beyond;
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.
838 * Since: 1.0
840 void
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.
856 * Since: 1.0
858 gdouble
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.
877 * Since: 1.0
879 void
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.
894 * Since: 1.0
896 gdouble
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.
915 * Since: 1.0
917 void
918 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const CpmlPair *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.
933 * Since: 1.0
935 const CpmlPair *
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.
954 * Since: 1.0
956 void
957 adg_dim_style_set_limits_shift(AdgDimStyle *dim_style, const CpmlPair *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.
972 * Since: 1.0
974 const CpmlPair *
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.
993 * Since: 1.0
995 void
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.
1012 * Since: 1.0
1014 const gchar *
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
1029 * @tag: the new tag
1031 * Sets a new tag in the #AdgDimStyle:number-tag property.
1033 * Since: 1.0
1035 void
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.
1055 * Since: 1.0
1057 const gchar *
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;
1070 static void
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);
1077 static AdgMarker *
1078 _adg_marker_new(const AdgMarkerData *marker_data)
1080 if (marker_data->type == 0)
1081 return NULL;
1083 return g_object_newv(marker_data->type,
1084 marker_data->n_parameters,
1085 marker_data->parameters);
1088 static void
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);
1096 if (marker) {
1097 GObject *object;
1098 GParamSpec **specs;
1099 GParamSpec *spec;
1100 GParameter *parameter;
1101 guint n;
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) {
1111 spec = specs[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(&parameter->value, spec->value_type);
1120 g_object_get_property(object, spec->name, &parameter->value);
1123 g_free(specs);
1127 static void
1128 _adg_free_marker(AdgMarkerData *marker_data)
1130 guint n;
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;