[AdgText] Using logical_rect instead of ink_rect for extents
[adg.git] / src / adg / adg-dim-style.c
bloba77338d3c346494f6125a8d9a07f5bd526194fbd
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011 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...
30 /**
31 * AdgDimStyle:
33 * All fields are private and should not be used directly.
34 * Use its public methods instead.
35 **/
38 #include "adg-internal.h"
39 #include "adg-style.h"
40 #include "adg-font-style.h"
41 #include "adg-line-style.h"
42 #include "adg-dress.h"
43 #include "adg-dress-builtins.h"
44 #include "adg-model.h"
45 #include "adg-trail.h"
46 #include "adg-marker.h"
48 #include "adg-dim-style.h"
49 #include "adg-dim-style-private.h"
52 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE)
54 enum {
55 PROP_0,
56 PROP_MARKER1,
57 PROP_MARKER2,
58 PROP_COLOR_DRESS,
59 PROP_VALUE_DRESS,
60 PROP_MIN_DRESS,
61 PROP_MAX_DRESS,
62 PROP_LINE_DRESS,
63 PROP_FROM_OFFSET,
64 PROP_TO_OFFSET,
65 PROP_BEYOND,
66 PROP_BASELINE_SPACING,
67 PROP_LIMITS_SPACING,
68 PROP_QUOTE_SHIFT,
69 PROP_LIMITS_SHIFT,
70 PROP_NUMBER_FORMAT,
71 PROP_NUMBER_TAG
75 static void _adg_finalize (GObject *object);
76 static void _adg_get_property (GObject *object,
77 guint prop_id,
78 GValue *value,
79 GParamSpec *pspec);
80 static void _adg_set_property (GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec);
84 static void _adg_apply (AdgStyle *style,
85 AdgEntity *entity,
86 cairo_t *cr);
87 static AdgMarker * _adg_marker_new (const AdgMarkerData
88 *marker_data);
89 static void _adg_set_marker (AdgMarkerData *marker_data,
90 AdgMarker *marker);
91 static void _adg_free_marker (AdgMarkerData *marker_data);
94 static void
95 adg_dim_style_class_init(AdgDimStyleClass *klass)
97 GObjectClass *gobject_class;
98 AdgStyleClass *style_class;
99 GParamSpec *param;
101 gobject_class = (GObjectClass *) klass;
102 style_class = (AdgStyleClass *) klass;
104 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
106 gobject_class->finalize = _adg_finalize;
107 gobject_class->get_property = _adg_get_property;
108 gobject_class->set_property = _adg_set_property;
110 style_class->apply = _adg_apply;
112 param = g_param_spec_object("marker1",
113 P_("First Marker"),
114 P_("The template entity to use as first marker"),
115 ADG_TYPE_MARKER,
116 G_PARAM_WRITABLE);
117 g_object_class_install_property(gobject_class, PROP_MARKER1, param);
119 param = g_param_spec_object("marker2",
120 P_("Second Marker"),
121 P_("The template entity to use as second marker"),
122 ADG_TYPE_MARKER,
123 G_PARAM_WRITABLE);
124 g_object_class_install_property(gobject_class, PROP_MARKER2, param);
126 param = adg_param_spec_dress("color-dress",
127 P_("Color Dress"),
128 P_("Color dress for the whole dimension"),
129 ADG_DRESS_COLOR_DIMENSION,
130 G_PARAM_READWRITE);
131 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
133 param = adg_param_spec_dress("value-dress",
134 P_("Value Dress"),
135 P_("Font dress for the nominal value of the dimension"),
136 ADG_DRESS_FONT_QUOTE_TEXT,
137 G_PARAM_READWRITE);
138 g_object_class_install_property(gobject_class, PROP_VALUE_DRESS, param);
140 param = adg_param_spec_dress("min-dress",
141 P_("Minimum Limit Dress"),
142 P_("Font dress for the lower limit value"),
143 ADG_DRESS_FONT_QUOTE_ANNOTATION,
144 G_PARAM_READWRITE);
145 g_object_class_install_property(gobject_class, PROP_MIN_DRESS, param);
147 param = adg_param_spec_dress("max-dress",
148 P_("Maximum Limit Dress"),
149 P_("Font dress for the upper limit value"),
150 ADG_DRESS_FONT_QUOTE_ANNOTATION,
151 G_PARAM_READWRITE);
152 g_object_class_install_property(gobject_class, PROP_MAX_DRESS, param);
154 param = adg_param_spec_dress("line-dress",
155 P_("Line Dress"),
156 P_("Line dress for the baseline and the extension lines"),
157 ADG_DRESS_LINE_DIMENSION,
158 G_PARAM_READWRITE);
159 g_object_class_install_property(gobject_class, PROP_LINE_DRESS, param);
161 param = g_param_spec_double("from-offset",
162 P_("From Offset"),
163 P_("Offset (in global space) of the extension lines from the path to the quote"),
164 0, G_MAXDOUBLE, 5,
165 G_PARAM_READWRITE);
166 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET, param);
168 param = g_param_spec_double("to-offset",
169 P_("To Offset"),
170 P_("How many extend (in global space) the extension lines after hitting the baseline"),
171 0, G_MAXDOUBLE, 5,
172 G_PARAM_READWRITE);
173 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
175 param = g_param_spec_double("beyond",
176 P_("Beyond Length"),
177 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside markers"),
178 0, G_MAXDOUBLE, 20,
179 G_PARAM_READWRITE);
180 g_object_class_install_property(gobject_class, PROP_BEYOND, param);
182 param = g_param_spec_double("baseline-spacing",
183 P_("Baseline Spacing"),
184 P_("Distance between two consecutive baselines while stacking dimensions"),
185 0, G_MAXDOUBLE, 32,
186 G_PARAM_READWRITE);
187 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING, param);
189 param = g_param_spec_double("limits-spacing",
190 P_("Limits Spacing"),
191 P_("Distance between limits/tolerances"),
192 0, G_MAXDOUBLE, 2,
193 G_PARAM_READWRITE);
194 g_object_class_install_property(gobject_class, PROP_LIMITS_SPACING, param);
196 param = g_param_spec_boxed("quote-shift",
197 P_("Quote Shift"),
198 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)"),
199 ADG_TYPE_PAIR,
200 G_PARAM_READWRITE);
201 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT, param);
203 param = g_param_spec_boxed("limits-shift",
204 P_("Limits Shift"),
205 P_("Used to specify a smooth displacement (in global space) for the limits/tolerances by taking as reference the perfect compact position"),
206 ADG_TYPE_PAIR,
207 G_PARAM_READWRITE);
208 g_object_class_install_property(gobject_class, PROP_LIMITS_SHIFT, param);
210 param = g_param_spec_string("number-format",
211 P_("Number Format"),
212 P_("The format (in printf style) of the numeric component of the basic value"),
213 "%-.7g",
214 G_PARAM_READWRITE);
215 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT, param);
217 param = g_param_spec_string("number-tag",
218 P_("Number Tag"),
219 P_("The tag to substitute inside the value template string"),
220 "<>",
221 G_PARAM_READWRITE);
222 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
225 static void
226 adg_dim_style_init(AdgDimStyle *dim_style)
228 AdgDimStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
229 ADG_TYPE_DIM_STYLE,
230 AdgDimStylePrivate);
232 data->marker1.type = 0;
233 data->marker1.n_parameters = 0;
234 data->marker1.parameters = NULL;
235 data->marker2.type = 0;
236 data->marker2.n_parameters = 0;
237 data->marker2.parameters = NULL;
238 data->color_dress = ADG_DRESS_COLOR_DIMENSION;
239 data->value_dress = ADG_DRESS_FONT_QUOTE_TEXT;
240 data->min_dress = ADG_DRESS_FONT_QUOTE_ANNOTATION;
241 data->max_dress = ADG_DRESS_FONT_QUOTE_ANNOTATION;
242 data->line_dress = ADG_DRESS_LINE_DIMENSION;
243 data->marker_dress = ADG_DRESS_UNDEFINED;
244 data->from_offset = 6;
245 data->to_offset = 6;
246 data->beyond = 20;
247 data->baseline_spacing = 32;
248 data->limits_spacing = 0;
249 data->quote_shift.x = 4;
250 data->quote_shift.y = -1;
251 data->limits_shift.x = +2;
252 data->limits_shift.y = +2;
253 data->number_format = g_strdup("%-.7g");
254 data->number_tag = g_strdup("<>");
256 dim_style->data = data;
259 static void
260 _adg_finalize(GObject *object)
262 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
264 _adg_free_marker(&data->marker1);
265 _adg_free_marker(&data->marker2);
267 g_free(data->number_format);
268 data->number_format = NULL;
270 g_free(data->number_tag);
271 data->number_tag = NULL;
274 static void
275 _adg_get_property(GObject *object, guint prop_id,
276 GValue *value, GParamSpec *pspec)
278 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
280 switch (prop_id) {
281 case PROP_COLOR_DRESS:
282 g_value_set_int(value, data->color_dress);
283 break;
284 case PROP_VALUE_DRESS:
285 g_value_set_int(value, data->value_dress);
286 break;
287 case PROP_MIN_DRESS:
288 g_value_set_int(value, data->min_dress);
289 break;
290 case PROP_MAX_DRESS:
291 g_value_set_int(value, data->max_dress);
292 break;
293 case PROP_LINE_DRESS:
294 g_value_set_int(value, data->line_dress);
295 break;
296 case PROP_FROM_OFFSET:
297 g_value_set_double(value, data->from_offset);
298 break;
299 case PROP_TO_OFFSET:
300 g_value_set_double(value, data->to_offset);
301 break;
302 case PROP_BEYOND:
303 g_value_set_double(value, data->beyond);
304 break;
305 case PROP_BASELINE_SPACING:
306 g_value_set_double(value, data->baseline_spacing);
307 break;
308 case PROP_LIMITS_SPACING:
309 g_value_set_double(value, data->limits_spacing);
310 break;
311 case PROP_QUOTE_SHIFT:
312 g_value_set_boxed(value, &data->quote_shift);
313 break;
314 case PROP_LIMITS_SHIFT:
315 g_value_set_boxed(value, &data->limits_shift);
316 break;
317 case PROP_NUMBER_FORMAT:
318 g_value_set_string(value, data->number_format);
319 break;
320 case PROP_NUMBER_TAG:
321 g_value_set_string(value, data->number_tag);
322 break;
323 default:
324 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
325 break;
329 static void
330 _adg_set_property(GObject *object, guint prop_id,
331 const GValue *value, GParamSpec *pspec)
333 AdgDimStyle *dim_style;
334 AdgDimStylePrivate *data;
336 dim_style = (AdgDimStyle *) object;
337 data = dim_style->data;
339 switch (prop_id) {
340 case PROP_MARKER1:
341 _adg_set_marker(&data->marker1, g_value_get_object(value));
342 break;
343 case PROP_MARKER2:
344 _adg_set_marker(&data->marker2, g_value_get_object(value));
345 break;
346 case PROP_COLOR_DRESS:
347 data->color_dress = g_value_get_int(value);
348 break;
349 case PROP_VALUE_DRESS:
350 data->value_dress = g_value_get_int(value);
351 break;
352 case PROP_MIN_DRESS:
353 data->min_dress = g_value_get_int(value);
354 break;
355 case PROP_MAX_DRESS:
356 data->max_dress = g_value_get_int(value);
357 break;
358 case PROP_LINE_DRESS:
359 data->line_dress = g_value_get_int(value);
360 break;
361 case PROP_FROM_OFFSET:
362 data->from_offset = g_value_get_double(value);
363 break;
364 case PROP_TO_OFFSET:
365 data->to_offset = g_value_get_double(value);
366 break;
367 case PROP_BEYOND:
368 data->beyond = g_value_get_double(value);
369 break;
370 case PROP_BASELINE_SPACING:
371 data->baseline_spacing = g_value_get_double(value);
372 break;
373 case PROP_LIMITS_SPACING:
374 data->limits_spacing = g_value_get_double(value);
375 break;
376 case PROP_QUOTE_SHIFT:
377 adg_pair_copy(&data->quote_shift, g_value_get_boxed(value));
378 break;
379 case PROP_LIMITS_SHIFT:
380 adg_pair_copy(&data->limits_shift, g_value_get_boxed(value));
381 break;
382 case PROP_NUMBER_FORMAT:
383 g_free(data->number_format);
384 data->number_format = g_value_dup_string(value);
385 break;
386 case PROP_NUMBER_TAG:
387 g_free(data->number_tag);
388 data->number_tag = g_value_dup_string(value);
389 break;
390 default:
391 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
392 break;
398 * adg_dim_style_new:
400 * Constructs a new empty dimension style initialized with default params.
402 * Returns: a newly created dimension style
404 AdgDimStyle *
405 adg_dim_style_new(void)
407 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
411 * adg_dim_style_set_marker1:
412 * @dim_style: an #AdgStyle
413 * @marker: an #AdgMarker derived entity
415 * Uses @marker as entity template to generate a new marker entity
416 * when a call to adg_dim_style_marker1_new() is made. It is allowed
417 * to pass %NULL as @marker, in which case the template data of the
418 * first marker are unset.
420 * This method duplicates internally the property values of @marker,
421 * so any further change to @marker does not affect @dim_style anymore.
422 * This also means @marker could be destroyed without problems after
423 * this call because @dim_style uses only its property values and does
424 * not add any references to @marker.
426 void
427 adg_dim_style_set_marker1(AdgDimStyle *dim_style, AdgMarker *marker)
429 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
430 g_object_set(dim_style, "marker1", marker, NULL);
434 * adg_dim_style_marker1_new:
435 * @dim_style: an #AdgDimStyle
437 * Creates a new marker entity by cloning the #AdgMarker:marker1
438 * object. The returned entity should be unreferenced with
439 * g_object_unref() when no longer needed.
441 * Returns: a newly created marker or %NULL if the #AdgDimStyle:marker1
442 * property is not set or on errors
444 AdgMarker *
445 adg_dim_style_marker1_new(AdgDimStyle *dim_style)
447 AdgDimStylePrivate *data;
449 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
451 data = dim_style->data;
453 return _adg_marker_new(&data->marker1);
457 * adg_dim_style_set_marker2:
458 * @dim_style: an #AdgStyle
459 * @marker: an #AdgMarker derived entity
461 * Uses @marker as entity template to generate a new marker entity
462 * when a call to adg_dim_style_marker2_new() is made. It is allowed
463 * to pass %NULL as @marker, in which case the template data of the
464 * second marker are unset.
466 * This method duplicates internally the property values of @marker,
467 * so any further change to @marker does not affect @dim_style anymore.
468 * This also means @marker could be destroyed without problems after
469 * this call because @dim_style uses only its property values and does
470 * not add any references to @marker.
472 void
473 adg_dim_style_set_marker2(AdgDimStyle *dim_style, AdgMarker *marker)
475 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
476 g_object_set(dim_style, "marker2", marker, NULL);
480 * adg_dim_style_marker2_new:
481 * @dim_style: an #AdgDimStyle
483 * Creates a new marker entity by cloning the #AdgMarker:marker2
484 * object. The returned entity should be unreferenced with
485 * g_object_unref() when no longer needed.
487 * Returns: a newly created marker or %NULL if the #AdgDimStyle:marker2
488 * property is not set or on errors
490 AdgMarker *
491 adg_dim_style_marker2_new(AdgDimStyle *dim_style)
493 AdgDimStylePrivate *data;
495 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
497 data = dim_style->data;
499 return _adg_marker_new(&data->marker2);
503 * adg_dim_style_set_color_dress:
504 * @dim_style: an #AdgDimStyle object
505 * @dress: the new color dress
507 * Sets a new color dress on @dim_style.
509 void
510 adg_dim_style_set_color_dress(AdgDimStyle *dim_style, AdgDress dress)
512 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
513 g_object_set(dim_style, "color-dress", dress, NULL);
517 * adg_dim_style_get_color_dress:
518 * @dim_style: an #AdgDimStyle object
520 * Gets the @dim_style color dress to be used. This dress should be
521 * intended as a fallback color as it could be overriden by more
522 * specific dresses, such as a color explicitely specified on the
523 * #AdgDimStyle:value-dress.
525 * Returns: the color dress
527 AdgDress
528 adg_dim_style_get_color_dress(AdgDimStyle *dim_style)
530 AdgDimStylePrivate *data;
532 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
534 data = dim_style->data;
536 return data->color_dress;
540 * adg_dim_style_set_value_dress:
541 * @dim_style: an #AdgDimStyle object
542 * @dress: the new basic value font style
544 * Sets a new dress on @dim_style for the basic value.
546 void
547 adg_dim_style_set_value_dress(AdgDimStyle *dim_style, AdgDress dress)
549 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
550 g_object_set(dim_style, "value-dress", dress, NULL);
554 * adg_dim_style_get_value_dress:
555 * @dim_style: an #AdgDimStyle object
557 * Gets the font dress to be used for the basic value of dimensions
558 * with @dim_style.
560 * Returns: the font dress
562 AdgDress
563 adg_dim_style_get_value_dress(AdgDimStyle *dim_style)
565 AdgDimStylePrivate *data;
567 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
569 data = dim_style->data;
571 return data->value_dress;
575 * adg_dim_style_set_min_dress:
576 * @dim_style: an #AdgDimStyle object
577 * @dress: the new lower limit dress
579 * Sets a new dress on @dim_style for the lower limit value.
581 void
582 adg_dim_style_set_min_dress(AdgDimStyle *dim_style, AdgDress dress)
584 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
585 g_object_set(dim_style, "min-dress", dress, NULL);
589 * adg_dim_style_get_min_dress:
590 * @dim_style: an #AdgDimStyle object
592 * Gets the @dim_style dress to be used for the lower limit.
594 * Returns: the lower limit dress
596 AdgDress
597 adg_dim_style_get_min_dress(AdgDimStyle *dim_style)
599 AdgDimStylePrivate *data;
601 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
603 data = dim_style->data;
605 return data->min_dress;
609 * adg_dim_style_set_max_dress:
610 * @dim_style: an #AdgDimStyle object
611 * @dress: the new upper limit dress
613 * Sets a new dress on @dim_style for the upper limit value.
615 void
616 adg_dim_style_set_max_dress(AdgDimStyle *dim_style, AdgDress dress)
618 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
619 g_object_set(dim_style, "max-dress", dress, NULL);
623 * adg_dim_style_get_max_dress:
624 * @dim_style: an #AdgDimStyle object
626 * Gets the @dim_style dress to be used for the upper limit.
628 * Returns: the upper limit dress
630 AdgDress
631 adg_dim_style_get_max_dress(AdgDimStyle *dim_style)
633 AdgDimStylePrivate *data;
635 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
637 data = dim_style->data;
639 return data->max_dress;
643 * adg_dim_style_set_line_dress:
644 * @dim_style: an #AdgDimStyle object
645 * @dress: the new line dress
647 * Sets a new line dress on @dim_style.
649 void
650 adg_dim_style_set_line_dress(AdgDimStyle *dim_style, AdgDress dress)
652 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
653 g_object_set(dim_style, "line-dress", dress, NULL);
657 * adg_dim_style_get_line_dress:
658 * @dim_style: an #AdgDimStyle object
660 * Gets the line dress to be used for rendering the base and
661 * the extension lines with @dim_style.
663 * Returns: the line dress
665 AdgDress
666 adg_dim_style_get_line_dress(AdgDimStyle *dim_style)
668 AdgDimStylePrivate *data;
670 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
672 data = dim_style->data;
674 return data->line_dress;
678 * adg_dim_style_set_from_offset:
679 * @dim_style: an #AdgDimStyle object
680 * @offset: the new offset
682 * Sets a new value in the #AdgDimStyle:from-offset property.
684 void
685 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
687 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
688 g_object_set(dim_style, "from-offset", offset, NULL);
692 * adg_dim_style_get_from_offset:
693 * @dim_style: an #AdgDimStyle object
695 * Gets the distance (in global space) the extension lines must keep from the
696 * sensed points.
698 * Returns: the requested distance
700 gdouble
701 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
703 AdgDimStylePrivate *data;
705 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
707 data = dim_style->data;
709 return data->from_offset;
713 * adg_dim_style_set_to_offset:
714 * @dim_style: an #AdgDimStyle object
715 * @offset: the new offset
717 * Sets a new value in the #AdgDimStyle:to-offset property.
719 void
720 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
722 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
723 g_object_set(dim_style, "to-offset", offset, NULL);
727 * adg_dim_style_get_to_offset:
728 * @dim_style: an #AdgDimStyle object
730 * Gets how much (in global space) the extension lines must extend after
731 * crossing the baseline.
733 * Returns: the requested distance
735 gdouble
736 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
738 AdgDimStylePrivate *data;
740 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
742 data = dim_style->data;
744 return data->to_offset;
748 * adg_dim_style_set_beyond:
749 * @dim_style: an #AdgDimStyle object
750 * @beyond: the new length
752 * Sets a new value in the #AdgDimStyle:beyond property.
754 void
755 adg_dim_style_set_beyond(AdgDimStyle *dim_style, gdouble beyond)
757 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
758 g_object_set(dim_style, "beyond", beyond, NULL);
762 * adg_dim_style_get_beyond:
763 * @dim_style: an #AdgDimStyle object
765 * Gets how much (in global space) the baseline should extend beyond
766 * the extension lines on dimension with outside markers.
768 * Returns: the requested beyond length
770 gdouble
771 adg_dim_style_get_beyond(AdgDimStyle *dim_style)
773 AdgDimStylePrivate *data;
775 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
777 data = dim_style->data;
779 return data->beyond;
783 * adg_dim_style_set_baseline_spacing:
784 * @dim_style: an #AdgDimStyle object
785 * @spacing: the new spacing
787 * Sets a new value in the #AdgDimStyle:baseline-spacing value.
789 void
790 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
792 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
793 g_object_set(dim_style, "baseline-spacing", spacing, NULL);
797 * adg_dim_style_get_baseline_spacing:
798 * @dim_style: an #AdgDimStyle object
800 * Gets the distance between two consecutive baselines
801 * while stacking dimensions.
803 * Returns: the requested spacing
805 gdouble
806 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
808 AdgDimStylePrivate *data;
810 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
812 data = dim_style->data;
814 return data->baseline_spacing;
818 * adg_dim_style_set_limits_spacing:
819 * @dim_style: an #AdgDimStyle object
820 * @spacing: the new spacing
822 * Sets a new #AdgDimStyle:limits-spacing value.
824 void
825 adg_dim_style_set_limits_spacing(AdgDimStyle *dim_style, gdouble spacing)
827 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
828 g_object_set(dim_style, "limits-spacing", spacing, NULL);
832 * adg_dim_style_get_limits_spacing:
833 * @dim_style: an #AdgDimStyle object
835 * Gets the distance (in global space) between the limits/tolerances.
837 * Returns: the requested spacing
839 gdouble
840 adg_dim_style_get_limits_spacing(AdgDimStyle *dim_style)
842 AdgDimStylePrivate *data;
844 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
846 data = dim_style->data;
848 return data->limits_spacing;
852 * adg_dim_style_set_quote_shift:
853 * @dim_style: an #AdgDimStyle object
854 * @shift: the new displacement
856 * Sets a new #AdgDimStyle:quote-shift value.
858 void
859 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
861 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
862 g_object_set(dim_style, "quote-shift", shift, NULL);
866 * adg_dim_style_get_quote_shift:
867 * @dim_style: an #AdgDimStyle object
869 * Gets the smooth displacement of the quote. The returned pointer refers
870 * to an internal allocated struct and must not be modified or freed.
872 * Returns: the requested shift
874 const AdgPair *
875 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
877 AdgDimStylePrivate *data;
879 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
881 data = dim_style->data;
883 return &data->quote_shift;
887 * adg_dim_style_set_limits_shift:
888 * @dim_style: an #AdgDimStyle object
889 * @shift: the new displacement
891 * Sets a new #AdgDimStyle:limits-shift value.
893 void
894 adg_dim_style_set_limits_shift(AdgDimStyle *dim_style, const AdgPair *shift)
896 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
897 g_object_set(dim_style, "limits-shift", shift, NULL);
901 * adg_dim_style_get_limits_shift:
902 * @dim_style: an #AdgDimStyle object
904 * Gets the smooth displacement for the limits. The returned pointer
905 * refers to an internal allocated struct and must not be modified or freed.
907 * Returns: the requested shift
909 const AdgPair *
910 adg_dim_style_get_limits_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->limits_shift;
922 * adg_dim_style_set_number_format:
923 * @dim_style: an #AdgDimStyle object
924 * @format: the new format to adopt
926 * Sets a new value in the #AdgDimStyle:number-format property.
928 void
929 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
931 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
932 g_object_set(dim_style, "number-format", format, NULL);
936 * adg_dim_style_get_number_format:
937 * @dim_style: an #AdgDimStyle object
939 * Gets the number format (in printf style) of this quoting style. The
940 * returned pointer refers to internally managed text that must not be
941 * modified or freed.
943 * Returns: the requested format
945 const gchar *
946 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
948 AdgDimStylePrivate *data;
950 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
952 data = dim_style->data;
954 return data->number_format;
958 * adg_dim_style_set_number_tag:
959 * @dim_style: an #AdgDimStyle object
960 * @tag: the new tag
962 * Sets a new tag in the #AdgDimStyle:number-tag property.
964 void
965 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
967 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
968 g_object_set(dim_style, "number-tag", tag, NULL);
972 * adg_dim_style_get_number_tag:
973 * @dim_style: an #AdgDimStyle object
975 * Gets the number tag of @dim_style. This tag will be used while
976 * generating the set values of the dimensions bound to this style:
977 * check the #AdgDim:value documentation for further details.
979 * The returned pointer refers to internally managed text that
980 * must not be modified or freed.
982 * Returns: the requested tag
984 const gchar *
985 adg_dim_style_get_number_tag(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_tag;
997 static void
998 _adg_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
1000 AdgDimStylePrivate *data = ((AdgDimStyle *) style)->data;
1001 adg_entity_apply_dress(entity, data->color_dress, cr);
1004 static AdgMarker *
1005 _adg_marker_new(const AdgMarkerData *marker_data)
1007 if (marker_data->type == 0)
1008 return NULL;
1010 return g_object_newv(marker_data->type,
1011 marker_data->n_parameters,
1012 marker_data->parameters);
1015 static void
1016 _adg_set_marker(AdgMarkerData *marker_data, AdgMarker *marker)
1018 g_return_if_fail(marker == NULL || ADG_IS_MARKER(marker));
1020 /* Free the previous marker data, if any */
1021 _adg_free_marker(marker_data);
1023 if (marker) {
1024 GObject *object;
1025 GParamSpec **specs;
1026 GParamSpec *spec;
1027 GParameter *parameter;
1028 guint n;
1030 object = (GObject *) marker;
1031 specs = g_object_class_list_properties(G_OBJECT_GET_CLASS(marker),
1032 &marker_data->n_parameters);
1034 marker_data->type = G_TYPE_FROM_INSTANCE(marker);
1035 marker_data->parameters = g_new0(GParameter, marker_data->n_parameters);
1037 for (n = 0; n < marker_data->n_parameters; ++n) {
1038 spec = specs[n];
1039 parameter = &marker_data->parameters[n];
1041 /* Using intern strings because GParameter:name is const.
1042 * GObject properties are internally managed using non-static
1043 * GQuark, so g_intern_string() is the way to go */
1044 parameter->name = g_intern_string(spec->name);
1046 g_value_init(&parameter->value, spec->value_type);
1047 g_object_get_property(object, spec->name, &parameter->value);
1050 g_free(specs);
1054 static void
1055 _adg_free_marker(AdgMarkerData *marker_data)
1057 guint n;
1059 for (n = 0; n < marker_data->n_parameters; ++n)
1060 g_value_unset(&marker_data->parameters[n].value);
1062 marker_data->type = 0;
1063 marker_data->n_parameters = 0;
1064 marker_data->parameters = NULL;