1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML library. |
---|
3 | |
---|
4 | Copyright (C) 1997 Martin Jones (mjones@kde.org) |
---|
5 | Copyright (C) 1997 Torben Weis (weis@kde.org) |
---|
6 | Copyright (C) 1999, 2000 Helix Code, Inc. |
---|
7 | |
---|
8 | This library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU Library General Public |
---|
10 | License as published by the Free Software Foundation; either |
---|
11 | version 2 of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | This library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | Library General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Library General Public License |
---|
19 | along with this library; see the file COPYING.LIB. If not, write to |
---|
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef _HTMLPAINTER_H_ |
---|
25 | #define _HTMLPAINTER_H_ |
---|
26 | |
---|
27 | #include <gdk-pixbuf/gdk-pixbuf.h> |
---|
28 | #include <gdk/gdktypes.h> |
---|
29 | #include <glib-object.h> |
---|
30 | #include <gtk/gtkwidget.h> |
---|
31 | |
---|
32 | #include "gtkhtml-enums.h" |
---|
33 | #include "htmltypes.h" |
---|
34 | #include "htmlfontmanager.h" |
---|
35 | |
---|
36 | |
---|
37 | #define HTML_TYPE_PAINTER (html_painter_get_type ()) |
---|
38 | #define HTML_PAINTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HTML_TYPE_PAINTER, HTMLPainter)) |
---|
39 | #define HTML_PAINTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HTML_TYPE_PAINTER, HTMLPainterClass)) |
---|
40 | #define HTML_IS_PAINTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HTML_TYPE_PAINTER)) |
---|
41 | #define HTML_IS_PAINTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HTML_TYPE_PAINTER)) |
---|
42 | |
---|
43 | |
---|
44 | struct _HTMLPainter { |
---|
45 | GObject base; |
---|
46 | |
---|
47 | GtkWidget *widget; |
---|
48 | HTMLFontManager font_manager; |
---|
49 | HTMLFontFace *font_face; |
---|
50 | GtkHTMLFontStyle font_style; |
---|
51 | |
---|
52 | gboolean focus; |
---|
53 | }; |
---|
54 | |
---|
55 | struct _HTMLPainterClass { |
---|
56 | GObjectClass base; |
---|
57 | |
---|
58 | void (* set_widget) (HTMLPainter *painter, GtkWidget *widget); |
---|
59 | void (* begin) (HTMLPainter *painter, int x1, int y1, int x2, int y2); |
---|
60 | void (* end) (HTMLPainter *painter); |
---|
61 | |
---|
62 | HTMLFont * (* alloc_font) (HTMLPainter *p, gchar *face_name, gdouble size, gboolean points, GtkHTMLFontStyle style); |
---|
63 | void (* ref_font) (HTMLPainter *p, HTMLFont *font); |
---|
64 | void (* unref_font) (HTMLPainter *p, HTMLFont *font); |
---|
65 | |
---|
66 | void (* alloc_color) (HTMLPainter *painter, GdkColor *color); |
---|
67 | void (* free_color) (HTMLPainter *painter, GdkColor *color); |
---|
68 | |
---|
69 | void (* calc_text_size) (HTMLPainter *p, const gchar *text, guint len, HTMLTextPangoInfo *pi, PangoAttrList *attrs, GList *glyphs, gint start_byte_offset, |
---|
70 | GtkHTMLFontStyle font_style, HTMLFontFace *face, gint *width, gint *asc, gint *dsc); |
---|
71 | void (* calc_text_size_bytes) (HTMLPainter *p, const gchar *text, guint len, HTMLTextPangoInfo *pi, PangoAttrList *attrs, GList *glyphs, gint start_byte_offset, |
---|
72 | HTMLFont *font, GtkHTMLFontStyle font_style, gint *width, gint *asc, gint *dsc); |
---|
73 | |
---|
74 | void (* set_pen) (HTMLPainter *painter, const GdkColor *color); |
---|
75 | const GdkColor * (* get_black) (const HTMLPainter *painter); |
---|
76 | void (* draw_line) (HTMLPainter *painter, gint x1, gint y1, gint x2, gint y2); |
---|
77 | void (* draw_rect) (HTMLPainter *painter, gint x, gint y, gint width, gint height); |
---|
78 | gint (* draw_text) (HTMLPainter *painter, gint x, gint y, const gchar *text, gint len, HTMLTextPangoInfo *pi, PangoAttrList *attrs, GList *glyphs, gint start_byte_offset); |
---|
79 | gint (* draw_spell_error) (HTMLPainter *painter, gint x, gint y, const gchar *text, gint len, HTMLTextPangoInfo *pi, GList *glyphs, gint start_byte_offset); |
---|
80 | void (* fill_rect) (HTMLPainter *painter, gint x, gint y, gint width, gint height); |
---|
81 | void (* draw_pixmap) (HTMLPainter *painter, GdkPixbuf *pixbuf, |
---|
82 | gint x, gint y, |
---|
83 | gint scale_width, |
---|
84 | gint scale_height, |
---|
85 | const GdkColor *color); |
---|
86 | void (* draw_ellipse) (HTMLPainter *painter, gint x, gint y, gint width, gint height); |
---|
87 | void (* clear) (HTMLPainter *painter); |
---|
88 | void (* set_background_color) (HTMLPainter *painter, const GdkColor *color); |
---|
89 | void (* draw_shade_line) (HTMLPainter *p, gint x, gint y, gint width); |
---|
90 | void (* draw_panel) (HTMLPainter *painter, GdkColor *bg, |
---|
91 | gint x, gint y, gint width, gint height, |
---|
92 | GtkHTMLEtchStyle inset, gint bordersize); |
---|
93 | |
---|
94 | void (* set_clip_rectangle) (HTMLPainter *painter, gint x, gint y, gint width, gint height); |
---|
95 | void (* draw_background) (HTMLPainter *painter, GdkColor *color, GdkPixbuf *pixbuf, |
---|
96 | gint x, gint y, gint width, gint height, gint tile_x, gint tile_y); |
---|
97 | guint (* get_pixel_size) (HTMLPainter *painter); |
---|
98 | void (* draw_embedded) (HTMLPainter *painter, HTMLEmbedded *element, gint x, gint y); |
---|
99 | |
---|
100 | guint (*get_page_width) (HTMLPainter *painter, HTMLEngine *e); |
---|
101 | guint (*get_page_height) (HTMLPainter *painter, HTMLEngine *e); |
---|
102 | }; |
---|
103 | |
---|
104 | |
---|
105 | /* Creation. */ |
---|
106 | GType html_painter_get_type (void); |
---|
107 | |
---|
108 | void html_painter_set_widget (HTMLPainter *painter, |
---|
109 | GtkWidget *widget); |
---|
110 | |
---|
111 | /* Functions to drive the painting process. */ |
---|
112 | void html_painter_begin (HTMLPainter *painter, |
---|
113 | int x1, |
---|
114 | int y1, |
---|
115 | int x2, |
---|
116 | int y2); |
---|
117 | void html_painter_end (HTMLPainter *painter); |
---|
118 | |
---|
119 | /* Color control. */ |
---|
120 | void html_painter_alloc_color (HTMLPainter *painter, |
---|
121 | GdkColor *color); |
---|
122 | void html_painter_free_color (HTMLPainter *painter, |
---|
123 | GdkColor *color); |
---|
124 | |
---|
125 | /* Color set handling. */ |
---|
126 | const GdkColor *html_painter_get_default_background_color (HTMLPainter *painter); |
---|
127 | const GdkColor *html_painter_get_default_foreground_color (HTMLPainter *painter); |
---|
128 | const GdkColor *html_painter_get_default_link_color (HTMLPainter *painter); |
---|
129 | const GdkColor *html_painter_get_default_highlight_color (HTMLPainter *painter); |
---|
130 | const GdkColor *html_painter_get_default_highlight_foreground_color (HTMLPainter *painter); |
---|
131 | const GdkColor *html_painter_get_black (const HTMLPainter *painter); |
---|
132 | |
---|
133 | /* Font handling. */ |
---|
134 | HTMLFontFace *html_painter_find_font_face (HTMLPainter *p, |
---|
135 | const gchar *families); |
---|
136 | void html_painter_set_font_style (HTMLPainter *p, |
---|
137 | GtkHTMLFontStyle f); |
---|
138 | GtkHTMLFontStyle html_painter_get_font_style (HTMLPainter *p); |
---|
139 | void html_painter_set_font_face (HTMLPainter *p, |
---|
140 | HTMLFontFace *f); |
---|
141 | gpointer html_painter_get_font (HTMLPainter *painter, |
---|
142 | HTMLFontFace *face, |
---|
143 | GtkHTMLFontStyle style); |
---|
144 | void html_painter_calc_text_size (HTMLPainter *p, |
---|
145 | const gchar *text, |
---|
146 | guint len, |
---|
147 | HTMLTextPangoInfo *pi, |
---|
148 | PangoAttrList *attrs, |
---|
149 | GList *glyphs, |
---|
150 | gint start_byte_offset, |
---|
151 | gint *line_offset, |
---|
152 | GtkHTMLFontStyle font_style, |
---|
153 | HTMLFontFace *face, |
---|
154 | gint *width, |
---|
155 | gint *asc, |
---|
156 | gint *dsc); |
---|
157 | void html_painter_calc_text_size_bytes (HTMLPainter *p, |
---|
158 | const gchar *text, |
---|
159 | guint len, |
---|
160 | HTMLTextPangoInfo *pi, |
---|
161 | PangoAttrList *attrs, |
---|
162 | GList *glyphs, |
---|
163 | gint start_byte_offset, |
---|
164 | gint *line_offset, |
---|
165 | HTMLFont *font, |
---|
166 | GtkHTMLFontStyle font_style, |
---|
167 | gint *width, |
---|
168 | gint *asc, |
---|
169 | gint *dsc); |
---|
170 | |
---|
171 | /* The actual paint operations. */ |
---|
172 | void html_painter_set_pen (HTMLPainter *painter, |
---|
173 | const GdkColor *color); |
---|
174 | void html_painter_draw_line (HTMLPainter *painter, |
---|
175 | gint x1, |
---|
176 | gint y1, |
---|
177 | gint x2, |
---|
178 | gint y2); |
---|
179 | void html_painter_draw_rect (HTMLPainter *painter, |
---|
180 | gint x, |
---|
181 | gint y, |
---|
182 | gint width, |
---|
183 | gint height); |
---|
184 | gint html_painter_draw_text (HTMLPainter *painter, |
---|
185 | gint x, |
---|
186 | gint y, |
---|
187 | const gchar *text, |
---|
188 | gint len, |
---|
189 | HTMLTextPangoInfo *pi, |
---|
190 | PangoAttrList *attrs, |
---|
191 | GList *glyphs, |
---|
192 | gint start_byte_offset, |
---|
193 | gint line_offset); |
---|
194 | void html_painter_fill_rect (HTMLPainter *painter, |
---|
195 | gint x, |
---|
196 | gint y, |
---|
197 | gint width, |
---|
198 | gint height); |
---|
199 | void html_painter_draw_pixmap (HTMLPainter *painter, |
---|
200 | GdkPixbuf *pixbuf, |
---|
201 | gint x, |
---|
202 | gint y, |
---|
203 | gint scale_width, |
---|
204 | gint scale_height, |
---|
205 | const GdkColor *color); |
---|
206 | void html_painter_draw_ellipse (HTMLPainter *painter, |
---|
207 | gint x, |
---|
208 | gint y, |
---|
209 | gint width, |
---|
210 | gint height); |
---|
211 | void html_painter_clear (HTMLPainter *painter); |
---|
212 | void html_painter_set_background_color (HTMLPainter *painter, |
---|
213 | const GdkColor *color); |
---|
214 | void html_painter_draw_shade_line (HTMLPainter *p, |
---|
215 | gint x, |
---|
216 | gint y, |
---|
217 | gint width); |
---|
218 | void html_painter_draw_panel (HTMLPainter *painter, |
---|
219 | GdkColor *bg, |
---|
220 | gint x, |
---|
221 | gint y, |
---|
222 | gint width, |
---|
223 | gint height, |
---|
224 | GtkHTMLEtchStyle inset, |
---|
225 | gint bordersize); |
---|
226 | |
---|
227 | /* Passing 0 for width/height means remove clip rectangle */ |
---|
228 | void html_painter_set_clip_rectangle (HTMLPainter *painter, |
---|
229 | gint x, |
---|
230 | gint y, |
---|
231 | gint width, |
---|
232 | gint height); |
---|
233 | |
---|
234 | /* Passing 0 for pix_width / pix_height makes it use the image width */ |
---|
235 | void html_painter_draw_background (HTMLPainter *painter, |
---|
236 | GdkColor *color, |
---|
237 | GdkPixbuf *pixbuf, |
---|
238 | gint x, |
---|
239 | gint y, |
---|
240 | gint width, |
---|
241 | gint height, |
---|
242 | gint tile_x, |
---|
243 | gint tile_y); |
---|
244 | guint html_painter_get_pixel_size (HTMLPainter *painter); |
---|
245 | gint html_painter_draw_spell_error (HTMLPainter *painter, |
---|
246 | gint x, |
---|
247 | gint y, |
---|
248 | const gchar *text, |
---|
249 | gint len, |
---|
250 | HTMLTextPangoInfo *pi, |
---|
251 | GList *glyphs, |
---|
252 | gint start_byte_offset); |
---|
253 | HTMLFont *html_painter_alloc_font (HTMLPainter *painter, |
---|
254 | gchar *face_name, |
---|
255 | gdouble size, |
---|
256 | gboolean points, |
---|
257 | GtkHTMLFontStyle style); |
---|
258 | void html_painter_ref_font (HTMLPainter *painter, |
---|
259 | HTMLFont *font); |
---|
260 | void html_painter_unref_font (HTMLPainter *painter, |
---|
261 | HTMLFont *font); |
---|
262 | guint html_painter_get_space_width (HTMLPainter *painter, |
---|
263 | GtkHTMLFontStyle font_style, |
---|
264 | HTMLFontFace *face); |
---|
265 | guint html_painter_get_space_asc (HTMLPainter *painter, |
---|
266 | GtkHTMLFontStyle font_style, |
---|
267 | HTMLFontFace *face); |
---|
268 | guint html_painter_get_space_dsc (HTMLPainter *painter, |
---|
269 | GtkHTMLFontStyle font_style, |
---|
270 | HTMLFontFace *face); |
---|
271 | guint html_painter_get_e_width (HTMLPainter *painter, |
---|
272 | GtkHTMLFontStyle font_style, |
---|
273 | HTMLFontFace *face); |
---|
274 | guint html_painter_get_block_indent_width (HTMLPainter *painter, |
---|
275 | GtkHTMLFontStyle font_style, |
---|
276 | HTMLFontFace *face); |
---|
277 | guint html_painter_get_block_cite_width (HTMLPainter *painter, |
---|
278 | GtkHTMLFontStyle font_style, |
---|
279 | HTMLFontFace *face); |
---|
280 | void html_painter_draw_embedded (HTMLPainter *painter, |
---|
281 | HTMLEmbedded *element, |
---|
282 | gint x, |
---|
283 | gint y); |
---|
284 | guint html_painter_get_page_width (HTMLPainter *painter, |
---|
285 | HTMLEngine *e); |
---|
286 | guint html_painter_get_page_height (HTMLPainter *painter, |
---|
287 | HTMLEngine *e); |
---|
288 | void html_painter_set_focus (HTMLPainter *painter, |
---|
289 | gboolean focus); |
---|
290 | void html_replace_tabs (const gchar *text, |
---|
291 | gchar *translated, |
---|
292 | guint bytes); |
---|
293 | |
---|
294 | HTMLTextPangoInfo *html_painter_text_itemize_and_prepare_glyphs (HTMLPainter *painter, |
---|
295 | PangoFontDescription *desc, |
---|
296 | const gchar *text, |
---|
297 | gint bytes, |
---|
298 | GList **glyphs, |
---|
299 | PangoAttrList *attrs); |
---|
300 | void html_painter_glyphs_destroy (GList *glyphs); |
---|
301 | |
---|
302 | #define HTML_BLOCK_INDENT " " |
---|
303 | #define HTML_BLOCK_CITE "> " |
---|
304 | #define HTML_ALLOCA_MAX 2048 |
---|
305 | |
---|
306 | #endif /* _HTMLPAINTER_H_ */ |
---|