[docs] Updated TODO.xml
[adg.git] / adg / adg-dim-style.c
blob6d903104bf1be233de3446a27792c7ac58307a24
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 * Return value: 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_BASELINE_SPACING,
67 PROP_TOLERANCE_SPACING,
68 PROP_QUOTE_SHIFT,
69 PROP_TOLERANCE_SHIFT,
70 PROP_NOTE_SHIFT,
71 PROP_NUMBER_FORMAT,
72 PROP_NUMBER_TAG
76 static void get_property (GObject *object,
77 guint prop_id,
78 GValue *value,
79 GParamSpec *pspec);
80 static void set_property (GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec);
84 static GPtrArray * get_pool (void);
85 static void set_value_style (AdgDimStyle *dim_style,
86 AdgFontStyle *style);
87 static void set_tolerance_style (AdgDimStyle *dim_style,
88 AdgFontStyle *style);
89 static void set_note_style (AdgDimStyle *dim_style,
90 AdgFontStyle *style);
91 static void set_line_style (AdgDimStyle *dim_style,
92 AdgLineStyle *style);
93 static void set_arrow_style (AdgDimStyle *dim_style,
94 AdgArrowStyle *style);
95 static void set_quote_shift (AdgDimStyle *dim_style,
96 const AdgPair *shift);
97 static void set_tolerance_shift (AdgDimStyle *dim_style,
98 const AdgPair *shift);
99 static void set_note_shift (AdgDimStyle *dim_style,
100 const AdgPair *shift);
101 static void set_number_format (AdgDimStyle *dim_style,
102 const gchar *format);
103 static void set_number_tag (AdgDimStyle *dim_style,
104 const gchar *tag);
107 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE)
110 static void
111 adg_dim_style_class_init(AdgDimStyleClass *klass)
113 GObjectClass *gobject_class;
114 AdgStyleClass *style_class;
115 GParamSpec *param;
117 gobject_class = (GObjectClass *) klass;
118 style_class = (AdgStyleClass *) klass;
120 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
122 gobject_class->get_property = get_property;
123 gobject_class->set_property = set_property;
125 style_class->get_pool = get_pool;
127 param = g_param_spec_object("value-style",
128 P_("Value Style"),
129 P_("Font style for the basic value of the dimension"),
130 ADG_TYPE_STYLE, G_PARAM_READWRITE);
131 g_object_class_install_property(gobject_class, PROP_VALUE_STYLE,
132 param);
134 param = g_param_spec_object("tolerance-style",
135 P_("Tolerance Style"),
136 P_("Font style for the tolerances"),
137 ADG_TYPE_STYLE, G_PARAM_READWRITE);
138 g_object_class_install_property(gobject_class, PROP_TOLERANCE_STYLE,
139 param);
141 param = g_param_spec_object("note-style",
142 P_("Note Style"),
143 P_("Font style for the note (the text after or under the basic value)"),
144 ADG_TYPE_STYLE, G_PARAM_READWRITE);
145 g_object_class_install_property(gobject_class, PROP_NOTE_STYLE, param);
147 param = g_param_spec_object("line-style",
148 P_("Line Style"),
149 P_("Line style for the baseline and the extension lines"),
150 ADG_TYPE_STYLE, G_PARAM_READWRITE);
151 g_object_class_install_property(gobject_class, PROP_LINE_STYLE, param);
153 param = g_param_spec_object("arrow-style",
154 P_("Arrow Style"),
155 P_("Arrow style to use on the baseline"),
156 ADG_TYPE_STYLE, G_PARAM_READWRITE);
157 g_object_class_install_property(gobject_class, PROP_ARROW_STYLE,
158 param);
160 param = g_param_spec_double("from-offset",
161 P_("From Offset"),
162 P_("Offset (in global space) of the extension lines from the path to the quote"),
163 0, G_MAXDOUBLE, 5, G_PARAM_READWRITE);
164 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET,
165 param);
167 param = g_param_spec_double("to-offset",
168 P_("To Offset"),
169 P_("How many extend (in global space) the extension lines after hitting the baseline"),
170 0, G_MAXDOUBLE, 5, G_PARAM_READWRITE);
171 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
173 param = g_param_spec_double("baseline-spacing",
174 P_("Baseline Spacing"),
175 P_("Distance between two consecutive baselines while stacking dimensions"),
176 0, G_MAXDOUBLE, 30, G_PARAM_READWRITE);
177 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING,
178 param);
180 param = g_param_spec_double("tolerance-spacing",
181 P_("Tolerance Spacing"),
182 P_("Distance between up and down tolerance text"),
183 0, G_MAXDOUBLE, 2, G_PARAM_READWRITE);
184 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SPACING,
185 param);
187 param = g_param_spec_boxed("quote-shift",
188 P_("Quote Shift"),
189 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)"),
190 ADG_TYPE_PAIR, G_PARAM_READWRITE);
191 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT,
192 param);
194 param = g_param_spec_boxed("tolerance-shift",
195 P_("Tolerance Shift"),
196 P_("Used to specify a smooth displacement (in global space) for the tolerance text by taking as reference the perfect compact position"),
197 ADG_TYPE_PAIR, G_PARAM_READWRITE);
198 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SHIFT,
199 param);
201 param = g_param_spec_boxed("note-shift",
202 P_("Note Shift"),
203 P_("Used to specify a smooth displacement (in global space) for the note 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_NOTE_SHIFT, param);
207 param = g_param_spec_string("number-format",
208 P_("Number Format"),
209 P_("The format (in printf style) of the numeric component of the basic value"),
210 "%-.7g", G_PARAM_READWRITE);
211 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT,
212 param);
214 param = g_param_spec_string("number-tag",
215 P_("Number Tag"),
216 P_("The tag to substitute inside the basic value pattern"),
217 "<>", G_PARAM_READWRITE);
218 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
221 static void
222 adg_dim_style_init(AdgDimStyle *dim_style)
224 AdgDimStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
225 ADG_TYPE_DIM_STYLE,
226 AdgDimStylePrivate);
228 data->value_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
229 ADG_FONT_STYLE_VALUE);
230 data->tolerance_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
231 ADG_FONT_STYLE_TOLERANCE);
232 data->note_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
233 ADG_FONT_STYLE_NOTE);
234 data->line_style = adg_style_from_id(ADG_TYPE_LINE_STYLE,
235 ADG_LINE_STYLE_DIM);
236 data->arrow_style = adg_style_from_id(ADG_TYPE_ARROW_STYLE,
237 ADG_ARROW_STYLE_ARROW);
238 data->from_offset = 6;
239 data->to_offset = 6;
240 data->baseline_spacing = 30;
241 data->tolerance_spacing = 1;
242 data->quote_shift.x = 0;
243 data->quote_shift.y = -4;
244 data->tolerance_shift.x = +2;
245 data->tolerance_shift.y = -2;
246 data->note_shift.x = +4;
247 data->note_shift.y = 0;
248 data->number_format = g_strdup("%-.7g");
249 data->number_tag = g_strdup("<>");
251 dim_style->data = data;
254 static void
255 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
257 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
259 switch (prop_id) {
260 case PROP_VALUE_STYLE:
261 g_value_set_object(value, data->value_style);
262 break;
263 case PROP_TOLERANCE_STYLE:
264 g_value_set_object(value, data->tolerance_style);
265 break;
266 case PROP_NOTE_STYLE:
267 g_value_set_object(value, data->note_style);
268 break;
269 case PROP_LINE_STYLE:
270 g_value_set_object(value, data->line_style);
271 break;
272 case PROP_ARROW_STYLE:
273 g_value_set_object(value, data->arrow_style);
274 break;
275 case PROP_FROM_OFFSET:
276 g_value_set_double(value, data->from_offset);
277 break;
278 case PROP_TO_OFFSET:
279 g_value_set_double(value, data->to_offset);
280 break;
281 case PROP_BASELINE_SPACING:
282 g_value_set_double(value, data->baseline_spacing);
283 break;
284 case PROP_TOLERANCE_SPACING:
285 g_value_set_double(value, data->tolerance_spacing);
286 break;
287 case PROP_QUOTE_SHIFT:
288 g_value_set_boxed(value, &data->quote_shift);
289 break;
290 case PROP_TOLERANCE_SHIFT:
291 g_value_set_boxed(value, &data->tolerance_shift);
292 break;
293 case PROP_NOTE_SHIFT:
294 g_value_set_boxed(value, &data->note_shift);
295 break;
296 case PROP_NUMBER_FORMAT:
297 g_value_set_string(value, data->number_format);
298 break;
299 case PROP_NUMBER_TAG:
300 g_value_set_string(value, data->number_tag);
301 break;
302 default:
303 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
304 break;
308 static void
309 set_property(GObject *object,
310 guint prop_id, const GValue *value, GParamSpec *pspec)
312 AdgDimStyle *dim_style;
313 AdgDimStylePrivate *data;
315 dim_style = (AdgDimStyle *) object;
316 data = dim_style->data;
318 switch (prop_id) {
319 case PROP_VALUE_STYLE:
320 set_value_style(dim_style, g_value_get_object(value));
321 break;
322 case PROP_TOLERANCE_STYLE:
323 set_tolerance_style(dim_style, g_value_get_object(value));
324 break;
325 case PROP_NOTE_STYLE:
326 set_note_style(dim_style, g_value_get_object(value));
327 break;
328 case PROP_LINE_STYLE:
329 set_line_style(dim_style, g_value_get_object(value));
330 break;
331 case PROP_ARROW_STYLE:
332 set_arrow_style(dim_style, g_value_get_object(value));
333 break;
334 case PROP_FROM_OFFSET:
335 data->from_offset = g_value_get_double(value);
336 break;
337 case PROP_TO_OFFSET:
338 data->to_offset = g_value_get_double(value);
339 break;
340 case PROP_BASELINE_SPACING:
341 data->baseline_spacing = g_value_get_double(value);
342 break;
343 case PROP_TOLERANCE_SPACING:
344 data->tolerance_spacing = g_value_get_double(value);
345 break;
346 case PROP_QUOTE_SHIFT:
347 set_quote_shift(dim_style, g_value_get_boxed(value));
348 break;
349 case PROP_TOLERANCE_SHIFT:
350 set_tolerance_shift(dim_style, g_value_get_boxed(value));
351 break;
352 case PROP_NOTE_SHIFT:
353 set_note_shift(dim_style, g_value_get_boxed(value));
354 break;
355 case PROP_NUMBER_FORMAT:
356 set_number_format(dim_style, g_value_get_string(value));
357 break;
358 case PROP_NUMBER_TAG:
359 set_number_tag(dim_style, g_value_get_string(value));
360 break;
361 default:
362 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
363 break;
368 AdgStyleSlot
369 _adg_dim_style_get_slot(void)
371 static AdgStyleSlot slot = -1;
373 if (G_UNLIKELY(slot < 0))
374 slot = adg_context_get_slot(ADG_TYPE_DIM_STYLE);
376 return slot;
380 * adg_dim_style_new:
382 * Constructs a new dimension style initialized with default params.
384 * Return value: a new dimension style
386 AdgStyle *
387 adg_dim_style_new(void)
389 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
393 * adg_dim_style_get_value_style:
394 * @dim_style: an #AdgDimStyle object
396 * Gets the basic value font style of @dim_style. No reference will
397 * be added to the returned style; it should not be unreferenced.
399 * Return value: the basic value style or %NULL on errors
401 AdgStyle *
402 adg_dim_style_get_value_style(AdgDimStyle *dim_style)
404 AdgDimStylePrivate *data;
406 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
408 data = dim_style->data;
410 return data->value_style;
414 * adg_dim_style_set_value_style:
415 * @dim_style: an #AdgDimStyle object
416 * @style: the new basic value font style
418 * Sets a new font style on @dim_style for basic values. The old
419 * font style (if any) will be unreferenced while a new reference
420 * will be added to @style.
422 void
423 adg_dim_style_set_value_style(AdgDimStyle *dim_style, AdgFontStyle *style)
425 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
426 g_return_if_fail(ADG_IS_FONT_STYLE(style));
428 set_value_style(dim_style, style);
429 g_object_notify((GObject *) dim_style, "value-style");
433 * adg_dim_style_get_tolerance_style:
434 * @dim_style: an #AdgDimStyle object
436 * Gets the tolerance style of @dim_style. No reference will be added to the
437 * returned style; it should not be unreferenced.
439 * Return value: the tolerance style or %NULL on errors
441 AdgStyle *
442 adg_dim_style_get_tolerance_style(AdgDimStyle *dim_style)
444 AdgDimStylePrivate *data;
446 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
448 data = dim_style->data;
450 return data->tolerance_style;
454 * adg_dim_style_set_tolerance_style:
455 * @dim_style: an #AdgDimStyle object
456 * @style: the new tolerance style
458 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
459 * will be unreferenced while a new reference will be added to @style.
461 void
462 adg_dim_style_set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
464 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
465 g_return_if_fail(ADG_IS_FONT_STYLE(style));
467 set_tolerance_style(dim_style, style);
468 g_object_notify((GObject *) dim_style, "tolerance-style");
472 * adg_dim_style_get_note_style:
473 * @dim_style: an #AdgDimStyle object
475 * Gets the note style of @dim_style. No reference will be added to the
476 * returned style; it should not be unreferenced.
478 * Return value: the note style or %NULL on errors
480 AdgStyle *
481 adg_dim_style_get_note_style(AdgDimStyle *dim_style)
483 AdgDimStylePrivate *data;
485 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
487 data = dim_style->data;
489 return data->note_style;
493 * adg_dim_style_set_note_style:
494 * @dim_style: an #AdgDimStyle object
495 * @style: the new note style
497 * Sets a new note style on @dim_style. The old note style (if any) will be
498 * unreferenced while a new reference will be added to @style.
500 void
501 adg_dim_style_set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
503 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
504 g_return_if_fail(ADG_IS_FONT_STYLE(style));
506 set_note_style(dim_style, style);
507 g_object_notify((GObject *) dim_style, "note-style");
511 * adg_dim_style_get_line_style:
512 * @dim_style: an #AdgDimStyle object
514 * Gets the line style of @dim_style. No reference will be added to the
515 * returned style; it should not be unreferenced.
517 * Return value: the line style or %NULL on errors
519 AdgStyle *
520 adg_dim_style_get_line_style(AdgDimStyle *dim_style)
522 AdgDimStylePrivate *data;
524 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
526 data = dim_style->data;
528 return data->line_style;
532 * adg_dim_style_set_line_style:
533 * @dim_style: an #AdgDimStyle object
534 * @style: the new line style
536 * Sets a new line style on @dim_style. The old line style (if any) will be
537 * unreferenced while a new reference will be added to @style.
539 void
540 adg_dim_style_set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
542 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
543 g_return_if_fail(ADG_IS_LINE_STYLE(style));
545 set_line_style(dim_style, style);
546 g_object_notify((GObject *) dim_style, "line-style");
550 * adg_dim_style_get_arrow_style:
551 * @dim_style: an #AdgDimStyle object
553 * Gets the arrow style of @dim_style. No reference will be added to the
554 * returned style; it should not be unreferenced.
556 * Return value: the arrow style or %NULL on errors
558 AdgStyle *
559 adg_dim_style_get_arrow_style(AdgDimStyle *dim_style)
561 AdgDimStylePrivate *data;
563 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
565 data = dim_style->data;
567 return data->arrow_style;
571 * adg_dim_style_set_arrow_style:
572 * @dim_style: an #AdgDimStyle object
573 * @style: the new arrow style
575 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
576 * unreferenced while a new reference will be added to @style.
578 void
579 adg_dim_style_set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
581 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
582 g_return_if_fail(ADG_IS_ARROW_STYLE(style));
584 set_arrow_style(dim_style, style);
585 g_object_notify((GObject *) dim_style, "arrow-style");
589 * adg_dim_style_get_from_offset:
590 * @dim_style: an #AdgDimStyle object
592 * Gets the distance (in global space) the extension lines must keep from the
593 * sensed points.
595 * Return value: the requested distance
597 gdouble
598 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
600 AdgDimStylePrivate *data;
602 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
604 data = dim_style->data;
606 return data->from_offset;
610 * adg_dim_style_set_from_offset:
611 * @dim_style: an #AdgDimStyle object
612 * @offset: the new offset
614 * Sets a new "from-offset" value.
616 void
617 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
619 AdgDimStylePrivate *data;
621 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
623 data = dim_style->data;
624 data->from_offset = offset;
626 g_object_notify((GObject *) dim_style, "from-offset");
630 * adg_dim_style_get_to_offset:
631 * @dim_style: an #AdgDimStyle object
633 * Gets how much (in global space) the extension lines must extend after
634 * crossing the baseline.
636 * Return value: the requested distance
638 gdouble
639 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
641 AdgDimStylePrivate *data;
643 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
645 data = dim_style->data;
647 return data->to_offset;
651 * adg_dim_style_set_to_offset:
652 * @dim_style: an #AdgDimStyle object
653 * @offset: the new offset
655 * Sets a new "to-offset" value.
657 void
658 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
660 AdgDimStylePrivate *data;
662 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
664 data = dim_style->data;
665 data->to_offset = offset;
667 g_object_notify((GObject *) dim_style, "to-offset");
671 * adg_dim_style_get_baseline_spacing:
672 * @dim_style: an #AdgDimStyle object
674 * Gets the distance between two consecutive baselines
675 * while stacking dimensions.
677 * Return value: the requested spacing
679 gdouble
680 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
682 AdgDimStylePrivate *data;
684 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
686 data = dim_style->data;
688 return data->baseline_spacing;
692 * adg_dim_style_set_baseline_spacing:
693 * @dim_style: an #AdgDimStyle object
694 * @spacing: the new spacing
696 * Sets a new "baseline-spacing" value.
698 void
699 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
701 AdgDimStylePrivate *data;
703 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
705 data = dim_style->data;
706 data->baseline_spacing = spacing;
708 g_object_notify((GObject *) dim_style, "baseline-spacing");
712 * adg_dim_style_get_tolerance_spacing:
713 * @dim_style: an #AdgDimStyle object
715 * Gets the distance (in global space) between up and down tolerances.
717 * Return value: the requested spacing
719 gdouble
720 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
722 AdgDimStylePrivate *data;
724 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
726 data = dim_style->data;
728 return data->tolerance_spacing;
732 * adg_dim_style_set_tolerance_spacing:
733 * @dim_style: an #AdgDimStyle object
734 * @spacing: the new spacing
736 * Sets a new "tolerance-spacing" value.
738 void
739 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
741 AdgDimStylePrivate *data;
743 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
745 data = dim_style->data;
746 data->tolerance_spacing = spacing;
748 g_object_notify((GObject *) dim_style, "tolerance-spacing");
752 * adg_dim_style_get_quote_shift:
753 * @dim_style: an #AdgDimStyle object
755 * Gets the smooth displacement of the quote. The returned pointer refers
756 * to an internal allocated struct and must not be modified or freed.
758 * Return value: the requested shift
760 const AdgPair *
761 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
763 AdgDimStylePrivate *data;
765 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
767 data = dim_style->data;
769 return &data->quote_shift;
773 * adg_dim_style_set_quote_shift:
774 * @dim_style: an #AdgDimStyle object
775 * @shift: the new displacement
777 * Sets a new "quote-shift" value.
779 void
780 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
782 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
784 set_quote_shift(dim_style, shift);
785 g_object_notify((GObject *) dim_style, "quote-shift");
789 * adg_dim_style_get_tolerance_shift:
790 * @dim_style: an #AdgDimStyle object
792 * Gets the smooth displacement of the tolerance text. The returned pointer
793 * refers to an internal allocated struct and must not be modified or freed.
795 * Return value: the requested shift
797 const AdgPair *
798 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
800 AdgDimStylePrivate *data;
802 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
804 data = dim_style->data;
806 return &data->tolerance_shift;
810 * adg_dim_style_set_tolerance_shift:
811 * @dim_style: an #AdgDimStyle object
812 * @shift: the new displacement
814 * Sets a new "tolerance-shift" value.
816 void
817 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
819 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
821 set_tolerance_shift(dim_style, shift);
822 g_object_notify((GObject *) dim_style, "tolerance-shift");
826 * adg_dim_style_get_note_shift:
827 * @dim_style: an #AdgDimStyle object
829 * Gets the smooth displacement of the note text. The returned pointer
830 * refers to an internal allocated struct and must not be modified or freed.
832 * Return value: the requested shift
834 const AdgPair *
835 adg_dim_style_get_note_shift(AdgDimStyle *dim_style)
837 AdgDimStylePrivate *data;
839 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
841 data = dim_style->data;
843 return &data->note_shift;
847 * adg_dim_style_set_note_shift:
848 * @dim_style: an #AdgDimStyle object
849 * @shift: the new displacement
851 * Sets a new "note-shift" value.
853 void
854 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
856 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
858 set_note_shift(dim_style, shift);
859 g_object_notify((GObject *) dim_style, "note-shift");
863 * adg_dim_style_get_number_format:
864 * @dim_style: an #AdgDimStyle object
866 * Gets the number format (in printf style) of this quoting style. The
867 * returned pointer refers to internally managed text that must not be
868 * modified or freed.
870 * Return value: the requested format
872 const gchar *
873 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
875 AdgDimStylePrivate *data;
877 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
879 data = dim_style->data;
881 return data->number_format;
885 * adg_dim_style_set_number_format:
886 * @dim_style: an #AdgDimStyle object
887 * @format: the new format to adopt
889 * Sets a new "number-format" value.
891 void
892 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
894 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
896 set_number_format(dim_style, format);
897 g_object_notify((GObject *) dim_style, "number-format");
901 * adg_dim_style_get_number_tag:
902 * @dim_style: an #AdgDimStyle object
904 * Gets the number tag to substitute while building the basic value. The
905 * returned pointer refers to internally managed text that must not be
906 * modified or freed.
908 * Return value: the requested tag
910 const gchar *
911 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
913 AdgDimStylePrivate *data;
915 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
917 data = dim_style->data;
919 return data->number_tag;
923 * adg_dim_style_set_number_tag:
924 * @dim_style: an #AdgDimStyle object
925 * @tag: the new tag
927 * Sets a new "number-tag" value.
929 void
930 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
932 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
934 set_number_tag(dim_style, tag);
935 g_object_notify((GObject *) dim_style, "number-tag");
939 static GPtrArray *
940 get_pool(void)
942 static GPtrArray *pool = NULL;
944 if (G_UNLIKELY(pool == NULL)) {
945 cairo_pattern_t *pattern;
947 pool = g_ptr_array_sized_new(ADG_DIM_STYLE_LAST);
949 /* No need to specify further params: the default is already ISO */
950 pattern = cairo_pattern_create_rgb(1, 0, 0);
951 pool->pdata[ADG_DIM_STYLE_ISO] = g_object_new(ADG_TYPE_DIM_STYLE,
952 "pattern", pattern,
953 NULL);
954 cairo_pattern_destroy(pattern);
956 pool->len = ADG_DIM_STYLE_LAST;
959 return pool;
962 static void
963 set_value_style(AdgDimStyle *dim_style, AdgFontStyle *style)
965 AdgDimStylePrivate *data = dim_style->data;
967 if (data->value_style)
968 g_object_unref(data->value_style);
970 g_object_ref(style);
971 data->value_style = (AdgStyle *) style;
974 static void
975 set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
977 AdgDimStylePrivate *data = dim_style->data;
979 if (data->tolerance_style)
980 g_object_unref(data->tolerance_style);
982 g_object_ref(style);
983 data->tolerance_style = (AdgStyle *) style;
986 static void
987 set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
989 AdgDimStylePrivate *data = dim_style->data;
991 if (data->note_style)
992 g_object_unref(data->note_style);
994 g_object_ref(style);
995 data->note_style = (AdgStyle *) style;
998 static void
999 set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
1001 AdgDimStylePrivate *data = dim_style->data;
1003 if (data->line_style)
1004 g_object_unref(data->line_style);
1006 g_object_ref(style);
1007 data->line_style = (AdgStyle *) style;
1010 static void
1011 set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
1013 AdgDimStylePrivate *data = dim_style->data;
1015 if (data->arrow_style)
1016 g_object_unref(data->arrow_style);
1018 g_object_ref(style);
1019 data->arrow_style = (AdgStyle *) style;
1022 static void
1023 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1025 AdgDimStylePrivate *data = dim_style->data;
1027 cpml_pair_copy(&data->quote_shift, shift);
1030 static void
1031 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1033 AdgDimStylePrivate *data = dim_style->data;
1035 cpml_pair_copy(&data->tolerance_shift, shift);
1038 static void
1039 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1041 AdgDimStylePrivate *data = dim_style->data;
1043 cpml_pair_copy(&data->note_shift, shift);
1046 static void
1047 set_number_format(AdgDimStyle *dim_style, const gchar *format)
1049 AdgDimStylePrivate *data = dim_style->data;
1051 g_free(data->number_format);
1052 data->number_format = g_strdup(format);
1055 static void
1056 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
1058 AdgDimStylePrivate *data = dim_style->data;
1060 g_free(data->number_tag);
1061 data->number_tag = g_strdup(tag);