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.
24 * @short_description: Dimension style related stuff
26 * Contains parameters on how to build dimensions such as the different font
27 * styles (for quote, tolerance and note), line style, offsets of the various
28 * dimension components etc...
31 #include "adg-dim-style.h"
32 #include "adg-dim-style-private.h"
33 #include "adg-font-style.h"
34 #include "adg-line-style.h"
35 #include "adg-arrow-style.h"
36 #include "adg-context.h"
40 #define PARENT_CLASS ((AdgStyleClass *) adg_dim_style_parent_class)
52 PROP_BASELINE_SPACING
,
53 PROP_TOLERANCE_SPACING
,
62 static void get_property (GObject
*object
,
66 static void set_property (GObject
*object
,
70 static GPtrArray
* get_pool (void);
71 static void set_quote_style (AdgDimStyle
*dim_style
,
73 static void set_tolerance_style (AdgDimStyle
*dim_style
,
75 static void set_note_style (AdgDimStyle
*dim_style
,
77 static void set_line_style (AdgDimStyle
*dim_style
,
79 static void set_arrow_style (AdgDimStyle
*dim_style
,
80 AdgArrowStyle
*style
);
81 static void set_quote_shift (AdgDimStyle
*dim_style
,
82 const AdgPair
*shift
);
83 static void set_tolerance_shift (AdgDimStyle
*dim_style
,
84 const AdgPair
*shift
);
85 static void set_note_shift (AdgDimStyle
*dim_style
,
86 const AdgPair
*shift
);
87 static void set_number_format (AdgDimStyle
*dim_style
,
89 static void set_number_tag (AdgDimStyle
*dim_style
,
93 G_DEFINE_TYPE(AdgDimStyle
, adg_dim_style
, ADG_TYPE_STYLE
)
97 adg_dim_style_class_init(AdgDimStyleClass
*klass
)
99 GObjectClass
*gobject_class
;
100 AdgStyleClass
*style_class
;
103 gobject_class
= (GObjectClass
*) klass
;
104 style_class
= (AdgStyleClass
*) klass
;
106 g_type_class_add_private(klass
, sizeof(AdgDimStylePrivate
));
108 gobject_class
->get_property
= get_property
;
109 gobject_class
->set_property
= set_property
;
111 style_class
->get_pool
= get_pool
;
113 param
= g_param_spec_object("quote-style",
115 P_("Font style for the quote"),
116 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
117 g_object_class_install_property(gobject_class
, PROP_QUOTE_STYLE
,
120 param
= g_param_spec_object("tolerance-style",
121 P_("Tolerance Style"),
122 P_("Font style for the tolerances"),
123 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
124 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_STYLE
,
127 param
= g_param_spec_object("note-style",
129 P_("Font style for the note (the text after or under the quote)"),
130 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
131 g_object_class_install_property(gobject_class
, PROP_NOTE_STYLE
, param
);
133 param
= g_param_spec_object("line-style",
135 P_("Line style for the baseline and the extension lines"),
136 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
137 g_object_class_install_property(gobject_class
, PROP_LINE_STYLE
, param
);
139 param
= g_param_spec_object("arrow-style",
141 P_("Arrow style to use on the baseline"),
142 ADG_TYPE_STYLE
, G_PARAM_READWRITE
);
143 g_object_class_install_property(gobject_class
, PROP_ARROW_STYLE
,
146 param
= g_param_spec_double("from-offset",
148 P_("Offset (in paper space) of the extension lines from the path to quote"),
149 0., G_MAXDOUBLE
, 5., G_PARAM_READWRITE
);
150 g_object_class_install_property(gobject_class
, PROP_FROM_OFFSET
,
153 param
= g_param_spec_double("to-offset",
155 P_("How many extend (in paper space) the extension lines after hitting the baseline"),
156 0., G_MAXDOUBLE
, 5., G_PARAM_READWRITE
);
157 g_object_class_install_property(gobject_class
, PROP_TO_OFFSET
, param
);
159 param
= g_param_spec_double("baseline-spacing",
160 P_("Baseline Spacing"),
161 P_("Distance between two consecutive baselines while stacking dimensions"),
162 0., G_MAXDOUBLE
, 30., G_PARAM_READWRITE
);
163 g_object_class_install_property(gobject_class
, PROP_BASELINE_SPACING
,
166 param
= g_param_spec_double("tolerance-spacing",
167 P_("Tolerance Spacing"),
168 P_("Distance between up and down tolerance text"),
169 0., G_MAXDOUBLE
, 2., G_PARAM_READWRITE
);
170 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_SPACING
,
173 param
= g_param_spec_boxed("quote-shift",
175 P_("Used to specify a smooth displacement (in paper units) for the quote text by taking as reference the perfect compact position (the middle of the baseline on common linear quotes, for instance)"),
176 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
177 g_object_class_install_property(gobject_class
, PROP_QUOTE_SHIFT
,
180 param
= g_param_spec_boxed("tolerance-shift",
181 P_("Tolerance Shift"),
182 P_("Used to specify a smooth displacement (in paper units) for the tolerance text by taking as reference the perfect compact position"),
183 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
184 g_object_class_install_property(gobject_class
, PROP_TOLERANCE_SHIFT
,
187 param
= g_param_spec_boxed("note-shift",
189 P_("Used to specify a smooth displacement (in paper units) for the note text by taking as reference the perfect compact position"),
190 ADG_TYPE_PAIR
, G_PARAM_READWRITE
);
191 g_object_class_install_property(gobject_class
, PROP_NOTE_SHIFT
, param
);
193 param
= g_param_spec_string("number-format",
195 P_("The format (in printf style) of the numeric component of the quote"),
196 "%-.7g", G_PARAM_READWRITE
);
197 g_object_class_install_property(gobject_class
, PROP_NUMBER_FORMAT
,
200 param
= g_param_spec_string("number-tag",
202 P_("The tag to substitute inside the quote pattern"),
203 "<>", G_PARAM_READWRITE
);
204 g_object_class_install_property(gobject_class
, PROP_NUMBER_TAG
, param
);
208 adg_dim_style_init(AdgDimStyle
*dim_style
)
210 AdgDimStylePrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE(dim_style
,
214 priv
->quote_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
215 ADG_FONT_STYLE_QUOTE
);
216 priv
->tolerance_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
217 ADG_FONT_STYLE_TOLERANCE
);
218 priv
->note_style
= adg_style_from_id(ADG_TYPE_FONT_STYLE
,
219 ADG_FONT_STYLE_NOTE
);
220 priv
->line_style
= adg_style_from_id(ADG_TYPE_LINE_STYLE
,
222 priv
->arrow_style
= adg_style_from_id(ADG_TYPE_ARROW_STYLE
,
223 ADG_ARROW_STYLE_ARROW
);
224 priv
->from_offset
= 5.;
225 priv
->to_offset
= 5.;
226 priv
->baseline_spacing
= 30.;
227 priv
->tolerance_spacing
= 2.;
228 priv
->quote_shift
.x
= 0.;
229 priv
->quote_shift
.y
= -3.;
230 priv
->tolerance_shift
.x
= +5.;
231 priv
->tolerance_shift
.y
= -4.;
232 priv
->note_shift
.x
= +5.;
233 priv
->note_shift
.y
= 0.;
234 priv
->number_format
= g_strdup("%-.7g");
235 priv
->number_tag
= g_strdup("<>");
237 dim_style
->priv
= priv
;
241 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
243 AdgDimStyle
*dim_style
= (AdgDimStyle
*) object
;
246 case PROP_QUOTE_STYLE
:
247 g_value_set_object(value
, dim_style
->priv
->quote_style
);
249 case PROP_TOLERANCE_STYLE
:
250 g_value_set_object(value
, dim_style
->priv
->tolerance_style
);
252 case PROP_NOTE_STYLE
:
253 g_value_set_object(value
, dim_style
->priv
->note_style
);
255 case PROP_LINE_STYLE
:
256 g_value_set_object(value
, dim_style
->priv
->line_style
);
258 case PROP_ARROW_STYLE
:
259 g_value_set_object(value
, dim_style
->priv
->arrow_style
);
261 case PROP_FROM_OFFSET
:
262 g_value_set_double(value
, dim_style
->priv
->from_offset
);
265 g_value_set_double(value
, dim_style
->priv
->to_offset
);
267 case PROP_BASELINE_SPACING
:
268 g_value_set_double(value
, dim_style
->priv
->baseline_spacing
);
270 case PROP_TOLERANCE_SPACING
:
271 g_value_set_double(value
, dim_style
->priv
->tolerance_spacing
);
273 case PROP_QUOTE_SHIFT
:
274 g_value_set_boxed(value
, &dim_style
->priv
->quote_shift
);
276 case PROP_TOLERANCE_SHIFT
:
277 g_value_set_boxed(value
, &dim_style
->priv
->tolerance_shift
);
279 case PROP_NOTE_SHIFT
:
280 g_value_set_boxed(value
, &dim_style
->priv
->note_shift
);
282 case PROP_NUMBER_FORMAT
:
283 g_value_set_string(value
, dim_style
->priv
->number_format
);
285 case PROP_NUMBER_TAG
:
286 g_value_set_string(value
, dim_style
->priv
->number_tag
);
289 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
295 set_property(GObject
*object
,
296 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
298 AdgDimStyle
*dim_style
= (AdgDimStyle
*) object
;
301 case PROP_QUOTE_STYLE
:
302 set_quote_style(dim_style
, g_value_get_object(value
));
304 case PROP_TOLERANCE_STYLE
:
305 set_tolerance_style(dim_style
, g_value_get_object(value
));
307 case PROP_NOTE_STYLE
:
308 set_note_style(dim_style
, g_value_get_object(value
));
310 case PROP_LINE_STYLE
:
311 set_line_style(dim_style
, g_value_get_object(value
));
313 case PROP_ARROW_STYLE
:
314 set_arrow_style(dim_style
, g_value_get_object(value
));
316 case PROP_FROM_OFFSET
:
317 dim_style
->priv
->from_offset
= g_value_get_double(value
);
320 dim_style
->priv
->to_offset
= g_value_get_double(value
);
322 case PROP_BASELINE_SPACING
:
323 dim_style
->priv
->baseline_spacing
= g_value_get_double(value
);
325 case PROP_TOLERANCE_SPACING
:
326 dim_style
->priv
->tolerance_spacing
= g_value_get_double(value
);
328 case PROP_QUOTE_SHIFT
:
329 set_quote_shift(dim_style
, g_value_get_boxed(value
));
331 case PROP_TOLERANCE_SHIFT
:
332 set_tolerance_shift(dim_style
, g_value_get_boxed(value
));
334 case PROP_NOTE_SHIFT
:
335 set_note_shift(dim_style
, g_value_get_boxed(value
));
337 case PROP_NUMBER_FORMAT
:
338 set_number_format(dim_style
, g_value_get_string(value
));
340 case PROP_NUMBER_TAG
:
341 set_number_tag(dim_style
, g_value_get_string(value
));
344 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
351 * adg_dim_style_get_slot:
353 * Gets the slot id for this style class.
355 * Return value: the slot
358 adg_dim_style_get_slot(void)
360 static AdgStyleSlot slot
= -1;
362 if (G_UNLIKELY(slot
< 0))
363 slot
= adg_context_get_slot(ADG_TYPE_DIM_STYLE
);
371 * Constructs a new dimension style initialized with default params.
373 * Return value: a new dimension style
376 adg_dim_style_new(void)
378 return g_object_new(ADG_TYPE_DIM_STYLE
, NULL
);
382 * adg_dim_style_get_quote_style:
383 * @dim_style: an #AdgDimStyle object
385 * Gets the quote style of @dim_style. No reference will be added to the
386 * returned style; it should not be unreferenced.
388 * Return value: the quote style or %NULL on errors
391 adg_dim_style_get_quote_style(AdgDimStyle
*dim_style
)
393 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
395 return dim_style
->priv
->quote_style
;
399 * adg_dim_style_set_quote_style:
400 * @dim_style: an #AdgDimStyle object
401 * @style: the new quote style
403 * Sets a new quote style on @dim_style. The old quote style (if any) will be
404 * unreferenced while a new reference will be added to @style.
407 adg_dim_style_set_quote_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
409 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
410 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
412 set_quote_style(dim_style
, style
);
413 g_object_notify((GObject
*) dim_style
, "quote-style");
417 * adg_dim_style_get_tolerance_style:
418 * @dim_style: an #AdgDimStyle object
420 * Gets the tolerance style of @dim_style. No reference will be added to the
421 * returned style; it should not be unreferenced.
423 * Return value: the tolerance style or %NULL on errors
426 adg_dim_style_get_tolerance_style(AdgDimStyle
*dim_style
)
428 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
430 return dim_style
->priv
->tolerance_style
;
434 * adg_dim_style_set_tolerance_style:
435 * @dim_style: an #AdgDimStyle object
436 * @style: the new tolerance style
438 * Sets a new tolerance style on @dim_style. The old tolerance style (if any)
439 * will be unreferenced while a new reference will be added to @style.
442 adg_dim_style_set_tolerance_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
444 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
445 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
447 set_tolerance_style(dim_style
, style
);
448 g_object_notify((GObject
*) dim_style
, "tolerance-style");
452 * adg_dim_style_get_note_style:
453 * @dim_style: an #AdgDimStyle object
455 * Gets the note style of @dim_style. No reference will be added to the
456 * returned style; it should not be unreferenced.
458 * Return value: the note style or %NULL on errors
461 adg_dim_style_get_note_style(AdgDimStyle
*dim_style
)
463 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
465 return dim_style
->priv
->note_style
;
469 * adg_dim_style_set_note_style:
470 * @dim_style: an #AdgDimStyle object
471 * @style: the new note style
473 * Sets a new note style on @dim_style. The old note style (if any) will be
474 * unreferenced while a new reference will be added to @style.
477 adg_dim_style_set_note_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
479 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
480 g_return_if_fail(ADG_IS_FONT_STYLE(style
));
482 set_note_style(dim_style
, style
);
483 g_object_notify((GObject
*) dim_style
, "note-style");
487 * adg_dim_style_get_line_style:
488 * @dim_style: an #AdgDimStyle object
490 * Gets the line style of @dim_style. No reference will be added to the
491 * returned style; it should not be unreferenced.
493 * Return value: the line style or %NULL on errors
496 adg_dim_style_get_line_style(AdgDimStyle
*dim_style
)
498 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
500 return dim_style
->priv
->line_style
;
504 * adg_dim_style_set_line_style:
505 * @dim_style: an #AdgDimStyle object
506 * @style: the new line style
508 * Sets a new line style on @dim_style. The old line style (if any) will be
509 * unreferenced while a new reference will be added to @style.
512 adg_dim_style_set_line_style(AdgDimStyle
*dim_style
, AdgLineStyle
*style
)
514 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
515 g_return_if_fail(ADG_IS_LINE_STYLE(style
));
517 set_line_style(dim_style
, style
);
518 g_object_notify((GObject
*) dim_style
, "line-style");
522 * adg_dim_style_get_arrow_style:
523 * @dim_style: an #AdgDimStyle object
525 * Gets the arrow style of @dim_style. No reference will be added to the
526 * returned style; it should not be unreferenced.
528 * Return value: the arrow style or %NULL on errors
531 adg_dim_style_get_arrow_style(AdgDimStyle
*dim_style
)
533 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
535 return dim_style
->priv
->arrow_style
;
539 * adg_dim_style_set_arrow_style:
540 * @dim_style: an #AdgDimStyle object
541 * @style: the new arrow style
543 * Sets a new arrow style on @dim_style. The old arrow style (if any) will be
544 * unreferenced while a new reference will be added to @style.
547 adg_dim_style_set_arrow_style(AdgDimStyle
*dim_style
, AdgArrowStyle
*style
)
549 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
550 g_return_if_fail(ADG_IS_ARROW_STYLE(style
));
552 set_arrow_style(dim_style
, style
);
553 g_object_notify((GObject
*) dim_style
, "arrow-style");
557 * adg_dim_style_get_from_offset:
558 * @dim_style: an #AdgDimStyle object
560 * Gets the distance (in paper space) the extension lines must keep from the
563 * Return value: the requested distance
566 adg_dim_style_get_from_offset(AdgDimStyle
*dim_style
)
568 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
570 return dim_style
->priv
->from_offset
;
574 * adg_dim_style_set_from_offset:
575 * @dim_style: an #AdgDimStyle object
576 * @offset: the new offset
578 * Sets a new "from-offset" value.
581 adg_dim_style_set_from_offset(AdgDimStyle
*dim_style
, gdouble offset
)
583 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
585 dim_style
->priv
->from_offset
= offset
;
586 g_object_notify((GObject
*) dim_style
, "from-offset");
590 * adg_dim_style_get_to_offset:
591 * @dim_style: an #AdgDimStyle object
593 * Gets how much (in paper space) the extension lines must extend after
594 * crossing the baseline.
596 * Return value: the requested distance
599 adg_dim_style_get_to_offset(AdgDimStyle
*dim_style
)
601 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
603 return dim_style
->priv
->to_offset
;
607 * adg_dim_style_set_to_offset:
608 * @dim_style: an #AdgDimStyle object
609 * @offset: the new offset
611 * Sets a new "to-offset" value.
614 adg_dim_style_set_to_offset(AdgDimStyle
*dim_style
, gdouble offset
)
616 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
618 dim_style
->priv
->to_offset
= offset
;
619 g_object_notify((GObject
*) dim_style
, "to-offset");
623 * adg_dim_style_get_baseline_spacing:
624 * @dim_style: an #AdgDimStyle object
626 * Gets the distance between two consecutive baselines
627 * while stacking dimensions.
629 * Return value: the requested spacing
632 adg_dim_style_get_baseline_spacing(AdgDimStyle
*dim_style
)
634 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
636 return dim_style
->priv
->baseline_spacing
;
640 * adg_dim_style_set_baseline_spacing:
641 * @dim_style: an #AdgDimStyle object
642 * @spacing: the new spacing
644 * Sets a new "baseline-spacing" value.
647 adg_dim_style_set_baseline_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
649 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
651 dim_style
->priv
->baseline_spacing
= spacing
;
652 g_object_notify((GObject
*) dim_style
, "baseline-spacing");
656 * adg_dim_style_get_tolerance_spacing:
657 * @dim_style: an #AdgDimStyle object
659 * Gets the distance (in paper space) between up and down tolerances.
661 * Return value: the requested spacing
664 adg_dim_style_get_tolerance_spacing(AdgDimStyle
*dim_style
)
666 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), 0.);
668 return dim_style
->priv
->tolerance_spacing
;
672 * adg_dim_style_set_tolerance_spacing:
673 * @dim_style: an #AdgDimStyle object
674 * @spacing: the new spacing
676 * Sets a new "tolerance-spacing" value.
679 adg_dim_style_set_tolerance_spacing(AdgDimStyle
*dim_style
, gdouble spacing
)
681 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
683 dim_style
->priv
->tolerance_spacing
= spacing
;
684 g_object_notify((GObject
*) dim_style
, "tolerance-spacing");
688 * adg_dim_style_get_quote_shift:
689 * @dim_style: an #AdgDimStyle object
691 * Gets the smooth displacement of the quote text. The returned pointer
692 * refers to an internal allocated struct and must not be modified or freed.
694 * Return value: the requested shift
697 adg_dim_style_get_quote_shift(AdgDimStyle
*dim_style
)
699 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
701 return &dim_style
->priv
->quote_shift
;
705 * adg_dim_style_set_quote_shift:
706 * @dim_style: an #AdgDimStyle object
707 * @shift: the new displacement
709 * Sets a new "quote-shift" value.
712 adg_dim_style_set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
714 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
716 set_quote_shift(dim_style
, shift
);
717 g_object_notify((GObject
*) dim_style
, "quote-shift");
721 * adg_dim_style_get_tolerance_shift:
722 * @dim_style: an #AdgDimStyle object
724 * Gets the smooth displacement of the tolerance text. The returned pointer
725 * refers to an internal allocated struct and must not be modified or freed.
727 * Return value: the requested shift
730 adg_dim_style_get_tolerance_shift(AdgDimStyle
*dim_style
)
732 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
734 return &dim_style
->priv
->tolerance_shift
;
738 * adg_dim_style_set_tolerance_shift:
739 * @dim_style: an #AdgDimStyle object
740 * @shift: the new displacement
742 * Sets a new "tolerance-shift" value.
745 adg_dim_style_set_tolerance_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
747 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
749 set_tolerance_shift(dim_style
, shift
);
750 g_object_notify((GObject
*) dim_style
, "tolerance-shift");
754 * adg_dim_style_get_note_shift:
755 * @dim_style: an #AdgDimStyle object
757 * Gets the smooth displacement of the note text. The returned pointer
758 * refers to an internal allocated struct and must not be modified or freed.
760 * Return value: the requested shift
763 adg_dim_style_get_note_shift(AdgDimStyle
*dim_style
)
765 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
767 return &dim_style
->priv
->note_shift
;
771 * adg_dim_style_set_note_shift:
772 * @dim_style: an #AdgDimStyle object
773 * @shift: the new displacement
775 * Sets a new "note-shift" value.
778 adg_dim_style_set_note_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
780 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
782 set_note_shift(dim_style
, shift
);
783 g_object_notify((GObject
*) dim_style
, "note-shift");
787 * adg_dim_style_get_number_format:
788 * @dim_style: an #AdgDimStyle object
790 * Gets the number format (in printf style) of this quoting style. The
791 * returned pointer refers to internally managed text that must not be
794 * Return value: the requested format
797 adg_dim_style_get_number_format(AdgDimStyle
*dim_style
)
799 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
801 return dim_style
->priv
->number_format
;
805 * adg_dim_style_set_number_format:
806 * @dim_style: an #AdgDimStyle object
807 * @format: the new format to adopt
809 * Sets a new "number-format" value.
812 adg_dim_style_set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
814 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
816 set_number_format(dim_style
, format
);
817 g_object_notify((GObject
*) dim_style
, "number-format");
821 * adg_dim_style_get_number_tag:
822 * @dim_style: an #AdgDimStyle object
824 * Gets the number tag to substitute while building the quote text. The
825 * returned pointer refers to internally managed text that must not be
828 * Return value: the requested tag
831 adg_dim_style_get_number_tag(AdgDimStyle
*dim_style
)
833 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style
), NULL
);
835 return dim_style
->priv
->number_tag
;
839 * adg_dim_style_set_number_tag:
840 * @dim_style: an #AdgDimStyle object
843 * Sets a new "number-tag" value.
846 adg_dim_style_set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
848 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style
));
850 set_number_tag(dim_style
, tag
);
851 g_object_notify((GObject
*) dim_style
, "number-tag");
858 static GPtrArray
*pool
= NULL
;
860 if (G_UNLIKELY(pool
== NULL
)) {
861 cairo_pattern_t
*pattern
;
863 pool
= g_ptr_array_sized_new(ADG_DIM_STYLE_LAST
);
865 /* No need to specify further params: the default is already ISO */
866 pattern
= cairo_pattern_create_rgb(1., 0., 0.);
867 pool
->pdata
[ADG_DIM_STYLE_ISO
] = g_object_new(ADG_TYPE_DIM_STYLE
,
870 cairo_pattern_destroy(pattern
);
872 pool
->len
= ADG_DIM_STYLE_LAST
;
879 set_quote_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
881 if (dim_style
->priv
->quote_style
)
882 g_object_unref(dim_style
->priv
->quote_style
);
885 dim_style
->priv
->quote_style
= (AdgStyle
*) style
;
889 set_tolerance_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
891 if (dim_style
->priv
->tolerance_style
)
892 g_object_unref(dim_style
->priv
->tolerance_style
);
895 dim_style
->priv
->tolerance_style
= (AdgStyle
*) style
;
899 set_note_style(AdgDimStyle
*dim_style
, AdgFontStyle
*style
)
901 if (dim_style
->priv
->note_style
)
902 g_object_unref(dim_style
->priv
->note_style
);
905 dim_style
->priv
->note_style
= (AdgStyle
*) style
;
909 set_line_style(AdgDimStyle
*dim_style
, AdgLineStyle
*style
)
911 if (dim_style
->priv
->line_style
)
912 g_object_unref(dim_style
->priv
->line_style
);
915 dim_style
->priv
->line_style
= (AdgStyle
*) style
;
919 set_arrow_style(AdgDimStyle
*dim_style
, AdgArrowStyle
*style
)
921 if (dim_style
->priv
->arrow_style
)
922 g_object_unref(dim_style
->priv
->arrow_style
);
925 dim_style
->priv
->arrow_style
= (AdgStyle
*) style
;
929 set_quote_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
931 cpml_pair_copy(&dim_style
->priv
->quote_shift
, shift
);
935 set_tolerance_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
937 cpml_pair_copy(&dim_style
->priv
->tolerance_shift
, shift
);
941 set_note_shift(AdgDimStyle
*dim_style
, const AdgPair
*shift
)
943 cpml_pair_copy(&dim_style
->priv
->note_shift
, shift
);
947 set_number_format(AdgDimStyle
*dim_style
, const gchar
*format
)
949 g_free(dim_style
->priv
->number_format
);
950 dim_style
->priv
->number_format
= g_strdup(format
);
954 set_number_tag(AdgDimStyle
*dim_style
, const gchar
*tag
)
956 g_free(dim_style
->priv
->number_tag
);
957 dim_style
->priv
->number_tag
= g_strdup(tag
);