[AdgPositionable] Documented args for "origin-moved" signals
[adg.git] / adg / adg-dim-style.c
bloba93788eead02bece4cf3d20b7bbaab3a6a9a3688
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2008, 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-intl.h"
37 #include "adg-util.h"
39 #define PARENT_CLASS ((AdgStyleClass *) adg_dim_style_parent_class)
42 enum {
43 PROP_0,
44 PROP_QUOTE_STYLE,
45 PROP_TOLERANCE_STYLE,
46 PROP_NOTE_STYLE,
47 PROP_LINE_STYLE,
48 PROP_ARROW_STYLE,
49 PROP_FROM_OFFSET,
50 PROP_TO_OFFSET,
51 PROP_BASELINE_SPACING,
52 PROP_TOLERANCE_SPACING,
53 PROP_QUOTE_SHIFT,
54 PROP_TOLERANCE_SHIFT,
55 PROP_NOTE_SHIFT,
56 PROP_NUMBER_FORMAT,
57 PROP_NUMBER_TAG
61 static void get_property (GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec);
65 static void set_property (GObject *object,
66 guint prop_id,
67 const GValue *value,
68 GParamSpec *pspec);
69 static GPtrArray * get_pool (void);
70 static void set_quote_style (AdgDimStyle *dim_style,
71 AdgFontStyle *style);
72 static void set_tolerance_style (AdgDimStyle *dim_style,
73 AdgFontStyle *style);
74 static void set_note_style (AdgDimStyle *dim_style,
75 AdgFontStyle *style);
76 static void set_line_style (AdgDimStyle *dim_style,
77 AdgLineStyle *style);
78 static void set_arrow_style (AdgDimStyle *dim_style,
79 AdgArrowStyle *style);
80 static void set_quote_shift (AdgDimStyle *dim_style,
81 const AdgPair *shift);
82 static void set_tolerance_shift (AdgDimStyle *dim_style,
83 const AdgPair *shift);
84 static void set_note_shift (AdgDimStyle *dim_style,
85 const AdgPair *shift);
86 static void set_number_format (AdgDimStyle *dim_style,
87 const gchar *format);
88 static void set_number_tag (AdgDimStyle *dim_style,
89 const gchar *tag);
92 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE)
95 static void
96 adg_dim_style_class_init(AdgDimStyleClass *klass)
98 GObjectClass *gobject_class;
99 AdgStyleClass *style_class;
100 GParamSpec *param;
102 gobject_class = (GObjectClass *) klass;
103 style_class = (AdgStyleClass *) klass;
105 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
107 gobject_class->get_property = get_property;
108 gobject_class->set_property = set_property;
110 style_class->get_pool = get_pool;
112 param = g_param_spec_object("quote-style",
113 P_("Quote Style"),
114 P_("Font style for the quote"),
115 ADG_TYPE_STYLE, G_PARAM_READWRITE);
116 g_object_class_install_property(gobject_class, PROP_QUOTE_STYLE,
117 param);
119 param = g_param_spec_object("tolerance-style",
120 P_("Tolerance Style"),
121 P_("Font style for the tolerances"),
122 ADG_TYPE_STYLE, G_PARAM_READWRITE);
123 g_object_class_install_property(gobject_class, PROP_TOLERANCE_STYLE,
124 param);
126 param = g_param_spec_object("note-style",
127 P_("Note Style"),
128 P_("Font style for the note (the text after or under the quote)"),
129 ADG_TYPE_STYLE, G_PARAM_READWRITE);
130 g_object_class_install_property(gobject_class, PROP_NOTE_STYLE, param);
132 param = g_param_spec_object("line-style",
133 P_("Line Style"),
134 P_("Line style for the baseline and the extension lines"),
135 ADG_TYPE_STYLE, G_PARAM_READWRITE);
136 g_object_class_install_property(gobject_class, PROP_LINE_STYLE, param);
138 param = g_param_spec_object("arrow-style",
139 P_("Arrow Style"),
140 P_("Arrow style to use on the baseline"),
141 ADG_TYPE_STYLE, G_PARAM_READWRITE);
142 g_object_class_install_property(gobject_class, PROP_ARROW_STYLE,
143 param);
145 param = g_param_spec_double("from-offset",
146 P_("From Offset"),
147 P_("Offset (in paper space) of the extension lines from the path to quote"),
148 0., G_MAXDOUBLE, 5., G_PARAM_READWRITE);
149 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET,
150 param);
152 param = g_param_spec_double("to-offset",
153 P_("To Offset"),
154 P_("How many extend (in paper space) the extension lines after hitting the baseline"),
155 0., G_MAXDOUBLE, 5., G_PARAM_READWRITE);
156 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
158 param = g_param_spec_double("baseline-spacing",
159 P_("Baseline Spacing"),
160 P_("Distance between two consecutive baselines while stacking dimensions"),
161 0., G_MAXDOUBLE, 30., G_PARAM_READWRITE);
162 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING,
163 param);
165 param = g_param_spec_double("tolerance-spacing",
166 P_("Tolerance Spacing"),
167 P_("Distance between up and down tolerance text"),
168 0., G_MAXDOUBLE, 2., G_PARAM_READWRITE);
169 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SPACING,
170 param);
172 param = g_param_spec_boxed("quote-shift",
173 P_("Quote Shift"),
174 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)"),
175 ADG_TYPE_PAIR, G_PARAM_READWRITE);
176 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT,
177 param);
179 param = g_param_spec_boxed("tolerance-shift",
180 P_("Tolerance Shift"),
181 P_("Used to specify a smooth displacement (in paper units) for the tolerance text by taking as reference the perfect compact position"),
182 ADG_TYPE_PAIR, G_PARAM_READWRITE);
183 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SHIFT,
184 param);
186 param = g_param_spec_boxed("note-shift",
187 P_("Note Shift"),
188 P_("Used to specify a smooth displacement (in paper units) for the note text by taking as reference the perfect compact position"),
189 ADG_TYPE_PAIR, G_PARAM_READWRITE);
190 g_object_class_install_property(gobject_class, PROP_NOTE_SHIFT, param);
192 param = g_param_spec_string("number-format",
193 P_("Number Format"),
194 P_("The format (in printf style) of the numeric component of the quote"),
195 "%-.7g", G_PARAM_READWRITE);
196 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT,
197 param);
199 param = g_param_spec_string("number-tag",
200 P_("Number Tag"),
201 P_("The tag to substitute inside the quote pattern"),
202 "<>", G_PARAM_READWRITE);
203 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
206 static void
207 adg_dim_style_init(AdgDimStyle *dim_style)
209 AdgDimStylePrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
210 ADG_TYPE_DIM_STYLE,
211 AdgDimStylePrivate);
213 priv->quote_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
214 ADG_FONT_STYLE_QUOTE);
215 priv->tolerance_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
216 ADG_FONT_STYLE_TOLERANCE);
217 priv->note_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
218 ADG_FONT_STYLE_NOTE);
219 priv->line_style = adg_style_from_id(ADG_TYPE_LINE_STYLE,
220 ADG_LINE_STYLE_DIM);
221 priv->arrow_style = adg_style_from_id(ADG_TYPE_ARROW_STYLE,
222 ADG_ARROW_STYLE_ARROW);
223 priv->from_offset = 5.;
224 priv->to_offset = 5.;
225 priv->baseline_spacing = 30.;
226 priv->tolerance_spacing = 2.;
227 priv->quote_shift.x = 0.;
228 priv->quote_shift.y = -3.;
229 priv->tolerance_shift.x = +5.;
230 priv->tolerance_shift.y = -4.;
231 priv->note_shift.x = +5.;
232 priv->note_shift.y = 0.;
233 priv->number_format = g_strdup("%-.7g");
234 priv->number_tag = g_strdup("<>");
236 dim_style->priv = priv;
239 static void
240 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
242 AdgDimStyle *dim_style = (AdgDimStyle *) object;
244 switch (prop_id) {
245 case PROP_QUOTE_STYLE:
246 g_value_set_object(value, dim_style->priv->quote_style);
247 break;
248 case PROP_TOLERANCE_STYLE:
249 g_value_set_object(value, dim_style->priv->tolerance_style);
250 break;
251 case PROP_NOTE_STYLE:
252 g_value_set_object(value, dim_style->priv->note_style);
253 break;
254 case PROP_LINE_STYLE:
255 g_value_set_object(value, dim_style->priv->line_style);
256 break;
257 case PROP_ARROW_STYLE:
258 g_value_set_object(value, dim_style->priv->arrow_style);
259 break;
260 case PROP_FROM_OFFSET:
261 g_value_set_double(value, dim_style->priv->from_offset);
262 break;
263 case PROP_TO_OFFSET:
264 g_value_set_double(value, dim_style->priv->to_offset);
265 break;
266 case PROP_BASELINE_SPACING:
267 g_value_set_double(value, dim_style->priv->baseline_spacing);
268 break;
269 case PROP_TOLERANCE_SPACING:
270 g_value_set_double(value, dim_style->priv->tolerance_spacing);
271 break;
272 case PROP_QUOTE_SHIFT:
273 g_value_set_boxed(value, &dim_style->priv->quote_shift);
274 break;
275 case PROP_TOLERANCE_SHIFT:
276 g_value_set_boxed(value, &dim_style->priv->tolerance_shift);
277 break;
278 case PROP_NOTE_SHIFT:
279 g_value_set_boxed(value, &dim_style->priv->note_shift);
280 break;
281 case PROP_NUMBER_FORMAT:
282 g_value_set_string(value, dim_style->priv->number_format);
283 break;
284 case PROP_NUMBER_TAG:
285 g_value_set_string(value, dim_style->priv->number_tag);
286 break;
287 default:
288 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
289 break;
293 static void
294 set_property(GObject *object,
295 guint prop_id, const GValue *value, GParamSpec *pspec)
297 AdgDimStyle *dim_style = (AdgDimStyle *) object;
299 switch (prop_id) {
300 case PROP_QUOTE_STYLE:
301 set_quote_style(dim_style, g_value_get_object(value));
302 break;
303 case PROP_TOLERANCE_STYLE:
304 set_tolerance_style(dim_style, g_value_get_object(value));
305 break;
306 case PROP_NOTE_STYLE:
307 set_note_style(dim_style, g_value_get_object(value));
308 break;
309 case PROP_LINE_STYLE:
310 set_line_style(dim_style, g_value_get_object(value));
311 break;
312 case PROP_ARROW_STYLE:
313 set_arrow_style(dim_style, g_value_get_object(value));
314 break;
315 case PROP_FROM_OFFSET:
316 dim_style->priv->from_offset = g_value_get_double(value);
317 break;
318 case PROP_TO_OFFSET:
319 dim_style->priv->to_offset = g_value_get_double(value);
320 break;
321 case PROP_BASELINE_SPACING:
322 dim_style->priv->baseline_spacing = g_value_get_double(value);
323 break;
324 case PROP_TOLERANCE_SPACING:
325 dim_style->priv->tolerance_spacing = g_value_get_double(value);
326 break;
327 case PROP_QUOTE_SHIFT:
328 set_quote_shift(dim_style, g_value_get_boxed(value));
329 break;
330 case PROP_TOLERANCE_SHIFT:
331 set_tolerance_shift(dim_style, g_value_get_boxed(value));
332 break;
333 case PROP_NOTE_SHIFT:
334 set_note_shift(dim_style, g_value_get_boxed(value));
335 break;
336 case PROP_NUMBER_FORMAT:
337 set_number_format(dim_style, g_value_get_string(value));
338 break;
339 case PROP_NUMBER_TAG:
340 set_number_tag(dim_style, g_value_get_string(value));
341 break;
342 default:
343 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
344 break;
350 * adg_dim_style_get_slot:
352 * Gets the slot id for this style class.
354 * Return value: the slot
356 AdgStyleSlot
357 adg_dim_style_get_slot(void)
359 static AdgStyleSlot slot = -1;
361 if (G_UNLIKELY(slot < 0))
362 slot = adg_context_get_slot(ADG_TYPE_DIM_STYLE);
364 return slot;
368 * adg_dim_style_new:
370 * Constructs a new dimension style initialized with default params.
372 * Return value: a new dimension style
374 AdgStyle *
375 adg_dim_style_new(void)
377 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
381 * adg_dim_style_get_quote_style:
382 * @dim_style: an #AdgDimStyle object
384 * Gets the quote style of @dim_style. No reference will be added to the
385 * returned style; it should not be unreferenced.
387 * Return value: the quote style or %NULL on errors
389 AdgStyle *
390 adg_dim_style_get_quote_style(AdgDimStyle *dim_style)
392 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
394 return dim_style->priv->quote_style;
398 * adg_dim_style_set_quote_style:
399 * @dim_style: an #AdgDimStyle object
400 * @style: the new quote style
402 * Sets a new quote style on @dim_style. The old quote style (if any) will be
403 * unreferenced while a new reference will be added to @style.
405 void
406 adg_dim_style_set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
408 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
409 g_return_if_fail(ADG_IS_FONT_STYLE(style));
411 set_quote_style(dim_style, style);
412 g_object_notify((GObject *) dim_style, "quote-style");
416 * adg_dim_style_get_tolerance_style:
417 * @dim_style: an #AdgDimStyle object
419 * Gets the tolerance style of @dim_style. No reference will be added to the
420 * returned style; it should not be unreferenced.
422 * Return value: the tolerance style or %NULL on errors
424 AdgStyle *
425 adg_dim_style_get_tolerance_style(AdgDimStyle *dim_style)
427 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
429 return dim_style->priv->tolerance_style;
433 * adg_dim_style_set_tolerance_style:
434 * @dim_style: an #AdgDimStyle object
435 * @style: the new tolerance style
437 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
438 * will be unreferenced while a new reference will be added to @style.
440 void
441 adg_dim_style_set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
443 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
444 g_return_if_fail(ADG_IS_FONT_STYLE(style));
446 set_tolerance_style(dim_style, style);
447 g_object_notify((GObject *) dim_style, "tolerance-style");
451 * adg_dim_style_get_note_style:
452 * @dim_style: an #AdgDimStyle object
454 * Gets the note style of @dim_style. No reference will be added to the
455 * returned style; it should not be unreferenced.
457 * Return value: the note style or %NULL on errors
459 AdgStyle *
460 adg_dim_style_get_note_style(AdgDimStyle *dim_style)
462 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
464 return dim_style->priv->note_style;
468 * adg_dim_style_set_note_style:
469 * @dim_style: an #AdgDimStyle object
470 * @style: the new note style
472 * Sets a new note style on @dim_style. The old note style (if any) will be
473 * unreferenced while a new reference will be added to @style.
475 void
476 adg_dim_style_set_note_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_note_style(dim_style, style);
482 g_object_notify((GObject *) dim_style, "note-style");
486 * adg_dim_style_get_line_style:
487 * @dim_style: an #AdgDimStyle object
489 * Gets the line style of @dim_style. No reference will be added to the
490 * returned style; it should not be unreferenced.
492 * Return value: the line style or %NULL on errors
494 AdgStyle *
495 adg_dim_style_get_line_style(AdgDimStyle *dim_style)
497 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
499 return dim_style->priv->line_style;
503 * adg_dim_style_set_line_style:
504 * @dim_style: an #AdgDimStyle object
505 * @style: the new line style
507 * Sets a new line style on @dim_style. The old line style (if any) will be
508 * unreferenced while a new reference will be added to @style.
510 void
511 adg_dim_style_set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
513 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
514 g_return_if_fail(ADG_IS_LINE_STYLE(style));
516 set_line_style(dim_style, style);
517 g_object_notify((GObject *) dim_style, "line-style");
521 * adg_dim_style_get_arrow_style:
522 * @dim_style: an #AdgDimStyle object
524 * Gets the arrow style of @dim_style. No reference will be added to the
525 * returned style; it should not be unreferenced.
527 * Return value: the arrow style or %NULL on errors
529 AdgStyle *
530 adg_dim_style_get_arrow_style(AdgDimStyle *dim_style)
532 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
534 return dim_style->priv->arrow_style;
538 * adg_dim_style_set_arrow_style:
539 * @dim_style: an #AdgDimStyle object
540 * @style: the new arrow style
542 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
543 * unreferenced while a new reference will be added to @style.
545 void
546 adg_dim_style_set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
548 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
549 g_return_if_fail(ADG_IS_ARROW_STYLE(style));
551 set_arrow_style(dim_style, style);
552 g_object_notify((GObject *) dim_style, "arrow-style");
556 * adg_dim_style_get_from_offset:
557 * @dim_style: an #AdgDimStyle object
559 * Gets the distance (in paper space) the extension lines must keep from the
560 * sensed points.
562 * Return value: the requested distance
564 gdouble
565 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
567 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
569 return dim_style->priv->from_offset;
573 * adg_dim_style_set_from_offset:
574 * @dim_style: an #AdgDimStyle object
575 * @offset: the new offset
577 * Sets a new "from-offset" value.
579 void
580 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
582 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
584 dim_style->priv->from_offset = offset;
585 g_object_notify((GObject *) dim_style, "from-offset");
589 * adg_dim_style_get_to_offset:
590 * @dim_style: an #AdgDimStyle object
592 * Gets how much (in paper space) the extension lines must extend after
593 * crossing the baseline.
595 * Return value: the requested distance
597 gdouble
598 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
600 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
602 return dim_style->priv->to_offset;
606 * adg_dim_style_set_to_offset:
607 * @dim_style: an #AdgDimStyle object
608 * @offset: the new offset
610 * Sets a new "to-offset" value.
612 void
613 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
615 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
617 dim_style->priv->to_offset = offset;
618 g_object_notify((GObject *) dim_style, "to-offset");
622 * adg_dim_style_get_baseline_spacing:
623 * @dim_style: an #AdgDimStyle object
625 * Gets the distance between two consecutive baselines
626 * while stacking dimensions.
628 * Return value: the requested spacing
630 gdouble
631 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
633 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
635 return dim_style->priv->baseline_spacing;
639 * adg_dim_style_set_baseline_spacing:
640 * @dim_style: an #AdgDimStyle object
641 * @spacing: the new spacing
643 * Sets a new "baseline-spacing" value.
645 void
646 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
648 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
650 dim_style->priv->baseline_spacing = spacing;
651 g_object_notify((GObject *) dim_style, "baseline-spacing");
655 * adg_dim_style_get_tolerance_spacing:
656 * @dim_style: an #AdgDimStyle object
658 * Gets the distance (in paper space) between up and down tolerances.
660 * Return value: the requested spacing
662 gdouble
663 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
665 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
667 return dim_style->priv->tolerance_spacing;
671 * adg_dim_style_set_tolerance_spacing:
672 * @dim_style: an #AdgDimStyle object
673 * @spacing: the new spacing
675 * Sets a new "tolerance-spacing" value.
677 void
678 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
680 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
682 dim_style->priv->tolerance_spacing = spacing;
683 g_object_notify((GObject *) dim_style, "tolerance-spacing");
687 * adg_dim_style_get_quote_shift:
688 * @dim_style: an #AdgDimStyle object
690 * Gets the smooth displacement of the quote text. The returned pointer
691 * refers to an internal allocated struct and must not be modified or freed.
693 * Return value: the requested shift
695 const AdgPair *
696 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
698 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
700 return &dim_style->priv->quote_shift;
704 * adg_dim_style_set_quote_shift:
705 * @dim_style: an #AdgDimStyle object
706 * @shift: the new displacement
708 * Sets a new "quote-shift" value.
710 void
711 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
713 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
715 set_quote_shift(dim_style, shift);
716 g_object_notify((GObject *) dim_style, "quote-shift");
720 * adg_dim_style_get_tolerance_shift:
721 * @dim_style: an #AdgDimStyle object
723 * Gets the smooth displacement of the tolerance text. The returned pointer
724 * refers to an internal allocated struct and must not be modified or freed.
726 * Return value: the requested shift
728 const AdgPair *
729 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
731 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
733 return &dim_style->priv->tolerance_shift;
737 * adg_dim_style_set_tolerance_shift:
738 * @dim_style: an #AdgDimStyle object
739 * @shift: the new displacement
741 * Sets a new "tolerance-shift" value.
743 void
744 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
746 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
748 set_tolerance_shift(dim_style, shift);
749 g_object_notify((GObject *) dim_style, "tolerance-shift");
753 * adg_dim_style_get_note_shift:
754 * @dim_style: an #AdgDimStyle object
756 * Gets the smooth displacement of the note text. The returned pointer
757 * refers to an internal allocated struct and must not be modified or freed.
759 * Return value: the requested shift
761 const AdgPair *
762 adg_dim_style_get_note_shift(AdgDimStyle *dim_style)
764 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
766 return &dim_style->priv->note_shift;
770 * adg_dim_style_set_note_shift:
771 * @dim_style: an #AdgDimStyle object
772 * @shift: the new displacement
774 * Sets a new "note-shift" value.
776 void
777 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
779 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
781 set_note_shift(dim_style, shift);
782 g_object_notify((GObject *) dim_style, "note-shift");
786 * adg_dim_style_get_number_format:
787 * @dim_style: an #AdgDimStyle object
789 * Gets the number format (in printf style) of this quoting style. The
790 * returned pointer refers to internally managed text that must not be
791 * modified or freed.
793 * Return value: the requested format
795 const gchar *
796 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
798 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
800 return dim_style->priv->number_format;
804 * adg_dim_style_set_number_format:
805 * @dim_style: an #AdgDimStyle object
806 * @format: the new format to adopt
808 * Sets a new "number-format" value.
810 void
811 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
813 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
815 set_number_format(dim_style, format);
816 g_object_notify((GObject *) dim_style, "number-format");
820 * adg_dim_style_get_number_tag:
821 * @dim_style: an #AdgDimStyle object
823 * Gets the number tag to substitute while building the quote text. The
824 * returned pointer refers to internally managed text that must not be
825 * modified or freed.
827 * Return value: the requested tag
829 const gchar *
830 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
832 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
834 return dim_style->priv->number_tag;
838 * adg_dim_style_set_number_tag:
839 * @dim_style: an #AdgDimStyle object
840 * @tag: the new tag
842 * Sets a new "number-tag" value.
844 void
845 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
847 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
849 set_number_tag(dim_style, tag);
850 g_object_notify((GObject *) dim_style, "number-tag");
854 static GPtrArray *
855 get_pool(void)
857 static GPtrArray *pool = NULL;
859 if (G_UNLIKELY(pool == NULL)) {
860 cairo_pattern_t *pattern;
862 pool = g_ptr_array_sized_new(ADG_DIM_STYLE_LAST);
864 /* No need to specify further params: the default is already ISO */
865 pattern = cairo_pattern_create_rgb(1., 0., 0.);
866 pool->pdata[ADG_DIM_STYLE_ISO] = g_object_new(ADG_TYPE_DIM_STYLE,
867 "pattern", pattern,
868 NULL);
869 cairo_pattern_destroy(pattern);
871 pool->len = ADG_DIM_STYLE_LAST;
874 return pool;
877 static void
878 set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
880 if (dim_style->priv->quote_style)
881 g_object_unref(dim_style->priv->quote_style);
883 g_object_ref(style);
884 dim_style->priv->quote_style = (AdgStyle *) style;
887 static void
888 set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
890 if (dim_style->priv->tolerance_style)
891 g_object_unref(dim_style->priv->tolerance_style);
893 g_object_ref(style);
894 dim_style->priv->tolerance_style = (AdgStyle *) style;
897 static void
898 set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
900 if (dim_style->priv->note_style)
901 g_object_unref(dim_style->priv->note_style);
903 g_object_ref(style);
904 dim_style->priv->note_style = (AdgStyle *) style;
907 static void
908 set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
910 if (dim_style->priv->line_style)
911 g_object_unref(dim_style->priv->line_style);
913 g_object_ref(style);
914 dim_style->priv->line_style = (AdgStyle *) style;
917 static void
918 set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
920 if (dim_style->priv->arrow_style)
921 g_object_unref(dim_style->priv->arrow_style);
923 g_object_ref(style);
924 dim_style->priv->arrow_style = (AdgStyle *) style;
927 static void
928 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
930 cpml_pair_copy(&dim_style->priv->quote_shift, shift);
933 static void
934 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
936 cpml_pair_copy(&dim_style->priv->tolerance_shift, shift);
939 static void
940 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
942 cpml_pair_copy(&dim_style->priv->note_shift, shift);
945 static void
946 set_number_format(AdgDimStyle *dim_style, const gchar *format)
948 g_free(dim_style->priv->number_format);
949 dim_style->priv->number_format = g_strdup(format);
952 static void
953 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
955 g_free(dim_style->priv->number_tag);
956 dim_style->priv->number_tag = g_strdup(tag);