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., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include <config.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include "htmlentity.h"
27 #include "htmlgdkpainter.h"
28 #include "htmlplainpainter.h"
29 #include "htmlcolor.h"
30 #include "htmlcolorset.h"
31 #include "htmlengine.h"
32 #include "htmltext.h"
33
34 static HTMLGdkPainterClass *parent_class = NULL;
35
36 static void
draw_border(HTMLPainter * painter,GdkColor * bg,gint x,gint y,gint width,gint height,HTMLBorderStyle style,gint bordersize)37 draw_border (HTMLPainter *painter,
38 GdkColor *bg,
39 gint x,
40 gint y,
41 gint width,
42 gint height,
43 HTMLBorderStyle style,
44 gint bordersize)
45 {
46 }
47
48 static void
draw_background(HTMLPainter * painter,GdkColor * color,GdkPixbuf * pixbuf,gint x,gint y,gint width,gint height,gint tile_x,gint tile_y)49 draw_background (HTMLPainter *painter,
50 GdkColor *color,
51 GdkPixbuf *pixbuf,
52 gint x,
53 gint y,
54 gint width,
55 gint height,
56 gint tile_x,
57 gint tile_y)
58 {
59 HTMLGdkPainter *gdk_painter;
60 GdkRectangle expose, paint, clip;
61
62 gdk_painter = HTML_GDK_PAINTER (painter);
63
64 expose.x = x;
65 expose.y = y;
66 expose.width = width;
67 expose.height = height;
68
69 clip.x = gdk_painter->x1;
70 clip.width = gdk_painter->x2 - gdk_painter->x1;
71 clip.y = gdk_painter->y1;
72 clip.height = gdk_painter->y2 - gdk_painter->y1;
73
74 if (!gdk_rectangle_intersect (&clip, &expose, &paint))
75 return;
76
77 if (!color && !pixbuf)
78 return;
79
80 if (color) {
81 gdk_cairo_set_source_color (gdk_painter->cr, color);
82 cairo_rectangle (gdk_painter->cr, paint.x - clip.x, paint.y - clip.y, paint.width, paint.height);
83 cairo_fill (gdk_painter->cr);
84 }
85
86 return;
87 }
88
89 static void
draw_pixmap(HTMLPainter * painter,GdkPixbuf * pixbuf,gint x,gint y,gint scale_width,gint scale_height,const GdkColor * color)90 draw_pixmap (HTMLPainter *painter,
91 GdkPixbuf *pixbuf,
92 gint x,
93 gint y,
94 gint scale_width,
95 gint scale_height,
96 const GdkColor *color)
97 {
98 }
99
100 static void
fill_rect(HTMLPainter * painter,gint x,gint y,gint width,gint height)101 fill_rect (HTMLPainter *painter,
102 gint x,
103 gint y,
104 gint width,
105 gint height)
106 {
107 HTMLGdkPainter *gdk_painter;
108
109 gdk_painter = HTML_GDK_PAINTER (painter);
110
111 cairo_rectangle (gdk_painter->cr, x - gdk_painter->x1, y - gdk_painter->y1, width, height);
112 cairo_fill (gdk_painter->cr);
113 }
114
115 static void
draw_shade_line(HTMLPainter * painter,gint x,gint y,gint width)116 draw_shade_line (HTMLPainter *painter,
117 gint x,
118 gint y,
119 gint width)
120 {
121 }
122
123 static void
html_plain_painter_init(GObject * object)124 html_plain_painter_init (GObject *object)
125 {
126 }
127
128 static void
draw_rect(HTMLPainter * painter,gint x,gint y,gint width,gint height)129 draw_rect (HTMLPainter *painter,
130 gint x,
131 gint y,
132 gint width,
133 gint height)
134 {
135 }
136
137 static guint
get_page_width(HTMLPainter * painter,HTMLEngine * e)138 get_page_width (HTMLPainter *painter,
139 HTMLEngine *e)
140 {
141 return MIN (72 * MAX (html_painter_get_space_width (painter, GTK_HTML_FONT_STYLE_SIZE_3 | GTK_HTML_FONT_STYLE_FIXED, NULL),
142 html_painter_get_e_width (painter, GTK_HTML_FONT_STYLE_SIZE_3 | GTK_HTML_FONT_STYLE_FIXED, NULL)),
143 html_engine_get_view_width (e)) + (html_engine_get_left_border (e) + html_engine_get_right_border (e));
144 }
145
146 static guint
get_page_height(HTMLPainter * painter,HTMLEngine * e)147 get_page_height (HTMLPainter *painter,
148 HTMLEngine *e)
149 {
150 return html_engine_get_view_height (e) + (html_engine_get_top_border (e) + html_engine_get_bottom_border (e));
151 }
152
153 static void
html_plain_painter_class_init(GObjectClass * object_class)154 html_plain_painter_class_init (GObjectClass *object_class)
155 {
156 HTMLPainterClass *painter_class;
157
158 painter_class = HTML_PAINTER_CLASS (object_class);
159 parent_class = g_type_class_ref (HTML_TYPE_GDK_PAINTER);
160
161 painter_class->draw_rect = draw_rect;
162 painter_class->fill_rect = fill_rect;
163 painter_class->draw_pixmap = draw_pixmap;
164 painter_class->draw_shade_line = draw_shade_line;
165 painter_class->draw_border = draw_border;
166 painter_class->draw_background = draw_background;
167 painter_class->get_page_width = get_page_width;
168 painter_class->get_page_height = get_page_height;
169 }
170
171 GType
html_plain_painter_get_type(void)172 html_plain_painter_get_type (void)
173 {
174 static GType html_plain_painter_type = 0;
175
176 if (html_plain_painter_type == 0) {
177 static const GTypeInfo html_plain_painter_info = {
178 sizeof (HTMLPlainPainterClass),
179 NULL,
180 NULL,
181 (GClassInitFunc) html_plain_painter_class_init,
182 NULL,
183 NULL,
184 sizeof (HTMLPlainPainter),
185 1,
186 (GInstanceInitFunc) html_plain_painter_init,
187 };
188 html_plain_painter_type = g_type_register_static (HTML_TYPE_GDK_PAINTER, "HTMLPlainPainter",
189 &html_plain_painter_info, 0);
190 }
191
192 return html_plain_painter_type;
193 }
194
195 HTMLPainter *
html_plain_painter_new(GtkWidget * widget,gboolean double_buffer)196 html_plain_painter_new (GtkWidget *widget,
197 gboolean double_buffer)
198 {
199 HTMLPlainPainter *new;
200
201 new = g_object_new (HTML_TYPE_PLAIN_PAINTER, NULL);
202 html_painter_set_widget (HTML_PAINTER (new), widget);
203 HTML_GDK_PAINTER (new)->double_buffer = double_buffer;
204
205 return HTML_PAINTER (new);
206 }
207