[AdgDim] Properly use the "value" property
[adg.git] / src / adg / adg-dim-style.c
blobd74e45b8d186d26806d1ad4b66201612ac96707a
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.
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-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"
46 enum {
47 PROP_0,
48 PROP_MARKER1,
49 PROP_MARKER2,
50 PROP_COLOR_DRESS,
51 PROP_VALUE_DRESS,
52 PROP_MIN_DRESS,
53 PROP_MAX_DRESS,
54 PROP_LINE_DRESS,
55 PROP_FROM_OFFSET,
56 PROP_TO_OFFSET,
57 PROP_BEYOND,
58 PROP_BASELINE_SPACING,
59 PROP_LIMITS_SPACING,
60 PROP_QUOTE_SHIFT,
61 PROP_LIMITS_SHIFT,
62 PROP_NUMBER_FORMAT,
63 PROP_NUMBER_TAG
67 static void finalize (GObject *object);
68 static void get_property (GObject *object,
69 guint prop_id,
70 GValue *value,
71 GParamSpec *pspec);
72 static void set_property (GObject *object,
73 guint prop_id,
74 const GValue *value,
75 GParamSpec *pspec);
76 static void apply (AdgStyle *style,
77 AdgEntity *entity,
78 cairo_t *cr);
79 static gboolean set_from_offset (AdgDimStyle *dim_style,
80 gdouble offset);
81 static gboolean set_to_offset (AdgDimStyle *dim_style,
82 gdouble offset);
83 static gboolean set_baseline_spacing (AdgDimStyle *dim_style,
84 gdouble spacing);
85 static gboolean set_limits_spacing (AdgDimStyle *dim_style,
86 gdouble spacing);
87 static gboolean set_beyond (AdgDimStyle *dim_style,
88 gdouble beyond);
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,
94 const gchar *format);
95 static void set_number_tag (AdgDimStyle *dim_style,
96 const gchar *tag);
97 static AdgMarker * marker_new (const AdgMarkerData
98 *marker_data);
99 static gboolean set_marker (AdgMarkerData *marker_data,
100 AdgMarker *marker);
101 static void free_marker (AdgMarkerData *marker_data);
104 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE);
107 static void
108 adg_dim_style_class_init(AdgDimStyleClass *klass)
110 GObjectClass *gobject_class;
111 AdgStyleClass *style_class;
112 GParamSpec *param;
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",
126 P_("First Marker"),
127 P_("The template entity to use as first marker"),
128 ADG_TYPE_MARKER,
129 G_PARAM_WRITABLE);
130 g_object_class_install_property(gobject_class, PROP_MARKER1, param);
132 param = g_param_spec_object("marker2",
133 P_("Second Marker"),
134 P_("The template entity to use as second marker"),
135 ADG_TYPE_MARKER,
136 G_PARAM_WRITABLE);
137 g_object_class_install_property(gobject_class, PROP_MARKER2, param);
139 param = adg_param_spec_dress("color-dress",
140 P_("Color Dress"),
141 P_("Color dress for the whole dimension"),
142 ADG_DRESS_COLOR_DIMENSION,
143 G_PARAM_READWRITE);
144 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
146 param = adg_param_spec_dress("value-dress",
147 P_("Value Dress"),
148 P_("Font dress for the nominal value of the dimension"),
149 ADG_DRESS_FONT_QUOTE_TEXT,
150 G_PARAM_READWRITE);
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,
157 G_PARAM_READWRITE);
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,
164 G_PARAM_READWRITE);
165 g_object_class_install_property(gobject_class, PROP_MAX_DRESS, param);
167 param = adg_param_spec_dress("line-dress",
168 P_("Line Dress"),
169 P_("Line dress for the baseline and the extension lines"),
170 ADG_DRESS_LINE_DIMENSION,
171 G_PARAM_READWRITE);
172 g_object_class_install_property(gobject_class, PROP_LINE_DRESS, param);
174 param = g_param_spec_double("from-offset",
175 P_("From Offset"),
176 P_("Offset (in global space) of the extension lines from the path to the quote"),
177 0, G_MAXDOUBLE, 5,
178 G_PARAM_READWRITE);
179 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET, param);
181 param = g_param_spec_double("to-offset",
182 P_("To Offset"),
183 P_("How many extend (in global space) the extension lines after hitting the baseline"),
184 0, G_MAXDOUBLE, 5,
185 G_PARAM_READWRITE);
186 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
188 param = g_param_spec_double("beyond",
189 P_("Beyond Length"),
190 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside markers"),
191 0, G_MAXDOUBLE, 20,
192 G_PARAM_READWRITE);
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"),
198 0, G_MAXDOUBLE, 30,
199 G_PARAM_READWRITE);
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"),
205 0, G_MAXDOUBLE, 2,
206 G_PARAM_READWRITE);
207 g_object_class_install_property(gobject_class, PROP_LIMITS_SPACING, param);
209 param = g_param_spec_boxed("quote-shift",
210 P_("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)"),
212 ADG_TYPE_PAIR,
213 G_PARAM_READWRITE);
214 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT, param);
216 param = g_param_spec_boxed("limits-shift",
217 P_("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"),
219 ADG_TYPE_PAIR,
220 G_PARAM_READWRITE);
221 g_object_class_install_property(gobject_class, PROP_LIMITS_SHIFT, param);
223 param = g_param_spec_string("number-format",
224 P_("Number Format"),
225 P_("The format (in printf style) of the numeric component of the basic value"),
226 "%-.7g",
227 G_PARAM_READWRITE);
228 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT, param);
230 param = g_param_spec_string("number-tag",
231 P_("Number Tag"),
232 P_("The tag to substitute inside the value template string"),
233 "<>",
234 G_PARAM_READWRITE);
235 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
238 static void
239 adg_dim_style_init(AdgDimStyle *dim_style)
241 AdgDimStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
242 ADG_TYPE_DIM_STYLE,
243 AdgDimStylePrivate);
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;
258 data->to_offset = 6;
259 data->beyond = 20;
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;
272 static void
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;
287 static void
288 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
290 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
292 switch (prop_id) {
293 case PROP_COLOR_DRESS:
294 g_value_set_int(value, data->color_dress);
295 break;
296 case PROP_VALUE_DRESS:
297 g_value_set_int(value, data->value_dress);
298 break;
299 case PROP_MIN_DRESS:
300 g_value_set_int(value, data->min_dress);
301 break;
302 case PROP_MAX_DRESS:
303 g_value_set_int(value, data->max_dress);
304 break;
305 case PROP_LINE_DRESS:
306 g_value_set_int(value, data->line_dress);
307 break;
308 case PROP_FROM_OFFSET:
309 g_value_set_double(value, data->from_offset);
310 break;
311 case PROP_TO_OFFSET:
312 g_value_set_double(value, data->to_offset);
313 break;
314 case PROP_BEYOND:
315 g_value_set_double(value, data->beyond);
316 break;
317 case PROP_BASELINE_SPACING:
318 g_value_set_double(value, data->baseline_spacing);
319 break;
320 case PROP_LIMITS_SPACING:
321 g_value_set_double(value, data->limits_spacing);
322 break;
323 case PROP_QUOTE_SHIFT:
324 g_value_set_boxed(value, &data->quote_shift);
325 break;
326 case PROP_LIMITS_SHIFT:
327 g_value_set_boxed(value, &data->limits_shift);
328 break;
329 case PROP_NUMBER_FORMAT:
330 g_value_set_string(value, data->number_format);
331 break;
332 case PROP_NUMBER_TAG:
333 g_value_set_string(value, data->number_tag);
334 break;
335 default:
336 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
337 break;
341 static void
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;
351 switch (prop_id) {
352 case PROP_MARKER1:
353 set_marker(&data->marker1, g_value_get_object(value));
354 break;
355 case PROP_MARKER2:
356 set_marker(&data->marker2, g_value_get_object(value));
357 break;
358 case PROP_COLOR_DRESS:
359 data->color_dress = g_value_get_int(value);
360 break;
361 case PROP_VALUE_DRESS:
362 data->value_dress = g_value_get_int(value);
363 break;
364 case PROP_MIN_DRESS:
365 data->min_dress = g_value_get_int(value);
366 break;
367 case PROP_MAX_DRESS:
368 data->max_dress = g_value_get_int(value);
369 break;
370 case PROP_LINE_DRESS:
371 data->line_dress = g_value_get_int(value);
372 break;
373 case PROP_FROM_OFFSET:
374 set_from_offset(dim_style, g_value_get_double(value));
375 break;
376 case PROP_TO_OFFSET:
377 set_to_offset(dim_style, g_value_get_double(value));
378 break;
379 case PROP_BEYOND:
380 set_beyond(dim_style, g_value_get_double(value));
381 break;
382 case PROP_BASELINE_SPACING:
383 set_baseline_spacing(dim_style, g_value_get_double(value));
384 break;
385 case PROP_LIMITS_SPACING:
386 set_limits_spacing(dim_style, g_value_get_double(value));
387 break;
388 case PROP_QUOTE_SHIFT:
389 set_quote_shift(dim_style, g_value_get_boxed(value));
390 break;
391 case PROP_LIMITS_SHIFT:
392 set_limits_shift(dim_style, g_value_get_boxed(value));
393 break;
394 case PROP_NUMBER_FORMAT:
395 set_number_format(dim_style, g_value_get_string(value));
396 break;
397 case PROP_NUMBER_TAG:
398 set_number_tag(dim_style, g_value_get_string(value));
399 break;
400 default:
401 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
402 break;
408 * adg_dim_style_new:
410 * Constructs a new empty dimension style initialized with default params.
412 * Returns: a newly created dimension style
414 AdgDimStyle *
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.
436 void
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
460 AdgMarker *
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.
488 void
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
513 AdgMarker *
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.
532 void
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
550 AdgDress
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.
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((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
581 * with @dim_style.
583 * Returns: the font dress
585 AdgDress
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.
604 void
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
619 AdgDress
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.
638 void
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
653 AdgDress
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.
672 void
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
688 AdgDress
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.
707 void
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
721 * sensed points.
723 * Returns: the requested distance
725 gdouble
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.
744 void
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
762 gdouble
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.
781 void
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
799 gdouble
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;
808 return data->beyond;
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.
818 void
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
836 gdouble
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.
855 void
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
872 gdouble
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.
891 void
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
909 const AdgPair *
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.
928 void
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
946 const AdgPair *
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.
965 void
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
980 * modified or freed.
982 * Returns: the requested format
984 const gchar *
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
999 * @tag: the new tag
1001 * Sets a new tag in the #AdgDimStyle:number-tag property.
1003 void
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
1025 const gchar *
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;
1038 static void
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);
1045 static gboolean
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)
1054 return FALSE;
1056 data->from_offset = offset;
1057 return TRUE;
1060 static gboolean
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)
1069 return FALSE;
1071 data->to_offset = offset;
1072 return TRUE;
1075 static gboolean
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)
1084 return FALSE;
1086 data->baseline_spacing = spacing;
1087 return TRUE;
1090 static gboolean
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)
1099 return FALSE;
1101 data->limits_spacing = spacing;
1102 return TRUE;
1105 static gboolean
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)
1114 return FALSE;
1116 data->beyond = beyond;
1117 return TRUE;
1120 static gboolean
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))
1130 return FALSE;
1132 data->quote_shift = *shift;
1134 return TRUE;
1137 static gboolean
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))
1147 return FALSE;
1149 data->limits_shift = *shift;
1151 return TRUE;
1154 static void
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);
1163 static void
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);
1172 static AdgMarker *
1173 marker_new(const AdgMarkerData *marker_data)
1175 if (marker_data->type == 0)
1176 return NULL;
1178 return g_object_newv(marker_data->type,
1179 marker_data->n_parameters,
1180 marker_data->parameters);
1183 static gboolean
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);
1191 if (marker) {
1192 GObject *object;
1193 GParamSpec **specs;
1194 GParamSpec *spec;
1195 GParameter *parameter;
1196 guint n;
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) {
1206 spec = specs[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(&parameter->value, spec->value_type);
1215 g_object_get_property(object, spec->name, &parameter->value);
1218 g_free(specs);
1221 return TRUE;
1224 static void
1225 free_marker(AdgMarkerData *marker_data)
1227 guint n;
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;