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) 2000 Helix Code, Inc. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library 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 GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | #include <string.h> |
---|
24 | #include <stdlib.h> |
---|
25 | #include <gdk/gdkx.h> |
---|
26 | #include <libart_lgpl/art_rect.h> |
---|
27 | |
---|
28 | #include "htmlentity.h" |
---|
29 | #include "htmlgdkpainter.h" |
---|
30 | #include "htmlplainpainter.h" |
---|
31 | #include "htmlcolor.h" |
---|
32 | #include "htmlcolorset.h" |
---|
33 | #include "htmlengine.h" |
---|
34 | #include "htmltext.h" |
---|
35 | |
---|
36 | static HTMLGdkPainterClass *parent_class = NULL; |
---|
37 | |
---|
38 | static void |
---|
39 | draw_panel (HTMLPainter *painter, |
---|
40 | GdkColor *bg, |
---|
41 | gint x, gint y, |
---|
42 | gint width, gint height, |
---|
43 | GtkHTMLEtchStyle inset, |
---|
44 | gint bordersize) |
---|
45 | { |
---|
46 | } |
---|
47 | |
---|
48 | static void |
---|
49 | draw_background (HTMLPainter *painter, |
---|
50 | GdkColor *color, |
---|
51 | GdkPixbuf *pixbuf, |
---|
52 | gint x, gint y, |
---|
53 | gint width, gint height, |
---|
54 | gint tile_x, gint tile_y) |
---|
55 | { |
---|
56 | HTMLGdkPainter *gdk_painter; |
---|
57 | GdkRectangle expose, paint, clip; |
---|
58 | |
---|
59 | gdk_painter = HTML_GDK_PAINTER (painter); |
---|
60 | |
---|
61 | expose.x = x; |
---|
62 | expose.y = y; |
---|
63 | expose.width = width; |
---|
64 | expose.height = height; |
---|
65 | |
---|
66 | clip.x = gdk_painter->x1; |
---|
67 | clip.width = gdk_painter->x2 - gdk_painter->x1; |
---|
68 | clip.y = gdk_painter->y1; |
---|
69 | clip.height = gdk_painter->y2 - gdk_painter->y1; |
---|
70 | |
---|
71 | if (!gdk_rectangle_intersect (&clip, &expose, &paint)) |
---|
72 | return; |
---|
73 | |
---|
74 | if (!color && !pixbuf) |
---|
75 | return; |
---|
76 | |
---|
77 | if (color) { |
---|
78 | gdk_gc_set_foreground (gdk_painter->gc, color); |
---|
79 | gdk_draw_rectangle (gdk_painter->pixmap, gdk_painter->gc, |
---|
80 | TRUE, paint.x - clip.x, paint.y - clip.y, |
---|
81 | paint.width, paint.height); |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | return; |
---|
86 | } |
---|
87 | |
---|
88 | static void |
---|
89 | draw_pixmap (HTMLPainter *painter, |
---|
90 | GdkPixbuf *pixbuf, |
---|
91 | gint x, gint y, |
---|
92 | gint scale_width, gint scale_height, |
---|
93 | const GdkColor *color) |
---|
94 | { |
---|
95 | } |
---|
96 | |
---|
97 | static void |
---|
98 | fill_rect (HTMLPainter *painter, |
---|
99 | gint x, gint y, |
---|
100 | gint width, gint height) |
---|
101 | { |
---|
102 | HTMLGdkPainter *gdk_painter; |
---|
103 | |
---|
104 | gdk_painter = HTML_GDK_PAINTER (painter); |
---|
105 | |
---|
106 | gdk_draw_rectangle (gdk_painter->pixmap, gdk_painter->gc, |
---|
107 | TRUE, x - gdk_painter->x1, y - gdk_painter->y1, |
---|
108 | width, height); |
---|
109 | } |
---|
110 | |
---|
111 | static HTMLFont * |
---|
112 | alloc_fixed_font (HTMLPainter *painter, gchar *face, gdouble size, gboolean points, GtkHTMLFontStyle style) |
---|
113 | { |
---|
114 | return HTML_PAINTER_CLASS (parent_class)->alloc_font (painter, |
---|
115 | face ? painter->font_manager.fixed.face : NULL, |
---|
116 | painter->font_manager.fix_size, painter->font_manager.fix_points, |
---|
117 | GTK_HTML_FONT_STYLE_DEFAULT); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | static void |
---|
122 | draw_shade_line (HTMLPainter *painter, |
---|
123 | gint x, gint y, |
---|
124 | gint width) |
---|
125 | { |
---|
126 | } |
---|
127 | |
---|
128 | static void |
---|
129 | html_plain_painter_init (GObject *object) |
---|
130 | { |
---|
131 | } |
---|
132 | |
---|
133 | static void |
---|
134 | draw_rect (HTMLPainter *painter, |
---|
135 | gint x, gint y, |
---|
136 | gint width, gint height) |
---|
137 | { |
---|
138 | } |
---|
139 | |
---|
140 | static guint |
---|
141 | get_page_width (HTMLPainter *painter, HTMLEngine *e) |
---|
142 | { |
---|
143 | return MIN (72 * MAX (html_painter_get_space_width (painter, GTK_HTML_FONT_STYLE_SIZE_3 | GTK_HTML_FONT_STYLE_FIXED, NULL), |
---|
144 | html_painter_get_e_width (painter, GTK_HTML_FONT_STYLE_SIZE_3 | GTK_HTML_FONT_STYLE_FIXED, NULL)), |
---|
145 | html_engine_get_view_width (e)) + (html_engine_get_left_border (e) + html_engine_get_right_border (e)); |
---|
146 | } |
---|
147 | |
---|
148 | static guint |
---|
149 | get_page_height (HTMLPainter *painter, HTMLEngine *e) |
---|
150 | { |
---|
151 | return html_engine_get_view_height (e) + (html_engine_get_top_border (e) + html_engine_get_bottom_border (e)); |
---|
152 | } |
---|
153 | |
---|
154 | static void |
---|
155 | html_plain_painter_class_init (GObjectClass *object_class) |
---|
156 | { |
---|
157 | HTMLPainterClass *painter_class; |
---|
158 | |
---|
159 | painter_class = HTML_PAINTER_CLASS (object_class); |
---|
160 | parent_class = g_type_class_ref (HTML_TYPE_GDK_PAINTER); |
---|
161 | |
---|
162 | painter_class->alloc_font = alloc_fixed_font; |
---|
163 | painter_class->draw_rect = draw_rect; |
---|
164 | painter_class->fill_rect = fill_rect; |
---|
165 | painter_class->draw_pixmap = draw_pixmap; |
---|
166 | painter_class->draw_shade_line = draw_shade_line; |
---|
167 | painter_class->draw_panel = draw_panel; |
---|
168 | painter_class->draw_background = draw_background; |
---|
169 | painter_class->get_page_width = get_page_width; |
---|
170 | painter_class->get_page_height = get_page_height; |
---|
171 | } |
---|
172 | |
---|
173 | GType |
---|
174 | html_plain_painter_get_type (void) |
---|
175 | { |
---|
176 | static GType html_plain_painter_type = 0; |
---|
177 | |
---|
178 | if (html_plain_painter_type == 0) { |
---|
179 | static const GTypeInfo html_plain_painter_info = { |
---|
180 | sizeof (HTMLPlainPainterClass), |
---|
181 | NULL, |
---|
182 | NULL, |
---|
183 | (GClassInitFunc) html_plain_painter_class_init, |
---|
184 | NULL, |
---|
185 | NULL, |
---|
186 | sizeof (HTMLPlainPainter), |
---|
187 | 1, |
---|
188 | (GInstanceInitFunc) html_plain_painter_init, |
---|
189 | }; |
---|
190 | html_plain_painter_type = g_type_register_static (HTML_TYPE_GDK_PAINTER, "HTMLPlainPainter", |
---|
191 | &html_plain_painter_info, 0); |
---|
192 | } |
---|
193 | |
---|
194 | return html_plain_painter_type; |
---|
195 | } |
---|
196 | |
---|
197 | HTMLPainter * |
---|
198 | html_plain_painter_new (GtkWidget *widget, gboolean double_buffer) |
---|
199 | { |
---|
200 | HTMLPlainPainter *new; |
---|
201 | |
---|
202 | new = g_object_new (HTML_TYPE_PLAIN_PAINTER, NULL); |
---|
203 | html_painter_set_widget (HTML_PAINTER (new), widget); |
---|
204 | HTML_GDK_PAINTER (new)->double_buffer = double_buffer; |
---|
205 | HTML_GDK_PAINTER (new)->pc = gtk_widget_get_pango_context (widget); |
---|
206 | g_object_ref (HTML_GDK_PAINTER (new)->pc); |
---|
207 | |
---|
208 | return HTML_PAINTER (new); |
---|
209 | } |
---|