[docs] Added missing AdgSegment reference
[adg.git] / adg / adg-dim-style.c
blob68ccffadab887e2918d417a6c3887e95c2ad0776
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:dim-style
23 * @title: AdgDimStyle
24 * @short_description: Dimension style related stuff
26 * Contains parameters on how to build dimensions such as the different font
27 * styles (for quote, tolerance and note), line style, offsets of the various
28 * dimension components etc...
31 #include "adg-dim-style.h"
32 #include "adg-dim-style-private.h"
33 #include "adg-font-style.h"
34 #include "adg-line-style.h"
35 #include "adg-arrow-style.h"
36 #include "adg-context.h"
37 #include "adg-intl.h"
38 #include "adg-util.h"
41 enum {
42 PROP_0,
43 PROP_QUOTE_STYLE,
44 PROP_TOLERANCE_STYLE,
45 PROP_NOTE_STYLE,
46 PROP_LINE_STYLE,
47 PROP_ARROW_STYLE,
48 PROP_FROM_OFFSET,
49 PROP_TO_OFFSET,
50 PROP_BASELINE_SPACING,
51 PROP_TOLERANCE_SPACING,
52 PROP_QUOTE_SHIFT,
53 PROP_TOLERANCE_SHIFT,
54 PROP_NOTE_SHIFT,
55 PROP_NUMBER_FORMAT,
56 PROP_NUMBER_TAG
60 static void get_property (GObject *object,
61 guint prop_id,
62 GValue *value,
63 GParamSpec *pspec);
64 static void set_property (GObject *object,
65 guint prop_id,
66 const GValue *value,
67 GParamSpec *pspec);
68 static GPtrArray * get_pool (void);
69 static void set_quote_style (AdgDimStyle *dim_style,
70 AdgFontStyle *style);
71 static void set_tolerance_style (AdgDimStyle *dim_style,
72 AdgFontStyle *style);
73 static void set_note_style (AdgDimStyle *dim_style,
74 AdgFontStyle *style);
75 static void set_line_style (AdgDimStyle *dim_style,
76 AdgLineStyle *style);
77 static void set_arrow_style (AdgDimStyle *dim_style,
78 AdgArrowStyle *style);
79 static void set_quote_shift (AdgDimStyle *dim_style,
80 const AdgPair *shift);
81 static void set_tolerance_shift (AdgDimStyle *dim_style,
82 const AdgPair *shift);
83 static void set_note_shift (AdgDimStyle *dim_style,
84 const AdgPair *shift);
85 static void set_number_format (AdgDimStyle *dim_style,
86 const gchar *format);
87 static void set_number_tag (AdgDimStyle *dim_style,
88 const gchar *tag);
91 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE)
94 static void
95 adg_dim_style_class_init(AdgDimStyleClass *klass)
97 GObjectClass *gobject_class;
98 AdgStyleClass *style_class;
99 GParamSpec *param;
101 gobject_class = (GObjectClass *) klass;
102 style_class = (AdgStyleClass *) klass;
104 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
106 gobject_class->get_property = get_property;
107 gobject_class->set_property = set_property;
109 style_class->get_pool = get_pool;
111 param = g_param_spec_object("quote-style",
112 P_("Quote Style"),
113 P_("Font style for the quote"),
114 ADG_TYPE_STYLE, G_PARAM_READWRITE);
115 g_object_class_install_property(gobject_class, PROP_QUOTE_STYLE,
116 param);
118 param = g_param_spec_object("tolerance-style",
119 P_("Tolerance Style"),
120 P_("Font style for the tolerances"),
121 ADG_TYPE_STYLE, G_PARAM_READWRITE);
122 g_object_class_install_property(gobject_class, PROP_TOLERANCE_STYLE,
123 param);
125 param = g_param_spec_object("note-style",
126 P_("Note Style"),
127 P_("Font style for the note (the text after or under the quote)"),
128 ADG_TYPE_STYLE, G_PARAM_READWRITE);
129 g_object_class_install_property(gobject_class, PROP_NOTE_STYLE, param);
131 param = g_param_spec_object("line-style",
132 P_("Line Style"),
133 P_("Line style for the baseline and the extension lines"),
134 ADG_TYPE_STYLE, G_PARAM_READWRITE);
135 g_object_class_install_property(gobject_class, PROP_LINE_STYLE, param);
137 param = g_param_spec_object("arrow-style",
138 P_("Arrow Style"),
139 P_("Arrow style to use on the baseline"),
140 ADG_TYPE_STYLE, G_PARAM_READWRITE);
141 g_object_class_install_property(gobject_class, PROP_ARROW_STYLE,
142 param);
144 param = g_param_spec_double("from-offset",
145 P_("From Offset"),
146 P_("Offset (in paper space) of the extension lines from the path to quote"),
147 0., G_MAXDOUBLE, 5., G_PARAM_READWRITE);
148 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET,
149 param);
151 param = g_param_spec_double("to-offset",
152 P_("To Offset"),
153 P_("How many extend (in paper space) the extension lines after hitting the baseline"),
154 0., G_MAXDOUBLE, 5., G_PARAM_READWRITE);
155 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
157 param = g_param_spec_double("baseline-spacing",
158 P_("Baseline Spacing"),
159 P_("Distance between two consecutive baselines while stacking dimensions"),
160 0., G_MAXDOUBLE, 30., G_PARAM_READWRITE);
161 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING,
162 param);
164 param = g_param_spec_double("tolerance-spacing",
165 P_("Tolerance Spacing"),
166 P_("Distance between up and down tolerance text"),
167 0., G_MAXDOUBLE, 2., G_PARAM_READWRITE);
168 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SPACING,
169 param);
171 param = g_param_spec_boxed("quote-shift",
172 P_("Quote Shift"),
173 P_("Used to specify a smooth displacement (in paper units) for the quote text by taking as reference the perfect compact position (the middle of the baseline on common linear quotes, for instance)"),
174 ADG_TYPE_PAIR, G_PARAM_READWRITE);
175 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT,
176 param);
178 param = g_param_spec_boxed("tolerance-shift",
179 P_("Tolerance Shift"),
180 P_("Used to specify a smooth displacement (in paper units) for the tolerance text by taking as reference the perfect compact position"),
181 ADG_TYPE_PAIR, G_PARAM_READWRITE);
182 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SHIFT,
183 param);
185 param = g_param_spec_boxed("note-shift",
186 P_("Note Shift"),
187 P_("Used to specify a smooth displacement (in paper units) for the note text by taking as reference the perfect compact position"),
188 ADG_TYPE_PAIR, G_PARAM_READWRITE);
189 g_object_class_install_property(gobject_class, PROP_NOTE_SHIFT, param);
191 param = g_param_spec_string("number-format",
192 P_("Number Format"),
193 P_("The format (in printf style) of the numeric component of the quote"),
194 "%-.7g", G_PARAM_READWRITE);
195 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT,
196 param);
198 param = g_param_spec_string("number-tag",
199 P_("Number Tag"),
200 P_("The tag to substitute inside the quote pattern"),
201 "<>", G_PARAM_READWRITE);
202 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
205 static void
206 adg_dim_style_init(AdgDimStyle *dim_style)
208 AdgDimStylePrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
209 ADG_TYPE_DIM_STYLE,
210 AdgDimStylePrivate);
212 priv->quote_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
213 ADG_FONT_STYLE_QUOTE);
214 priv->tolerance_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
215 ADG_FONT_STYLE_TOLERANCE);
216 priv->note_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
217 ADG_FONT_STYLE_NOTE);
218 priv->line_style = adg_style_from_id(ADG_TYPE_LINE_STYLE,
219 ADG_LINE_STYLE_DIM);
220 priv->arrow_style = adg_style_from_id(ADG_TYPE_ARROW_STYLE,
221 ADG_ARROW_STYLE_ARROW);
222 priv->from_offset = 5.;
223 priv->to_offset = 5.;
224 priv->baseline_spacing = 30.;
225 priv->tolerance_spacing = 2.;
226 priv->quote_shift.x = 0.;
227 priv->quote_shift.y = -3.;
228 priv->tolerance_shift.x = +5.;
229 priv->tolerance_shift.y = -4.;
230 priv->note_shift.x = +5.;
231 priv->note_shift.y = 0.;
232 priv->number_format = g_strdup("%-.7g");
233 priv->number_tag = g_strdup("<>");
235 dim_style->priv = priv;
238 static void
239 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
241 AdgDimStyle *dim_style = (AdgDimStyle *) object;
243 switch (prop_id) {
244 case PROP_QUOTE_STYLE:
245 g_value_set_object(value, dim_style->priv->quote_style);
246 break;
247 case PROP_TOLERANCE_STYLE:
248 g_value_set_object(value, dim_style->priv->tolerance_style);
249 break;
250 case PROP_NOTE_STYLE:
251 g_value_set_object(value, dim_style->priv->note_style);
252 break;
253 case PROP_LINE_STYLE:
254 g_value_set_object(value, dim_style->priv->line_style);
255 break;
256 case PROP_ARROW_STYLE:
257 g_value_set_object(value, dim_style->priv->arrow_style);
258 break;
259 case PROP_FROM_OFFSET:
260 g_value_set_double(value, dim_style->priv->from_offset);
261 break;
262 case PROP_TO_OFFSET:
263 g_value_set_double(value, dim_style->priv->to_offset);
264 break;
265 case PROP_BASELINE_SPACING:
266 g_value_set_double(value, dim_style->priv->baseline_spacing);
267 break;
268 case PROP_TOLERANCE_SPACING:
269 g_value_set_double(value, dim_style->priv->tolerance_spacing);
270 break;
271 case PROP_QUOTE_SHIFT:
272 g_value_set_boxed(value, &dim_style->priv->quote_shift);
273 break;
274 case PROP_TOLERANCE_SHIFT:
275 g_value_set_boxed(value, &dim_style->priv->tolerance_shift);
276 break;
277 case PROP_NOTE_SHIFT:
278 g_value_set_boxed(value, &dim_style->priv->note_shift);
279 break;
280 case PROP_NUMBER_FORMAT:
281 g_value_set_string(value, dim_style->priv->number_format);
282 break;
283 case PROP_NUMBER_TAG:
284 g_value_set_string(value, dim_style->priv->number_tag);
285 break;
286 default:
287 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
288 break;
292 static void
293 set_property(GObject *object,
294 guint prop_id, const GValue *value, GParamSpec *pspec)
296 AdgDimStyle *dim_style = (AdgDimStyle *) object;
298 switch (prop_id) {
299 case PROP_QUOTE_STYLE:
300 set_quote_style(dim_style, g_value_get_object(value));
301 break;
302 case PROP_TOLERANCE_STYLE:
303 set_tolerance_style(dim_style, g_value_get_object(value));
304 break;
305 case PROP_NOTE_STYLE:
306 set_note_style(dim_style, g_value_get_object(value));
307 break;
308 case PROP_LINE_STYLE:
309 set_line_style(dim_style, g_value_get_object(value));
310 break;
311 case PROP_ARROW_STYLE:
312 set_arrow_style(dim_style, g_value_get_object(value));
313 break;
314 case PROP_FROM_OFFSET:
315 dim_style->priv->from_offset = g_value_get_double(value);
316 break;
317 case PROP_TO_OFFSET:
318 dim_style->priv->to_offset = g_value_get_double(value);
319 break;
320 case PROP_BASELINE_SPACING:
321 dim_style->priv->baseline_spacing = g_value_get_double(value);
322 break;
323 case PROP_TOLERANCE_SPACING:
324 dim_style->priv->tolerance_spacing = g_value_get_double(value);
325 break;
326 case PROP_QUOTE_SHIFT:
327 set_quote_shift(dim_style, g_value_get_boxed(value));
328 break;
329 case PROP_TOLERANCE_SHIFT:
330 set_tolerance_shift(dim_style, g_value_get_boxed(value));
331 break;
332 case PROP_NOTE_SHIFT:
333 set_note_shift(dim_style, g_value_get_boxed(value));
334 break;
335 case PROP_NUMBER_FORMAT:
336 set_number_format(dim_style, g_value_get_string(value));
337 break;
338 case PROP_NUMBER_TAG:
339 set_number_tag(dim_style, g_value_get_string(value));
340 break;
341 default:
342 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
343 break;
349 * adg_dim_style_get_slot:
351 * Gets the slot id for this style class.
353 * Return value: the slot
355 AdgStyleSlot
356 adg_dim_style_get_slot(void)
358 static AdgStyleSlot slot = -1;
360 if (G_UNLIKELY(slot < 0))
361 slot = adg_context_get_slot(ADG_TYPE_DIM_STYLE);
363 return slot;
367 * adg_dim_style_new:
369 * Constructs a new dimension style initialized with default params.
371 * Return value: a new dimension style
373 AdgStyle *
374 adg_dim_style_new(void)
376 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
380 * adg_dim_style_get_quote_style:
381 * @dim_style: an #AdgDimStyle object
383 * Gets the quote style of @dim_style. No reference will be added to the
384 * returned style; it should not be unreferenced.
386 * Return value: the quote style or %NULL on errors
388 AdgStyle *
389 adg_dim_style_get_quote_style(AdgDimStyle *dim_style)
391 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
393 return dim_style->priv->quote_style;
397 * adg_dim_style_set_quote_style:
398 * @dim_style: an #AdgDimStyle object
399 * @style: the new quote style
401 * Sets a new quote style on @dim_style. The old quote style (if any) will be
402 * unreferenced while a new reference will be added to @style.
404 void
405 adg_dim_style_set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
407 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
408 g_return_if_fail(ADG_IS_FONT_STYLE(style));
410 set_quote_style(dim_style, style);
411 g_object_notify((GObject *) dim_style, "quote-style");
415 * adg_dim_style_get_tolerance_style:
416 * @dim_style: an #AdgDimStyle object
418 * Gets the tolerance style of @dim_style. No reference will be added to the
419 * returned style; it should not be unreferenced.
421 * Return value: the tolerance style or %NULL on errors
423 AdgStyle *
424 adg_dim_style_get_tolerance_style(AdgDimStyle *dim_style)
426 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
428 return dim_style->priv->tolerance_style;
432 * adg_dim_style_set_tolerance_style:
433 * @dim_style: an #AdgDimStyle object
434 * @style: the new tolerance style
436 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
437 * will be unreferenced while a new reference will be added to @style.
439 void
440 adg_dim_style_set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
442 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
443 g_return_if_fail(ADG_IS_FONT_STYLE(style));
445 set_tolerance_style(dim_style, style);
446 g_object_notify((GObject *) dim_style, "tolerance-style");
450 * adg_dim_style_get_note_style:
451 * @dim_style: an #AdgDimStyle object
453 * Gets the note style of @dim_style. No reference will be added to the
454 * returned style; it should not be unreferenced.
456 * Return value: the note style or %NULL on errors
458 AdgStyle *
459 adg_dim_style_get_note_style(AdgDimStyle *dim_style)
461 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
463 return dim_style->priv->note_style;
467 * adg_dim_style_set_note_style:
468 * @dim_style: an #AdgDimStyle object
469 * @style: the new note style
471 * Sets a new note style on @dim_style. The old note style (if any) will be
472 * unreferenced while a new reference will be added to @style.
474 void
475 adg_dim_style_set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
477 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
478 g_return_if_fail(ADG_IS_FONT_STYLE(style));
480 set_note_style(dim_style, style);
481 g_object_notify((GObject *) dim_style, "note-style");
485 * adg_dim_style_get_line_style:
486 * @dim_style: an #AdgDimStyle object
488 * Gets the line style of @dim_style. No reference will be added to the
489 * returned style; it should not be unreferenced.
491 * Return value: the line style or %NULL on errors
493 AdgStyle *
494 adg_dim_style_get_line_style(AdgDimStyle *dim_style)
496 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
498 return dim_style->priv->line_style;
502 * adg_dim_style_set_line_style:
503 * @dim_style: an #AdgDimStyle object
504 * @style: the new line style
506 * Sets a new line style on @dim_style. The old line style (if any) will be
507 * unreferenced while a new reference will be added to @style.
509 void
510 adg_dim_style_set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
512 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
513 g_return_if_fail(ADG_IS_LINE_STYLE(style));
515 set_line_style(dim_style, style);
516 g_object_notify((GObject *) dim_style, "line-style");
520 * adg_dim_style_get_arrow_style:
521 * @dim_style: an #AdgDimStyle object
523 * Gets the arrow style of @dim_style. No reference will be added to the
524 * returned style; it should not be unreferenced.
526 * Return value: the arrow style or %NULL on errors
528 AdgStyle *
529 adg_dim_style_get_arrow_style(AdgDimStyle *dim_style)
531 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
533 return dim_style->priv->arrow_style;
537 * adg_dim_style_set_arrow_style:
538 * @dim_style: an #AdgDimStyle object
539 * @style: the new arrow style
541 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
542 * unreferenced while a new reference will be added to @style.
544 void
545 adg_dim_style_set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
547 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
548 g_return_if_fail(ADG_IS_ARROW_STYLE(style));
550 set_arrow_style(dim_style, style);
551 g_object_notify((GObject *) dim_style, "arrow-style");
555 * adg_dim_style_get_from_offset:
556 * @dim_style: an #AdgDimStyle object
558 * Gets the distance (in paper space) the extension lines must keep from the
559 * sensed points.
561 * Return value: the requested distance
563 gdouble
564 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
566 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
568 return dim_style->priv->from_offset;
572 * adg_dim_style_set_from_offset:
573 * @dim_style: an #AdgDimStyle object
574 * @offset: the new offset
576 * Sets a new "from-offset" value.
578 void
579 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
581 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
583 dim_style->priv->from_offset = offset;
584 g_object_notify((GObject *) dim_style, "from-offset");
588 * adg_dim_style_get_to_offset:
589 * @dim_style: an #AdgDimStyle object
591 * Gets how much (in paper space) the extension lines must extend after
592 * crossing the baseline.
594 * Return value: the requested distance
596 gdouble
597 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
599 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
601 return dim_style->priv->to_offset;
605 * adg_dim_style_set_to_offset:
606 * @dim_style: an #AdgDimStyle object
607 * @offset: the new offset
609 * Sets a new "to-offset" value.
611 void
612 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
614 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
616 dim_style->priv->to_offset = offset;
617 g_object_notify((GObject *) dim_style, "to-offset");
621 * adg_dim_style_get_baseline_spacing:
622 * @dim_style: an #AdgDimStyle object
624 * Gets the distance between two consecutive baselines
625 * while stacking dimensions.
627 * Return value: the requested spacing
629 gdouble
630 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
632 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
634 return dim_style->priv->baseline_spacing;
638 * adg_dim_style_set_baseline_spacing:
639 * @dim_style: an #AdgDimStyle object
640 * @spacing: the new spacing
642 * Sets a new "baseline-spacing" value.
644 void
645 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
647 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
649 dim_style->priv->baseline_spacing = spacing;
650 g_object_notify((GObject *) dim_style, "baseline-spacing");
654 * adg_dim_style_get_tolerance_spacing:
655 * @dim_style: an #AdgDimStyle object
657 * Gets the distance (in paper space) between up and down tolerances.
659 * Return value: the requested spacing
661 gdouble
662 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
664 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
666 return dim_style->priv->tolerance_spacing;
670 * adg_dim_style_set_tolerance_spacing:
671 * @dim_style: an #AdgDimStyle object
672 * @spacing: the new spacing
674 * Sets a new "tolerance-spacing" value.
676 void
677 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
679 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
681 dim_style->priv->tolerance_spacing = spacing;
682 g_object_notify((GObject *) dim_style, "tolerance-spacing");
686 * adg_dim_style_get_quote_shift:
687 * @dim_style: an #AdgDimStyle object
689 * Gets the smooth displacement of the quote text. The returned pointer
690 * refers to an internal allocated struct and must not be modified or freed.
692 * Return value: the requested shift
694 const AdgPair *
695 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
697 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
699 return &dim_style->priv->quote_shift;
703 * adg_dim_style_set_quote_shift:
704 * @dim_style: an #AdgDimStyle object
705 * @shift: the new displacement
707 * Sets a new "quote-shift" value.
709 void
710 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
712 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
714 set_quote_shift(dim_style, shift);
715 g_object_notify((GObject *) dim_style, "quote-shift");
719 * adg_dim_style_get_tolerance_shift:
720 * @dim_style: an #AdgDimStyle object
722 * Gets the smooth displacement of the tolerance text. The returned pointer
723 * refers to an internal allocated struct and must not be modified or freed.
725 * Return value: the requested shift
727 const AdgPair *
728 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
730 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
732 return &dim_style->priv->tolerance_shift;
736 * adg_dim_style_set_tolerance_shift:
737 * @dim_style: an #AdgDimStyle object
738 * @shift: the new displacement
740 * Sets a new "tolerance-shift" value.
742 void
743 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
745 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
747 set_tolerance_shift(dim_style, shift);
748 g_object_notify((GObject *) dim_style, "tolerance-shift");
752 * adg_dim_style_get_note_shift:
753 * @dim_style: an #AdgDimStyle object
755 * Gets the smooth displacement of the note text. The returned pointer
756 * refers 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_note_shift(AdgDimStyle *dim_style)
763 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
765 return &dim_style->priv->note_shift;
769 * adg_dim_style_set_note_shift:
770 * @dim_style: an #AdgDimStyle object
771 * @shift: the new displacement
773 * Sets a new "note-shift" value.
775 void
776 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
778 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
780 set_note_shift(dim_style, shift);
781 g_object_notify((GObject *) dim_style, "note-shift");
785 * adg_dim_style_get_number_format:
786 * @dim_style: an #AdgDimStyle object
788 * Gets the number format (in printf style) of this quoting style. The
789 * returned pointer refers to internally managed text that must not be
790 * modified or freed.
792 * Return value: the requested format
794 const gchar *
795 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
797 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
799 return dim_style->priv->number_format;
803 * adg_dim_style_set_number_format:
804 * @dim_style: an #AdgDimStyle object
805 * @format: the new format to adopt
807 * Sets a new "number-format" value.
809 void
810 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
812 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
814 set_number_format(dim_style, format);
815 g_object_notify((GObject *) dim_style, "number-format");
819 * adg_dim_style_get_number_tag:
820 * @dim_style: an #AdgDimStyle object
822 * Gets the number tag to substitute while building the quote text. The
823 * returned pointer refers to internally managed text that must not be
824 * modified or freed.
826 * Return value: the requested tag
828 const gchar *
829 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
831 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
833 return dim_style->priv->number_tag;
837 * adg_dim_style_set_number_tag:
838 * @dim_style: an #AdgDimStyle object
839 * @tag: the new tag
841 * Sets a new "number-tag" value.
843 void
844 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
846 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
848 set_number_tag(dim_style, tag);
849 g_object_notify((GObject *) dim_style, "number-tag");
853 static GPtrArray *
854 get_pool(void)
856 static GPtrArray *pool = NULL;
858 if (G_UNLIKELY(pool == NULL)) {
859 cairo_pattern_t *pattern;
861 pool = g_ptr_array_sized_new(ADG_DIM_STYLE_LAST);
863 /* No need to specify further params: the default is already ISO */
864 pattern = cairo_pattern_create_rgb(1., 0., 0.);
865 pool->pdata[ADG_DIM_STYLE_ISO] = g_object_new(ADG_TYPE_DIM_STYLE,
866 "pattern", pattern,
867 NULL);
868 cairo_pattern_destroy(pattern);
870 pool->len = ADG_DIM_STYLE_LAST;
873 return pool;
876 static void
877 set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
879 if (dim_style->priv->quote_style)
880 g_object_unref(dim_style->priv->quote_style);
882 g_object_ref(style);
883 dim_style->priv->quote_style = (AdgStyle *) style;
886 static void
887 set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
889 if (dim_style->priv->tolerance_style)
890 g_object_unref(dim_style->priv->tolerance_style);
892 g_object_ref(style);
893 dim_style->priv->tolerance_style = (AdgStyle *) style;
896 static void
897 set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
899 if (dim_style->priv->note_style)
900 g_object_unref(dim_style->priv->note_style);
902 g_object_ref(style);
903 dim_style->priv->note_style = (AdgStyle *) style;
906 static void
907 set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
909 if (dim_style->priv->line_style)
910 g_object_unref(dim_style->priv->line_style);
912 g_object_ref(style);
913 dim_style->priv->line_style = (AdgStyle *) style;
916 static void
917 set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
919 if (dim_style->priv->arrow_style)
920 g_object_unref(dim_style->priv->arrow_style);
922 g_object_ref(style);
923 dim_style->priv->arrow_style = (AdgStyle *) style;
926 static void
927 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
929 cpml_pair_copy(&dim_style->priv->quote_shift, shift);
932 static void
933 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
935 cpml_pair_copy(&dim_style->priv->tolerance_shift, shift);
938 static void
939 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
941 cpml_pair_copy(&dim_style->priv->note_shift, shift);
944 static void
945 set_number_format(AdgDimStyle *dim_style, const gchar *format)
947 g_free(dim_style->priv->number_format);
948 dim_style->priv->number_format = g_strdup(format);
951 static void
952 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
954 g_free(dim_style->priv->number_tag);
955 dim_style->priv->number_tag = g_strdup(tag);