1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2008, 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 Library 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 * Library 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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 * @title: AdgLineStyle
24 * @short_description: Line style related stuff
26 * Contains parameters on how to draw lines such as width, cap mode, join mode
27 * and dash composition, if used.
30 #include "adg-line-style.h"
31 #include "adg-line-style-private.h"
35 #define PARENT_CLASS ((AdgStyleClass *) adg_line_style_parent_class)
50 static void get_property (GObject
*object
,
54 static void set_property (GObject
*object
,
60 G_DEFINE_TYPE (AdgLineStyle
, adg_line_style
, ADG_TYPE_STYLE
)
64 adg_line_style_class_init (AdgLineStyleClass
*klass
)
66 GObjectClass
*gobject_class
;
69 gobject_class
= (GObjectClass
*) klass
;
71 g_type_class_add_private (klass
, sizeof (AdgLineStylePrivate
));
73 gobject_class
->get_property
= get_property
;
74 gobject_class
->set_property
= set_property
;
76 param
= g_param_spec_double ("width",
78 P_("The line thickness in device unit"),
81 g_object_class_install_property (gobject_class
, PROP_WIDTH
, param
);
83 param
= g_param_spec_int ("cap",
85 P_("The line cap mode"),
86 G_MININT
, G_MAXINT
, CAIRO_LINE_CAP_ROUND
,
88 g_object_class_install_property (gobject_class
, PROP_CAP
, param
);
90 param
= g_param_spec_int ("join",
92 P_("The line join mode"),
93 G_MININT
, G_MAXINT
, CAIRO_LINE_JOIN_MITER
,
95 g_object_class_install_property (gobject_class
, PROP_JOIN
, param
);
97 param
= g_param_spec_double ("miter-limit",
99 P_("Whether the lines should be joined with a bevel instead of a miter"),
100 0., G_MAXDOUBLE
, 10.,
102 g_object_class_install_property (gobject_class
, PROP_MITER_LIMIT
, param
);
104 param
= g_param_spec_int ("antialias",
105 P_("Antialiasing Mode"),
106 P_("Type of antialiasing to do when rendering lines"),
107 G_MININT
, G_MAXINT
, CAIRO_ANTIALIAS_DEFAULT
,
109 g_object_class_install_property (gobject_class
, PROP_ANTIALIAS
, param
);
111 /* TODO: PROP_DASH (PROP_DASHES, PROP_NUM_DASHES, PROP_DASH_OFFSET) */
115 adg_line_style_init (AdgLineStyle
*line_style
)
117 AdgLineStylePrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (line_style
,
119 AdgLineStylePrivate
);
122 priv
->cap
= CAIRO_LINE_CAP_ROUND
;
123 priv
->join
= CAIRO_LINE_JOIN_MITER
;
124 priv
->miter_limit
= 10.;
126 priv
->num_dashes
= 0;
127 priv
->dash_offset
= 0.;
129 line_style
->priv
= priv
;
133 get_property (GObject
*object
,
138 AdgLineStyle
*line_style
= (AdgLineStyle
*) object
;
143 g_value_set_double (value
, line_style
->priv
->width
);
146 g_value_set_int (value
, line_style
->priv
->cap
);
149 g_value_set_int (value
, line_style
->priv
->join
);
151 case PROP_MITER_LIMIT
:
152 g_value_set_double (value
, line_style
->priv
->miter_limit
);
155 g_value_set_int (value
, line_style
->priv
->antialias
);
161 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
167 set_property (GObject
*object
,
172 AdgLineStyle
*line_style
= (AdgLineStyle
*) object
;
177 line_style
->priv
->width
= g_value_get_double (value
);
180 line_style
->priv
->cap
= g_value_get_int (value
);
183 line_style
->priv
->join
= g_value_get_int (value
);
185 case PROP_MITER_LIMIT
:
186 line_style
->priv
->miter_limit
= g_value_get_double (value
);
189 line_style
->priv
->antialias
= g_value_get_int (value
);
195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
202 adg_line_style_from_id (AdgLineStyleId id
)
204 static AdgStyle
**builtins
= NULL
;
206 if G_UNLIKELY (builtins
== NULL
)
208 builtins
= g_new (AdgStyle
*, ADG_LINE_STYLE_LAST
);
210 builtins
[ADG_LINE_STYLE_DRAW
] = g_object_new (ADG_TYPE_LINE_STYLE
,
213 builtins
[ADG_LINE_STYLE_CENTER
] = g_object_new (ADG_TYPE_LINE_STYLE
,
217 builtins
[ADG_LINE_STYLE_HIDDEN
] = g_object_new (ADG_TYPE_LINE_STYLE
,
221 builtins
[ADG_LINE_STYLE_XATCH
] = g_object_new (ADG_TYPE_LINE_STYLE
,
225 builtins
[ADG_LINE_STYLE_DIM
] = g_object_new (ADG_TYPE_LINE_STYLE
,
231 g_return_val_if_fail (id
< ADG_LINE_STYLE_LAST
, NULL
);
236 adg_line_style_apply (const AdgLineStyle
*line_style
,
242 g_return_if_fail (line_style
!= NULL
);
243 g_return_if_fail (cr
!= NULL
);
245 device_width
= line_style
->priv
->width
;
246 cairo_device_to_user_distance (cr
, &device_width
, &dummy
);
247 cairo_set_line_width (cr
, device_width
);
249 cairo_set_line_cap (cr
, line_style
->priv
->cap
);
250 cairo_set_line_join (cr
, line_style
->priv
->join
);
251 cairo_set_miter_limit (cr
, line_style
->priv
->miter_limit
);
252 cairo_set_antialias (cr
, line_style
->priv
->antialias
);
254 if (line_style
->priv
->num_dashes
> 0)
256 g_return_if_fail (line_style
->priv
->dashes
!= NULL
);
258 cairo_set_dash (cr
, line_style
->priv
->dashes
, line_style
->priv
->num_dashes
,
259 line_style
->priv
->dash_offset
);