adg: removed AdgPattern
[adg.git] / src / adg / adg-dress-builtins.c
blobe8977c47e0f0f8677b5add002e20dad02e56e198
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012 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-dress-builtins
23 * @Section_Id:dress-builtins
24 * @title: Built-in dresses
25 * @short_description: A list of predefined dresses implemented
26 * by the ADG canvas
28 * This is a collection of built-it dresses used internally by
29 * the ADG library to provide some useful defaults.
31 * Since: 1.0
32 **/
35 #include "adg-internal.h"
36 #include "adg-text-internal.h"
38 #include "adg-model.h"
39 #include "adg-trail.h"
40 #include "adg-marker.h"
41 #include "adg-dress.h"
42 #include "adg-color-style.h"
43 #include "adg-dash.h"
44 #include "adg-line-style.h"
45 #include "adg-fill-style.h"
46 #include "adg-dim-style.h"
47 #include "adg-table-style.h"
48 #include "adg-arrow.h"
49 #include "adg-ruled-fill.h"
51 #include "adg-dress-builtins.h"
53 #define MM *2.83464566927
56 /**
57 * ADG_DRESS_UNDEFINED:
59 * A value reperesenting an undefined #AdgDress.
61 * Since: 1.0
62 **/
64 /**
65 * ADG_DRESS_COLOR:
67 * The default builtin #AdgDress color.
68 * This is a pass-through dress, that is it does not change
69 * the cairo context when it is applied.
71 * This dress will be resolved to an #AdgColorStyle instance.
73 * Since: 1.0
74 **/
75 AdgDress
76 _adg_dress_color(void)
78 static AdgDress dress = 0;
80 if (G_UNLIKELY(dress == 0)) {
81 dress = adg_dress_new_full("color", NULL, ADG_TYPE_COLOR_STYLE);
84 return dress;
87 /**
88 * ADG_DRESS_COLOR_BACKGROUND:
90 * The default builtin #AdgDress color to be used as the #AdgCanvas
91 * background. The fallback style is a full opaque white.
93 * This dress will be resolved to an #AdgColorStyle instance.
95 * Since: 1.0
96 **/
97 AdgDress
98 _adg_dress_color_background(void)
100 static AdgDress dress = 0;
102 if (G_UNLIKELY(dress == 0)) {
103 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE,
104 "blue", 1., "green", 1.,
105 "red", 1., NULL);
107 dress = adg_dress_new("color-background", fallback);
108 g_object_unref(fallback);
111 return dress;
115 * ADG_DRESS_COLOR_STROKE:
117 * The default builtin #AdgDress color for #AdgStroke entities.
118 * The fallback style is a full opaque black.
120 * This dress will be resolved to an #AdgColorStyle instance.
122 * Since: 1.0
124 AdgDress
125 _adg_dress_color_stroke(void)
127 static AdgDress dress = 0;
129 if (G_UNLIKELY(dress == 0)) {
130 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE, NULL);
132 dress = adg_dress_new("color-stroke", fallback);
133 g_object_unref(fallback);
136 return dress;
140 * ADG_DRESS_COLOR_DIMENSION:
142 * The builtin #AdgDress color used by default in #AdgDimStyle.
143 * The fallback style is a somewhat full opaque blue.
145 * This dress will be resolved to an #AdgColorStyle instance.
147 * Since: 1.0
149 AdgDress
150 _adg_dress_color_dimension(void)
152 static AdgDress dress = 0;
154 if (G_UNLIKELY(dress == 0)) {
155 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE,
156 "red", 0.,
157 "green", 0.4,
158 "blue", 0.6,
159 NULL);
161 dress = adg_dress_new("color-dimension", fallback);
162 g_object_unref(fallback);
165 return dress;
169 * ADG_DRESS_COLOR_ANNOTATION:
171 * The builtin #AdgDress color used for rendering helper entities
172 * such as #AdgToyText, #AdgTable and #AdgTitleBlock. The fallback
173 * style is a full opaque greenish variant.
175 * This dress will be resolved to an #AdgColorStyle instance.
177 * Since: 1.0
179 AdgDress
180 _adg_dress_color_annotation(void)
182 static AdgDress dress = 0;
184 if (G_UNLIKELY(dress == 0)) {
185 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE,
186 "red", 0.4,
187 "green", 0.4,
188 "blue", 0.2,
189 NULL);
191 dress = adg_dress_new("color-annotation", fallback);
192 g_object_unref(fallback);
195 return dress;
199 * ADG_DRESS_COLOR_FILL:
201 * The builtin #AdgDress color used by default by #AdgFillStyle
202 * based styles. The fallback style is a full opaque %0.25 gray.
204 * This dress will be resolved to an #AdgColorStyle instance.
206 * Since: 1.0
208 AdgDress
209 _adg_dress_color_fill(void)
211 static AdgDress dress = 0;
213 if (G_UNLIKELY(dress == 0)) {
214 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE,
215 "red", 0.25,
216 "green", 0.25,
217 "blue", 0.25, NULL);
219 dress = adg_dress_new("color-fill", fallback);
220 g_object_unref(fallback);
223 return dress;
227 * ADG_DRESS_COLOR_AXIS:
229 * The default builtin #AdgDress color for stroking #ADG_DRESS_LINE_AXIS
230 * lines. The fallback color is green.
232 * This dress will be resolved to an #AdgColorStyle instance.
234 * Since: 1.0
236 AdgDress
237 _adg_dress_color_axis(void)
239 static AdgDress dress = 0;
241 if (G_UNLIKELY(dress == 0)) {
242 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE,
243 "red", 0.,
244 "green", 0.75,
245 "blue", 0.25, NULL);
247 dress = adg_dress_new("color-axis", fallback);
248 g_object_unref(fallback);
251 return dress;
255 * ADG_DRESS_COLOR_HIDDEN:
257 * The default builtin #AdgDress color for stroking #ADG_DRESS_LINE_HIDDEN
258 * lines. The fallback color is gray.
260 * This dress will be resolved to an #AdgColorStyle instance.
262 * Since: 1.0
264 AdgDress
265 _adg_dress_color_hidden(void)
267 static AdgDress dress = 0;
269 if (G_UNLIKELY(dress == 0)) {
270 AdgStyle *fallback = g_object_new(ADG_TYPE_COLOR_STYLE,
271 "red", 0.5,
272 "green", 0.5,
273 "blue", 0.5, NULL);
275 dress = adg_dress_new("color-hidden", fallback);
276 g_object_unref(fallback);
279 return dress;
283 * ADG_DRESS_LINE:
285 * The default builtin #AdgDress line.
286 * This is a pass-through dress, that is it does not change
287 * the cairo context when it is applied.
289 * This dress will be resolved to an #AdgLineStyle instance.
291 * Since: 1.0
293 AdgDress
294 _adg_dress_line(void)
296 static AdgDress dress = 0;
298 if (G_UNLIKELY(dress == 0)) {
299 dress = adg_dress_new_full("line", NULL, ADG_TYPE_LINE_STYLE);
302 return dress;
306 * ADG_DRESS_LINE_STROKE:
308 * The builtin #AdgDress line type to be used by default
309 * for rendering #AdgStroke entities. The fallback style is
310 * a line with #ADG_DRESS_COLOR_STROKE color and a thickness
311 * of %1.5.
313 * This dress will be resolved to an #AdgLineStyle instance.
315 * Since: 1.0
317 AdgDress
318 _adg_dress_line_stroke(void)
320 static AdgDress dress = 0;
322 if (G_UNLIKELY(dress == 0)) {
323 AdgStyle *fallback = g_object_new(ADG_TYPE_LINE_STYLE,
324 "color-dress", ADG_DRESS_COLOR_STROKE,
325 "width", 1.5, NULL);
327 dress = adg_dress_new("line-stroke", fallback);
328 g_object_unref(fallback);
331 return dress;
335 * ADG_DRESS_LINE_DIMENSION:
337 * The builtin #AdgDress line type used by default
338 * for rendering base and extension lines of dimensions.
339 * The fallback style is a line with a thickness of %0.5
340 * and a pass-through color dress.
342 * This dress will be resolved to an #AdgLineStyle instance.
344 * Since: 1.0
346 AdgDress
347 _adg_dress_line_dimension(void)
349 static AdgDress dress = 0;
351 if (G_UNLIKELY(dress == 0)) {
352 AdgStyle *fallback = g_object_new(ADG_TYPE_LINE_STYLE,
353 "width", 0.5, NULL);
355 dress = adg_dress_new("line-dimension", fallback);
356 g_object_unref(fallback);
359 return dress;
363 * ADG_DRESS_LINE_FILL:
365 * The builtin #AdgDress line type used by #AdgFillStyle
366 * based styles. The fallback style is a line with
367 * #ADG_DRESS_COLOR_FILL color and a thickness of %0.5.
369 * This dress will be resolved to an #AdgLineStyle instance.
371 * Since: 1.0
373 AdgDress
374 _adg_dress_line_fill(void)
376 static AdgDress dress = 0;
378 if (G_UNLIKELY(dress == 0)) {
379 AdgStyle *fallback = g_object_new(ADG_TYPE_LINE_STYLE,
380 "color-dress", ADG_DRESS_COLOR_FILL,
381 "width", 0.5, NULL);
383 dress = adg_dress_new("line-fill", fallback);
384 g_object_unref(fallback);
387 return dress;
391 * ADG_DRESS_LINE_GRID:
393 * The builtin #AdgDress line type used for rendering the grid
394 * of #AdgTable entities, that is the frame of the cells.
395 * The fallback style is a line with a thickness of %1 and a
396 * pass-through color dress, rendered without antialiasing.
398 * This dress will be resolved to an #AdgLineStyle instance.
400 * Since: 1.0
402 AdgDress
403 _adg_dress_line_grid(void)
405 static AdgDress dress = 0;
407 if (G_UNLIKELY(dress == 0)) {
408 AdgStyle *fallback = g_object_new(ADG_TYPE_LINE_STYLE,
409 "antialias", CAIRO_ANTIALIAS_NONE,
410 "width", 1., NULL);
412 dress = adg_dress_new("line-grid", fallback);
413 g_object_unref(fallback);
416 return dress;
420 * ADG_DRESS_LINE_FRAME:
422 * The builtin #AdgDress line type used for rendering the frame
423 * of #AdgTable entities, that is the frame around the whole table.
424 * The fallback style is a line with a thickness of %2 and a
425 * #ADG_DRESS_COLOR_ANNOTATION color dress, rendered without
426 * antialiasing.
428 * This dress will be resolved to an #AdgLineStyle instance.
430 * Since: 1.0
432 AdgDress
433 _adg_dress_line_frame(void)
435 static AdgDress dress = 0;
437 if (G_UNLIKELY(dress == 0)) {
438 AdgStyle *fallback = g_object_new(ADG_TYPE_LINE_STYLE,
439 "color-dress", ADG_DRESS_COLOR_ANNOTATION,
440 "antialias", CAIRO_ANTIALIAS_NONE,
441 "width", 2., NULL);
443 dress = adg_dress_new("line-frame", fallback);
444 g_object_unref(fallback);
447 return dress;
451 * ADG_DRESS_LINE_AXIS:
453 * The builtin #AdgDress line type used for rendering axis and
454 * centerlines.
456 * This dress will be resolved to an #AdgLineStyle instance.
458 * Since: 1.0
460 AdgDress
461 _adg_dress_line_axis(void)
463 static AdgDress dress = 0;
465 if (G_UNLIKELY(dress == 0)) {
466 AdgDash *dash;
467 AdgStyle *fallback;
469 dash = adg_dash_new_with_dashes(4, 2 MM, 2 MM, 10 MM, 2 MM);
470 fallback = g_object_new(ADG_TYPE_LINE_STYLE,
471 "dash", dash,
472 "color-dress", ADG_DRESS_COLOR_AXIS,
473 "width", 0.25 MM, NULL);
474 adg_dash_destroy(dash);
476 dress = adg_dress_new("line-axis", fallback);
477 g_object_unref(fallback);
480 return dress;
484 * ADG_DRESS_LINE_HIDDEN:
486 * The builtin #AdgDress line type used for rendering hidden
487 * lines and edges.
489 * This dress will be resolved to an #AdgLineStyle instance.
491 * Since: 1.0
493 AdgDress
494 _adg_dress_line_hidden(void)
496 static AdgDress dress = 0;
498 if (G_UNLIKELY(dress == 0)) {
499 AdgDash *dash;
500 AdgStyle *fallback;
502 dash = adg_dash_new_with_dashes(2, 6 MM, 6 MM);
503 fallback = g_object_new(ADG_TYPE_LINE_STYLE,
504 "dash", dash,
505 "color-dress", ADG_DRESS_COLOR_HIDDEN,
506 "width", 0.25 MM, NULL);
507 adg_dash_destroy(dash);
509 dress = adg_dress_new("line-hidden", fallback);
510 g_object_unref(fallback);
513 return dress;
517 * ADG_DRESS_FONT:
519 * The default builtin #AdgDress font. The fallback style is
520 * a %Sans %14 font with a pass-through color dress.
522 * This dress will be resolved to an #AdgFontStyle instance.
524 * Since: 1.0
526 AdgDress
527 _adg_dress_font(void)
529 static AdgDress dress = 0;
531 if (G_UNLIKELY(dress == 0)) {
532 AdgStyle *fallback = g_object_new(ADG_TYPE_BEST_FONT_STYLE,
533 "family", "Serif",
534 "size", 14., NULL);
536 dress = adg_dress_new("font", fallback);
537 g_object_unref(fallback);
540 return dress;
544 * ADG_DRESS_FONT_TEXT:
546 * The builtin #AdgDress font used by default for rendering
547 * common text such as #AdgToyText or the value of #AdgTable
548 * entities. The fallback style is %Sans %12 %bold with an
549 * #ADG_DRESS_COLOR_ANNOTATION color dress.
551 * This dress will be resolved to an #AdgFontStyle instance.
553 * Since: 1.0
555 AdgDress
556 _adg_dress_font_text(void)
558 static AdgDress dress = 0;
560 if (G_UNLIKELY(dress == 0)) {
561 AdgStyle *fallback = g_object_new(ADG_TYPE_BEST_FONT_STYLE,
562 "color-dress", ADG_DRESS_COLOR_ANNOTATION,
563 "family", "Sans",
564 "weight", CAIRO_FONT_WEIGHT_BOLD,
565 "size", 12., NULL);
567 dress = adg_dress_new("font-text", fallback);
568 g_object_unref(fallback);
571 return dress;
575 * ADG_DRESS_FONT_ANNOTATION:
577 * The builtin #AdgDress font used for rendering auxiliary text,
578 * such as the titles on #AdgTable entities. The fallback style
579 * is a %Sans %8 with an #ADG_DRESS_COLOR_ANNOTATION color dress.
581 * This dress will be resolved to an #AdgFontStyle instance.
583 * Since: 1.0
585 AdgDress
586 _adg_dress_font_annotation(void)
588 static AdgDress dress = 0;
590 if (G_UNLIKELY(dress == 0)) {
591 AdgStyle *fallback = g_object_new(ADG_TYPE_BEST_FONT_STYLE,
592 "color-dress", ADG_DRESS_COLOR_ANNOTATION,
593 "family", "Sans",
594 "size", 8., NULL);
596 dress = adg_dress_new("font-annotation", fallback);
597 g_object_unref(fallback);
600 return dress;
604 * ADG_DRESS_FONT_QUOTE_TEXT:
606 * The builtin #AdgDress font used for rendering regular text
607 * on dimension entities, such as the nominal value and the
608 * notes of a quote. The fallback style is %Sans %12 %bold with
609 * a pass-through color dress.
611 * This dress will be resolved to an #AdgFontStyle instance.
613 * Since: 1.0
615 AdgDress
616 _adg_dress_font_quote_text(void)
618 static AdgDress dress = 0;
620 if (G_UNLIKELY(dress == 0)) {
621 AdgStyle *fallback = g_object_new(ADG_TYPE_BEST_FONT_STYLE,
622 "family", "Sans",
623 "weight", CAIRO_FONT_WEIGHT_BOLD,
624 "size", 12., NULL);
626 dress = adg_dress_new("font-quote-text", fallback);
627 g_object_unref(fallback);
630 return dress;
634 * ADG_DRESS_FONT_QUOTE_ANNOTATION:
636 * The builtin #AdgDress font used for rendering auxiliary text
637 * on dimension entities, such as the min and max limits of a
638 * quote. The fallback style is a %Sans %8 with a pass-through
639 * color dress.
641 * This dress will be resolved to an #AdgFontStyle instance.
643 * Since: 1.0
645 AdgDress
646 _adg_dress_font_quote_annotation(void)
648 static AdgDress dress = 0;
650 if (G_UNLIKELY(dress == 0)) {
651 AdgStyle *fallback = g_object_new(ADG_TYPE_BEST_FONT_STYLE,
652 "family", "Sans",
653 "size", 8., NULL);
655 dress = adg_dress_new("font-quote-annotation", fallback);
656 g_object_unref(fallback);
659 return dress;
663 * ADG_DRESS_DIMENSION:
665 * The default builtin #AdgDress for dimensions. The fallback
666 * style is the default #AdgDimStyle implementation with
667 * #AdgArrow markers (as returned by adg_arrow_new() on both sides.
669 * This dress will be resolved to an #AdgDimStyle instance.
671 * Since: 1.0
673 AdgDress
674 _adg_dress_dimension(void)
676 static AdgDress dress = 0;
678 if (G_UNLIKELY(dress == 0)) {
679 AdgMarker *arrow = (AdgMarker *) adg_arrow_new();
680 AdgStyle *fallback = g_object_new(ADG_TYPE_DIM_STYLE, NULL);
682 adg_dim_style_set_marker1((AdgDimStyle *) fallback, arrow);
683 adg_marker_set_pos(arrow, 1);
684 adg_dim_style_set_marker2((AdgDimStyle *) fallback, arrow);
686 dress = adg_dress_new("dimension", fallback);
687 g_object_unref(fallback);
688 g_object_unref(arrow);
691 return dress;
695 * ADG_DRESS_FILL:
697 * The default builtin #AdgDress for filling.
698 * This is a pass-through dress, that is it does not change
699 * the cairo context when it is applied.
701 * This dress will be resolved to an #AdgFillStyle derived instance.
703 * Since: 1.0
705 AdgDress
706 _adg_dress_fill(void)
708 static AdgDress dress = 0;
710 if (G_UNLIKELY(dress == 0)) {
711 dress = adg_dress_new_full("fill", NULL, ADG_TYPE_FILL_STYLE);
714 return dress;
718 * ADG_DRESS_FILL_HATCH:
720 * The builtin dress used by default by #AdgHatch instances.
721 * The fallback style is the default implementation of the
722 * #AdgRuledFill instance.
724 * This dress will be resolved to an #AdgFillStyle derived instance.
726 * Since: 1.0
728 AdgDress
729 _adg_dress_fill_hatch(void)
731 static AdgDress dress = 0;
733 if (G_UNLIKELY(dress == 0)) {
734 AdgStyle *fallback = g_object_new(ADG_TYPE_RULED_FILL,
735 "line-dress", ADG_DRESS_LINE_FILL,
736 NULL);
738 dress = adg_dress_new_full("fill-hatch", fallback, ADG_TYPE_FILL_STYLE);
739 g_object_unref(fallback);
742 return dress;
746 * ADG_DRESS_TABLE:
748 * The default builtin #AdgDress for tables. The fallback style
749 * is the default implementation of the #AdgTableStyle instance.
751 * This dress will be resolved to an #AdgTableStyle derived instance.
753 * Since: 1.0
755 AdgDress
756 _adg_dress_table(void)
758 static AdgDress dress = 0;
760 if (G_UNLIKELY(dress == 0)) {
761 AdgStyle *fallback = g_object_new(ADG_TYPE_TABLE_STYLE, NULL);
762 dress = adg_dress_new_full("table", fallback, ADG_TYPE_TABLE_STYLE);
763 g_object_unref(fallback);
766 return dress;