source: trunk/third/gtkhtml/src/htmlplainpainter.c @ 18136

Revision 18136, 6.7 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18135, which included commits to RCS files with non-trunk default branches.
Line 
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#include <gal/unicode/gunicode.h>
28#include <gal/widgets/e-font.h>
29
30#include "htmlentity.h"
31#include "htmlgdkpainter.h"
32#include "htmlplainpainter.h"
33#include "htmlcolor.h"
34#include "htmlcolorset.h"
35#include "htmlengine.h"
36
37static HTMLGdkPainterClass *parent_class = NULL;
38
39static EFontStyle e_style (GtkHTMLFontStyle style);
40
41static void
42draw_panel (HTMLPainter *painter,
43            GdkColor *bg,
44            gint x, gint y,
45            gint width, gint height,
46            GtkHTMLEtchStyle inset,
47            gint bordersize)
48{
49}
50
51static void
52draw_background (HTMLPainter *painter,
53                 GdkColor *color,
54                 GdkPixbuf *pixbuf,
55                 gint x, gint y,
56                 gint width, gint height,
57                 gint tile_x, gint tile_y)
58{
59        HTMLGdkPainter *gdk_painter;
60        ArtIRect expose, paint, clip;
61
62        gdk_painter = HTML_GDK_PAINTER (painter);
63
64        expose.x0 = x;
65        expose.y0 = y;
66        expose.x1 = x + width;
67        expose.y1 = y + height;
68
69        clip.x0 = gdk_painter->x1;
70        clip.x1 = gdk_painter->x2;
71        clip.y0 = gdk_painter->y1;
72        clip.y1 = gdk_painter->y2;
73        clip.x0 = gdk_painter->x1;
74
75        art_irect_intersect (&paint, &clip, &expose);
76        if (art_irect_empty (&paint))
77            return;
78
79        width = paint.x1 - paint.x0;
80        height = paint.y1 - paint.y0;   
81       
82        tile_x += paint.x0 - x;
83        tile_y += paint.y0 - y;
84       
85        x = paint.x0;
86        y = paint.y0;
87
88        if (!color && !pixbuf)
89                return;
90
91        if (color) {
92                gdk_gc_set_foreground (gdk_painter->gc, color);
93                gdk_draw_rectangle (gdk_painter->pixmap, gdk_painter->gc,
94                                    TRUE, x - gdk_painter->x1, y - gdk_painter->y1,
95                                    width, height);     
96               
97        }
98
99        return;
100}
101
102static void
103draw_pixmap (HTMLPainter *painter,
104             GdkPixbuf *pixbuf,
105             gint x, gint y,
106             gint scale_width, gint scale_height,
107             const GdkColor *color)
108{
109}
110
111static void
112fill_rect (HTMLPainter *painter,
113           gint x, gint y,
114           gint width, gint height)
115{
116        HTMLGdkPainter *gdk_painter;
117
118        gdk_painter = HTML_GDK_PAINTER (painter);
119
120        gdk_draw_rectangle (gdk_painter->pixmap, gdk_painter->gc,
121                            TRUE, x - gdk_painter->x1, y - gdk_painter->y1,
122                            width, height);
123}
124
125static EFontStyle
126e_style (GtkHTMLFontStyle style)
127{
128        EFontStyle rv = E_FONT_PLAIN;
129        return rv;
130}
131
132static HTMLFont *
133alloc_fixed_font (gchar *face, gdouble size, gboolean points, GtkHTMLFontStyle style)
134{
135        HTMLFontManager *fm = html_engine_class_gdk_font_manager ();
136        gpointer plain_font;
137
138        plain_font = html_font_manager_get_font (fm, NULL, GTK_HTML_FONT_STYLE_SIZE_3 | GTK_HTML_FONT_STYLE_FIXED);
139        HTML_PAINTER_CLASS (parent_class)->ref_font (plain_font);
140
141        return plain_font;
142}
143
144static void
145draw_shade_line (HTMLPainter *painter,
146                 gint x, gint y,
147                 gint width)
148{
149}
150
151static void
152init (GtkObject *object)
153{
154}
155
156static void
157draw_text (HTMLPainter *painter,
158           gint x, gint y,
159           const gchar *text,
160           gint len)
161{
162        HTMLGdkPainter *gdk_painter;
163        EFont *e_font;
164
165        gdk_painter = HTML_GDK_PAINTER (painter);
166
167        if (len == -1)
168                len = g_utf8_strlen (text, -1);
169
170        x -= gdk_painter->x1;
171        y -= gdk_painter->y1;
172
173        e_font = html_painter_get_font (painter, painter->font_face,
174                                        painter->font_style);
175
176        e_font_draw_utf8_text (gdk_painter->pixmap, e_font,
177                               e_style (painter->font_style), gdk_painter->gc,
178                               x, y, text,
179                               g_utf8_offset_to_pointer (text, len) - text);
180
181        if (painter->font_style & (GTK_HTML_FONT_STYLE_UNDERLINE
182                                   | GTK_HTML_FONT_STYLE_STRIKEOUT)) {
183                /*
184                guint width;
185
186                width = e_font_utf8_text_width (e_font, e_style (painter->font_style),
187                                                text, g_utf8_offset_to_pointer (text, len) - text);
188
189                if (painter->font_style & GTK_HTML_FONT_STYLE_UNDERLINE)
190                        gdk_draw_line (gdk_painter->pixmap, gdk_painter->gc,
191                                       x, y + 1,
192                                       x + width, y + 1);
193
194                if (painter->font_style & GTK_HTML_FONT_STYLE_STRIKEOUT)
195                        gdk_draw_line (gdk_painter->pixmap, gdk_painter->gc,
196                                       x, y - e_font_ascent (e_font) / 2,
197                                       x + width, y - e_font_ascent (e_font) / 2);
198                */
199        }
200}
201
202static void
203draw_rect (HTMLPainter *painter,
204           gint x, gint y,
205           gint width, gint height)
206{
207}
208
209static guint
210get_page_width (HTMLPainter *painter, HTMLEngine *e)
211{
212        return MIN (72 * html_painter_get_space_width (painter, GTK_HTML_FONT_STYLE_SIZE_3, NULL),
213                    html_engine_get_view_width (e)) + e->leftBorder + e->rightBorder;
214}
215
216static guint
217get_page_height (HTMLPainter *painter, HTMLEngine *e)
218{
219        return html_engine_get_view_height (e) + e->topBorder + e->bottomBorder;
220}
221
222static HTMLFontManagerId
223get_font_manager_id ()
224{
225        return HTML_FONT_MANAGER_ID_PLAIN;
226}
227
228static void
229class_init (GtkObjectClass *object_class)
230{
231        HTMLPainterClass *painter_class;
232
233        painter_class = HTML_PAINTER_CLASS (object_class);
234
235        painter_class->alloc_font = alloc_fixed_font;
236        painter_class->draw_rect = draw_rect;
237        painter_class->draw_text = draw_text;
238        painter_class->fill_rect = fill_rect;
239        painter_class->draw_pixmap = draw_pixmap;
240        painter_class->draw_shade_line = draw_shade_line;
241        painter_class->draw_panel = draw_panel;
242        painter_class->draw_background = draw_background;
243        painter_class->get_page_width = get_page_width;
244        painter_class->get_page_height = get_page_height;
245        painter_class->get_font_manager_id = get_font_manager_id;
246
247        parent_class = gtk_type_class (html_gdk_painter_get_type ());
248}
249
250GtkType
251html_plain_painter_get_type (void)
252{
253        static GtkType type = 0;
254
255        if (type == 0) {
256                static const GtkTypeInfo info = {
257                        "HTMLPlainPainter",
258                        sizeof (HTMLPlainPainter),
259                        sizeof (HTMLPlainPainterClass),
260                        (GtkClassInitFunc) class_init,
261                        (GtkObjectInitFunc) init,
262                        /* reserved_1 */ NULL,
263                        /* reserved_2 */ NULL,
264                        (GtkClassInitFunc) NULL,
265                };
266
267                type = gtk_type_unique (HTML_TYPE_GDK_PAINTER, &info);
268        }
269
270        return type;
271}
272
273
274HTMLPainter *
275html_plain_painter_new (gboolean double_buffer)
276{
277        HTMLPlainPainter *new;
278
279        new = gtk_type_new (html_plain_painter_get_type ());
280
281        HTML_GDK_PAINTER (new)->double_buffer = double_buffer;
282
283        return HTML_PAINTER (new);
284}
Note: See TracBrowser for help on using the repository browser.