[AdgADim] Added "angle1" and "angle2" properties
[adg.git] / adg / adg-dim-style.c
blob75d0f092b7f267de32412f87edcdc209c0595a9f
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 quote, 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_QUOTE_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_quote_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("quote-style",
128 P_("Quote Style"),
129 P_("Font style for the quote"),
130 ADG_TYPE_STYLE, G_PARAM_READWRITE);
131 g_object_class_install_property(gobject_class, PROP_QUOTE_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 quote)"),
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 paper space) of the extension lines from the path to 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 paper 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 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)"),
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 paper units) 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 paper units) 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 quote"),
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 quote 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->quote_style = adg_style_from_id(ADG_TYPE_FONT_STYLE,
229 ADG_FONT_STYLE_QUOTE);
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 = 5.;
239 data->to_offset = 5.;
240 data->baseline_spacing = 30.;
241 data->tolerance_spacing = 2.;
242 data->quote_shift.x = 0.;
243 data->quote_shift.y = -3.;
244 data->tolerance_shift.x = +5.;
245 data->tolerance_shift.y = -4.;
246 data->note_shift.x = +5.;
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_QUOTE_STYLE:
261 g_value_set_object(value, data->quote_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_QUOTE_STYLE:
320 set_quote_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_quote_style:
394 * @dim_style: an #AdgDimStyle object
396 * Gets the quote style of @dim_style. No reference will be added to the
397 * returned style; it should not be unreferenced.
399 * Return value: the quote style or %NULL on errors
401 AdgStyle *
402 adg_dim_style_get_quote_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->quote_style;
414 * adg_dim_style_set_quote_style:
415 * @dim_style: an #AdgDimStyle object
416 * @style: the new quote style
418 * Sets a new quote style on @dim_style. The old quote style (if any) will be
419 * unreferenced while a new reference will be added to @style.
421 void
422 adg_dim_style_set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
424 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
425 g_return_if_fail(ADG_IS_FONT_STYLE(style));
427 set_quote_style(dim_style, style);
428 g_object_notify((GObject *) dim_style, "quote-style");
432 * adg_dim_style_get_tolerance_style:
433 * @dim_style: an #AdgDimStyle object
435 * Gets the tolerance style of @dim_style. No reference will be added to the
436 * returned style; it should not be unreferenced.
438 * Return value: the tolerance style or %NULL on errors
440 AdgStyle *
441 adg_dim_style_get_tolerance_style(AdgDimStyle *dim_style)
443 AdgDimStylePrivate *data;
445 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
447 data = dim_style->data;
449 return data->tolerance_style;
453 * adg_dim_style_set_tolerance_style:
454 * @dim_style: an #AdgDimStyle object
455 * @style: the new tolerance style
457 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
458 * will be unreferenced while a new reference will be added to @style.
460 void
461 adg_dim_style_set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
463 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
464 g_return_if_fail(ADG_IS_FONT_STYLE(style));
466 set_tolerance_style(dim_style, style);
467 g_object_notify((GObject *) dim_style, "tolerance-style");
471 * adg_dim_style_get_note_style:
472 * @dim_style: an #AdgDimStyle object
474 * Gets the note style of @dim_style. No reference will be added to the
475 * returned style; it should not be unreferenced.
477 * Return value: the note style or %NULL on errors
479 AdgStyle *
480 adg_dim_style_get_note_style(AdgDimStyle *dim_style)
482 AdgDimStylePrivate *data;
484 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
486 data = dim_style->data;
488 return data->note_style;
492 * adg_dim_style_set_note_style:
493 * @dim_style: an #AdgDimStyle object
494 * @style: the new note style
496 * Sets a new note style on @dim_style. The old note style (if any) will be
497 * unreferenced while a new reference will be added to @style.
499 void
500 adg_dim_style_set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
502 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
503 g_return_if_fail(ADG_IS_FONT_STYLE(style));
505 set_note_style(dim_style, style);
506 g_object_notify((GObject *) dim_style, "note-style");
510 * adg_dim_style_get_line_style:
511 * @dim_style: an #AdgDimStyle object
513 * Gets the line style of @dim_style. No reference will be added to the
514 * returned style; it should not be unreferenced.
516 * Return value: the line style or %NULL on errors
518 AdgStyle *
519 adg_dim_style_get_line_style(AdgDimStyle *dim_style)
521 AdgDimStylePrivate *data;
523 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
525 data = dim_style->data;
527 return data->line_style;
531 * adg_dim_style_set_line_style:
532 * @dim_style: an #AdgDimStyle object
533 * @style: the new line style
535 * Sets a new line style on @dim_style. The old line style (if any) will be
536 * unreferenced while a new reference will be added to @style.
538 void
539 adg_dim_style_set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
541 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
542 g_return_if_fail(ADG_IS_LINE_STYLE(style));
544 set_line_style(dim_style, style);
545 g_object_notify((GObject *) dim_style, "line-style");
549 * adg_dim_style_get_arrow_style:
550 * @dim_style: an #AdgDimStyle object
552 * Gets the arrow style of @dim_style. No reference will be added to the
553 * returned style; it should not be unreferenced.
555 * Return value: the arrow style or %NULL on errors
557 AdgStyle *
558 adg_dim_style_get_arrow_style(AdgDimStyle *dim_style)
560 AdgDimStylePrivate *data;
562 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
564 data = dim_style->data;
566 return data->arrow_style;
570 * adg_dim_style_set_arrow_style:
571 * @dim_style: an #AdgDimStyle object
572 * @style: the new arrow style
574 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
575 * unreferenced while a new reference will be added to @style.
577 void
578 adg_dim_style_set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
580 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
581 g_return_if_fail(ADG_IS_ARROW_STYLE(style));
583 set_arrow_style(dim_style, style);
584 g_object_notify((GObject *) dim_style, "arrow-style");
588 * adg_dim_style_get_from_offset:
589 * @dim_style: an #AdgDimStyle object
591 * Gets the distance (in paper space) the extension lines must keep from the
592 * sensed points.
594 * Return value: the requested distance
596 gdouble
597 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
599 AdgDimStylePrivate *data;
601 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
603 data = dim_style->data;
605 return data->from_offset;
609 * adg_dim_style_set_from_offset:
610 * @dim_style: an #AdgDimStyle object
611 * @offset: the new offset
613 * Sets a new "from-offset" value.
615 void
616 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
618 AdgDimStylePrivate *data;
620 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
622 data = dim_style->data;
623 data->from_offset = offset;
625 g_object_notify((GObject *) dim_style, "from-offset");
629 * adg_dim_style_get_to_offset:
630 * @dim_style: an #AdgDimStyle object
632 * Gets how much (in paper space) the extension lines must extend after
633 * crossing the baseline.
635 * Return value: the requested distance
637 gdouble
638 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
640 AdgDimStylePrivate *data;
642 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
644 data = dim_style->data;
646 return data->to_offset;
650 * adg_dim_style_set_to_offset:
651 * @dim_style: an #AdgDimStyle object
652 * @offset: the new offset
654 * Sets a new "to-offset" value.
656 void
657 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
659 AdgDimStylePrivate *data;
661 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
663 data = dim_style->data;
664 data->to_offset = offset;
666 g_object_notify((GObject *) dim_style, "to-offset");
670 * adg_dim_style_get_baseline_spacing:
671 * @dim_style: an #AdgDimStyle object
673 * Gets the distance between two consecutive baselines
674 * while stacking dimensions.
676 * Return value: the requested spacing
678 gdouble
679 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
681 AdgDimStylePrivate *data;
683 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
685 data = dim_style->data;
687 return data->baseline_spacing;
691 * adg_dim_style_set_baseline_spacing:
692 * @dim_style: an #AdgDimStyle object
693 * @spacing: the new spacing
695 * Sets a new "baseline-spacing" value.
697 void
698 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
700 AdgDimStylePrivate *data;
702 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
704 data = dim_style->data;
705 data->baseline_spacing = spacing;
707 g_object_notify((GObject *) dim_style, "baseline-spacing");
711 * adg_dim_style_get_tolerance_spacing:
712 * @dim_style: an #AdgDimStyle object
714 * Gets the distance (in paper space) between up and down tolerances.
716 * Return value: the requested spacing
718 gdouble
719 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
721 AdgDimStylePrivate *data;
723 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0.);
725 data = dim_style->data;
727 return data->tolerance_spacing;
731 * adg_dim_style_set_tolerance_spacing:
732 * @dim_style: an #AdgDimStyle object
733 * @spacing: the new spacing
735 * Sets a new "tolerance-spacing" value.
737 void
738 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
740 AdgDimStylePrivate *data;
742 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
744 data = dim_style->data;
745 data->tolerance_spacing = spacing;
747 g_object_notify((GObject *) dim_style, "tolerance-spacing");
751 * adg_dim_style_get_quote_shift:
752 * @dim_style: an #AdgDimStyle object
754 * Gets the smooth displacement of the quote text. The returned pointer
755 * refers to an internal allocated struct and must not be modified or freed.
757 * Return value: the requested shift
759 const AdgPair *
760 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
762 AdgDimStylePrivate *data;
764 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
766 data = dim_style->data;
768 return &data->quote_shift;
772 * adg_dim_style_set_quote_shift:
773 * @dim_style: an #AdgDimStyle object
774 * @shift: the new displacement
776 * Sets a new "quote-shift" value.
778 void
779 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
781 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
783 set_quote_shift(dim_style, shift);
784 g_object_notify((GObject *) dim_style, "quote-shift");
788 * adg_dim_style_get_tolerance_shift:
789 * @dim_style: an #AdgDimStyle object
791 * Gets the smooth displacement of the tolerance text. The returned pointer
792 * refers to an internal allocated struct and must not be modified or freed.
794 * Return value: the requested shift
796 const AdgPair *
797 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
799 AdgDimStylePrivate *data;
801 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
803 data = dim_style->data;
805 return &data->tolerance_shift;
809 * adg_dim_style_set_tolerance_shift:
810 * @dim_style: an #AdgDimStyle object
811 * @shift: the new displacement
813 * Sets a new "tolerance-shift" value.
815 void
816 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
818 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
820 set_tolerance_shift(dim_style, shift);
821 g_object_notify((GObject *) dim_style, "tolerance-shift");
825 * adg_dim_style_get_note_shift:
826 * @dim_style: an #AdgDimStyle object
828 * Gets the smooth displacement of the note text. The returned pointer
829 * refers to an internal allocated struct and must not be modified or freed.
831 * Return value: the requested shift
833 const AdgPair *
834 adg_dim_style_get_note_shift(AdgDimStyle *dim_style)
836 AdgDimStylePrivate *data;
838 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
840 data = dim_style->data;
842 return &data->note_shift;
846 * adg_dim_style_set_note_shift:
847 * @dim_style: an #AdgDimStyle object
848 * @shift: the new displacement
850 * Sets a new "note-shift" value.
852 void
853 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
855 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
857 set_note_shift(dim_style, shift);
858 g_object_notify((GObject *) dim_style, "note-shift");
862 * adg_dim_style_get_number_format:
863 * @dim_style: an #AdgDimStyle object
865 * Gets the number format (in printf style) of this quoting style. The
866 * returned pointer refers to internally managed text that must not be
867 * modified or freed.
869 * Return value: the requested format
871 const gchar *
872 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
874 AdgDimStylePrivate *data;
876 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
878 data = dim_style->data;
880 return data->number_format;
884 * adg_dim_style_set_number_format:
885 * @dim_style: an #AdgDimStyle object
886 * @format: the new format to adopt
888 * Sets a new "number-format" value.
890 void
891 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
893 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
895 set_number_format(dim_style, format);
896 g_object_notify((GObject *) dim_style, "number-format");
900 * adg_dim_style_get_number_tag:
901 * @dim_style: an #AdgDimStyle object
903 * Gets the number tag to substitute while building the quote text. The
904 * returned pointer refers to internally managed text that must not be
905 * modified or freed.
907 * Return value: the requested tag
909 const gchar *
910 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
912 AdgDimStylePrivate *data;
914 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
916 data = dim_style->data;
918 return data->number_tag;
922 * adg_dim_style_set_number_tag:
923 * @dim_style: an #AdgDimStyle object
924 * @tag: the new tag
926 * Sets a new "number-tag" value.
928 void
929 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
931 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
933 set_number_tag(dim_style, tag);
934 g_object_notify((GObject *) dim_style, "number-tag");
938 static GPtrArray *
939 get_pool(void)
941 static GPtrArray *pool = NULL;
943 if (G_UNLIKELY(pool == NULL)) {
944 cairo_pattern_t *pattern;
946 pool = g_ptr_array_sized_new(ADG_DIM_STYLE_LAST);
948 /* No need to specify further params: the default is already ISO */
949 pattern = cairo_pattern_create_rgb(1., 0., 0.);
950 pool->pdata[ADG_DIM_STYLE_ISO] = g_object_new(ADG_TYPE_DIM_STYLE,
951 "pattern", pattern,
952 NULL);
953 cairo_pattern_destroy(pattern);
955 pool->len = ADG_DIM_STYLE_LAST;
958 return pool;
961 static void
962 set_quote_style(AdgDimStyle *dim_style, AdgFontStyle *style)
964 AdgDimStylePrivate *data = dim_style->data;
966 if (data->quote_style)
967 g_object_unref(data->quote_style);
969 g_object_ref(style);
970 data->quote_style = (AdgStyle *) style;
973 static void
974 set_tolerance_style(AdgDimStyle *dim_style, AdgFontStyle *style)
976 AdgDimStylePrivate *data = dim_style->data;
978 if (data->tolerance_style)
979 g_object_unref(data->tolerance_style);
981 g_object_ref(style);
982 data->tolerance_style = (AdgStyle *) style;
985 static void
986 set_note_style(AdgDimStyle *dim_style, AdgFontStyle *style)
988 AdgDimStylePrivate *data = dim_style->data;
990 if (data->note_style)
991 g_object_unref(data->note_style);
993 g_object_ref(style);
994 data->note_style = (AdgStyle *) style;
997 static void
998 set_line_style(AdgDimStyle *dim_style, AdgLineStyle *style)
1000 AdgDimStylePrivate *data = dim_style->data;
1002 if (data->line_style)
1003 g_object_unref(data->line_style);
1005 g_object_ref(style);
1006 data->line_style = (AdgStyle *) style;
1009 static void
1010 set_arrow_style(AdgDimStyle *dim_style, AdgArrowStyle *style)
1012 AdgDimStylePrivate *data = dim_style->data;
1014 if (data->arrow_style)
1015 g_object_unref(data->arrow_style);
1017 g_object_ref(style);
1018 data->arrow_style = (AdgStyle *) style;
1021 static void
1022 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1024 AdgDimStylePrivate *data = dim_style->data;
1026 cpml_pair_copy(&data->quote_shift, shift);
1029 static void
1030 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1032 AdgDimStylePrivate *data = dim_style->data;
1034 cpml_pair_copy(&data->tolerance_shift, shift);
1037 static void
1038 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1040 AdgDimStylePrivate *data = dim_style->data;
1042 cpml_pair_copy(&data->note_shift, shift);
1045 static void
1046 set_number_format(AdgDimStyle *dim_style, const gchar *format)
1048 AdgDimStylePrivate *data = dim_style->data;
1050 g_free(data->number_format);
1051 data->number_format = g_strdup(format);
1054 static void
1055 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
1057 AdgDimStylePrivate *data = dim_style->data;
1059 g_free(data->number_tag);
1060 data->number_tag = g_strdup(tag);