[demo] Do not define static function when not required
[adg.git] / adg / adg-dim-style.c
blobd328b3f39d73cba6ad2f9e084cca70863bd33edc
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"
40 #define PARENT_CLASS ((AdgStyleClass *) adg_dim_style_parent_class)
43 enum {
44 PROP_0,
45 PROP_QUOTE_STYLE,
46 PROP_TOLERANCE_STYLE,
47 PROP_NOTE_STYLE,
48 PROP_LINE_STYLE,
49 PROP_ARROW_STYLE,
50 PROP_FROM_OFFSET,
51 PROP_TO_OFFSET,
52 PROP_BASELINE_SPACING,
53 PROP_TOLERANCE_SPACING,
54 PROP_QUOTE_SHIFT,
55 PROP_TOLERANCE_SHIFT,
56 PROP_NOTE_SHIFT,
57 PROP_NUMBER_FORMAT,
58 PROP_NUMBER_TAG
62 static void get_property (GObject *object,
63 guint prop_id,
64 GValue *value,
65 GParamSpec *pspec);
66 static void set_property (GObject *object,
67 guint prop_id,
68 const GValue *value,
69 GParamSpec *pspec);
70 static GPtrArray * get_pool (void);
71 static void set_quote_style (AdgDimStyle *dim_style,
72 AdgFontStyle *style);
73 static void set_tolerance_style (AdgDimStyle *dim_style,
74 AdgFontStyle *style);
75 static void set_note_style (AdgDimStyle *dim_style,
76 AdgFontStyle *style);
77 static void set_line_style (AdgDimStyle *dim_style,
78 AdgLineStyle *style);
79 static void set_arrow_style (AdgDimStyle *dim_style,
80 AdgArrowStyle *style);
81 static void set_quote_shift (AdgDimStyle *dim_style,
82 const AdgPair *shift);
83 static void set_tolerance_shift (AdgDimStyle *dim_style,
84 const AdgPair *shift);
85 static void set_note_shift (AdgDimStyle *dim_style,
86 const AdgPair *shift);
87 static void set_number_format (AdgDimStyle *dim_style,
88 const gchar *format);
89 static void set_number_tag (AdgDimStyle *dim_style,
90 const gchar *tag);
93 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE)
96 static void
97 adg_dim_style_class_init(AdgDimStyleClass *klass)
99 GObjectClass *gobject_class;
100 AdgStyleClass *style_class;
101 GParamSpec *param;
103 gobject_class = (GObjectClass *) klass;
104 style_class = (AdgStyleClass *) klass;
106 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
108 gobject_class->get_property = get_property;
109 gobject_class->set_property = set_property;
111 style_class->get_pool = get_pool;
113 param = g_param_spec_object("quote-style",
114 P_("Quote Style"),
115 P_("Font style for the quote"),
116 ADG_TYPE_STYLE, G_PARAM_READWRITE);
117 g_object_class_install_property(gobject_class, PROP_QUOTE_STYLE,
118 param);
120 param = g_param_spec_object("tolerance-style",
121 P_("Tolerance Style"),
122 P_("Font style for the tolerances"),
123 ADG_TYPE_STYLE, G_PARAM_READWRITE);
124 g_object_class_install_property(gobject_class, PROP_TOLERANCE_STYLE,
125 param);
127 param = g_param_spec_object("note-style",
128 P_("Note Style"),
129 P_("Font style for the note (the text after or under the quote)"),
130 ADG_TYPE_STYLE, G_PARAM_READWRITE);
131 g_object_class_install_property(gobject_class, PROP_NOTE_STYLE, param);
133 param = g_param_spec_object("line-style",
134 P_("Line Style"),
135 P_("Line style for the baseline and the extension lines"),
136 ADG_TYPE_STYLE, G_PARAM_READWRITE);
137 g_object_class_install_property(gobject_class, PROP_LINE_STYLE, param);
139 param = g_param_spec_object("arrow-style",
140 P_("Arrow Style"),
141 P_("Arrow style to use on the baseline"),
142 ADG_TYPE_STYLE, G_PARAM_READWRITE);
143 g_object_class_install_property(gobject_class, PROP_ARROW_STYLE,
144 param);
146 param = g_param_spec_double("from-offset",
147 P_("From Offset"),
148 P_("Offset (in paper space) of the extension lines from the path to quote"),
149 0., G_MAXDOUBLE, 5., G_PARAM_READWRITE);
150 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET,
151 param);
153 param = g_param_spec_double("to-offset",
154 P_("To Offset"),
155 P_("How many extend (in paper space) the extension lines after hitting the baseline"),
156 0., G_MAXDOUBLE, 5., G_PARAM_READWRITE);
157 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
159 param = g_param_spec_double("baseline-spacing",
160 P_("Baseline Spacing"),
161 P_("Distance between two consecutive baselines while stacking dimensions"),
162 0., G_MAXDOUBLE, 30., G_PARAM_READWRITE);
163 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING,
164 param);
166 param = g_param_spec_double("tolerance-spacing",
167 P_("Tolerance Spacing"),
168 P_("Distance between up and down tolerance text"),
169 0., G_MAXDOUBLE, 2., G_PARAM_READWRITE);
170 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SPACING,
171 param);
173 param = g_param_spec_boxed("quote-shift",
174 P_("Quote Shift"),
175 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)"),
176 ADG_TYPE_PAIR, G_PARAM_READWRITE);
177 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT,
178 param);
180 param = g_param_spec_boxed("tolerance-shift",
181 P_("Tolerance Shift"),
182 P_("Used to specify a smooth displacement (in paper units) for the tolerance text by taking as reference the perfect compact position"),
183 ADG_TYPE_PAIR, G_PARAM_READWRITE);
184 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SHIFT,
185 param);
187 param = g_param_spec_boxed("note-shift",
188 P_("Note Shift"),
189 P_("Used to specify a smooth displacement (in paper units) for the note text by taking as reference the perfect compact position"),
190 ADG_TYPE_PAIR, G_PARAM_READWRITE);
191 g_object_class_install_property(gobject_class, PROP_NOTE_SHIFT, param);
193 param = g_param_spec_string("number-format",
194 P_("Number Format"),
195 P_("The format (in printf style) of the numeric component of the quote"),
196 "%-.7g", G_PARAM_READWRITE);
197 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT,
198 param);
200 param = g_param_spec_string("number-tag",
201 P_("Number Tag"),
202 P_("The tag to substitute inside the quote pattern"),
203 "<>", G_PARAM_READWRITE);
204 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
207 static void
208 adg_dim_style_init(AdgDimStyle *dim_style)
210 AdgDimStylePrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
211 ADG_TYPE_DIM_STYLE,
212 AdgDimStylePrivate);
214 priv->quote_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
215 ADG_FONT_STYLE_QUOTE);
216 priv->tolerance_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
217 ADG_FONT_STYLE_TOLERANCE);
218 priv->note_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
219 ADG_FONT_STYLE_NOTE);
220 priv->line_style = adg_style_from_id(ADG_TYPE_LINE_STYLE,
221 ADG_LINE_STYLE_DIM);
222 priv->arrow_style = adg_style_from_id(ADG_TYPE_ARROW_STYLE,
223 ADG_ARROW_STYLE_ARROW);
224 priv->from_offset = 5.;
225 priv->to_offset = 5.;
226 priv->baseline_spacing = 30.;
227 priv->tolerance_spacing = 2.;
228 priv->quote_shift.x = 0.;
229 priv->quote_shift.y = -3.;
230 priv->tolerance_shift.x = +5.;
231 priv->tolerance_shift.y = -4.;
232 priv->note_shift.x = +5.;
233 priv->note_shift.y = 0.;
234 priv->number_format = g_strdup("%-.7g");
235 priv->number_tag = g_strdup("<>");
237 dim_style->priv = priv;
240 static void
241 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
243 AdgDimStyle *dim_style = (AdgDimStyle *) object;
245 switch (prop_id) {
246 case PROP_QUOTE_STYLE:
247 g_value_set_object(value, dim_style->priv->quote_style);
248 break;
249 case PROP_TOLERANCE_STYLE:
250 g_value_set_object(value, dim_style->priv->tolerance_style);
251 break;
252 case PROP_NOTE_STYLE:
253 g_value_set_object(value, dim_style->priv->note_style);
254 break;
255 case PROP_LINE_STYLE:
256 g_value_set_object(value, dim_style->priv->line_style);
257 break;
258 case PROP_ARROW_STYLE:
259 g_value_set_object(value, dim_style->priv->arrow_style);
260 break;
261 case PROP_FROM_OFFSET:
262 g_value_set_double(value, dim_style->priv->from_offset);
263 break;
264 case PROP_TO_OFFSET:
265 g_value_set_double(value, dim_style->priv->to_offset);
266 break;
267 case PROP_BASELINE_SPACING:
268 g_value_set_double(value, dim_style->priv->baseline_spacing);
269 break;
270 case PROP_TOLERANCE_SPACING:
271 g_value_set_double(value, dim_style->priv->tolerance_spacing);
272 break;
273 case PROP_QUOTE_SHIFT:
274 g_value_set_boxed(value, &dim_style->priv->quote_shift);
275 break;
276 case PROP_TOLERANCE_SHIFT:
277 g_value_set_boxed(value, &dim_style->priv->tolerance_shift);
278 break;
279 case PROP_NOTE_SHIFT:
280 g_value_set_boxed(value, &dim_style->priv->note_shift);
281 break;
282 case PROP_NUMBER_FORMAT:
283 g_value_set_string(value, dim_style->priv->number_format);
284 break;
285 case PROP_NUMBER_TAG:
286 g_value_set_string(value, dim_style->priv->number_tag);
287 break;
288 default:
289 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
290 break;
294 static void
295 set_property(GObject *object,
296 guint prop_id, const GValue *value, GParamSpec *pspec)
298 AdgDimStyle *dim_style = (AdgDimStyle *) object;
300 switch (prop_id) {
301 case PROP_QUOTE_STYLE:
302 set_quote_style(dim_style, g_value_get_object(value));
303 break;
304 case PROP_TOLERANCE_STYLE:
305 set_tolerance_style(dim_style, g_value_get_object(value));
306 break;
307 case PROP_NOTE_STYLE:
308 set_note_style(dim_style, g_value_get_object(value));
309 break;
310 case PROP_LINE_STYLE:
311 set_line_style(dim_style, g_value_get_object(value));
312 break;
313 case PROP_ARROW_STYLE:
314 set_arrow_style(dim_style, g_value_get_object(value));
315 break;
316 case PROP_FROM_OFFSET:
317 dim_style->priv->from_offset = g_value_get_double(value);
318 break;
319 case PROP_TO_OFFSET:
320 dim_style->priv->to_offset = g_value_get_double(value);
321 break;
322 case PROP_BASELINE_SPACING:
323 dim_style->priv->baseline_spacing = g_value_get_double(value);
324 break;
325 case PROP_TOLERANCE_SPACING:
326 dim_style->priv->tolerance_spacing = g_value_get_double(value);
327 break;
328 case PROP_QUOTE_SHIFT:
329 set_quote_shift(dim_style, g_value_get_boxed(value));
330 break;
331 case PROP_TOLERANCE_SHIFT:
332 set_tolerance_shift(dim_style, g_value_get_boxed(value));
333 break;
334 case PROP_NOTE_SHIFT:
335 set_note_shift(dim_style, g_value_get_boxed(value));
336 break;
337 case PROP_NUMBER_FORMAT:
338 set_number_format(dim_style, g_value_get_string(value));
339 break;
340 case PROP_NUMBER_TAG:
341 set_number_tag(dim_style, g_value_get_string(value));
342 break;
343 default:
344 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
345 break;
351 * adg_dim_style_get_slot:
353 * Gets the slot id for this style class.
355 * Return value: the slot
357 AdgStyleSlot
358 adg_dim_style_get_slot(void)
360 static AdgStyleSlot slot = -1;
362 if (G_UNLIKELY(slot < 0))
363 slot = adg_context_get_slot(ADG_TYPE_DIM_STYLE);
365 return slot;
369 * adg_dim_style_new:
371 * Constructs a new dimension style initialized with default params.
373 * Return value: a new dimension style
375 AdgStyle *
376 adg_dim_style_new(void)
378 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
382 * adg_dim_style_get_quote_style:
383 * @dim_style: an #AdgDimStyle object
385 * Gets the quote style of @dim_style. No reference will be added to the
386 * returned style; it should not be unreferenced.
388 * Return value: the quote style or %NULL on errors
390 AdgStyle *
391 adg_dim_style_get_quote_style(AdgDimStyle *dim_style)
393 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
395 return dim_style->priv->quote_style;
399 * adg_dim_style_set_quote_style:
400 * @dim_style: an #AdgDimStyle object
401 * @style: the new quote style
403 * Sets a new quote style on @dim_style. The old quote style (if any) will be
404 * unreferenced while a new reference will be added to @style.
406 void
407 adg_dim_style_set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
409 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
410 g_return_if_fail(ADG_IS_FONT_STYLE(style));
412 set_quote_style(dim_style, style);
413 g_object_notify((GObject *) dim_style, "quote-style");
417 * adg_dim_style_get_tolerance_style:
418 * @dim_style: an #AdgDimStyle object
420 * Gets the tolerance style of @dim_style. No reference will be added to the
421 * returned style; it should not be unreferenced.
423 * Return value: the tolerance style or %NULL on errors
425 AdgStyle *
426 adg_dim_style_get_tolerance_style(AdgDimStyle *dim_style)
428 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
430 return dim_style->priv->tolerance_style;
434 * adg_dim_style_set_tolerance_style:
435 * @dim_style: an #AdgDimStyle object
436 * @style: the new tolerance style
438 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
439 * will be unreferenced while a new reference will be added to @style.
441 void
442 adg_dim_style_set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
444 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
445 g_return_if_fail(ADG_IS_FONT_STYLE(style));
447 set_tolerance_style(dim_style, style);
448 g_object_notify((GObject *) dim_style, "tolerance-style");
452 * adg_dim_style_get_note_style:
453 * @dim_style: an #AdgDimStyle object
455 * Gets the note style of @dim_style. No reference will be added to the
456 * returned style; it should not be unreferenced.
458 * Return value: the note style or %NULL on errors
460 AdgStyle *
461 adg_dim_style_get_note_style(AdgDimStyle *dim_style)
463 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
465 return dim_style->priv->note_style;
469 * adg_dim_style_set_note_style:
470 * @dim_style: an #AdgDimStyle object
471 * @style: the new note style
473 * Sets a new note style on @dim_style. The old note style (if any) will be
474 * unreferenced while a new reference will be added to @style.
476 void
477 adg_dim_style_set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
479 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
480 g_return_if_fail(ADG_IS_FONT_STYLE(style));
482 set_note_style(dim_style, style);
483 g_object_notify((GObject *) dim_style, "note-style");
487 * adg_dim_style_get_line_style:
488 * @dim_style: an #AdgDimStyle object
490 * Gets the line style of @dim_style. No reference will be added to the
491 * returned style; it should not be unreferenced.
493 * Return value: the line style or %NULL on errors
495 AdgStyle *
496 adg_dim_style_get_line_style(AdgDimStyle *dim_style)
498 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
500 return dim_style->priv->line_style;
504 * adg_dim_style_set_line_style:
505 * @dim_style: an #AdgDimStyle object
506 * @style: the new line style
508 * Sets a new line style on @dim_style. The old line style (if any) will be
509 * unreferenced while a new reference will be added to @style.
511 void
512 adg_dim_style_set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
514 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
515 g_return_if_fail(ADG_IS_LINE_STYLE(style));
517 set_line_style(dim_style, style);
518 g_object_notify((GObject *) dim_style, "line-style");
522 * adg_dim_style_get_arrow_style:
523 * @dim_style: an #AdgDimStyle object
525 * Gets the arrow style of @dim_style. No reference will be added to the
526 * returned style; it should not be unreferenced.
528 * Return value: the arrow style or %NULL on errors
530 AdgStyle *
531 adg_dim_style_get_arrow_style(AdgDimStyle *dim_style)
533 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
535 return dim_style->priv->arrow_style;
539 * adg_dim_style_set_arrow_style:
540 * @dim_style: an #AdgDimStyle object
541 * @style: the new arrow style
543 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
544 * unreferenced while a new reference will be added to @style.
546 void
547 adg_dim_style_set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
549 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
550 g_return_if_fail(ADG_IS_ARROW_STYLE(style));
552 set_arrow_style(dim_style, style);
553 g_object_notify((GObject *) dim_style, "arrow-style");
557 * adg_dim_style_get_from_offset:
558 * @dim_style: an #AdgDimStyle object
560 * Gets the distance (in paper space) the extension lines must keep from the
561 * sensed points.
563 * Return value: the requested distance
565 gdouble
566 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
568 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
570 return dim_style->priv->from_offset;
574 * adg_dim_style_set_from_offset:
575 * @dim_style: an #AdgDimStyle object
576 * @offset: the new offset
578 * Sets a new "from-offset" value.
580 void
581 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
583 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
585 dim_style->priv->from_offset = offset;
586 g_object_notify((GObject *) dim_style, "from-offset");
590 * adg_dim_style_get_to_offset:
591 * @dim_style: an #AdgDimStyle object
593 * Gets how much (in paper space) the extension lines must extend after
594 * crossing the baseline.
596 * Return value: the requested distance
598 gdouble
599 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
601 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
603 return dim_style->priv->to_offset;
607 * adg_dim_style_set_to_offset:
608 * @dim_style: an #AdgDimStyle object
609 * @offset: the new offset
611 * Sets a new "to-offset" value.
613 void
614 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
616 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
618 dim_style->priv->to_offset = offset;
619 g_object_notify((GObject *) dim_style, "to-offset");
623 * adg_dim_style_get_baseline_spacing:
624 * @dim_style: an #AdgDimStyle object
626 * Gets the distance between two consecutive baselines
627 * while stacking dimensions.
629 * Return value: the requested spacing
631 gdouble
632 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
634 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
636 return dim_style->priv->baseline_spacing;
640 * adg_dim_style_set_baseline_spacing:
641 * @dim_style: an #AdgDimStyle object
642 * @spacing: the new spacing
644 * Sets a new "baseline-spacing" value.
646 void
647 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
649 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
651 dim_style->priv->baseline_spacing = spacing;
652 g_object_notify((GObject *) dim_style, "baseline-spacing");
656 * adg_dim_style_get_tolerance_spacing:
657 * @dim_style: an #AdgDimStyle object
659 * Gets the distance (in paper space) between up and down tolerances.
661 * Return value: the requested spacing
663 gdouble
664 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
666 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
668 return dim_style->priv->tolerance_spacing;
672 * adg_dim_style_set_tolerance_spacing:
673 * @dim_style: an #AdgDimStyle object
674 * @spacing: the new spacing
676 * Sets a new "tolerance-spacing" value.
678 void
679 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
681 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
683 dim_style->priv->tolerance_spacing = spacing;
684 g_object_notify((GObject *) dim_style, "tolerance-spacing");
688 * adg_dim_style_get_quote_shift:
689 * @dim_style: an #AdgDimStyle object
691 * Gets the smooth displacement of the quote text. The returned pointer
692 * refers to an internal allocated struct and must not be modified or freed.
694 * Return value: the requested shift
696 const AdgPair *
697 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
699 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
701 return &dim_style->priv->quote_shift;
705 * adg_dim_style_set_quote_shift:
706 * @dim_style: an #AdgDimStyle object
707 * @shift: the new displacement
709 * Sets a new "quote-shift" value.
711 void
712 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
714 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
716 set_quote_shift(dim_style, shift);
717 g_object_notify((GObject *) dim_style, "quote-shift");
721 * adg_dim_style_get_tolerance_shift:
722 * @dim_style: an #AdgDimStyle object
724 * Gets the smooth displacement of the tolerance text. The returned pointer
725 * refers to an internal allocated struct and must not be modified or freed.
727 * Return value: the requested shift
729 const AdgPair *
730 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
732 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
734 return &dim_style->priv->tolerance_shift;
738 * adg_dim_style_set_tolerance_shift:
739 * @dim_style: an #AdgDimStyle object
740 * @shift: the new displacement
742 * Sets a new "tolerance-shift" value.
744 void
745 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
747 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
749 set_tolerance_shift(dim_style, shift);
750 g_object_notify((GObject *) dim_style, "tolerance-shift");
754 * adg_dim_style_get_note_shift:
755 * @dim_style: an #AdgDimStyle object
757 * Gets the smooth displacement of the note text. The returned pointer
758 * refers to an internal allocated struct and must not be modified or freed.
760 * Return value: the requested shift
762 const AdgPair *
763 adg_dim_style_get_note_shift(AdgDimStyle *dim_style)
765 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
767 return &dim_style->priv->note_shift;
771 * adg_dim_style_set_note_shift:
772 * @dim_style: an #AdgDimStyle object
773 * @shift: the new displacement
775 * Sets a new "note-shift" value.
777 void
778 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
780 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
782 set_note_shift(dim_style, shift);
783 g_object_notify((GObject *) dim_style, "note-shift");
787 * adg_dim_style_get_number_format:
788 * @dim_style: an #AdgDimStyle object
790 * Gets the number format (in printf style) of this quoting style. The
791 * returned pointer refers to internally managed text that must not be
792 * modified or freed.
794 * Return value: the requested format
796 const gchar *
797 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
799 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
801 return dim_style->priv->number_format;
805 * adg_dim_style_set_number_format:
806 * @dim_style: an #AdgDimStyle object
807 * @format: the new format to adopt
809 * Sets a new "number-format" value.
811 void
812 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
814 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
816 set_number_format(dim_style, format);
817 g_object_notify((GObject *) dim_style, "number-format");
821 * adg_dim_style_get_number_tag:
822 * @dim_style: an #AdgDimStyle object
824 * Gets the number tag to substitute while building the quote text. The
825 * returned pointer refers to internally managed text that must not be
826 * modified or freed.
828 * Return value: the requested tag
830 const gchar *
831 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
833 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
835 return dim_style->priv->number_tag;
839 * adg_dim_style_set_number_tag:
840 * @dim_style: an #AdgDimStyle object
841 * @tag: the new tag
843 * Sets a new "number-tag" value.
845 void
846 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
848 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
850 set_number_tag(dim_style, tag);
851 g_object_notify((GObject *) dim_style, "number-tag");
855 static GPtrArray *
856 get_pool(void)
858 static GPtrArray *pool = NULL;
860 if (G_UNLIKELY(pool == NULL)) {
861 cairo_pattern_t *pattern;
863 pool = g_ptr_array_sized_new(ADG_DIM_STYLE_LAST);
865 /* No need to specify further params: the default is already ISO */
866 pattern = cairo_pattern_create_rgb(1., 0., 0.);
867 pool->pdata[ADG_DIM_STYLE_ISO] = g_object_new(ADG_TYPE_DIM_STYLE,
868 "pattern", pattern,
869 NULL);
870 cairo_pattern_destroy(pattern);
872 pool->len = ADG_DIM_STYLE_LAST;
875 return pool;
878 static void
879 set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
881 if (dim_style->priv->quote_style)
882 g_object_unref(dim_style->priv->quote_style);
884 g_object_ref(style);
885 dim_style->priv->quote_style = (AdgStyle *) style;
888 static void
889 set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
891 if (dim_style->priv->tolerance_style)
892 g_object_unref(dim_style->priv->tolerance_style);
894 g_object_ref(style);
895 dim_style->priv->tolerance_style = (AdgStyle *) style;
898 static void
899 set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
901 if (dim_style->priv->note_style)
902 g_object_unref(dim_style->priv->note_style);
904 g_object_ref(style);
905 dim_style->priv->note_style = (AdgStyle *) style;
908 static void
909 set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
911 if (dim_style->priv->line_style)
912 g_object_unref(dim_style->priv->line_style);
914 g_object_ref(style);
915 dim_style->priv->line_style = (AdgStyle *) style;
918 static void
919 set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
921 if (dim_style->priv->arrow_style)
922 g_object_unref(dim_style->priv->arrow_style);
924 g_object_ref(style);
925 dim_style->priv->arrow_style = (AdgStyle *) style;
928 static void
929 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
931 cpml_pair_copy(&dim_style->priv->quote_shift, shift);
934 static void
935 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
937 cpml_pair_copy(&dim_style->priv->tolerance_shift, shift);
940 static void
941 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
943 cpml_pair_copy(&dim_style->priv->note_shift, shift);
946 static void
947 set_number_format(AdgDimStyle *dim_style, const gchar *format)
949 g_free(dim_style->priv->number_format);
950 dim_style->priv->number_format = g_strdup(format);
953 static void
954 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
956 g_free(dim_style->priv->number_tag);
957 dim_style->priv->number_tag = g_strdup(tag);