[AdgDimStyle] Updated documentation
[adg.git] / adg / adg-dim-style.c
blob2091ef0852b80db44e9b10cc44ac036ab8c1ec4d
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 value, 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 #include "adg-dim-style.h"
39 #include "adg-dim-style-private.h"
40 #include "adg-font-style.h"
41 #include "adg-line-style.h"
42 #include "adg-intl.h"
43 #include "adg-util.h"
46 enum {
47 PROP_0,
48 PROP_VALUE_DRESS,
49 PROP_UP_DRESS,
50 PROP_DOWN_DRESS,
51 PROP_NOTE_DRESS,
52 PROP_LINE_DRESS,
53 PROP_FROM_OFFSET,
54 PROP_TO_OFFSET,
55 PROP_BEYOND,
56 PROP_BASELINE_SPACING,
57 PROP_TOLERANCE_SPACING,
58 PROP_QUOTE_SHIFT,
59 PROP_TOLERANCE_SHIFT,
60 PROP_NOTE_SHIFT,
61 PROP_NUMBER_FORMAT,
62 PROP_NUMBER_TAG
66 static void get_property (GObject *object,
67 guint prop_id,
68 GValue *value,
69 GParamSpec *pspec);
70 static void set_property (GObject *object,
71 guint prop_id,
72 const GValue *value,
73 GParamSpec *pspec);
74 static void apply (AdgStyle *style,
75 cairo_t *cr);
76 static void set_quote_shift (AdgDimStyle *dim_style,
77 const AdgPair *shift);
78 static void set_tolerance_shift (AdgDimStyle *dim_style,
79 const AdgPair *shift);
80 static void set_note_shift (AdgDimStyle *dim_style,
81 const AdgPair *shift);
82 static void set_number_format (AdgDimStyle *dim_style,
83 const gchar *format);
84 static void set_number_tag (AdgDimStyle *dim_style,
85 const gchar *tag);
88 G_DEFINE_TYPE(AdgDimStyle, adg_dim_style, ADG_TYPE_STYLE);
91 static void
92 adg_dim_style_class_init(AdgDimStyleClass *klass)
94 GObjectClass *gobject_class;
95 AdgStyleClass *style_class;
96 GParamSpec *param;
98 gobject_class = (GObjectClass *) klass;
99 style_class = (AdgStyleClass *) klass;
101 g_type_class_add_private(klass, sizeof(AdgDimStylePrivate));
103 gobject_class->get_property = get_property;
104 gobject_class->set_property = set_property;
106 style_class->apply = apply;
108 param = adg_param_spec_dress("value-dress",
109 P_("Value Dress"),
110 P_("Font dress for the nominal value of the dimension"),
111 ADG_DRESS_TEXT_VALUE,
112 G_PARAM_READWRITE);
113 g_object_class_install_property(gobject_class, PROP_VALUE_DRESS, param);
115 param = adg_param_spec_dress("up-dress",
116 P_("Up-limit Dress"),
117 P_("Font dress for the upper limit value"),
118 ADG_DRESS_TEXT_LIMIT,
119 G_PARAM_READWRITE);
120 g_object_class_install_property(gobject_class, PROP_UP_DRESS, param);
122 param = adg_param_spec_dress("down-dress",
123 P_("Down-limit Dress"),
124 P_("Font dress for the lower limit value"),
125 ADG_DRESS_TEXT_LIMIT,
126 G_PARAM_READWRITE);
127 g_object_class_install_property(gobject_class, PROP_DOWN_DRESS, param);
129 param = adg_param_spec_dress("note-dress",
130 P_("Note Dress"),
131 P_("Font dress for the note"),
132 ADG_DRESS_TEXT_VALUE,
133 G_PARAM_READWRITE);
134 g_object_class_install_property(gobject_class, PROP_NOTE_DRESS, param);
136 param = adg_param_spec_dress("line-dress",
137 P_("Line Dress"),
138 P_("Line dress for the baseline and the extension lines"),
139 ADG_DRESS_LINE_DIMENSION,
140 G_PARAM_READWRITE);
141 g_object_class_install_property(gobject_class, PROP_LINE_DRESS, param);
143 param = g_param_spec_double("from-offset",
144 P_("From Offset"),
145 P_("Offset (in global space) of the extension lines from the path to the quote"),
146 0, G_MAXDOUBLE, 5,
147 G_PARAM_READWRITE);
148 g_object_class_install_property(gobject_class, PROP_FROM_OFFSET, param);
150 param = g_param_spec_double("to-offset",
151 P_("To Offset"),
152 P_("How many extend (in global space) the extension lines after hitting the baseline"),
153 0, G_MAXDOUBLE, 5,
154 G_PARAM_READWRITE);
155 g_object_class_install_property(gobject_class, PROP_TO_OFFSET, param);
157 param = g_param_spec_double("beyond",
158 P_("Beyond Length"),
159 P_("How much the baseline should be extended (in global space) beyond the extension lines on dimensions with outside markers: 0 means to automatically compute this value at run-time as 3*marker-size (got from the binded array-style)"),
160 0, G_MAXDOUBLE, 0,
161 G_PARAM_READWRITE);
162 g_object_class_install_property(gobject_class, PROP_BEYOND, param);
164 param = g_param_spec_double("baseline-spacing",
165 P_("Baseline Spacing"),
166 P_("Distance between two consecutive baselines while stacking dimensions"),
167 0, G_MAXDOUBLE, 30,
168 G_PARAM_READWRITE);
169 g_object_class_install_property(gobject_class, PROP_BASELINE_SPACING, param);
171 param = g_param_spec_double("tolerance-spacing",
172 P_("Tolerance Spacing"),
173 P_("Distance between up and down tolerance text"),
174 0, G_MAXDOUBLE, 2,
175 G_PARAM_READWRITE);
176 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SPACING, param);
178 param = g_param_spec_boxed("quote-shift",
179 P_("Quote Shift"),
180 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)"),
181 ADG_TYPE_PAIR, G_PARAM_READWRITE);
182 g_object_class_install_property(gobject_class, PROP_QUOTE_SHIFT, param);
184 param = g_param_spec_boxed("tolerance-shift",
185 P_("Tolerance Shift"),
186 P_("Used to specify a smooth displacement (in global space) for the tolerance text by taking as reference the perfect compact position"),
187 ADG_TYPE_PAIR, G_PARAM_READWRITE);
188 g_object_class_install_property(gobject_class, PROP_TOLERANCE_SHIFT,
189 param);
191 param = g_param_spec_boxed("note-shift",
192 P_("Note Shift"),
193 P_("Used to specify a smooth displacement (in global space) for the note text by taking as reference the perfect compact position"),
194 ADG_TYPE_PAIR, G_PARAM_READWRITE);
195 g_object_class_install_property(gobject_class, PROP_NOTE_SHIFT, param);
197 param = g_param_spec_string("number-format",
198 P_("Number Format"),
199 P_("The format (in printf style) of the numeric component of the basic value"),
200 "%-.7g", G_PARAM_READWRITE);
201 g_object_class_install_property(gobject_class, PROP_NUMBER_FORMAT,
202 param);
204 param = g_param_spec_string("number-tag",
205 P_("Number Tag"),
206 P_("The tag to substitute inside the basic value pattern"),
207 "<>", G_PARAM_READWRITE);
208 g_object_class_install_property(gobject_class, PROP_NUMBER_TAG, param);
211 static void
212 adg_dim_style_init(AdgDimStyle *dim_style)
214 AdgDimStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(dim_style,
215 ADG_TYPE_DIM_STYLE,
216 AdgDimStylePrivate);
218 data->value_dress = ADG_DRESS_TEXT_VALUE;
219 data->up_dress = ADG_DRESS_TEXT_LIMIT;
220 data->down_dress = ADG_DRESS_TEXT_LIMIT;
221 data->note_dress = ADG_DRESS_TEXT_VALUE;
222 data->line_dress = ADG_DRESS_LINE_DIMENSION;
223 data->marker_dress = ADG_DRESS_UNDEFINED;
224 data->from_offset = 6;
225 data->to_offset = 6;
226 data->beyond = 0;
227 data->baseline_spacing = 30;
228 data->tolerance_spacing = 1;
229 data->quote_shift.x = 0;
230 data->quote_shift.y = -4;
231 data->tolerance_shift.x = +2;
232 data->tolerance_shift.y = -2;
233 data->note_shift.x = +4;
234 data->note_shift.y = 0;
235 data->number_format = g_strdup("%-.7g");
236 data->number_tag = g_strdup("<>");
238 dim_style->data = data;
241 static void
242 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
244 AdgDimStylePrivate *data = ((AdgDimStyle *) object)->data;
246 switch (prop_id) {
247 case PROP_VALUE_DRESS:
248 g_value_set_int(value, data->value_dress);
249 break;
250 case PROP_UP_DRESS:
251 g_value_set_int(value, data->up_dress);
252 break;
253 case PROP_DOWN_DRESS:
254 g_value_set_int(value, data->down_dress);
255 break;
256 case PROP_NOTE_DRESS:
257 g_value_set_int(value, data->note_dress);
258 break;
259 case PROP_LINE_DRESS:
260 g_value_set_int(value, data->line_dress);
261 break;
262 case PROP_FROM_OFFSET:
263 g_value_set_double(value, data->from_offset);
264 break;
265 case PROP_TO_OFFSET:
266 g_value_set_double(value, data->to_offset);
267 break;
268 case PROP_BEYOND:
269 g_value_set_double(value, data->beyond);
270 break;
271 case PROP_BASELINE_SPACING:
272 g_value_set_double(value, data->baseline_spacing);
273 break;
274 case PROP_TOLERANCE_SPACING:
275 g_value_set_double(value, data->tolerance_spacing);
276 break;
277 case PROP_QUOTE_SHIFT:
278 g_value_set_boxed(value, &data->quote_shift);
279 break;
280 case PROP_TOLERANCE_SHIFT:
281 g_value_set_boxed(value, &data->tolerance_shift);
282 break;
283 case PROP_NOTE_SHIFT:
284 g_value_set_boxed(value, &data->note_shift);
285 break;
286 case PROP_NUMBER_FORMAT:
287 g_value_set_string(value, data->number_format);
288 break;
289 case PROP_NUMBER_TAG:
290 g_value_set_string(value, data->number_tag);
291 break;
292 default:
293 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
294 break;
298 static void
299 set_property(GObject *object,
300 guint prop_id, const GValue *value, GParamSpec *pspec)
302 AdgDimStyle *dim_style;
303 AdgDimStylePrivate *data;
305 dim_style = (AdgDimStyle *) object;
306 data = dim_style->data;
308 switch (prop_id) {
309 case PROP_VALUE_DRESS:
310 adg_dress_set(&data->value_dress, g_value_get_int(value));
311 break;
312 case PROP_UP_DRESS:
313 adg_dress_set(&data->up_dress, g_value_get_int(value));
314 break;
315 case PROP_DOWN_DRESS:
316 adg_dress_set(&data->down_dress, g_value_get_int(value));
317 break;
318 case PROP_NOTE_DRESS:
319 adg_dress_set(&data->note_dress, g_value_get_int(value));
320 break;
321 case PROP_LINE_DRESS:
322 adg_dress_set(&data->line_dress, g_value_get_int(value));
323 break;
324 case PROP_FROM_OFFSET:
325 data->from_offset = g_value_get_double(value);
326 break;
327 case PROP_TO_OFFSET:
328 data->to_offset = g_value_get_double(value);
329 break;
330 case PROP_BEYOND:
331 data->beyond = g_value_get_double(value);
332 break;
333 case PROP_BASELINE_SPACING:
334 data->baseline_spacing = g_value_get_double(value);
335 break;
336 case PROP_TOLERANCE_SPACING:
337 data->tolerance_spacing = g_value_get_double(value);
338 break;
339 case PROP_QUOTE_SHIFT:
340 set_quote_shift(dim_style, g_value_get_boxed(value));
341 break;
342 case PROP_TOLERANCE_SHIFT:
343 set_tolerance_shift(dim_style, g_value_get_boxed(value));
344 break;
345 case PROP_NOTE_SHIFT:
346 set_note_shift(dim_style, g_value_get_boxed(value));
347 break;
348 case PROP_NUMBER_FORMAT:
349 set_number_format(dim_style, g_value_get_string(value));
350 break;
351 case PROP_NUMBER_TAG:
352 set_number_tag(dim_style, g_value_get_string(value));
353 break;
354 default:
355 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
356 break;
362 * adg_dim_style_new:
364 * Constructs a new dimension style initialized with default params.
366 * Returns: a new dimension style
368 AdgStyle *
369 adg_dim_style_new(void)
371 return g_object_new(ADG_TYPE_DIM_STYLE, NULL);
375 * adg_dim_style_get_value_dress:
376 * @dim_style: an #AdgDimStyle object
378 * Gets the @dim_style dress to be used for the basic value.
380 * Returns: the basic value dress
382 AdgDress
383 adg_dim_style_get_value_dress(AdgDimStyle *dim_style)
385 AdgDimStylePrivate *data;
387 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
389 data = dim_style->data;
391 return data->value_dress;
395 * adg_dim_style_set_value_dress:
396 * @dim_style: an #AdgDimStyle object
397 * @style: the new basic value font style
399 * Sets a new dress on @dim_style for the basic value.
401 void
402 adg_dim_style_set_value_dress(AdgDimStyle *dim_style, AdgDress dress)
404 AdgDimStylePrivate *data;
406 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
408 data = dim_style->data;
410 if (adg_dress_set(&data->value_dress, dress))
411 g_object_notify((GObject *) dim_style, "value-dress");
415 * adg_dim_style_get_up_dress:
416 * @dim_style: an #AdgDimStyle object
418 * Gets the @dim_style dress to be used for the upper limit.
420 * Returns: the upper limit dress
422 AdgDress
423 adg_dim_style_get_up_dress(AdgDimStyle *dim_style)
425 AdgDimStylePrivate *data;
427 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
429 data = dim_style->data;
431 return data->up_dress;
435 * adg_dim_style_set_up_dress:
436 * @dim_style: an #AdgDimStyle object
437 * @dress: the new upper limit dress
439 * Sets a new dress on @dim_style for the upper limit value.
441 void
442 adg_dim_style_set_up_dress(AdgDimStyle *dim_style, AdgDress dress)
444 AdgDimStylePrivate *data;
446 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
448 data = dim_style->data;
450 if (adg_dress_set(&data->up_dress, dress))
451 g_object_notify((GObject *) dim_style, "up-dress");
455 * adg_dim_style_get_down_dress:
456 * @dim_style: an #AdgDimStyle object
458 * Gets the @dim_style dress to be used for the lower limit.
460 * Returns: the lower limit dress
462 AdgDress
463 adg_dim_style_get_down_dress(AdgDimStyle *dim_style)
465 AdgDimStylePrivate *data;
467 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
469 data = dim_style->data;
471 return data->down_dress;
475 * adg_dim_style_set_down_dress:
476 * @dim_style: an #AdgDimStyle object
477 * @dress: the new lower limit dress
479 * Sets a new dress on @dim_style for the lower limit value.
481 void
482 adg_dim_style_set_down_dress(AdgDimStyle *dim_style, AdgDress dress)
484 AdgDimStylePrivate *data;
486 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
488 data = dim_style->data;
490 if (adg_dress_set(&data->down_dress, dress))
491 g_object_notify((GObject *) dim_style, "down-dress");
495 * adg_dim_style_get_note_dress:
496 * @dim_style: an #AdgDimStyle object
498 * Gets the @dim_style dress to be used for the note text.
500 * Returns: the note dress
502 AdgDress
503 adg_dim_style_get_note_dress(AdgDimStyle *dim_style)
505 AdgDimStylePrivate *data;
507 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
509 data = dim_style->data;
511 return data->note_dress;
515 * adg_dim_style_set_note_dress:
516 * @dim_style: an #AdgDimStyle object
517 * @style: the new note style
519 * Sets a new dress on @dim_style for the note text.
521 void
522 adg_dim_style_set_note_dress(AdgDimStyle *dim_style, AdgDress dress)
524 AdgDimStylePrivate *data;
526 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
528 data = dim_style->data;
530 if (adg_dress_set(&data->note_dress, dress))
531 g_object_notify((GObject *) dim_style, "note-dress");
535 * adg_dim_style_get_line_dress:
536 * @dim_style: an #AdgDimStyle object
538 * Gets the @dim_style dress to be used for rendering the baseline and
539 * the extension lines.
541 * Returns: the line dress
543 AdgDress
544 adg_dim_style_get_line_dress(AdgDimStyle *dim_style)
546 AdgDimStylePrivate *data;
548 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), ADG_DRESS_UNDEFINED);
550 data = dim_style->data;
552 return data->line_dress;
556 * adg_dim_style_set_line_dress:
557 * @dim_style: an #AdgDimStyle object
558 * @dress: the new line dress
560 * Sets a new line dress on @dim_style.
562 void
563 adg_dim_style_set_line_dress(AdgDimStyle *dim_style, AdgDress dress)
565 AdgDimStylePrivate *data;
567 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
569 data = dim_style->data;
571 if (adg_dress_set(&data->line_dress, dress))
572 g_object_notify((GObject *) dim_style, "line-dress");
576 * adg_dim_style_get_from_offset:
577 * @dim_style: an #AdgDimStyle object
579 * Gets the distance (in global space) the extension lines must keep from the
580 * sensed points.
582 * Returns: the requested distance
584 gdouble
585 adg_dim_style_get_from_offset(AdgDimStyle *dim_style)
587 AdgDimStylePrivate *data;
589 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
591 data = dim_style->data;
593 return data->from_offset;
597 * adg_dim_style_set_from_offset:
598 * @dim_style: an #AdgDimStyle object
599 * @offset: the new offset
601 * Sets a new "from-offset" value.
603 void
604 adg_dim_style_set_from_offset(AdgDimStyle *dim_style, gdouble offset)
606 AdgDimStylePrivate *data;
608 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
610 data = dim_style->data;
611 data->from_offset = offset;
613 g_object_notify((GObject *) dim_style, "from-offset");
617 * adg_dim_style_get_to_offset:
618 * @dim_style: an #AdgDimStyle object
620 * Gets how much (in global space) the extension lines must extend after
621 * crossing the baseline.
623 * Returns: the requested distance
625 gdouble
626 adg_dim_style_get_to_offset(AdgDimStyle *dim_style)
628 AdgDimStylePrivate *data;
630 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
632 data = dim_style->data;
634 return data->to_offset;
638 * adg_dim_style_set_to_offset:
639 * @dim_style: an #AdgDimStyle object
640 * @offset: the new offset
642 * Sets a new "to-offset" value.
644 void
645 adg_dim_style_set_to_offset(AdgDimStyle *dim_style, gdouble offset)
647 AdgDimStylePrivate *data;
649 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
651 data = dim_style->data;
652 data->to_offset = offset;
654 g_object_notify((GObject *) dim_style, "to-offset");
658 * adg_dim_style_beyond:
659 * @dim_style: an #AdgDimStyle object
661 * Gets how much (in global space) the baseline should extend beyound
662 * the extension lines when a dimension has outside markers. If the
663 * underlying AdgDimStyle:beyond property is %0, this function returns
664 * the 3*"marker-size", where "marker-size" is the value returned by
665 * adg_marker_style_get_size() on #AdgMarkerStyle binded to @dim_style.
667 * Returns: the requested lenght
669 gdouble
670 adg_dim_style_beyond(AdgDimStyle *dim_style)
672 AdgDimStylePrivate *data;
673 gdouble marker_size;
675 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
677 data = dim_style->data;
678 marker_size = 10;
680 if (data->beyond > 0)
681 return data->beyond;
683 return marker_size * 3;
687 * adg_dim_style_get_beyond:
688 * @dim_style: an #AdgDimStyle object
690 * Gets how much (in global space) the baseline should extend beyound
691 * the extension lines on dimension with outside markers. This is an
692 * accessor method: if you need AdgDimStyle:beyond for rendering purpose,
693 * use adg_dim_style_beyond() instead.
695 * Returns: the requested lenght or %0 for automatic computation
697 gdouble
698 adg_dim_style_get_beyond(AdgDimStyle *dim_style)
700 AdgDimStylePrivate *data;
702 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
704 data = dim_style->data;
706 return data->beyond;
710 * adg_dim_style_set_beyond:
711 * @dim_style: an #AdgDimStyle object
712 * @length: the new length
714 * Sets a new "beyond" value.
716 void
717 adg_dim_style_set_beyond(AdgDimStyle *dim_style, gdouble length)
719 AdgDimStylePrivate *data;
721 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
723 data = dim_style->data;
724 data->beyond = length;
726 g_object_notify((GObject *) dim_style, "beyond");
730 * adg_dim_style_get_baseline_spacing:
731 * @dim_style: an #AdgDimStyle object
733 * Gets the distance between two consecutive baselines
734 * while stacking dimensions.
736 * Returns: the requested spacing
738 gdouble
739 adg_dim_style_get_baseline_spacing(AdgDimStyle *dim_style)
741 AdgDimStylePrivate *data;
743 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
745 data = dim_style->data;
747 return data->baseline_spacing;
751 * adg_dim_style_set_baseline_spacing:
752 * @dim_style: an #AdgDimStyle object
753 * @spacing: the new spacing
755 * Sets a new "baseline-spacing" value.
757 void
758 adg_dim_style_set_baseline_spacing(AdgDimStyle *dim_style, gdouble spacing)
760 AdgDimStylePrivate *data;
762 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
764 data = dim_style->data;
765 data->baseline_spacing = spacing;
767 g_object_notify((GObject *) dim_style, "baseline-spacing");
771 * adg_dim_style_get_tolerance_spacing:
772 * @dim_style: an #AdgDimStyle object
774 * Gets the distance (in global space) between up and down tolerances.
776 * Returns: the requested spacing
778 gdouble
779 adg_dim_style_get_tolerance_spacing(AdgDimStyle *dim_style)
781 AdgDimStylePrivate *data;
783 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), 0);
785 data = dim_style->data;
787 return data->tolerance_spacing;
791 * adg_dim_style_set_tolerance_spacing:
792 * @dim_style: an #AdgDimStyle object
793 * @spacing: the new spacing
795 * Sets a new "tolerance-spacing" value.
797 void
798 adg_dim_style_set_tolerance_spacing(AdgDimStyle *dim_style, gdouble spacing)
800 AdgDimStylePrivate *data;
802 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
804 data = dim_style->data;
805 data->tolerance_spacing = spacing;
807 g_object_notify((GObject *) dim_style, "tolerance-spacing");
811 * adg_dim_style_get_quote_shift:
812 * @dim_style: an #AdgDimStyle object
814 * Gets the smooth displacement of the quote. The returned pointer refers
815 * to an internal allocated struct and must not be modified or freed.
817 * Returns: the requested shift
819 const AdgPair *
820 adg_dim_style_get_quote_shift(AdgDimStyle *dim_style)
822 AdgDimStylePrivate *data;
824 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
826 data = dim_style->data;
828 return &data->quote_shift;
832 * adg_dim_style_set_quote_shift:
833 * @dim_style: an #AdgDimStyle object
834 * @shift: the new displacement
836 * Sets a new "quote-shift" value.
838 void
839 adg_dim_style_set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
841 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
843 set_quote_shift(dim_style, shift);
844 g_object_notify((GObject *) dim_style, "quote-shift");
848 * adg_dim_style_get_tolerance_shift:
849 * @dim_style: an #AdgDimStyle object
851 * Gets the smooth displacement of the tolerance text. The returned pointer
852 * refers to an internal allocated struct and must not be modified or freed.
854 * Returns: the requested shift
856 const AdgPair *
857 adg_dim_style_get_tolerance_shift(AdgDimStyle *dim_style)
859 AdgDimStylePrivate *data;
861 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
863 data = dim_style->data;
865 return &data->tolerance_shift;
869 * adg_dim_style_set_tolerance_shift:
870 * @dim_style: an #AdgDimStyle object
871 * @shift: the new displacement
873 * Sets a new "tolerance-shift" value.
875 void
876 adg_dim_style_set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
878 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
880 set_tolerance_shift(dim_style, shift);
881 g_object_notify((GObject *) dim_style, "tolerance-shift");
885 * adg_dim_style_get_note_shift:
886 * @dim_style: an #AdgDimStyle object
888 * Gets the smooth displacement of the note text. The returned pointer
889 * refers to an internal allocated struct and must not be modified or freed.
891 * Returns: the requested shift
893 const AdgPair *
894 adg_dim_style_get_note_shift(AdgDimStyle *dim_style)
896 AdgDimStylePrivate *data;
898 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
900 data = dim_style->data;
902 return &data->note_shift;
906 * adg_dim_style_set_note_shift:
907 * @dim_style: an #AdgDimStyle object
908 * @shift: the new displacement
910 * Sets a new "note-shift" value.
912 void
913 adg_dim_style_set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
915 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
917 set_note_shift(dim_style, shift);
918 g_object_notify((GObject *) dim_style, "note-shift");
922 * adg_dim_style_get_number_format:
923 * @dim_style: an #AdgDimStyle object
925 * Gets the number format (in printf style) of this quoting style. The
926 * returned pointer refers to internally managed text that must not be
927 * modified or freed.
929 * Returns: the requested format
931 const gchar *
932 adg_dim_style_get_number_format(AdgDimStyle *dim_style)
934 AdgDimStylePrivate *data;
936 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
938 data = dim_style->data;
940 return data->number_format;
944 * adg_dim_style_set_number_format:
945 * @dim_style: an #AdgDimStyle object
946 * @format: the new format to adopt
948 * Sets a new "number-format" value.
950 void
951 adg_dim_style_set_number_format(AdgDimStyle *dim_style, const gchar *format)
953 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
955 set_number_format(dim_style, format);
956 g_object_notify((GObject *) dim_style, "number-format");
960 * adg_dim_style_get_number_tag:
961 * @dim_style: an #AdgDimStyle object
963 * Gets the number tag to substitute while building the basic value. The
964 * returned pointer refers to internally managed text that must not be
965 * modified or freed.
967 * Returns: the requested tag
969 const gchar *
970 adg_dim_style_get_number_tag(AdgDimStyle *dim_style)
972 AdgDimStylePrivate *data;
974 g_return_val_if_fail(ADG_IS_DIM_STYLE(dim_style), NULL);
976 data = dim_style->data;
978 return data->number_tag;
982 * adg_dim_style_set_number_tag:
983 * @dim_style: an #AdgDimStyle object
984 * @tag: the new tag
986 * Sets a new "number-tag" value.
988 void
989 adg_dim_style_set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
991 g_return_if_fail(ADG_IS_DIM_STYLE(dim_style));
993 set_number_tag(dim_style, tag);
994 g_object_notify((GObject *) dim_style, "number-tag");
998 static void
999 apply(AdgStyle *style, cairo_t *cr)
1003 static void
1004 set_quote_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1006 AdgDimStylePrivate *data = dim_style->data;
1008 cpml_pair_copy(&data->quote_shift, shift);
1011 static void
1012 set_tolerance_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1014 AdgDimStylePrivate *data = dim_style->data;
1016 cpml_pair_copy(&data->tolerance_shift, shift);
1019 static void
1020 set_note_shift(AdgDimStyle *dim_style, const AdgPair *shift)
1022 AdgDimStylePrivate *data = dim_style->data;
1024 cpml_pair_copy(&data->note_shift, shift);
1027 static void
1028 set_number_format(AdgDimStyle *dim_style, const gchar *format)
1030 AdgDimStylePrivate *data = dim_style->data;
1032 g_free(data->number_format);
1033 data->number_format = g_strdup(format);
1036 static void
1037 set_number_tag(AdgDimStyle *dim_style, const gchar *tag)
1039 AdgDimStylePrivate *data = dim_style->data;
1041 g_free(data->number_tag);
1042 data->number_tag = g_strdup(tag);