diff options
author | James Bursa <james@netsurf-browser.org> | 2004-12-25 11:37:35 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2004-12-25 11:37:35 +0000 |
commit | ed05aa87f8cdd8c53b37d68d89d295848edf2534 (patch) | |
tree | 13515f17ceee5f3a033bd056eb08b3e1cc78aaa9 /gtk | |
parent | 6dd1ab8fadf21d30eba7053c828c4e3497a4a76b (diff) | |
download | netsurf-ed05aa87f8cdd8c53b37d68d89d295848edf2534.tar.gz netsurf-ed05aa87f8cdd8c53b37d68d89d295848edf2534.tar.bz2 |
[project @ 2004-12-25 11:37:35 by bursa]
Fix line endings.
svn path=/import/netsurf/; revision=1409
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtk_bitmap.c | 282 | ||||
-rw-r--r-- | gtk/gtk_plotters.c | 458 |
2 files changed, 370 insertions, 370 deletions
diff --git a/gtk/gtk_bitmap.c b/gtk/gtk_bitmap.c index ae9fd1695..0121963fe 100644 --- a/gtk/gtk_bitmap.c +++ b/gtk/gtk_bitmap.c @@ -1,141 +1,141 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Generic bitmap handling (GDK / GTK+ implementation).
- *
- * This implements the interface given by desktop/bitmap.h using GdkPixbufs.
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <string.h>
-#include <gdk/gdk.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "netsurf/content/content.h"
-#include "netsurf/image/bitmap.h"
-
-
-extern GdkDrawable *current_drawable;
-extern GdkGC *current_gc;
-
-
-struct bitmap;
-
-
-/**
- * Create a bitmap.
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-
-struct bitmap *bitmap_create(int width, int height)
-{
- GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8,
- width, height);
- return (struct bitmap *) pixbuf;
-}
-
-
-/**
- * Sets whether a bitmap should be plotted opaque
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param opaque whether the bitmap should be plotted opaque
- */
-void bitmap_set_opaque(struct bitmap *bitmap, bool opaque)
-{
- assert(bitmap);
-/* todo: set bitmap as opaque */
-}
-
-
-/**
- * Tests whether a bitmap has an opaque alpha channel
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return whether the bitmap is opaque
- */
-bool bitmap_test_opaque(struct bitmap *bitmap)
-{
- assert(bitmap);
-/* todo: test if bitmap as opaque */
- return false;
-}
-
-
-/**
- * Gets whether a bitmap should be plotted opaque
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-bool bitmap_get_opaque(struct bitmap *bitmap)
-{
- assert(bitmap);
-/* todo: get whether bitmap is opaque */
- return false;
-}
-
-
-/**
- * Return a pointer to the pixel data in a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return pointer to the pixel buffer
- *
- * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end
- * of rows. The width of a row in bytes is given by bitmap_get_rowstride().
- */
-
-char *bitmap_get_buffer(struct bitmap *bitmap)
-{
- assert(bitmap);
- return gdk_pixbuf_get_pixels((GdkPixbuf *) bitmap);
-}
-
-
-/**
- * Find the width of a pixel row in bytes.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return width of a pixel row in the bitmap
- */
-
-size_t bitmap_get_rowstride(struct bitmap *bitmap)
-{
- assert(bitmap);
- return gdk_pixbuf_get_rowstride((GdkPixbuf *) bitmap);
-}
-
-
-/**
- * Free a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-
-void bitmap_destroy(struct bitmap *bitmap)
-{
- assert(bitmap);
- g_object_unref((GdkPixbuf *) bitmap);
-}
-
-
-/**
- * Save a bitmap in the platform's native format.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param path pathname for file
- * \return true on success, false on error and error reported
- */
-
-bool bitmap_save(struct bitmap *bitmap, const char *path)
-{
- return true;
-}
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Generic bitmap handling (GDK / GTK+ implementation). + * + * This implements the interface given by desktop/bitmap.h using GdkPixbufs. + */ + +#include <assert.h> +#include <stdbool.h> +#include <string.h> +#include <gdk/gdk.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#include "netsurf/content/content.h" +#include "netsurf/image/bitmap.h" + + +extern GdkDrawable *current_drawable; +extern GdkGC *current_gc; + + +struct bitmap; + + +/** + * Create a bitmap. + * + * \param width width of image in pixels + * \param height width of image in pixels + * \return an opaque struct bitmap, or NULL on memory exhaustion + */ + +struct bitmap *bitmap_create(int width, int height) +{ + GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, + width, height); + return (struct bitmap *) pixbuf; +} + + +/** + * Sets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param opaque whether the bitmap should be plotted opaque + */ +void bitmap_set_opaque(struct bitmap *bitmap, bool opaque) +{ + assert(bitmap); +/* todo: set bitmap as opaque */ +} + + +/** + * Tests whether a bitmap has an opaque alpha channel + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return whether the bitmap is opaque + */ +bool bitmap_test_opaque(struct bitmap *bitmap) +{ + assert(bitmap); +/* todo: test if bitmap as opaque */ + return false; +} + + +/** + * Gets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +bool bitmap_get_opaque(struct bitmap *bitmap) +{ + assert(bitmap); +/* todo: get whether bitmap is opaque */ + return false; +} + + +/** + * Return a pointer to the pixel data in a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return pointer to the pixel buffer + * + * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end + * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). + */ + +char *bitmap_get_buffer(struct bitmap *bitmap) +{ + assert(bitmap); + return gdk_pixbuf_get_pixels((GdkPixbuf *) bitmap); +} + + +/** + * Find the width of a pixel row in bytes. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return width of a pixel row in the bitmap + */ + +size_t bitmap_get_rowstride(struct bitmap *bitmap) +{ + assert(bitmap); + return gdk_pixbuf_get_rowstride((GdkPixbuf *) bitmap); +} + + +/** + * Free a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ + +void bitmap_destroy(struct bitmap *bitmap) +{ + assert(bitmap); + g_object_unref((GdkPixbuf *) bitmap); +} + + +/** + * Save a bitmap in the platform's native format. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param path pathname for file + * \return true on success, false on error and error reported + */ + +bool bitmap_save(struct bitmap *bitmap, const char *path) +{ + return true; +} diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c index 3af8033a1..94d39fdd4 100644 --- a/gtk/gtk_plotters.c +++ b/gtk/gtk_plotters.c @@ -1,229 +1,229 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Target independent plotting (GDK / GTK+ implementation).
- */
-
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-#include "netsurf/desktop/plotters.h"
-#include "netsurf/render/font.h"
-#include "netsurf/utils/log.h"
-
-
-extern GtkWidget *current_widget;
-extern GdkDrawable *current_drawable;
-extern GdkGC *current_gc;
-
-
-static bool nsgtk_plot_clg(colour c);
-static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height,
- colour c, bool dotted);
-static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width,
- colour c, bool dotted, bool dashed);
-static bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill);
-static bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c);
-static bool nsgtk_plot_clip(int clip_x0, int clip_y0,
- int clip_x1, int clip_y1);
-static bool nsgtk_plot_text(int x, int y, struct font_data *font,
- const char *text, size_t length, colour bg, colour c);
-static bool nsgtk_plot_disc(int x, int y, int radius, colour colour);
-static bool nsgtk_plot_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg);
-static bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y);
-static bool nsgtk_plot_group_start(const char *name);
-static bool nsgtk_plot_group_end(void);
-static void nsgtk_set_colour(colour c);
-
-
-
-struct plotter_table plot;
-
-const struct plotter_table nsgtk_plotters = {
- nsgtk_plot_clg,
- nsgtk_plot_rectangle,
- nsgtk_plot_line,
- nsgtk_plot_polygon,
- nsgtk_plot_fill,
- nsgtk_plot_clip,
- nsgtk_plot_text,
- nsgtk_plot_disc,
- nsgtk_plot_bitmap,
- nsgtk_plot_bitmap_tile,
- nsgtk_plot_group_start,
- nsgtk_plot_group_end
-};
-
-
-bool nsgtk_plot_clg(colour c)
-{
- return true;
-}
-
-
-bool nsgtk_plot_rectangle(int x0, int y0, int width, int height,
- colour c, bool dotted)
-{
- nsgtk_set_colour(c);
- gdk_draw_rectangle(current_drawable, current_gc,
- FALSE, x0, y0, width, height);
- return true;
-}
-
-
-bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width,
- colour c, bool dotted, bool dashed)
-{
- nsgtk_set_colour(c);
- gdk_draw_line(current_drawable, current_gc,
- x0, y0, x1, y1);
- return true;
-}
-
-
-bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill)
-{
- unsigned int i;
- GdkPoint q[n];
- for (i = 0; i != n; i++) {
- q[i].x = p[i * 2];
- q[i].y = p[i * 2 + 1];
- }
- nsgtk_set_colour(fill);
- gdk_draw_polygon(current_drawable, current_gc,
- TRUE, q, n);
- return true;
-}
-
-
-bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c)
-{
- nsgtk_set_colour(c);
- gdk_draw_rectangle(current_drawable, current_gc,
- TRUE, x0, y0, x1 - x0, y1 - y0);
- return true;
-}
-
-
-bool nsgtk_plot_clip(int clip_x0, int clip_y0,
- int clip_x1, int clip_y1)
-{
- GdkRectangle clip = { clip_x0, clip_y0,
- clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1 };
- gdk_gc_set_clip_rectangle(current_gc, &clip);
- return true;
-}
-
-
-bool nsgtk_plot_text(int x, int y, struct font_data *font,
- const char *text, size_t length, colour bg, colour c)
-{
- PangoContext *context;
- PangoLayout *layout;
- PangoLayoutLine *line;
- GdkColor colour = { 0,
- ((c & 0xff) << 8) | (c & 0xff),
- (c & 0xff00) | (c & 0xff00 >> 8),
- ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) };
-
- context = gtk_widget_get_pango_context(current_widget);
- layout = pango_layout_new(context);
- pango_layout_set_font_description(layout,
- (const PangoFontDescription *) font->id);
- pango_layout_set_text(layout, text, length);
-
- line = pango_layout_get_line(layout, 0);
-
- gdk_draw_layout_line_with_colors(current_drawable, current_gc,
- x, y, line, &colour, 0);
-
- g_object_unref(layout);
-
- return true;
-}
-
-
-bool nsgtk_plot_disc(int x, int y, int radius, colour colour)
-{
- return true;
-}
-
-
-bool nsgtk_plot_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg)
-{
- GdkPixbuf *pixbuf = (GdkPixbuf *) bitmap;
-
- if (gdk_pixbuf_get_width(pixbuf) == width &&
- gdk_pixbuf_get_height(pixbuf) == height) {
- gdk_draw_pixbuf(current_drawable, current_gc,
- pixbuf,
- 0, 0,
- x, y,
- width, height,
- GDK_RGB_DITHER_NORMAL, 0, 0);
-
- } else {
- GdkPixbuf *scaled;
- scaled = gdk_pixbuf_scale_simple(pixbuf,
- width, height,
- GDK_INTERP_BILINEAR);
- if (!scaled)
- return false;
-
- gdk_draw_pixbuf(current_drawable, current_gc,
- scaled,
- 0, 0,
- x, y,
- width, height,
- GDK_RGB_DITHER_NORMAL, 0, 0);
-
- g_object_unref(scaled);
- }
-
- return true;
-}
-
-
-bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y)
-{
- return true;
-}
-
-bool nsgtk_plot_group_start(const char *name)
-{
- return true;
-}
-
-bool nsgtk_plot_group_end(void)
-{
- return true;
-}
-
-void nsgtk_set_colour(colour c)
-{
- int r, g, b;
- GdkColor colour;
-
- r = c & 0xff;
- g = (c & 0xff00) >> 8;
- b = (c & 0xff0000) >> 16;
-
- colour.red = r | (r << 8);
- colour.green = g | (g << 8);
- colour.blue = b | (b << 8);
- colour.pixel = (r << 16) | (g << 8) | b;
-
- gdk_color_alloc(gtk_widget_get_colormap(current_widget),
- &colour);
- gdk_gc_set_foreground(current_gc, &colour);
-}
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Target independent plotting (GDK / GTK+ implementation). + */ + +#include <gdk/gdk.h> +#include <gtk/gtk.h> +#include "netsurf/desktop/plotters.h" +#include "netsurf/render/font.h" +#include "netsurf/utils/log.h" + + +extern GtkWidget *current_widget; +extern GdkDrawable *current_drawable; +extern GdkGC *current_gc; + + +static bool nsgtk_plot_clg(colour c); +static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, + colour c, bool dotted); +static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed); +static bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill); +static bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c); +static bool nsgtk_plot_clip(int clip_x0, int clip_y0, + int clip_x1, int clip_y1); +static bool nsgtk_plot_text(int x, int y, struct font_data *font, + const char *text, size_t length, colour bg, colour c); +static bool nsgtk_plot_disc(int x, int y, int radius, colour colour); +static bool nsgtk_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg); +static bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y); +static bool nsgtk_plot_group_start(const char *name); +static bool nsgtk_plot_group_end(void); +static void nsgtk_set_colour(colour c); + + + +struct plotter_table plot; + +const struct plotter_table nsgtk_plotters = { + nsgtk_plot_clg, + nsgtk_plot_rectangle, + nsgtk_plot_line, + nsgtk_plot_polygon, + nsgtk_plot_fill, + nsgtk_plot_clip, + nsgtk_plot_text, + nsgtk_plot_disc, + nsgtk_plot_bitmap, + nsgtk_plot_bitmap_tile, + nsgtk_plot_group_start, + nsgtk_plot_group_end +}; + + +bool nsgtk_plot_clg(colour c) +{ + return true; +} + + +bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, + colour c, bool dotted) +{ + nsgtk_set_colour(c); + gdk_draw_rectangle(current_drawable, current_gc, + FALSE, x0, y0, width, height); + return true; +} + + +bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed) +{ + nsgtk_set_colour(c); + gdk_draw_line(current_drawable, current_gc, + x0, y0, x1, y1); + return true; +} + + +bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill) +{ + unsigned int i; + GdkPoint q[n]; + for (i = 0; i != n; i++) { + q[i].x = p[i * 2]; + q[i].y = p[i * 2 + 1]; + } + nsgtk_set_colour(fill); + gdk_draw_polygon(current_drawable, current_gc, + TRUE, q, n); + return true; +} + + +bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c) +{ + nsgtk_set_colour(c); + gdk_draw_rectangle(current_drawable, current_gc, + TRUE, x0, y0, x1 - x0, y1 - y0); + return true; +} + + +bool nsgtk_plot_clip(int clip_x0, int clip_y0, + int clip_x1, int clip_y1) +{ + GdkRectangle clip = { clip_x0, clip_y0, + clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1 }; + gdk_gc_set_clip_rectangle(current_gc, &clip); + return true; +} + + +bool nsgtk_plot_text(int x, int y, struct font_data *font, + const char *text, size_t length, colour bg, colour c) +{ + PangoContext *context; + PangoLayout *layout; + PangoLayoutLine *line; + GdkColor colour = { 0, + ((c & 0xff) << 8) | (c & 0xff), + (c & 0xff00) | (c & 0xff00 >> 8), + ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) }; + + context = gtk_widget_get_pango_context(current_widget); + layout = pango_layout_new(context); + pango_layout_set_font_description(layout, + (const PangoFontDescription *) font->id); + pango_layout_set_text(layout, text, length); + + line = pango_layout_get_line(layout, 0); + + gdk_draw_layout_line_with_colors(current_drawable, current_gc, + x, y, line, &colour, 0); + + g_object_unref(layout); + + return true; +} + + +bool nsgtk_plot_disc(int x, int y, int radius, colour colour) +{ + return true; +} + + +bool nsgtk_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg) +{ + GdkPixbuf *pixbuf = (GdkPixbuf *) bitmap; + + if (gdk_pixbuf_get_width(pixbuf) == width && + gdk_pixbuf_get_height(pixbuf) == height) { + gdk_draw_pixbuf(current_drawable, current_gc, + pixbuf, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_NORMAL, 0, 0); + + } else { + GdkPixbuf *scaled; + scaled = gdk_pixbuf_scale_simple(pixbuf, + width, height, + GDK_INTERP_BILINEAR); + if (!scaled) + return false; + + gdk_draw_pixbuf(current_drawable, current_gc, + scaled, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_NORMAL, 0, 0); + + g_object_unref(scaled); + } + + return true; +} + + +bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y) +{ + return true; +} + +bool nsgtk_plot_group_start(const char *name) +{ + return true; +} + +bool nsgtk_plot_group_end(void) +{ + return true; +} + +void nsgtk_set_colour(colour c) +{ + int r, g, b; + GdkColor colour; + + r = c & 0xff; + g = (c & 0xff00) >> 8; + b = (c & 0xff0000) >> 16; + + colour.red = r | (r << 8); + colour.green = g | (g << 8); + colour.blue = b | (b << 8); + colour.pixel = (r << 16) | (g << 8) | b; + + gdk_color_alloc(gtk_widget_get_colormap(current_widget), + &colour); + gdk_gc_set_foreground(current_gc, &colour); +} |