adg: require a valid layout in adg_table_row_arrange()
[adg.git] / src / adg / adg-dim-style.c
blob1110689e35810d6edf0c9208ae3930baa9be002a
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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 <constant>NULL</constant> as @marker, in which case the
425 * template data of the 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 #AdgDimStyle: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 <constant>NULL</constant> if the #AdgDimStyle:marker1 property is not set or on errors.
452 * Since: 1.0
454 AdgMarker *
455 adg_dim_style_marker1_new(AdgDimStyle *dim_style)
457 AdgDimStylePrivate *data;
459 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
461 data = dim_style->data;
463 return _adg_marker_new(&data->marker1);
467 * adg_dim_style_set_marker2:
468 * @dim_style: an #AdgStyle
469 * @marker: an #AdgMarker derived entity
471 * Uses @marker as entity template to generate a new marker entity
472 * when a call to adg_dim_style_marker2_new() is made. It is allowed
473 * to pass <constant>NULL</constant> as @marker, in which case the
474 * template data of the second marker are unset.
476 * This method duplicates internally the property values of @marker,
477 * so any further change to @marker does not affect @dim_style anymore.
478 * This also means @marker could be destroyed without problems after
479 * this call because @dim_style uses only its property values and does
480 * not add any references to @marker.
482 * Since: 1.0
484 void
485 adg_dim_style_set_marker2(AdgDimStyle *dim_style, AdgMarker *marker)
487 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
488 g_object_set(dim_style, "marker2", marker, NULL);
492 * adg_dim_style_marker2_new:
493 * @dim_style: an #AdgDimStyle
495 * Creates a new marker entity by cloning the #AdgDimStyle:marker2
496 * object. The returned entity should be unreferenced with
497 * g_object_unref() when no longer needed.
499 * Returns: (transfer full): a newly created marker or <constant>NULL</constant> if the #AdgDimStyle:marker2 property is not set or on errors.
501 * Since: 1.0
503 AdgMarker *
504 adg_dim_style_marker2_new(AdgDimStyle *dim_style)
506 AdgDimStylePrivate *data;
508 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
510 data = dim_style->data;
512 return _adg_marker_new(&data->marker2);
516 * adg_dim_style_set_color_dress:
517 * @dim_style: an #AdgDimStyle object
518 * @dress: the new color dress
520 * Sets a new color dress on @dim_style.
522 * Since: 1.0
524 void
525 adg_dim_style_set_color_dress(AdgDimStyle *dim_style, AdgDress dress)
527 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
528 g_object_set(dim_style, "color-dress", dress, NULL);
532 * adg_dim_style_get_color_dress:
533 * @dim_style: an #AdgDimStyle object
535 * Gets the @dim_style color dress to be used. This dress should be
536 * intended as a fallback color as it could be overriden by more
537 * specific dresses, such as a color explicitely specified on the
538 * #AdgDimStyle:value-dress.
540 * Returns: (transfer none): the color dress.
542 * Since: 1.0
544 AdgDress
545 adg_dim_style_get_color_dress(AdgDimStyle *dim_style)
547 AdgDimStylePrivate *data;
549 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
551 data = dim_style->data;
553 return data->color_dress;
557 * adg_dim_style_set_value_dress:
558 * @dim_style: an #AdgDimStyle object
559 * @dress: the new basic value font style
561 * Sets a new dress on @dim_style for the basic value.
563 * Since: 1.0
565 void
566 adg_dim_style_set_value_dress(AdgDimStyle *dim_style, AdgDress dress)
568 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
569 g_object_set(dim_style, "value-dress", dress, NULL);
573 * adg_dim_style_get_value_dress:
574 * @dim_style: an #AdgDimStyle object
576 * Gets the font dress to be used for the basic value of dimensions
577 * with @dim_style.
579 * Returns: (transfer none): the font dress.
581 * Since: 1.0
583 AdgDress
584 adg_dim_style_get_value_dress(AdgDimStyle *dim_style)
586 AdgDimStylePrivate *data;
588 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
590 data = dim_style->data;
592 return data->value_dress;
596 * adg_dim_style_set_min_dress:
597 * @dim_style: an #AdgDimStyle object
598 * @dress: the new lower limit dress
600 * Sets a new dress on @dim_style for the lower limit value.
602 * Since: 1.0
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(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: (transfer none): the lower limit dress.
619 * Since: 1.0
621 AdgDress
622 adg_dim_style_get_min_dress(AdgDimStyle *dim_style)
624 AdgDimStylePrivate *data;
626 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
628 data = dim_style->data;
630 return data->min_dress;
634 * adg_dim_style_set_max_dress:
635 * @dim_style: an #AdgDimStyle object
636 * @dress: the new upper limit dress
638 * Sets a new dress on @dim_style for the upper limit value.
640 * Since: 1.0
642 void
643 adg_dim_style_set_max_dress(AdgDimStyle *dim_style, AdgDress dress)
645 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
646 g_object_set(dim_style, "max-dress", dress, NULL);
650 * adg_dim_style_get_max_dress:
651 * @dim_style: an #AdgDimStyle object
653 * Gets the @dim_style dress to be used for the upper limit.
655 * Returns: (transfer none): the upper limit dress.
657 * Since: 1.0
659 AdgDress
660 adg_dim_style_get_max_dress(AdgDimStyle *dim_style)
662 AdgDimStylePrivate *data;
664 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
666 data = dim_style->data;
668 return data->max_dress;
672 * adg_dim_style_set_line_dress:
673 * @dim_style: an #AdgDimStyle object
674 * @dress: the new line dress
676 * Sets a new line dress on @dim_style.
678 * Since: 1.0
680 void
681 adg_dim_style_set_line_dress(AdgDimStyle *dim_style, AdgDress dress)
683 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
684 g_object_set(dim_style, "line-dress", dress, NULL);
688 * adg_dim_style_get_line_dress:
689 * @dim_style: an #AdgDimStyle object
691 * Gets the line dress to be used for rendering the base and
692 * the extension lines with @dim_style.
694 * Returns: (transfer none): the line dress.
696 * Since: 1.0
698 AdgDress
699 adg_dim_style_get_line_dress(AdgDimStyle *dim_style)
701 AdgDimStylePrivate *data;
703 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
705 data = dim_style->data;
707 return data->line_dress;
711 * adg_dim_style_set_from_offset:
712 * @dim_style: an #AdgDimStyle object
713 * @offset: the new offset
715 * Sets a new value in the #AdgDimStyle:from-offset property.
717 * Since: 1.0
719 void
720 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
722 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
723 g_object_set(dim_style, "from-offset", offset, NULL);
727 * adg_dim_style_get_from_offset:
728 * @dim_style: an #AdgDimStyle object
730 * Gets the distance (in global space) the extension lines must keep from the
731 * sensed points.
733 * Returns: the requested distance.
735 * Since: 1.0
737 gdouble
738 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
740 AdgDimStylePrivate *data;
742 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
744 data = dim_style->data;
746 return data->from_offset;
750 * adg_dim_style_set_to_offset:
751 * @dim_style: an #AdgDimStyle object
752 * @offset: the new offset
754 * Sets a new value in the #AdgDimStyle:to-offset property.
756 * Since: 1.0
758 void
759 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
761 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
762 g_object_set(dim_style, "to-offset", offset, NULL);
766 * adg_dim_style_get_to_offset:
767 * @dim_style: an #AdgDimStyle object
769 * Gets how much (in global space) the extension lines must extend after
770 * crossing the baseline.
772 * Returns: the requested distance.
774 * Since: 1.0
776 gdouble
777 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
779 AdgDimStylePrivate *data;
781 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
783 data = dim_style->data;
785 return data->to_offset;
789 * adg_dim_style_set_beyond:
790 * @dim_style: an #AdgDimStyle object
791 * @beyond: the new length
793 * Sets a new value in the #AdgDimStyle:beyond property.
795 * Since: 1.0
797 void
798 adg_dim_style_set_beyond(AdgDimStyle *dim_style, gdouble beyond)
800 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
801 g_object_set(dim_style, "beyond", beyond, NULL);
805 * adg_dim_style_get_beyond:
806 * @dim_style: an #AdgDimStyle object
808 * Gets how much (in global space) the baseline should extend beyond
809 * the extension lines on dimension with outside markers.
811 * Returns: the requested beyond length.
813 * Since: 1.0
815 gdouble
816 adg_dim_style_get_beyond(AdgDimStyle *dim_style)
818 AdgDimStylePrivate *data;
820 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
822 data = dim_style->data;
824 return data->beyond;
828 * adg_dim_style_set_baseline_spacing:
829 * @dim_style: an #AdgDimStyle object
830 * @spacing: the new spacing
832 * Sets a new value in the #AdgDimStyle:baseline-spacing value.
834 * Since: 1.0
836 void
837 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
839 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
840 g_object_set(dim_style, "baseline-spacing", spacing, NULL);
844 * adg_dim_style_get_baseline_spacing:
845 * @dim_style: an #AdgDimStyle object
847 * Gets the distance between two consecutive baselines
848 * while stacking dimensions.
850 * Returns: the requested spacing.
852 * Since: 1.0
854 gdouble
855 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
857 AdgDimStylePrivate *data;
859 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
861 data = dim_style->data;
863 return data->baseline_spacing;
867 * adg_dim_style_set_limits_spacing:
868 * @dim_style: an #AdgDimStyle object
869 * @spacing: the new spacing
871 * Sets a new #AdgDimStyle:limits-spacing value.
873 * Since: 1.0
875 void
876 adg_dim_style_set_limits_spacing(AdgDimStyle *dim_style, gdouble spacing)
878 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
879 g_object_set(dim_style, "limits-spacing", spacing, NULL);
883 * adg_dim_style_get_limits_spacing:
884 * @dim_style: an #AdgDimStyle object
886 * Gets the distance (in global space) between the limits/tolerances.
888 * Returns: the requested spacing.
890 * Since: 1.0
892 gdouble
893 adg_dim_style_get_limits_spacing(AdgDimStyle *dim_style)
895 AdgDimStylePrivate *data;
897 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
899 data = dim_style->data;
901 return data->limits_spacing;
905 * adg_dim_style_set_quote_shift:
906 * @dim_style: an #AdgDimStyle object
907 * @shift: the new displacement
909 * Sets a new #AdgDimStyle:quote-shift value.
911 * Since: 1.0
913 void
914 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const CpmlPair *shift)
916 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
917 g_object_set(dim_style, "quote-shift", shift, NULL);
921 * adg_dim_style_get_quote_shift:
922 * @dim_style: an #AdgDimStyle object
924 * Gets the smooth displacement of the quote. The returned pointer refers
925 * to an internal allocated struct and must not be modified or freed.
927 * Returns: (transfer none): the requested shift.
929 * Since: 1.0
931 const CpmlPair *
932 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
934 AdgDimStylePrivate *data;
936 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
938 data = dim_style->data;
940 return &data->quote_shift;
944 * adg_dim_style_set_limits_shift:
945 * @dim_style: an #AdgDimStyle object
946 * @shift: the new displacement
948 * Sets a new #AdgDimStyle:limits-shift value.
950 * Since: 1.0
952 void
953 adg_dim_style_set_limits_shift(AdgDimStyle *dim_style, const CpmlPair *shift)
955 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
956 g_object_set(dim_style, "limits-shift", shift, NULL);
960 * adg_dim_style_get_limits_shift:
961 * @dim_style: an #AdgDimStyle object
963 * Gets the smooth displacement for the limits. The returned pointer
964 * refers to an internal allocated struct and must not be modified or freed.
966 * Returns: (transfer none): the requested shift.
968 * Since: 1.0
970 const CpmlPair *
971 adg_dim_style_get_limits_shift(AdgDimStyle *dim_style)
973 AdgDimStylePrivate *data;
975 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
977 data = dim_style->data;
979 return &data->limits_shift;
983 * adg_dim_style_set_number_format:
984 * @dim_style: an #AdgDimStyle object
985 * @format: the new format to adopt
987 * Sets a new value in the #AdgDimStyle:number-format property.
989 * Since: 1.0
991 void
992 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
994 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
995 g_object_set(dim_style, "number-format", format, NULL);
999 * adg_dim_style_get_number_format:
1000 * @dim_style: an #AdgDimStyle object
1002 * Gets the number format (in printf style) of this quoting style. The
1003 * returned pointer refers to internally managed text that must not be
1004 * modified or freed.
1006 * Returns: (transfer none): the requested format.
1008 * Since: 1.0
1010 const gchar *
1011 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
1013 AdgDimStylePrivate *data;
1015 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
1017 data = dim_style->data;
1019 return data->number_format;
1023 * adg_dim_style_set_number_tag:
1024 * @dim_style: an #AdgDimStyle object
1025 * @tag: the new tag
1027 * Sets a new tag in the #AdgDimStyle:number-tag property.
1029 * Since: 1.0
1031 void
1032 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
1034 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
1035 g_object_set(dim_style, "number-tag", tag, NULL);
1039 * adg_dim_style_get_number_tag:
1040 * @dim_style: an #AdgDimStyle object
1042 * Gets the number tag of @dim_style. This tag will be used while
1043 * generating the set values of the dimensions bound to this style:
1044 * check the #AdgDim:value documentation for further details.
1046 * The returned pointer refers to internally managed text that
1047 * must not be modified or freed.
1049 * Returns: (transfer none): the requested tag.
1051 * Since: 1.0
1053 const gchar *
1054 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
1056 AdgDimStylePrivate *data;
1058 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
1060 data = dim_style->data;
1062 return data->number_tag;
1066 static void
1067 _adg_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
1069 AdgDimStylePrivate *data = ((AdgDimStyle *) style)->data;
1070 adg_entity_apply_dress(entity, data->color_dress, cr);
1073 static AdgMarker *
1074 _adg_marker_new(const AdgMarkerData *marker_data)
1076 if (marker_data->type == 0)
1077 return NULL;
1079 return g_object_newv(marker_data->type,
1080 marker_data->n_parameters,
1081 marker_data->parameters);
1084 static void
1085 _adg_set_marker(AdgMarkerData *marker_data, AdgMarker *marker)
1087 g_return_if_fail(marker == NULL || ADG_IS_MARKER(marker));
1089 /* Free the previous marker data, if any */
1090 _adg_free_marker(marker_data);
1092 if (marker) {
1093 GObject *object;
1094 GParamSpec **specs;
1095 GParamSpec *spec;
1096 GParameter *parameter;
1097 guint n;
1099 object = (GObject *) marker;
1100 specs = g_object_class_list_properties(G_OBJECT_GET_CLASS(marker),
1101 &marker_data->n_parameters);
1103 marker_data->type = G_TYPE_FROM_INSTANCE(marker);
1104 marker_data->parameters = g_new0(GParameter, marker_data->n_parameters);
1106 for (n = 0; n < marker_data->n_parameters; ++n) {
1107 spec = specs[n];
1108 parameter = &marker_data->parameters[n];
1110 /* Using intern strings because GParameter:name is const.
1111 * GObject properties are internally managed using non-static
1112 * GQuark, so g_intern_string() is the way to go */
1113 parameter->name = g_intern_string(spec->name);
1115 g_value_init(&parameter->value, spec->value_type);
1116 g_object_get_property(object, spec->name, &parameter->value);
1119 g_free(specs);
1123 static void
1124 _adg_free_marker(AdgMarkerData *marker_data)
1126 guint n;
1128 for (n = 0; n < marker_data->n_parameters; ++n)
1129 g_value_unset(&marker_data->parameters[n].value);
1131 marker_data->type = 0;
1132 marker_data->n_parameters = 0;
1133 marker_data->parameters = NULL;