[AdgPath] Added adg_path_get_segment()
[adg.git] / adg / adg-dim-style.c
blob24e35605a6add23789ce592eced7307ccbc2962c
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 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, tolerance and note), 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 /**
39 * ADG_SLOT_DIM_STYLE:
41 * Gets the slot id for this style class.
43 * Returns: the requested slot id
44 **/
47 #include "adg-dim-style.h"
48 #include "adg-dim-style-private.h"
49 #include "adg-font-style.h"
50 #include "adg-line-style.h"
51 #include "adg-arrow-style.h"
52 #include "adg-context.h"
53 #include "adg-intl.h"
54 #include "adg-util.h"
57 enum {
58 PROP_0,
59 PROP_VALUE_STYLE,
60 PROP_TOLERANCE_STYLE,
61 PROP_NOTE_STYLE,
62 PROP_LINE_STYLE,
63 PROP_ARROW_STYLE,
64 PROP_FROM_OFFSET,
65 PROP_TO_OFFSET,
66 PROP_BEYOND,
67 PROP_BASELINE_SPACING,
68 PROP_TOLERANCE_SPACING,
69 PROP_QUOTE_SHIFT,
70 PROP_TOLERANCE_SHIFT,
71 PROP_NOTE_SHIFT,
72 PROP_NUMBER_FORMAT,
73 PROP_NUMBER_TAG
77 static void get_property (GObject *object,
78 guint prop_id,
79 GValue *value,
80 GParamSpec *pspec);
81 static void set_property (GObject *object,
82 guint prop_id,
83 const GValue *value,
84 GParamSpec *pspec);
85 static GPtrArray * get_pool (void);
86 static void set_value_style (AdgDimStyle *dim_style,
87 AdgFontStyle *style);
88 static void set_tolerance_style (AdgDimStyle *dim_style,
89 AdgFontStyle *style);
90 static void set_note_style (AdgDimStyle *dim_style,
91 AdgFontStyle *style);
92 static void set_line_style (AdgDimStyle *dim_style,
93 AdgLineStyle *style);
94 static void set_arrow_style (AdgDimStyle *dim_style,
95 AdgArrowStyle *style);
96 static void set_quote_shift (AdgDimStyle *dim_style,
97 const AdgPair *shift);
98 static void set_tolerance_shift (AdgDimStyle *dim_style,
99 const AdgPair *shift);
100 static void set_note_shift (AdgDimStyle *dim_style,
101 const AdgPair *shift);
102 static void set_number_format (AdgDimStyle *dim_style,
103 const gchar *format);
104 static void set_number_tag (AdgDimStyle *dim_style,
105 const gchar *tag);
108 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE)
111 static void
112 adg_dim_style_class_init(AdgDimStyleClass *klass)
114 GObjectClass *gobject_class;
115 AdgStyleClass *style_class;
116 GParamSpec *param;
118 gobject_class = (GObjectClass *) klass;
119 style_class = (AdgStyleClass *) klass;
121 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
123 gobject_class->get_property = get_property;
124 gobject_class->set_property = set_property;
126 style_class->get_pool = get_pool;
128 param = g_param_spec_object("value-style",
129 P_("Value Style"),
130 P_("Font style for the basic value of the dimension"),
131 ADG_TYPE_STYLE, G_PARAM_READWRITE);
132 g_object_class_install_property(gobject_class, PROP_VALUE_STYLE,
133 param);
135 param = g_param_spec_object("tolerance-style",
136 P_("Tolerance Style"),
137 P_("Font style for the tolerances"),
138 ADG_TYPE_STYLE, G_PARAM_READWRITE);
139 g_object_class_install_property(gobject_class, PROP_TOLERANCE_STYLE,
140 param);
142 param = g_param_spec_object("note-style",
143 P_("Note Style"),
144 P_("Font style for the note (the text after or under the basic value)"),
145 ADG_TYPE_STYLE, G_PARAM_READWRITE);
146 g_object_class_install_property(gobject_class, PROP_NOTE_STYLE, param);
148 param = g_param_spec_object("line-style",
149 P_("Line Style"),
150 P_("Line style for the baseline and the extension lines"),
151 ADG_TYPE_STYLE, G_PARAM_READWRITE);
152 g_object_class_install_property(gobject_class, PROP_LINE_STYLE, param);
154 param = g_param_spec_object("arrow-style",
155 P_("Arrow Style"),
156 P_("Arrow style to use on the baseline"),
157 ADG_TYPE_STYLE, G_PARAM_READWRITE);
158 g_object_class_install_property(gobject_class, PROP_ARROW_STYLE,
159 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, G_PARAM_READWRITE);
165 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET,
166 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, G_PARAM_READWRITE);
172 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
174 param = g_param_spec_double("beyond",
175 P_("Beyond Length"),
176 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside arrows: 0 means to automatically compute this value at run-time as 3*arrow-size (got from the binded array-style)"),
177 0, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
178 g_object_class_install_property(gobject_class, PROP_BEYOND, param);
180 param = g_param_spec_double("baseline-spacing",
181 P_("Baseline Spacing"),
182 P_("Distance between two consecutive baselines while stacking dimensions"),
183 0, G_MAXDOUBLE, 30, G_PARAM_READWRITE);
184 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING,
185 param);
187 param = g_param_spec_double("tolerance-spacing",
188 P_("Tolerance Spacing"),
189 P_("Distance between up and down tolerance text"),
190 0, G_MAXDOUBLE, 2, G_PARAM_READWRITE);
191 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SPACING,
192 param);
194 param = g_param_spec_boxed("quote-shift",
195 P_("Quote Shift"),
196 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)"),
197 ADG_TYPE_PAIR, G_PARAM_READWRITE);
198 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT,
199 param);
201 param = g_param_spec_boxed("tolerance-shift",
202 P_("Tolerance Shift"),
203 P_("Used to specify a smooth displacement (in global space) for the tolerance text by taking as reference the perfect compact position"),
204 ADG_TYPE_PAIR, G_PARAM_READWRITE);
205 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SHIFT,
206 param);
208 param = g_param_spec_boxed("note-shift",
209 P_("Note Shift"),
210 P_("Used to specify a smooth displacement (in global space) for the note text by taking as reference the perfect compact position"),
211 ADG_TYPE_PAIR, G_PARAM_READWRITE);
212 g_object_class_install_property(gobject_class, PROP_NOTE_SHIFT, param);
214 param = g_param_spec_string("number-format",
215 P_("Number Format"),
216 P_("The format (in printf style) of the numeric component of the basic value"),
217 "%-.7g", G_PARAM_READWRITE);
218 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT,
219 param);
221 param = g_param_spec_string("number-tag",
222 P_("Number Tag"),
223 P_("The tag to substitute inside the basic value pattern"),
224 "<>", G_PARAM_READWRITE);
225 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
228 static void
229 adg_dim_style_init(AdgDimStyle *dim_style)
231 AdgDimStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
232 ADG_TYPE_DIM_STYLE,
233 AdgDimStylePrivate);
235 data->value_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
236 ADG_FONT_STYLE_VALUE);
237 data->tolerance_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
238 ADG_FONT_STYLE_TOLERANCE);
239 data->note_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
240 ADG_FONT_STYLE_NOTE);
241 data->line_style = adg_style_from_id(ADG_TYPE_LINE_STYLE,
242 ADG_LINE_STYLE_DIM);
243 data->arrow_style = adg_style_from_id(ADG_TYPE_ARROW_STYLE,
244 ADG_ARROW_STYLE_ARROW);
245 data->from_offset = 6;
246 data->to_offset = 6;
247 data->beyond = 0;
248 data->baseline_spacing = 30;
249 data->tolerance_spacing = 1;
250 data->quote_shift.x = 0;
251 data->quote_shift.y = -4;
252 data->tolerance_shift.x = +2;
253 data->tolerance_shift.y = -2;
254 data->note_shift.x = +4;
255 data->note_shift.y = 0;
256 data->number_format = g_strdup("%-.7g");
257 data->number_tag = g_strdup("<>");
259 dim_style->data = data;
262 static void
263 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
265 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
267 switch (prop_id) {
268 case PROP_VALUE_STYLE:
269 g_value_set_object(value, data->value_style);
270 break;
271 case PROP_TOLERANCE_STYLE:
272 g_value_set_object(value, data->tolerance_style);
273 break;
274 case PROP_NOTE_STYLE:
275 g_value_set_object(value, data->note_style);
276 break;
277 case PROP_LINE_STYLE:
278 g_value_set_object(value, data->line_style);
279 break;
280 case PROP_ARROW_STYLE:
281 g_value_set_object(value, data->arrow_style);
282 break;
283 case PROP_FROM_OFFSET:
284 g_value_set_double(value, data->from_offset);
285 break;
286 case PROP_TO_OFFSET:
287 g_value_set_double(value, data->to_offset);
288 break;
289 case PROP_BEYOND:
290 g_value_set_double(value, data->beyond);
291 break;
292 case PROP_BASELINE_SPACING:
293 g_value_set_double(value, data->baseline_spacing);
294 break;
295 case PROP_TOLERANCE_SPACING:
296 g_value_set_double(value, data->tolerance_spacing);
297 break;
298 case PROP_QUOTE_SHIFT:
299 g_value_set_boxed(value, &data->quote_shift);
300 break;
301 case PROP_TOLERANCE_SHIFT:
302 g_value_set_boxed(value, &data->tolerance_shift);
303 break;
304 case PROP_NOTE_SHIFT:
305 g_value_set_boxed(value, &data->note_shift);
306 break;
307 case PROP_NUMBER_FORMAT:
308 g_value_set_string(value, data->number_format);
309 break;
310 case PROP_NUMBER_TAG:
311 g_value_set_string(value, data->number_tag);
312 break;
313 default:
314 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
315 break;
319 static void
320 set_property(GObject *object,
321 guint prop_id, const GValue *value, GParamSpec *pspec)
323 AdgDimStyle *dim_style;
324 AdgDimStylePrivate *data;
326 dim_style = (AdgDimStyle *) object;
327 data = dim_style->data;
329 switch (prop_id) {
330 case PROP_VALUE_STYLE:
331 set_value_style(dim_style, g_value_get_object(value));
332 break;
333 case PROP_TOLERANCE_STYLE:
334 set_tolerance_style(dim_style, g_value_get_object(value));
335 break;
336 case PROP_NOTE_STYLE:
337 set_note_style(dim_style, g_value_get_object(value));
338 break;
339 case PROP_LINE_STYLE:
340 set_line_style(dim_style, g_value_get_object(value));
341 break;
342 case PROP_ARROW_STYLE:
343 set_arrow_style(dim_style, g_value_get_object(value));
344 break;
345 case PROP_FROM_OFFSET:
346 data->from_offset = g_value_get_double(value);
347 break;
348 case PROP_TO_OFFSET:
349 data->to_offset = g_value_get_double(value);
350 break;
351 case PROP_BEYOND:
352 data->beyond = g_value_get_double(value);
353 break;
354 case PROP_BASELINE_SPACING:
355 data->baseline_spacing = g_value_get_double(value);
356 break;
357 case PROP_TOLERANCE_SPACING:
358 data->tolerance_spacing = g_value_get_double(value);
359 break;
360 case PROP_QUOTE_SHIFT:
361 set_quote_shift(dim_style, g_value_get_boxed(value));
362 break;
363 case PROP_TOLERANCE_SHIFT:
364 set_tolerance_shift(dim_style, g_value_get_boxed(value));
365 break;
366 case PROP_NOTE_SHIFT:
367 set_note_shift(dim_style, g_value_get_boxed(value));
368 break;
369 case PROP_NUMBER_FORMAT:
370 set_number_format(dim_style, g_value_get_string(value));
371 break;
372 case PROP_NUMBER_TAG:
373 set_number_tag(dim_style, g_value_get_string(value));
374 break;
375 default:
376 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
377 break;
382 AdgStyleSlot
383 _adg_dim_style_get_slot(void)
385 static AdgStyleSlot slot = -1;
387 if (G_UNLIKELY(slot < 0))
388 slot = adg_context_get_slot(ADG_TYPE_DIM_STYLE);
390 return slot;
394 * adg_dim_style_new:
396 * Constructs a new dimension style initialized with default params.
398 * Returns: a new dimension style
400 AdgStyle *
401 adg_dim_style_new(void)
403 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
407 * adg_dim_style_get_value_style:
408 * @dim_style: an #AdgDimStyle object
410 * Gets the basic value font style of @dim_style. No reference will
411 * be added to the returned style; it should not be unreferenced.
413 * Returns: the basic value style or %NULL on errors
415 AdgStyle *
416 adg_dim_style_get_value_style(AdgDimStyle *dim_style)
418 AdgDimStylePrivate *data;
420 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
422 data = dim_style->data;
424 return data->value_style;
428 * adg_dim_style_set_value_style:
429 * @dim_style: an #AdgDimStyle object
430 * @style: the new basic value font style
432 * Sets a new font style on @dim_style for basic values. The old
433 * font style (if any) will be unreferenced while a new reference
434 * will be added to @style.
436 void
437 adg_dim_style_set_value_style(AdgDimStyle *dim_style, AdgFontStyle *style)
439 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
440 g_return_if_fail(ADG_IS_FONT_STYLE(style));
442 set_value_style(dim_style, style);
443 g_object_notify((GObject *) dim_style, "value-style");
447 * adg_dim_style_get_tolerance_style:
448 * @dim_style: an #AdgDimStyle object
450 * Gets the tolerance style of @dim_style. No reference will be added to the
451 * returned style; it should not be unreferenced.
453 * Returns: the tolerance style or %NULL on errors
455 AdgStyle *
456 adg_dim_style_get_tolerance_style(AdgDimStyle *dim_style)
458 AdgDimStylePrivate *data;
460 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
462 data = dim_style->data;
464 return data->tolerance_style;
468 * adg_dim_style_set_tolerance_style:
469 * @dim_style: an #AdgDimStyle object
470 * @style: the new tolerance style
472 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
473 * will be unreferenced while a new reference will be added to @style.
475 void
476 adg_dim_style_set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
478 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
479 g_return_if_fail(ADG_IS_FONT_STYLE(style));
481 set_tolerance_style(dim_style, style);
482 g_object_notify((GObject *) dim_style, "tolerance-style");
486 * adg_dim_style_get_note_style:
487 * @dim_style: an #AdgDimStyle object
489 * Gets the note style of @dim_style. No reference will be added to the
490 * returned style; it should not be unreferenced.
492 * Returns: the note style or %NULL on errors
494 AdgStyle *
495 adg_dim_style_get_note_style(AdgDimStyle *dim_style)
497 AdgDimStylePrivate *data;
499 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
501 data = dim_style->data;
503 return data->note_style;
507 * adg_dim_style_set_note_style:
508 * @dim_style: an #AdgDimStyle object
509 * @style: the new note style
511 * Sets a new note style on @dim_style. The old note style (if any) will be
512 * unreferenced while a new reference will be added to @style.
514 void
515 adg_dim_style_set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
517 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
518 g_return_if_fail(ADG_IS_FONT_STYLE(style));
520 set_note_style(dim_style, style);
521 g_object_notify((GObject *) dim_style, "note-style");
525 * adg_dim_style_get_line_style:
526 * @dim_style: an #AdgDimStyle object
528 * Gets the line style of @dim_style. No reference will be added to the
529 * returned style; it should not be unreferenced.
531 * Returns: the line style or %NULL on errors
533 AdgStyle *
534 adg_dim_style_get_line_style(AdgDimStyle *dim_style)
536 AdgDimStylePrivate *data;
538 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
540 data = dim_style->data;
542 return data->line_style;
546 * adg_dim_style_set_line_style:
547 * @dim_style: an #AdgDimStyle object
548 * @style: the new line style
550 * Sets a new line style on @dim_style. The old line style (if any) will be
551 * unreferenced while a new reference will be added to @style.
553 void
554 adg_dim_style_set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
556 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
557 g_return_if_fail(ADG_IS_LINE_STYLE(style));
559 set_line_style(dim_style, style);
560 g_object_notify((GObject *) dim_style, "line-style");
564 * adg_dim_style_get_arrow_style:
565 * @dim_style: an #AdgDimStyle object
567 * Gets the arrow style of @dim_style. No reference will be added to the
568 * returned style; it should not be unreferenced.
570 * Returns: the arrow style or %NULL on errors
572 AdgStyle *
573 adg_dim_style_get_arrow_style(AdgDimStyle *dim_style)
575 AdgDimStylePrivate *data;
577 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
579 data = dim_style->data;
581 return data->arrow_style;
585 * adg_dim_style_set_arrow_style:
586 * @dim_style: an #AdgDimStyle object
587 * @style: the new arrow style
589 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
590 * unreferenced while a new reference will be added to @style.
592 void
593 adg_dim_style_set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
595 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
596 g_return_if_fail(ADG_IS_ARROW_STYLE(style));
598 set_arrow_style(dim_style, style);
599 g_object_notify((GObject *) dim_style, "arrow-style");
603 * adg_dim_style_get_from_offset:
604 * @dim_style: an #AdgDimStyle object
606 * Gets the distance (in global space) the extension lines must keep from the
607 * sensed points.
609 * Returns: the requested distance
611 gdouble
612 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
614 AdgDimStylePrivate *data;
616 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
618 data = dim_style->data;
620 return data->from_offset;
624 * adg_dim_style_set_from_offset:
625 * @dim_style: an #AdgDimStyle object
626 * @offset: the new offset
628 * Sets a new "from-offset" value.
630 void
631 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
633 AdgDimStylePrivate *data;
635 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
637 data = dim_style->data;
638 data->from_offset = offset;
640 g_object_notify((GObject *) dim_style, "from-offset");
644 * adg_dim_style_get_to_offset:
645 * @dim_style: an #AdgDimStyle object
647 * Gets how much (in global space) the extension lines must extend after
648 * crossing the baseline.
650 * Returns: the requested distance
652 gdouble
653 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
655 AdgDimStylePrivate *data;
657 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
659 data = dim_style->data;
661 return data->to_offset;
665 * adg_dim_style_set_to_offset:
666 * @dim_style: an #AdgDimStyle object
667 * @offset: the new offset
669 * Sets a new "to-offset" value.
671 void
672 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
674 AdgDimStylePrivate *data;
676 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
678 data = dim_style->data;
679 data->to_offset = offset;
681 g_object_notify((GObject *) dim_style, "to-offset");
685 * adg_dim_style_beyond:
686 * @dim_style: an #AdgDimStyle object
688 * Gets how much (in global space) the baseline should extend beyound
689 * the extension lines when a dimension has outside arrows. If the
690 * underlying AdgDimStyle:beyond property is %0, this function returns
691 * the 3*"arrow-size", where "arrow-size" is the value returned by
692 * adg_arrow_style_get_size() on #AdgArrowStyle binded to @dim_style.
694 * Returns: the requested lenght
696 gdouble
697 adg_dim_style_beyond(AdgDimStyle *dim_style)
699 AdgDimStylePrivate *data;
700 gdouble arrow_size;
702 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
704 data = dim_style->data;
706 if (data->beyond > 0)
707 return data->beyond;
709 arrow_size = adg_arrow_style_get_size((AdgArrowStyle *) data->arrow_style);
711 return arrow_size * 3;
715 * adg_dim_style_get_beyond:
716 * @dim_style: an #AdgDimStyle object
718 * Gets how much (in global space) the baseline should extend beyound
719 * the extension lines on dimension with outside arrows. This is an
720 * accessor method: if you need AdgDimStyle:beyond for rendering purpose,
721 * use adg_dim_style_beyond() instead.
723 * Returns: the requested lenght or %0 for automatic computation
725 gdouble
726 adg_dim_style_get_beyond(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->beyond;
738 * adg_dim_style_set_beyond:
739 * @dim_style: an #AdgDimStyle object
740 * @length: the new length
742 * Sets a new "beyond" value.
744 void
745 adg_dim_style_set_beyond(AdgDimStyle *dim_style, gdouble length)
747 AdgDimStylePrivate *data;
749 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
751 data = dim_style->data;
752 data->beyond = length;
754 g_object_notify((GObject *) dim_style, "beyond");
758 * adg_dim_style_get_baseline_spacing:
759 * @dim_style: an #AdgDimStyle object
761 * Gets the distance between two consecutive baselines
762 * while stacking dimensions.
764 * Returns: the requested spacing
766 gdouble
767 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
769 AdgDimStylePrivate *data;
771 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
773 data = dim_style->data;
775 return data->baseline_spacing;
779 * adg_dim_style_set_baseline_spacing:
780 * @dim_style: an #AdgDimStyle object
781 * @spacing: the new spacing
783 * Sets a new "baseline-spacing" value.
785 void
786 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
788 AdgDimStylePrivate *data;
790 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
792 data = dim_style->data;
793 data->baseline_spacing = spacing;
795 g_object_notify((GObject *) dim_style, "baseline-spacing");
799 * adg_dim_style_get_tolerance_spacing:
800 * @dim_style: an #AdgDimStyle object
802 * Gets the distance (in global space) between up and down tolerances.
804 * Returns: the requested spacing
806 gdouble
807 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
809 AdgDimStylePrivate *data;
811 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
813 data = dim_style->data;
815 return data->tolerance_spacing;
819 * adg_dim_style_set_tolerance_spacing:
820 * @dim_style: an #AdgDimStyle object
821 * @spacing: the new spacing
823 * Sets a new "tolerance-spacing" value.
825 void
826 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
828 AdgDimStylePrivate *data;
830 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
832 data = dim_style->data;
833 data->tolerance_spacing = spacing;
835 g_object_notify((GObject *) dim_style, "tolerance-spacing");
839 * adg_dim_style_get_quote_shift:
840 * @dim_style: an #AdgDimStyle object
842 * Gets the smooth displacement of the quote. The returned pointer refers
843 * to an internal allocated struct and must not be modified or freed.
845 * Returns: the requested shift
847 const AdgPair *
848 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
850 AdgDimStylePrivate *data;
852 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
854 data = dim_style->data;
856 return &data->quote_shift;
860 * adg_dim_style_set_quote_shift:
861 * @dim_style: an #AdgDimStyle object
862 * @shift: the new displacement
864 * Sets a new "quote-shift" value.
866 void
867 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
869 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
871 set_quote_shift(dim_style, shift);
872 g_object_notify((GObject *) dim_style, "quote-shift");
876 * adg_dim_style_get_tolerance_shift:
877 * @dim_style: an #AdgDimStyle object
879 * Gets the smooth displacement of the tolerance text. The returned pointer
880 * refers to an internal allocated struct and must not be modified or freed.
882 * Returns: the requested shift
884 const AdgPair *
885 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
887 AdgDimStylePrivate *data;
889 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
891 data = dim_style->data;
893 return &data->tolerance_shift;
897 * adg_dim_style_set_tolerance_shift:
898 * @dim_style: an #AdgDimStyle object
899 * @shift: the new displacement
901 * Sets a new "tolerance-shift" value.
903 void
904 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
906 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
908 set_tolerance_shift(dim_style, shift);
909 g_object_notify((GObject *) dim_style, "tolerance-shift");
913 * adg_dim_style_get_note_shift:
914 * @dim_style: an #AdgDimStyle object
916 * Gets the smooth displacement of the note text. The returned pointer
917 * refers to an internal allocated struct and must not be modified or freed.
919 * Returns: the requested shift
921 const AdgPair *
922 adg_dim_style_get_note_shift(AdgDimStyle *dim_style)
924 AdgDimStylePrivate *data;
926 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
928 data = dim_style->data;
930 return &data->note_shift;
934 * adg_dim_style_set_note_shift:
935 * @dim_style: an #AdgDimStyle object
936 * @shift: the new displacement
938 * Sets a new "note-shift" value.
940 void
941 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
943 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
945 set_note_shift(dim_style, shift);
946 g_object_notify((GObject *) dim_style, "note-shift");
950 * adg_dim_style_get_number_format:
951 * @dim_style: an #AdgDimStyle object
953 * Gets the number format (in printf style) of this quoting style. The
954 * returned pointer refers to internally managed text that must not be
955 * modified or freed.
957 * Returns: the requested format
959 const gchar *
960 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
962 AdgDimStylePrivate *data;
964 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
966 data = dim_style->data;
968 return data->number_format;
972 * adg_dim_style_set_number_format:
973 * @dim_style: an #AdgDimStyle object
974 * @format: the new format to adopt
976 * Sets a new "number-format" value.
978 void
979 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
981 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
983 set_number_format(dim_style, format);
984 g_object_notify((GObject *) dim_style, "number-format");
988 * adg_dim_style_get_number_tag:
989 * @dim_style: an #AdgDimStyle object
991 * Gets the number tag to substitute while building the basic value. The
992 * returned pointer refers to internally managed text that must not be
993 * modified or freed.
995 * Returns: the requested tag
997 const gchar *
998 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
1000 AdgDimStylePrivate *data;
1002 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
1004 data = dim_style->data;
1006 return data->number_tag;
1010 * adg_dim_style_set_number_tag:
1011 * @dim_style: an #AdgDimStyle object
1012 * @tag: the new tag
1014 * Sets a new "number-tag" value.
1016 void
1017 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
1019 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
1021 set_number_tag(dim_style, tag);
1022 g_object_notify((GObject *) dim_style, "number-tag");
1026 static GPtrArray *
1027 get_pool(void)
1029 static GPtrArray *pool = NULL;
1031 if (G_UNLIKELY(pool == NULL)) {
1032 cairo_pattern_t *pattern;
1034 pool = g_ptr_array_sized_new(ADG_DIM_STYLE_LAST);
1036 /* No need to specify further params: the default is already ISO */
1037 pattern = cairo_pattern_create_rgb(1, 0, 0);
1038 pool->pdata[ADG_DIM_STYLE_ISO] = g_object_new(ADG_TYPE_DIM_STYLE,
1039 "pattern", pattern,
1040 NULL);
1041 cairo_pattern_destroy(pattern);
1043 pool->len = ADG_DIM_STYLE_LAST;
1046 return pool;
1049 static void
1050 set_value_style(AdgDimStyle *dim_style, AdgFontStyle *style)
1052 AdgDimStylePrivate *data = dim_style->data;
1054 if (data->value_style)
1055 g_object_unref(data->value_style);
1057 g_object_ref(style);
1058 data->value_style = (AdgStyle *) style;
1061 static void
1062 set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
1064 AdgDimStylePrivate *data = dim_style->data;
1066 if (data->tolerance_style)
1067 g_object_unref(data->tolerance_style);
1069 g_object_ref(style);
1070 data->tolerance_style = (AdgStyle *) style;
1073 static void
1074 set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
1076 AdgDimStylePrivate *data = dim_style->data;
1078 if (data->note_style)
1079 g_object_unref(data->note_style);
1081 g_object_ref(style);
1082 data->note_style = (AdgStyle *) style;
1085 static void
1086 set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
1088 AdgDimStylePrivate *data = dim_style->data;
1090 if (data->line_style)
1091 g_object_unref(data->line_style);
1093 g_object_ref(style);
1094 data->line_style = (AdgStyle *) style;
1097 static void
1098 set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
1100 AdgDimStylePrivate *data = dim_style->data;
1102 if (data->arrow_style)
1103 g_object_unref(data->arrow_style);
1105 g_object_ref(style);
1106 data->arrow_style = (AdgStyle *) style;
1109 static void
1110 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1112 AdgDimStylePrivate *data = dim_style->data;
1114 cpml_pair_copy(&data->quote_shift, shift);
1117 static void
1118 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1120 AdgDimStylePrivate *data = dim_style->data;
1122 cpml_pair_copy(&data->tolerance_shift, shift);
1125 static void
1126 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1128 AdgDimStylePrivate *data = dim_style->data;
1130 cpml_pair_copy(&data->note_shift, shift);
1133 static void
1134 set_number_format(AdgDimStyle *dim_style, const gchar *format)
1136 AdgDimStylePrivate *data = dim_style->data;
1138 g_free(data->number_format);
1139 data->number_format = g_strdup(format);
1142 static void
1143 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
1145 AdgDimStylePrivate *data = dim_style->data;
1147 g_free(data->number_tag);
1148 data->number_tag = g_strdup(tag);