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 * Returns: 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"
67 PROP_BASELINE_SPACING
,
68 PROP_TOLERANCE_SPACING
,
77 static void get_property (GObject
*object
,
81 static void set_property (GObject
*object
,
85 static GPtrArray
* get_pool (void);
86 static void set_value_style (AdgDimStyle
*dim_style
,
88 static void set_tolerance_style (AdgDimStyle
*dim_style
,
90 static void set_note_style (AdgDimStyle
*dim_style
,
92 static void set_line_style (AdgDimStyle
*dim_style
,
94 static void set_arrow_style (AdgDimStyle
*dim_style
,
95 AdgArrowStyle
*style
);
96 static void set_quote_shift (AdgDimStyle
*dim_style
,
97 const AdgPair
*shift
);
98 static void set_tolerance_shift (AdgDimStyle
*dim_style
,
99 const AdgPair
*shift
);
100 static void set_note_shift (AdgDimStyle
*dim_style
,
101 const AdgPair
*shift
);
102 static void set_number_format (AdgDimStyle
*dim_style
,
103 const gchar
*format
);
104 static void set_number_tag (AdgDimStyle
*dim_style
,
108 G_DEFINE_TYPE(AdgDimStyle
, adg_dim_style
, ADG_TYPE_STYLE
)
112 adg_dim_style_class_init(AdgDimStyleClass
*klass
)
114 GObjectClass
*gobject_class
;
115 AdgStyleClass
*style_class
;
118 gobject_class
= (GObjectClass
*) klass
;
119 style_class
= (AdgStyleClass
*) klass
;
121 g_type_class_add_private(klass
, sizeof(AdgDimStylePrivate
));
123 gobject_class
->get_property
= get_property
;
124 gobject_class
->set_property
= set_property
;
126 style_class
->get_pool
= get_pool
;
128 param
= g_param_spec_object("value-style",
130 P_("Font style for the basic value of the dimension"),
131 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
132 g_object_class_install_property(gobject_class
, PROP_VALUE_STYLE
,
135 param
= g_param_spec_object("tolerance-style",
136 P_("Tolerance Style"),
137 P_("Font style for the tolerances"),
138 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
139 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_STYLE
,
142 param
= g_param_spec_object("note-style",
144 P_("Font style for the note (the text after or under the basic value)"),
145 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
146 g_object_class_install_property(gobject_class
, PROP_NOTE_STYLE
, param
);
148 param
= g_param_spec_object("line-style",
150 P_("Line style for the baseline and the extension lines"),
151 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
152 g_object_class_install_property(gobject_class
, PROP_LINE_STYLE
, param
);
154 param
= g_param_spec_object("arrow-style",
156 P_("Arrow style to use on the baseline"),
157 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
158 g_object_class_install_property(gobject_class
, PROP_ARROW_STYLE
,
161 param
= g_param_spec_double("from-offset",
163 P_("Offset (in global space) of the extension lines from the path to the quote"),
164 0, G_MAXDOUBLE
, 5, G_PARAM_READWRITE
);
165 g_object_class_install_property(gobject_class
, PROP_FROM_OFFSET
,
168 param
= g_param_spec_double("to-offset",
170 P_("How many extend (in global space) the extension lines after hitting the baseline"),
171 0, G_MAXDOUBLE
, 5, G_PARAM_READWRITE
);
172 g_object_class_install_property(gobject_class
, PROP_TO_OFFSET
, param
);
174 param
= g_param_spec_double("beyond",
176 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside arrows: 0 means to automatically compute this value at run-time as 3*arrow-size (got from the binded array-style)"),
177 0, G_MAXDOUBLE
, 0, G_PARAM_READWRITE
);
178 g_object_class_install_property(gobject_class
, PROP_BEYOND
, param
);
180 param
= g_param_spec_double("baseline-spacing",
181 P_("Baseline Spacing"),
182 P_("Distance between two consecutive baselines while stacking dimensions"),
183 0, G_MAXDOUBLE
, 30, G_PARAM_READWRITE
);
184 g_object_class_install_property(gobject_class
, PROP_BASELINE_SPACING
,
187 param
= g_param_spec_double("tolerance-spacing",
188 P_("Tolerance Spacing"),
189 P_("Distance between up and down tolerance text"),
190 0, G_MAXDOUBLE
, 2, G_PARAM_READWRITE
);
191 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_SPACING
,
194 param
= g_param_spec_boxed("quote-shift",
196 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)"),
197 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
198 g_object_class_install_property(gobject_class
, PROP_QUOTE_SHIFT
,
201 param
= g_param_spec_boxed("tolerance-shift",
202 P_("Tolerance Shift"),
203 P_("Used to specify a smooth displacement (in global space) for the tolerance 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_TOLERANCE_SHIFT
,
208 param
= g_param_spec_boxed("note-shift",
210 P_("Used to specify a smooth displacement (in global space) for the note text by taking as reference the perfect compact position"),
211 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
212 g_object_class_install_property(gobject_class
, PROP_NOTE_SHIFT
, param
);
214 param
= g_param_spec_string("number-format",
216 P_("The format (in printf style) of the numeric component of the basic value"),
217 "%-.7g", G_PARAM_READWRITE
);
218 g_object_class_install_property(gobject_class
, PROP_NUMBER_FORMAT
,
221 param
= g_param_spec_string("number-tag",
223 P_("The tag to substitute inside the basic value pattern"),
224 "<>", G_PARAM_READWRITE
);
225 g_object_class_install_property(gobject_class
, PROP_NUMBER_TAG
, param
);
229 adg_dim_style_init(AdgDimStyle
*dim_style
)
231 AdgDimStylePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(dim_style
,
235 data
->value_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
236 ADG_FONT_STYLE_VALUE
);
237 data
->tolerance_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
238 ADG_FONT_STYLE_TOLERANCE
);
239 data
->note_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
240 ADG_FONT_STYLE_NOTE
);
241 data
->line_style
= adg_style_from_id(ADG_TYPE_LINE_STYLE
,
243 data
->arrow_style
= adg_style_from_id(ADG_TYPE_ARROW_STYLE
,
244 ADG_ARROW_STYLE_ARROW
);
245 data
->from_offset
= 6;
248 data
->baseline_spacing
= 30;
249 data
->tolerance_spacing
= 1;
250 data
->quote_shift
.x
= 0;
251 data
->quote_shift
.y
= -4;
252 data
->tolerance_shift
.x
= +2;
253 data
->tolerance_shift
.y
= -2;
254 data
->note_shift
.x
= +4;
255 data
->note_shift
.y
= 0;
256 data
->number_format
= g_strdup("%-.7g");
257 data
->number_tag
= g_strdup("<>");
259 dim_style
->data
= data
;
263 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
265 AdgDimStylePrivate
*data
= ((AdgDimStyle
*) object
)->data
;
268 case PROP_VALUE_STYLE
:
269 g_value_set_object(value
, data
->value_style
);
271 case PROP_TOLERANCE_STYLE
:
272 g_value_set_object(value
, data
->tolerance_style
);
274 case PROP_NOTE_STYLE
:
275 g_value_set_object(value
, data
->note_style
);
277 case PROP_LINE_STYLE
:
278 g_value_set_object(value
, data
->line_style
);
280 case PROP_ARROW_STYLE
:
281 g_value_set_object(value
, data
->arrow_style
);
283 case PROP_FROM_OFFSET
:
284 g_value_set_double(value
, data
->from_offset
);
287 g_value_set_double(value
, data
->to_offset
);
290 g_value_set_double(value
, data
->beyond
);
292 case PROP_BASELINE_SPACING
:
293 g_value_set_double(value
, data
->baseline_spacing
);
295 case PROP_TOLERANCE_SPACING
:
296 g_value_set_double(value
, data
->tolerance_spacing
);
298 case PROP_QUOTE_SHIFT
:
299 g_value_set_boxed(value
, &data
->quote_shift
);
301 case PROP_TOLERANCE_SHIFT
:
302 g_value_set_boxed(value
, &data
->tolerance_shift
);
304 case PROP_NOTE_SHIFT
:
305 g_value_set_boxed(value
, &data
->note_shift
);
307 case PROP_NUMBER_FORMAT
:
308 g_value_set_string(value
, data
->number_format
);
310 case PROP_NUMBER_TAG
:
311 g_value_set_string(value
, data
->number_tag
);
314 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
320 set_property(GObject
*object
,
321 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
323 AdgDimStyle
*dim_style
;
324 AdgDimStylePrivate
*data
;
326 dim_style
= (AdgDimStyle
*) object
;
327 data
= dim_style
->data
;
330 case PROP_VALUE_STYLE
:
331 set_value_style(dim_style
, g_value_get_object(value
));
333 case PROP_TOLERANCE_STYLE
:
334 set_tolerance_style(dim_style
, g_value_get_object(value
));
336 case PROP_NOTE_STYLE
:
337 set_note_style(dim_style
, g_value_get_object(value
));
339 case PROP_LINE_STYLE
:
340 set_line_style(dim_style
, g_value_get_object(value
));
342 case PROP_ARROW_STYLE
:
343 set_arrow_style(dim_style
, g_value_get_object(value
));
345 case PROP_FROM_OFFSET
:
346 data
->from_offset
= g_value_get_double(value
);
349 data
->to_offset
= g_value_get_double(value
);
352 data
->beyond
= g_value_get_double(value
);
354 case PROP_BASELINE_SPACING
:
355 data
->baseline_spacing
= g_value_get_double(value
);
357 case PROP_TOLERANCE_SPACING
:
358 data
->tolerance_spacing
= g_value_get_double(value
);
360 case PROP_QUOTE_SHIFT
:
361 set_quote_shift(dim_style
, g_value_get_boxed(value
));
363 case PROP_TOLERANCE_SHIFT
:
364 set_tolerance_shift(dim_style
, g_value_get_boxed(value
));
366 case PROP_NOTE_SHIFT
:
367 set_note_shift(dim_style
, g_value_get_boxed(value
));
369 case PROP_NUMBER_FORMAT
:
370 set_number_format(dim_style
, g_value_get_string(value
));
372 case PROP_NUMBER_TAG
:
373 set_number_tag(dim_style
, g_value_get_string(value
));
376 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
383 _adg_dim_style_get_slot(void)
385 static AdgStyleSlot slot
= -1;
387 if (G_UNLIKELY(slot
< 0))
388 slot
= adg_context_get_slot(ADG_TYPE_DIM_STYLE
);
396 * Constructs a new dimension style initialized with default params.
398 * Returns: a new dimension style
401 adg_dim_style_new(void)
403 return g_object_new(ADG_TYPE_DIM_STYLE
, NULL
);
407 * adg_dim_style_get_value_style:
408 * @dim_style: an #AdgDimStyle object
410 * Gets the basic value font style of @dim_style. No reference will
411 * be added to the returned style; it should not be unreferenced.
413 * Returns: the basic value style or %NULL on errors
416 adg_dim_style_get_value_style(AdgDimStyle
*dim_style
)
418 AdgDimStylePrivate
*data
;
420 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
422 data
= dim_style
->data
;
424 return data
->value_style
;
428 * adg_dim_style_set_value_style:
429 * @dim_style: an #AdgDimStyle object
430 * @style: the new basic value font style
432 * Sets a new font style on @dim_style for basic values. The old
433 * font style (if any) will be unreferenced while a new reference
434 * will be added to @style.
437 adg_dim_style_set_value_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
439 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
440 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
442 set_value_style(dim_style
, style
);
443 g_object_notify((GObject
*) dim_style
, "value-style");
447 * adg_dim_style_get_tolerance_style:
448 * @dim_style: an #AdgDimStyle object
450 * Gets the tolerance style of @dim_style. No reference will be added to the
451 * returned style; it should not be unreferenced.
453 * Returns: the tolerance style or %NULL on errors
456 adg_dim_style_get_tolerance_style(AdgDimStyle
*dim_style
)
458 AdgDimStylePrivate
*data
;
460 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
462 data
= dim_style
->data
;
464 return data
->tolerance_style
;
468 * adg_dim_style_set_tolerance_style:
469 * @dim_style: an #AdgDimStyle object
470 * @style: the new tolerance style
472 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
473 * will be unreferenced while a new reference will be added to @style.
476 adg_dim_style_set_tolerance_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_tolerance_style(dim_style
, style
);
482 g_object_notify((GObject
*) dim_style
, "tolerance-style");
486 * adg_dim_style_get_note_style:
487 * @dim_style: an #AdgDimStyle object
489 * Gets the note style of @dim_style. No reference will be added to the
490 * returned style; it should not be unreferenced.
492 * Returns: the note style or %NULL on errors
495 adg_dim_style_get_note_style(AdgDimStyle
*dim_style
)
497 AdgDimStylePrivate
*data
;
499 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
501 data
= dim_style
->data
;
503 return data
->note_style
;
507 * adg_dim_style_set_note_style:
508 * @dim_style: an #AdgDimStyle object
509 * @style: the new note style
511 * Sets a new note style on @dim_style. The old note style (if any) will be
512 * unreferenced while a new reference will be added to @style.
515 adg_dim_style_set_note_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
517 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
518 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
520 set_note_style(dim_style
, style
);
521 g_object_notify((GObject
*) dim_style
, "note-style");
525 * adg_dim_style_get_line_style:
526 * @dim_style: an #AdgDimStyle object
528 * Gets the line style of @dim_style. No reference will be added to the
529 * returned style; it should not be unreferenced.
531 * Returns: the line style or %NULL on errors
534 adg_dim_style_get_line_style(AdgDimStyle
*dim_style
)
536 AdgDimStylePrivate
*data
;
538 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
540 data
= dim_style
->data
;
542 return data
->line_style
;
546 * adg_dim_style_set_line_style:
547 * @dim_style: an #AdgDimStyle object
548 * @style: the new line style
550 * Sets a new line style on @dim_style. The old line style (if any) will be
551 * unreferenced while a new reference will be added to @style.
554 adg_dim_style_set_line_style(AdgDimStyle
*dim_style
, AdgLineStyle
*style
)
556 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
557 g_return_if_fail(ADG_IS_LINE_STYLE(style
));
559 set_line_style(dim_style
, style
);
560 g_object_notify((GObject
*) dim_style
, "line-style");
564 * adg_dim_style_get_arrow_style:
565 * @dim_style: an #AdgDimStyle object
567 * Gets the arrow style of @dim_style. No reference will be added to the
568 * returned style; it should not be unreferenced.
570 * Returns: the arrow style or %NULL on errors
573 adg_dim_style_get_arrow_style(AdgDimStyle
*dim_style
)
575 AdgDimStylePrivate
*data
;
577 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
579 data
= dim_style
->data
;
581 return data
->arrow_style
;
585 * adg_dim_style_set_arrow_style:
586 * @dim_style: an #AdgDimStyle object
587 * @style: the new arrow style
589 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
590 * unreferenced while a new reference will be added to @style.
593 adg_dim_style_set_arrow_style(AdgDimStyle
*dim_style
, AdgArrowStyle
*style
)
595 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
596 g_return_if_fail(ADG_IS_ARROW_STYLE(style
));
598 set_arrow_style(dim_style
, style
);
599 g_object_notify((GObject
*) dim_style
, "arrow-style");
603 * adg_dim_style_get_from_offset:
604 * @dim_style: an #AdgDimStyle object
606 * Gets the distance (in global space) the extension lines must keep from the
609 * Returns: the requested distance
612 adg_dim_style_get_from_offset(AdgDimStyle
*dim_style
)
614 AdgDimStylePrivate
*data
;
616 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
618 data
= dim_style
->data
;
620 return data
->from_offset
;
624 * adg_dim_style_set_from_offset:
625 * @dim_style: an #AdgDimStyle object
626 * @offset: the new offset
628 * Sets a new "from-offset" value.
631 adg_dim_style_set_from_offset(AdgDimStyle
*dim_style
, gdouble offset
)
633 AdgDimStylePrivate
*data
;
635 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
637 data
= dim_style
->data
;
638 data
->from_offset
= offset
;
640 g_object_notify((GObject
*) dim_style
, "from-offset");
644 * adg_dim_style_get_to_offset:
645 * @dim_style: an #AdgDimStyle object
647 * Gets how much (in global space) the extension lines must extend after
648 * crossing the baseline.
650 * Returns: the requested distance
653 adg_dim_style_get_to_offset(AdgDimStyle
*dim_style
)
655 AdgDimStylePrivate
*data
;
657 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
659 data
= dim_style
->data
;
661 return data
->to_offset
;
665 * adg_dim_style_set_to_offset:
666 * @dim_style: an #AdgDimStyle object
667 * @offset: the new offset
669 * Sets a new "to-offset" value.
672 adg_dim_style_set_to_offset(AdgDimStyle
*dim_style
, gdouble offset
)
674 AdgDimStylePrivate
*data
;
676 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
678 data
= dim_style
->data
;
679 data
->to_offset
= offset
;
681 g_object_notify((GObject
*) dim_style
, "to-offset");
685 * adg_dim_style_beyond:
686 * @dim_style: an #AdgDimStyle object
688 * Gets how much (in global space) the baseline should extend beyound
689 * the extension lines when a dimension has outside arrows. If the
690 * underlying AdgDimStyle:beyond property is %0, this function returns
691 * the 3*"arrow-size", where "arrow-size" is the value returned by
692 * adg_arrow_style_get_size() on #AdgArrowStyle binded to @dim_style.
694 * Returns: the requested lenght
697 adg_dim_style_beyond(AdgDimStyle
*dim_style
)
699 AdgDimStylePrivate
*data
;
702 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
704 data
= dim_style
->data
;
706 if (data
->beyond
> 0)
709 arrow_size
= adg_arrow_style_get_size((AdgArrowStyle
*) data
->arrow_style
);
711 return arrow_size
* 3;
715 * adg_dim_style_get_beyond:
716 * @dim_style: an #AdgDimStyle object
718 * Gets how much (in global space) the baseline should extend beyound
719 * the extension lines on dimension with outside arrows. This is an
720 * accessor method: if you need AdgDimStyle:beyond for rendering purpose,
721 * use adg_dim_style_beyond() instead.
723 * Returns: the requested lenght or %0 for automatic computation
726 adg_dim_style_get_beyond(AdgDimStyle
*dim_style
)
728 AdgDimStylePrivate
*data
;
730 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
732 data
= dim_style
->data
;
738 * adg_dim_style_set_beyond:
739 * @dim_style: an #AdgDimStyle object
740 * @length: the new length
742 * Sets a new "beyond" value.
745 adg_dim_style_set_beyond(AdgDimStyle
*dim_style
, gdouble length
)
747 AdgDimStylePrivate
*data
;
749 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
751 data
= dim_style
->data
;
752 data
->beyond
= length
;
754 g_object_notify((GObject
*) dim_style
, "beyond");
758 * adg_dim_style_get_baseline_spacing:
759 * @dim_style: an #AdgDimStyle object
761 * Gets the distance between two consecutive baselines
762 * while stacking dimensions.
764 * Returns: the requested spacing
767 adg_dim_style_get_baseline_spacing(AdgDimStyle
*dim_style
)
769 AdgDimStylePrivate
*data
;
771 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
773 data
= dim_style
->data
;
775 return data
->baseline_spacing
;
779 * adg_dim_style_set_baseline_spacing:
780 * @dim_style: an #AdgDimStyle object
781 * @spacing: the new spacing
783 * Sets a new "baseline-spacing" value.
786 adg_dim_style_set_baseline_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
788 AdgDimStylePrivate
*data
;
790 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
792 data
= dim_style
->data
;
793 data
->baseline_spacing
= spacing
;
795 g_object_notify((GObject
*) dim_style
, "baseline-spacing");
799 * adg_dim_style_get_tolerance_spacing:
800 * @dim_style: an #AdgDimStyle object
802 * Gets the distance (in global space) between up and down tolerances.
804 * Returns: the requested spacing
807 adg_dim_style_get_tolerance_spacing(AdgDimStyle
*dim_style
)
809 AdgDimStylePrivate
*data
;
811 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0);
813 data
= dim_style
->data
;
815 return data
->tolerance_spacing
;
819 * adg_dim_style_set_tolerance_spacing:
820 * @dim_style: an #AdgDimStyle object
821 * @spacing: the new spacing
823 * Sets a new "tolerance-spacing" value.
826 adg_dim_style_set_tolerance_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
828 AdgDimStylePrivate
*data
;
830 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
832 data
= dim_style
->data
;
833 data
->tolerance_spacing
= spacing
;
835 g_object_notify((GObject
*) dim_style
, "tolerance-spacing");
839 * adg_dim_style_get_quote_shift:
840 * @dim_style: an #AdgDimStyle object
842 * Gets the smooth displacement of the quote. The returned pointer refers
843 * to an internal allocated struct and must not be modified or freed.
845 * Returns: the requested shift
848 adg_dim_style_get_quote_shift(AdgDimStyle
*dim_style
)
850 AdgDimStylePrivate
*data
;
852 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
854 data
= dim_style
->data
;
856 return &data
->quote_shift
;
860 * adg_dim_style_set_quote_shift:
861 * @dim_style: an #AdgDimStyle object
862 * @shift: the new displacement
864 * Sets a new "quote-shift" value.
867 adg_dim_style_set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
869 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
871 set_quote_shift(dim_style
, shift
);
872 g_object_notify((GObject
*) dim_style
, "quote-shift");
876 * adg_dim_style_get_tolerance_shift:
877 * @dim_style: an #AdgDimStyle object
879 * Gets the smooth displacement of the tolerance text. The returned pointer
880 * refers to an internal allocated struct and must not be modified or freed.
882 * Returns: the requested shift
885 adg_dim_style_get_tolerance_shift(AdgDimStyle
*dim_style
)
887 AdgDimStylePrivate
*data
;
889 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
891 data
= dim_style
->data
;
893 return &data
->tolerance_shift
;
897 * adg_dim_style_set_tolerance_shift:
898 * @dim_style: an #AdgDimStyle object
899 * @shift: the new displacement
901 * Sets a new "tolerance-shift" value.
904 adg_dim_style_set_tolerance_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
906 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
908 set_tolerance_shift(dim_style
, shift
);
909 g_object_notify((GObject
*) dim_style
, "tolerance-shift");
913 * adg_dim_style_get_note_shift:
914 * @dim_style: an #AdgDimStyle object
916 * Gets the smooth displacement of the note text. The returned pointer
917 * refers to an internal allocated struct and must not be modified or freed.
919 * Returns: the requested shift
922 adg_dim_style_get_note_shift(AdgDimStyle
*dim_style
)
924 AdgDimStylePrivate
*data
;
926 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
928 data
= dim_style
->data
;
930 return &data
->note_shift
;
934 * adg_dim_style_set_note_shift:
935 * @dim_style: an #AdgDimStyle object
936 * @shift: the new displacement
938 * Sets a new "note-shift" value.
941 adg_dim_style_set_note_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
943 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
945 set_note_shift(dim_style
, shift
);
946 g_object_notify((GObject
*) dim_style
, "note-shift");
950 * adg_dim_style_get_number_format:
951 * @dim_style: an #AdgDimStyle object
953 * Gets the number format (in printf style) of this quoting style. The
954 * returned pointer refers to internally managed text that must not be
957 * Returns: the requested format
960 adg_dim_style_get_number_format(AdgDimStyle
*dim_style
)
962 AdgDimStylePrivate
*data
;
964 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
966 data
= dim_style
->data
;
968 return data
->number_format
;
972 * adg_dim_style_set_number_format:
973 * @dim_style: an #AdgDimStyle object
974 * @format: the new format to adopt
976 * Sets a new "number-format" value.
979 adg_dim_style_set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
981 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
983 set_number_format(dim_style
, format
);
984 g_object_notify((GObject
*) dim_style
, "number-format");
988 * adg_dim_style_get_number_tag:
989 * @dim_style: an #AdgDimStyle object
991 * Gets the number tag to substitute while building the basic value. The
992 * returned pointer refers to internally managed text that must not be
995 * Returns: the requested tag
998 adg_dim_style_get_number_tag(AdgDimStyle
*dim_style
)
1000 AdgDimStylePrivate
*data
;
1002 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
1004 data
= dim_style
->data
;
1006 return data
->number_tag
;
1010 * adg_dim_style_set_number_tag:
1011 * @dim_style: an #AdgDimStyle object
1014 * Sets a new "number-tag" value.
1017 adg_dim_style_set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
1019 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
1021 set_number_tag(dim_style
, tag
);
1022 g_object_notify((GObject
*) dim_style
, "number-tag");
1029 static GPtrArray
*pool
= NULL
;
1031 if (G_UNLIKELY(pool
== NULL
)) {
1032 cairo_pattern_t
*pattern
;
1034 pool
= g_ptr_array_sized_new(ADG_DIM_STYLE_LAST
);
1036 /* No need to specify further params: the default is already ISO */
1037 pattern
= cairo_pattern_create_rgb(1, 0, 0);
1038 pool
->pdata
[ADG_DIM_STYLE_ISO
] = g_object_new(ADG_TYPE_DIM_STYLE
,
1041 cairo_pattern_destroy(pattern
);
1043 pool
->len
= ADG_DIM_STYLE_LAST
;
1050 set_value_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
1052 AdgDimStylePrivate
*data
= dim_style
->data
;
1054 if (data
->value_style
)
1055 g_object_unref(data
->value_style
);
1057 g_object_ref(style
);
1058 data
->value_style
= (AdgStyle
*) style
;
1062 set_tolerance_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
1064 AdgDimStylePrivate
*data
= dim_style
->data
;
1066 if (data
->tolerance_style
)
1067 g_object_unref(data
->tolerance_style
);
1069 g_object_ref(style
);
1070 data
->tolerance_style
= (AdgStyle
*) style
;
1074 set_note_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
1076 AdgDimStylePrivate
*data
= dim_style
->data
;
1078 if (data
->note_style
)
1079 g_object_unref(data
->note_style
);
1081 g_object_ref(style
);
1082 data
->note_style
= (AdgStyle
*) style
;
1086 set_line_style(AdgDimStyle
*dim_style
, AdgLineStyle
*style
)
1088 AdgDimStylePrivate
*data
= dim_style
->data
;
1090 if (data
->line_style
)
1091 g_object_unref(data
->line_style
);
1093 g_object_ref(style
);
1094 data
->line_style
= (AdgStyle
*) style
;
1098 set_arrow_style(AdgDimStyle
*dim_style
, AdgArrowStyle
*style
)
1100 AdgDimStylePrivate
*data
= dim_style
->data
;
1102 if (data
->arrow_style
)
1103 g_object_unref(data
->arrow_style
);
1105 g_object_ref(style
);
1106 data
->arrow_style
= (AdgStyle
*) style
;
1110 set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1112 AdgDimStylePrivate
*data
= dim_style
->data
;
1114 cpml_pair_copy(&data
->quote_shift
, shift
);
1118 set_tolerance_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1120 AdgDimStylePrivate
*data
= dim_style
->data
;
1122 cpml_pair_copy(&data
->tolerance_shift
, shift
);
1126 set_note_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
1128 AdgDimStylePrivate
*data
= dim_style
->data
;
1130 cpml_pair_copy(&data
->note_shift
, shift
);
1134 set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
1136 AdgDimStylePrivate
*data
= dim_style
->data
;
1138 g_free(data
->number_format
);
1139 data
->number_format
= g_strdup(format
);
1143 set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
1145 AdgDimStylePrivate
*data
= dim_style
->data
;
1147 g_free(data
->number_tag
);
1148 data
->number_tag
= g_strdup(tag
);