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.
22 * SECTION:adg-dim-style
23 * @short_description: Dimension style related stuff
25 * Contains parameters on how to build dimensions such as the different font
26 * styles (for value, tolerance and note), line style, offsets of the various
27 * dimension components etc...
33 * All fields are private and should not be used directly.
34 * Use its public methods instead.
41 * Gets the slot id for this style class.
43 * Return value: the requested slot id
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"
66 PROP_BASELINE_SPACING
,
67 PROP_TOLERANCE_SPACING
,
76 static void get_property (GObject
*object
,
80 static void set_property (GObject
*object
,
84 static GPtrArray
* get_pool (void);
85 static void set_value_style (AdgDimStyle
*dim_style
,
87 static void set_tolerance_style (AdgDimStyle
*dim_style
,
89 static void set_note_style (AdgDimStyle
*dim_style
,
91 static void set_line_style (AdgDimStyle
*dim_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
,
107 G_DEFINE_TYPE(AdgDimStyle
, adg_dim_style
, ADG_TYPE_STYLE
)
111 adg_dim_style_class_init(AdgDimStyleClass
*klass
)
113 GObjectClass
*gobject_class
;
114 AdgStyleClass
*style_class
;
117 gobject_class
= (GObjectClass
*) klass
;
118 style_class
= (AdgStyleClass
*) klass
;
120 g_type_class_add_private(klass
, sizeof(AdgDimStylePrivate
));
122 gobject_class
->get_property
= get_property
;
123 gobject_class
->set_property
= set_property
;
125 style_class
->get_pool
= get_pool
;
127 param
= g_param_spec_object("value-style",
129 P_("Font style for the basic value of the dimension"),
130 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
131 g_object_class_install_property(gobject_class
, PROP_VALUE_STYLE
,
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
,
141 param
= g_param_spec_object("note-style",
143 P_("Font style for the note (the text after or under the basic value)"),
144 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
145 g_object_class_install_property(gobject_class
, PROP_NOTE_STYLE
, param
);
147 param
= g_param_spec_object("line-style",
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",
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
,
160 param
= g_param_spec_double("from-offset",
162 P_("Offset (in global space) of the extension lines from the path to the quote"),
163 0., G_MAXDOUBLE
, 5., G_PARAM_READWRITE
);
164 g_object_class_install_property(gobject_class
, PROP_FROM_OFFSET
,
167 param
= g_param_spec_double("to-offset",
169 P_("How many extend (in global space) the extension lines after hitting the baseline"),
170 0., G_MAXDOUBLE
, 5., G_PARAM_READWRITE
);
171 g_object_class_install_property(gobject_class
, PROP_TO_OFFSET
, param
);
173 param
= g_param_spec_double("baseline-spacing",
174 P_("Baseline Spacing"),
175 P_("Distance between two consecutive baselines while stacking dimensions"),
176 0., G_MAXDOUBLE
, 30., G_PARAM_READWRITE
);
177 g_object_class_install_property(gobject_class
, PROP_BASELINE_SPACING
,
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
,
187 param
= g_param_spec_boxed("quote-shift",
189 P_("Used to specify a smooth displacement (in global space) of the quote by taking as reference the perfect compact position (the middle of the baseline on common linear dimension, for instance)"),
190 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
191 g_object_class_install_property(gobject_class
, PROP_QUOTE_SHIFT
,
194 param
= g_param_spec_boxed("tolerance-shift",
195 P_("Tolerance Shift"),
196 P_("Used to specify a smooth displacement (in global space) for the tolerance text by taking as reference the perfect compact position"),
197 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
198 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_SHIFT
,
201 param
= g_param_spec_boxed("note-shift",
203 P_("Used to specify a smooth displacement (in global space) for the note text by taking as reference the perfect compact position"),
204 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
205 g_object_class_install_property(gobject_class
, PROP_NOTE_SHIFT
, param
);
207 param
= g_param_spec_string("number-format",
209 P_("The format (in printf style) of the numeric component of the basic value"),
210 "%-.7g", G_PARAM_READWRITE
);
211 g_object_class_install_property(gobject_class
, PROP_NUMBER_FORMAT
,
214 param
= g_param_spec_string("number-tag",
216 P_("The tag to substitute inside the basic value pattern"),
217 "<>", G_PARAM_READWRITE
);
218 g_object_class_install_property(gobject_class
, PROP_NUMBER_TAG
, param
);
222 adg_dim_style_init(AdgDimStyle
*dim_style
)
224 AdgDimStylePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim_style
,
228 data
->value_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
229 ADG_FONT_STYLE_VALUE
);
230 data
->tolerance_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
231 ADG_FONT_STYLE_TOLERANCE
);
232 data
->note_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
233 ADG_FONT_STYLE_NOTE
);
234 data
->line_style
= adg_style_from_id(ADG_TYPE_LINE_STYLE
,
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
;
255 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
257 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) object
)->data
;
260 case PROP_VALUE_STYLE
:
261 g_value_set_object(value
, data
->value_style
);
263 case PROP_TOLERANCE_STYLE
:
264 g_value_set_object(value
, data
->tolerance_style
);
266 case PROP_NOTE_STYLE
:
267 g_value_set_object(value
, data
->note_style
);
269 case PROP_LINE_STYLE
:
270 g_value_set_object(value
, data
->line_style
);
272 case PROP_ARROW_STYLE
:
273 g_value_set_object(value
, data
->arrow_style
);
275 case PROP_FROM_OFFSET
:
276 g_value_set_double(value
, data
->from_offset
);
279 g_value_set_double(value
, data
->to_offset
);
281 case PROP_BASELINE_SPACING
:
282 g_value_set_double(value
, data
->baseline_spacing
);
284 case PROP_TOLERANCE_SPACING
:
285 g_value_set_double(value
, data
->tolerance_spacing
);
287 case PROP_QUOTE_SHIFT
:
288 g_value_set_boxed(value
, &data
->quote_shift
);
290 case PROP_TOLERANCE_SHIFT
:
291 g_value_set_boxed(value
, &data
->tolerance_shift
);
293 case PROP_NOTE_SHIFT
:
294 g_value_set_boxed(value
, &data
->note_shift
);
296 case PROP_NUMBER_FORMAT
:
297 g_value_set_string(value
, data
->number_format
);
299 case PROP_NUMBER_TAG
:
300 g_value_set_string(value
, data
->number_tag
);
303 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
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
;
319 case PROP_VALUE_STYLE
:
320 set_value_style(dim_style
, g_value_get_object(value
));
322 case PROP_TOLERANCE_STYLE
:
323 set_tolerance_style(dim_style
, g_value_get_object(value
));
325 case PROP_NOTE_STYLE
:
326 set_note_style(dim_style
, g_value_get_object(value
));
328 case PROP_LINE_STYLE
:
329 set_line_style(dim_style
, g_value_get_object(value
));
331 case PROP_ARROW_STYLE
:
332 set_arrow_style(dim_style
, g_value_get_object(value
));
334 case PROP_FROM_OFFSET
:
335 data
->from_offset
= g_value_get_double(value
);
338 data
->to_offset
= g_value_get_double(value
);
340 case PROP_BASELINE_SPACING
:
341 data
->baseline_spacing
= g_value_get_double(value
);
343 case PROP_TOLERANCE_SPACING
:
344 data
->tolerance_spacing
= g_value_get_double(value
);
346 case PROP_QUOTE_SHIFT
:
347 set_quote_shift(dim_style
, g_value_get_boxed(value
));
349 case PROP_TOLERANCE_SHIFT
:
350 set_tolerance_shift(dim_style
, g_value_get_boxed(value
));
352 case PROP_NOTE_SHIFT
:
353 set_note_shift(dim_style
, g_value_get_boxed(value
));
355 case PROP_NUMBER_FORMAT
:
356 set_number_format(dim_style
, g_value_get_string(value
));
358 case PROP_NUMBER_TAG
:
359 set_number_tag(dim_style
, g_value_get_string(value
));
362 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
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
);
382 * Constructs a new dimension style initialized with default params.
384 * Return value: a new dimension style
387 adg_dim_style_new(void)
389 return g_object_new(ADG_TYPE_DIM_STYLE
, NULL
);
393 * adg_dim_style_get_value_style:
394 * @dim_style: an #AdgDimStyle object
396 * Gets the basic value font style of @dim_style. No reference will
397 * be added to the returned style; it should not be unreferenced.
399 * Return value: the basic value style or %NULL on errors
402 adg_dim_style_get_value_style(AdgDimStyle
*dim_style
)
404 AdgDimStylePrivate
*data
;
406 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
408 data
= dim_style
->data
;
410 return data
->value_style
;
414 * adg_dim_style_set_value_style:
415 * @dim_style: an #AdgDimStyle object
416 * @style: the new basic value font style
418 * Sets a new font style on @dim_style for basic values. The old
419 * font style (if any) will be unreferenced while a new reference
420 * will be added to @style.
423 adg_dim_style_set_value_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
425 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
426 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
428 set_value_style(dim_style
, style
);
429 g_object_notify((GObject
*) dim_style
, "value-style");
433 * adg_dim_style_get_tolerance_style:
434 * @dim_style: an #AdgDimStyle object
436 * Gets the tolerance style of @dim_style. No reference will be added to the
437 * returned style; it should not be unreferenced.
439 * Return value: the tolerance style or %NULL on errors
442 adg_dim_style_get_tolerance_style(AdgDimStyle
*dim_style
)
444 AdgDimStylePrivate
*data
;
446 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
448 data
= dim_style
->data
;
450 return data
->tolerance_style
;
454 * adg_dim_style_set_tolerance_style:
455 * @dim_style: an #AdgDimStyle object
456 * @style: the new tolerance style
458 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
459 * will be unreferenced while a new reference will be added to @style.
462 adg_dim_style_set_tolerance_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
464 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
465 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
467 set_tolerance_style(dim_style
, style
);
468 g_object_notify((GObject
*) dim_style
, "tolerance-style");
472 * adg_dim_style_get_note_style:
473 * @dim_style: an #AdgDimStyle object
475 * Gets the note style of @dim_style. No reference will be added to the
476 * returned style; it should not be unreferenced.
478 * Return value: the note style or %NULL on errors
481 adg_dim_style_get_note_style(AdgDimStyle
*dim_style
)
483 AdgDimStylePrivate
*data
;
485 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
487 data
= dim_style
->data
;
489 return data
->note_style
;
493 * adg_dim_style_set_note_style:
494 * @dim_style: an #AdgDimStyle object
495 * @style: the new note style
497 * Sets a new note style on @dim_style. The old note style (if any) will be
498 * unreferenced while a new reference will be added to @style.
501 adg_dim_style_set_note_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
503 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
504 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
506 set_note_style(dim_style
, style
);
507 g_object_notify((GObject
*) dim_style
, "note-style");
511 * adg_dim_style_get_line_style:
512 * @dim_style: an #AdgDimStyle object
514 * Gets the line style of @dim_style. No reference will be added to the
515 * returned style; it should not be unreferenced.
517 * Return value: the line style or %NULL on errors
520 adg_dim_style_get_line_style(AdgDimStyle
*dim_style
)
522 AdgDimStylePrivate
*data
;
524 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
526 data
= dim_style
->data
;
528 return data
->line_style
;
532 * adg_dim_style_set_line_style:
533 * @dim_style: an #AdgDimStyle object
534 * @style: the new line style
536 * Sets a new line style on @dim_style. The old line style (if any) will be
537 * unreferenced while a new reference will be added to @style.
540 adg_dim_style_set_line_style(AdgDimStyle
*dim_style
, AdgLineStyle
*style
)
542 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
543 g_return_if_fail(ADG_IS_LINE_STYLE(style
));
545 set_line_style(dim_style
, style
);
546 g_object_notify((GObject
*) dim_style
, "line-style");
550 * adg_dim_style_get_arrow_style:
551 * @dim_style: an #AdgDimStyle object
553 * Gets the arrow style of @dim_style. No reference will be added to the
554 * returned style; it should not be unreferenced.
556 * Return value: the arrow style or %NULL on errors
559 adg_dim_style_get_arrow_style(AdgDimStyle
*dim_style
)
561 AdgDimStylePrivate
*data
;
563 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
565 data
= dim_style
->data
;
567 return data
->arrow_style
;
571 * adg_dim_style_set_arrow_style:
572 * @dim_style: an #AdgDimStyle object
573 * @style: the new arrow style
575 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
576 * unreferenced while a new reference will be added to @style.
579 adg_dim_style_set_arrow_style(AdgDimStyle
*dim_style
, AdgArrowStyle
*style
)
581 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
582 g_return_if_fail(ADG_IS_ARROW_STYLE(style
));
584 set_arrow_style(dim_style
, style
);
585 g_object_notify((GObject
*) dim_style
, "arrow-style");
589 * adg_dim_style_get_from_offset:
590 * @dim_style: an #AdgDimStyle object
592 * Gets the distance (in global space) the extension lines must keep from the
595 * Return value: the requested distance
598 adg_dim_style_get_from_offset(AdgDimStyle
*dim_style
)
600 AdgDimStylePrivate
*data
;
602 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
604 data
= dim_style
->data
;
606 return data
->from_offset
;
610 * adg_dim_style_set_from_offset:
611 * @dim_style: an #AdgDimStyle object
612 * @offset: the new offset
614 * Sets a new "from-offset" value.
617 adg_dim_style_set_from_offset(AdgDimStyle
*dim_style
, gdouble offset
)
619 AdgDimStylePrivate
*data
;
621 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
623 data
= dim_style
->data
;
624 data
->from_offset
= offset
;
626 g_object_notify((GObject
*) dim_style
, "from-offset");
630 * adg_dim_style_get_to_offset:
631 * @dim_style: an #AdgDimStyle object
633 * Gets how much (in global space) the extension lines must extend after
634 * crossing the baseline.
636 * Return value: the requested distance
639 adg_dim_style_get_to_offset(AdgDimStyle
*dim_style
)
641 AdgDimStylePrivate
*data
;
643 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
645 data
= dim_style
->data
;
647 return data
->to_offset
;
651 * adg_dim_style_set_to_offset:
652 * @dim_style: an #AdgDimStyle object
653 * @offset: the new offset
655 * Sets a new "to-offset" value.
658 adg_dim_style_set_to_offset(AdgDimStyle
*dim_style
, gdouble offset
)
660 AdgDimStylePrivate
*data
;
662 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
664 data
= dim_style
->data
;
665 data
->to_offset
= offset
;
667 g_object_notify((GObject
*) dim_style
, "to-offset");
671 * adg_dim_style_get_baseline_spacing:
672 * @dim_style: an #AdgDimStyle object
674 * Gets the distance between two consecutive baselines
675 * while stacking dimensions.
677 * Return value: the requested spacing
680 adg_dim_style_get_baseline_spacing(AdgDimStyle
*dim_style
)
682 AdgDimStylePrivate
*data
;
684 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
686 data
= dim_style
->data
;
688 return data
->baseline_spacing
;
692 * adg_dim_style_set_baseline_spacing:
693 * @dim_style: an #AdgDimStyle object
694 * @spacing: the new spacing
696 * Sets a new "baseline-spacing" value.
699 adg_dim_style_set_baseline_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
701 AdgDimStylePrivate
*data
;
703 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
705 data
= dim_style
->data
;
706 data
->baseline_spacing
= spacing
;
708 g_object_notify((GObject
*) dim_style
, "baseline-spacing");
712 * adg_dim_style_get_tolerance_spacing:
713 * @dim_style: an #AdgDimStyle object
715 * Gets the distance (in global space) between up and down tolerances.
717 * Return value: the requested spacing
720 adg_dim_style_get_tolerance_spacing(AdgDimStyle
*dim_style
)
722 AdgDimStylePrivate
*data
;
724 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
726 data
= dim_style
->data
;
728 return data
->tolerance_spacing
;
732 * adg_dim_style_set_tolerance_spacing:
733 * @dim_style: an #AdgDimStyle object
734 * @spacing: the new spacing
736 * Sets a new "tolerance-spacing" value.
739 adg_dim_style_set_tolerance_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
741 AdgDimStylePrivate
*data
;
743 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
745 data
= dim_style
->data
;
746 data
->tolerance_spacing
= spacing
;
748 g_object_notify((GObject
*) dim_style
, "tolerance-spacing");
752 * adg_dim_style_get_quote_shift:
753 * @dim_style: an #AdgDimStyle object
755 * Gets the smooth displacement of the quote. The returned pointer refers
756 * to an internal allocated struct and must not be modified or freed.
758 * Return value: the requested shift
761 adg_dim_style_get_quote_shift(AdgDimStyle
*dim_style
)
763 AdgDimStylePrivate
*data
;
765 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
767 data
= dim_style
->data
;
769 return &data
->quote_shift
;
773 * adg_dim_style_set_quote_shift:
774 * @dim_style: an #AdgDimStyle object
775 * @shift: the new displacement
777 * Sets a new "quote-shift" value.
780 adg_dim_style_set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
782 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
784 set_quote_shift(dim_style
, shift
);
785 g_object_notify((GObject
*) dim_style
, "quote-shift");
789 * adg_dim_style_get_tolerance_shift:
790 * @dim_style: an #AdgDimStyle object
792 * Gets the smooth displacement of the tolerance text. The returned pointer
793 * refers to an internal allocated struct and must not be modified or freed.
795 * Return value: the requested shift
798 adg_dim_style_get_tolerance_shift(AdgDimStyle
*dim_style
)
800 AdgDimStylePrivate
*data
;
802 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
804 data
= dim_style
->data
;
806 return &data
->tolerance_shift
;
810 * adg_dim_style_set_tolerance_shift:
811 * @dim_style: an #AdgDimStyle object
812 * @shift: the new displacement
814 * Sets a new "tolerance-shift" value.
817 adg_dim_style_set_tolerance_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
819 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
821 set_tolerance_shift(dim_style
, shift
);
822 g_object_notify((GObject
*) dim_style
, "tolerance-shift");
826 * adg_dim_style_get_note_shift:
827 * @dim_style: an #AdgDimStyle object
829 * Gets the smooth displacement of the note text. The returned pointer
830 * refers to an internal allocated struct and must not be modified or freed.
832 * Return value: the requested shift
835 adg_dim_style_get_note_shift(AdgDimStyle
*dim_style
)
837 AdgDimStylePrivate
*data
;
839 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
841 data
= dim_style
->data
;
843 return &data
->note_shift
;
847 * adg_dim_style_set_note_shift:
848 * @dim_style: an #AdgDimStyle object
849 * @shift: the new displacement
851 * Sets a new "note-shift" value.
854 adg_dim_style_set_note_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
856 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
858 set_note_shift(dim_style
, shift
);
859 g_object_notify((GObject
*) dim_style
, "note-shift");
863 * adg_dim_style_get_number_format:
864 * @dim_style: an #AdgDimStyle object
866 * Gets the number format (in printf style) of this quoting style. The
867 * returned pointer refers to internally managed text that must not be
870 * Return value: the requested format
873 adg_dim_style_get_number_format(AdgDimStyle
*dim_style
)
875 AdgDimStylePrivate
*data
;
877 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
879 data
= dim_style
->data
;
881 return data
->number_format
;
885 * adg_dim_style_set_number_format:
886 * @dim_style: an #AdgDimStyle object
887 * @format: the new format to adopt
889 * Sets a new "number-format" value.
892 adg_dim_style_set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
894 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
896 set_number_format(dim_style
, format
);
897 g_object_notify((GObject
*) dim_style
, "number-format");
901 * adg_dim_style_get_number_tag:
902 * @dim_style: an #AdgDimStyle object
904 * Gets the number tag to substitute while building the basic value. The
905 * returned pointer refers to internally managed text that must not be
908 * Return value: the requested tag
911 adg_dim_style_get_number_tag(AdgDimStyle
*dim_style
)
913 AdgDimStylePrivate
*data
;
915 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
917 data
= dim_style
->data
;
919 return data
->number_tag
;
923 * adg_dim_style_set_number_tag:
924 * @dim_style: an #AdgDimStyle object
927 * Sets a new "number-tag" value.
930 adg_dim_style_set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
932 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
934 set_number_tag(dim_style
, tag
);
935 g_object_notify((GObject
*) dim_style
, "number-tag");
942 static GPtrArray
*pool
= NULL
;
944 if (G_UNLIKELY(pool
== NULL
)) {
945 cairo_pattern_t
*pattern
;
947 pool
= g_ptr_array_sized_new(ADG_DIM_STYLE_LAST
);
949 /* No need to specify further params: the default is already ISO */
950 pattern
= cairo_pattern_create_rgb(1., 0., 0.);
951 pool
->pdata
[ADG_DIM_STYLE_ISO
] = g_object_new(ADG_TYPE_DIM_STYLE
,
954 cairo_pattern_destroy(pattern
);
956 pool
->len
= ADG_DIM_STYLE_LAST
;
963 set_value_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
965 AdgDimStylePrivate
*data
= dim_style
->data
;
967 if (data
->value_style
)
968 g_object_unref(data
->value_style
);
971 data
->value_style
= (AdgStyle
*) style
;
975 set_tolerance_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
977 AdgDimStylePrivate
*data
= dim_style
->data
;
979 if (data
->tolerance_style
)
980 g_object_unref(data
->tolerance_style
);
983 data
->tolerance_style
= (AdgStyle
*) style
;
987 set_note_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
989 AdgDimStylePrivate
*data
= dim_style
->data
;
991 if (data
->note_style
)
992 g_object_unref(data
->note_style
);
995 data
->note_style
= (AdgStyle
*) style
;
999 set_line_style(AdgDimStyle
*dim_style
, AdgLineStyle
*style
)
1001 AdgDimStylePrivate
*data
= dim_style
->data
;
1003 if (data
->line_style
)
1004 g_object_unref(data
->line_style
);
1006 g_object_ref(style
);
1007 data
->line_style
= (AdgStyle
*) style
;
1011 set_arrow_style(AdgDimStyle
*dim_style
, AdgArrowStyle
*style
)
1013 AdgDimStylePrivate
*data
= dim_style
->data
;
1015 if (data
->arrow_style
)
1016 g_object_unref(data
->arrow_style
);
1018 g_object_ref(style
);
1019 data
->arrow_style
= (AdgStyle
*) style
;
1023 set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1025 AdgDimStylePrivate
*data
= dim_style
->data
;
1027 cpml_pair_copy(&data
->quote_shift
, shift
);
1031 set_tolerance_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1033 AdgDimStylePrivate
*data
= dim_style
->data
;
1035 cpml_pair_copy(&data
->tolerance_shift
, shift
);
1039 set_note_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1041 AdgDimStylePrivate
*data
= dim_style
->data
;
1043 cpml_pair_copy(&data
->note_shift
, shift
);
1047 set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
1049 AdgDimStylePrivate
*data
= dim_style
->data
;
1051 g_free(data
->number_format
);
1052 data
->number_format
= g_strdup(format
);
1056 set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
1058 AdgDimStylePrivate
*data
= dim_style
->data
;
1060 g_free(data
->number_tag
);
1061 data
->number_tag
= g_strdup(tag
);