1 /*
2  * go-style.h :
3  *
4  * Copyright (C) 2003-2004 Jody Goldberg (jody@gnome.org)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) version 3.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21 #ifndef GO_UTILS_STYLE_H
22 #define GO_UTILS_STYLE_H
23 
24 #include <goffice/goffice.h>
25 #include <goffice/utils/go-editor.h>
26 
27 G_BEGIN_DECLS
28 
29 #define GO_TYPE_STYLE	(go_style_get_type ())
30 #define GO_STYLE(o)	(G_TYPE_CHECK_INSTANCE_CAST ((o), GO_TYPE_STYLE, GOStyle))
31 #define GO_IS_STYLE(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GO_TYPE_STYLE))
32 
33 GType go_style_get_type (void);
34 
35 typedef enum {
36 	GO_STYLE_OUTLINE	= 1 << 0,
37 	GO_STYLE_FILL		= 1 << 1,
38 	GO_STYLE_LINE		= 1 << 2,
39 	GO_STYLE_MARKER	= 1 << 3,
40 	GO_STYLE_FONT		= 1 << 4,
41 	GO_STYLE_TEXT_LAYOUT	= 1 << 5,
42 	GO_STYLE_INTERPOLATION	= 1 << 6,
43 	GO_STYLE_MARKER_NO_COLOR	= 1 << 7,
44 	GO_STYLE_ALL		= 0x1F
45 } GOStyleFlag;
46 
47 typedef enum {
48 	GO_STYLE_FILL_NONE	= 0,
49 	GO_STYLE_FILL_PATTERN	= 1,
50 	GO_STYLE_FILL_GRADIENT	= 2,
51 	GO_STYLE_FILL_IMAGE	= 3
52 } GOStyleFill;
53 
54 typedef enum {
55 	GO_IMAGE_STRETCHED,
56 	GO_IMAGE_WALLPAPER,
57 	GO_IMAGE_CENTERED,
58 	GO_IMAGE_CENTERED_WALLPAPER
59 } GOImageType;
60 
61 typedef struct {
62 	/* <0 == no outline,
63 	 * =0 == hairline : unscaled, minimum useful (can be bigger than visible) size.
64 	 * >0 in pts */
65 	double	 	 width;
66 	GOLineDashType 	 dash_type;
67 	gboolean	 auto_dash;
68 	GOColor	 	 color; /* color is used as background for compatibility
69 						(pattern == 0 means filled with background color) */
70 	GOColor	 	 fore;
71 	gboolean 	 auto_color;
72 	gboolean 	 auto_fore;
73 	gboolean 	 auto_width;
74 	GOPatternType	 pattern;
75 	cairo_line_cap_t cap;
76 	cairo_line_join_t join;
77 	double		 miter_limit;
78 } GOStyleLine;
79 
80 typedef struct {
81 	GOMarker *mark;
82 	gboolean auto_shape;
83 	gboolean auto_outline_color;
84 	gboolean auto_fill_color;
85 } GOStyleMark;
86 
87 struct _GOStyle {
88 	GObject	base;
89 
90 	GOStyleFlag	interesting_fields;
91 	GOStyleFlag	disable_theming;
92 
93 	GOStyleLine	line;
94 	struct {
95 		GOStyleFill	type;
96 		gboolean	auto_type;
97 		gboolean	auto_fore, auto_back;	/* share between pattern and gradient */
98 		gboolean		auto_pattern;
99 		gboolean	invert_if_negative;	/* placeholder for XL */
100 
101 		/* This could all be a union but why bother ? */
102 		GOPattern pattern;
103 		struct _GOStyleGradient {
104 			GOGradientDirection dir;
105 			double brightness; /* < 0 => 2 color */
106 			gboolean auto_dir;
107 			gboolean auto_brightness;
108 		} gradient;
109 		struct _GOStyleImage {
110 			GOImageType	 type;
111 			GOImage	 *image;
112 		} image;
113 	} fill;
114 	GOStyleMark marker;
115 	struct {
116 		GOColor		 color;
117 		GOFont const 	*font;
118 		gboolean 	 auto_scale;
119 		gboolean	 auto_color;
120 		gboolean	 auto_font;
121 	} font;
122 	struct {
123 		double		 angle;
124 		gboolean	 auto_angle;
125 	} text_layout;
126 };
127 
128 GOStyle  *go_style_new			(void);
129 GOStyle  *go_style_dup			(GOStyle const *style);
130 void	   go_style_assign		(GOStyle *dst, GOStyle const *src);
131 void	   go_style_apply_theme		(GOStyle *dst, GOStyle const *src,
132 					 GOStyleFlag fields);
133 
134 GOMarker const *go_style_get_marker 	(GOStyle const *style);
135 void            go_style_set_marker 	(GOStyle *style, GOMarker *marker);
136 
137 void	   go_style_set_font_desc	(GOStyle *style,
138 					 PangoFontDescription *desc);
139 void	   go_style_set_font		(GOStyle *style, GOFont const *font);
140 void	   go_style_set_fill_brightness	(GOStyle *style, double brightness);
141 void	   go_style_set_text_angle     	(GOStyle *style, double angle);
142 
143 gboolean   go_style_is_different_size	(GOStyle const *a, GOStyle const *b);
144 gboolean   go_style_is_marker_visible	(GOStyle const *style);
145 gboolean   go_style_is_line_visible	(GOStyle const *style);
146 gboolean   go_style_is_outline_visible	(GOStyle const *style);
147 gboolean   go_style_is_fill_visible	(GOStyle const *style);
148 void	   go_style_force_auto		(GOStyle *style);
149 void	   go_style_clear_auto		(GOStyle *style);
150 gboolean   go_style_is_auto		(GOStyle *style);
151 
152 #ifdef GOFFICE_WITH_GTK
153 void 	   go_style_populate_editor 	(GOStyle *style,
154 					 GOEditor *editor,
155 					 GOStyle *default_style,
156 					 GOCmdContext *cc,
157 					 GObject *object_with_style,
158 					 gboolean watch_for_external_change);
159 gpointer   go_style_get_editor	     	(GOStyle *style,
160 					 GOStyle *default_style,
161 					 GOCmdContext *cc,
162 					 GObject *object_with_style);
163 #endif
164 
165 void     go_style_fill			(GOStyle const *style, cairo_t *cr,
166 			                 gboolean preserve);
167 gboolean go_style_set_cairo_line (GOStyle const *style, cairo_t *cr);
168 
169 G_END_DECLS
170 
171 #endif /* GO_UTILS_STYLE_H */
172