[GRASS-SVN] r62431 - in grass/trunk/lib: cairodriver htmldriver pngdriver psdriver

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 28 06:15:16 PDT 2014


Author: martinl
Date: 2014-10-28 06:15:16 -0700 (Tue, 28 Oct 2014)
New Revision: 62431

Added:
   grass/trunk/lib/cairodriver/box.c
   grass/trunk/lib/cairodriver/color.c
   grass/trunk/lib/cairodriver/draw.c
   grass/trunk/lib/cairodriver/draw_bitmap.c
   grass/trunk/lib/cairodriver/driver.c
   grass/trunk/lib/cairodriver/erase.c
   grass/trunk/lib/cairodriver/graph.c
   grass/trunk/lib/cairodriver/line_width.c
   grass/trunk/lib/cairodriver/makefile
   grass/trunk/lib/cairodriver/raster.c
   grass/trunk/lib/cairodriver/set_window.c
   grass/trunk/lib/cairodriver/text.c
   grass/trunk/lib/htmldriver/box.c
   grass/trunk/lib/htmldriver/draw.c
   grass/trunk/lib/htmldriver/driver.c
   grass/trunk/lib/htmldriver/graph_clse.c
   grass/trunk/lib/htmldriver/graph_set.c
   grass/trunk/lib/htmldriver/makefile
   grass/trunk/lib/htmldriver/polygon.c
   grass/trunk/lib/htmldriver/readme
   grass/trunk/lib/htmldriver/text.c
   grass/trunk/lib/pngdriver/box.c
   grass/trunk/lib/pngdriver/color.c
   grass/trunk/lib/pngdriver/color_table.c
   grass/trunk/lib/pngdriver/draw.c
   grass/trunk/lib/pngdriver/draw_bitmap.c
   grass/trunk/lib/pngdriver/draw_line.c
   grass/trunk/lib/pngdriver/draw_point.c
   grass/trunk/lib/pngdriver/driver.c
   grass/trunk/lib/pngdriver/erase.c
   grass/trunk/lib/pngdriver/graph_close.c
   grass/trunk/lib/pngdriver/graph_set.c
   grass/trunk/lib/pngdriver/line_width.c
   grass/trunk/lib/pngdriver/makefile
   grass/trunk/lib/pngdriver/point.c
   grass/trunk/lib/pngdriver/polygon.c
   grass/trunk/lib/pngdriver/raster.c
   grass/trunk/lib/pngdriver/set_window.c
   grass/trunk/lib/psdriver/box.c
   grass/trunk/lib/psdriver/color.c
   grass/trunk/lib/psdriver/draw.c
   grass/trunk/lib/psdriver/draw_bitmap.c
   grass/trunk/lib/psdriver/driver.c
   grass/trunk/lib/psdriver/erase.c
   grass/trunk/lib/psdriver/graph_close.c
   grass/trunk/lib/psdriver/graph_set.c
   grass/trunk/lib/psdriver/line_width.c
   grass/trunk/lib/psdriver/makefile
   grass/trunk/lib/psdriver/raster.c
   grass/trunk/lib/psdriver/set_window.c
Removed:
   grass/trunk/lib/cairodriver/Box.c
   grass/trunk/lib/cairodriver/Color.c
   grass/trunk/lib/cairodriver/Draw.c
   grass/trunk/lib/cairodriver/Draw_bitmap.c
   grass/trunk/lib/cairodriver/Driver.c
   grass/trunk/lib/cairodriver/Erase.c
   grass/trunk/lib/cairodriver/Graph.c
   grass/trunk/lib/cairodriver/Line_width.c
   grass/trunk/lib/cairodriver/Makefile
   grass/trunk/lib/cairodriver/Raster.c
   grass/trunk/lib/cairodriver/Set_window.c
   grass/trunk/lib/cairodriver/Text.c
   grass/trunk/lib/htmldriver/Box.c
   grass/trunk/lib/htmldriver/Draw.c
   grass/trunk/lib/htmldriver/Driver.c
   grass/trunk/lib/htmldriver/Graph_Clse.c
   grass/trunk/lib/htmldriver/Graph_Set.c
   grass/trunk/lib/htmldriver/Makefile
   grass/trunk/lib/htmldriver/Polygon.c
   grass/trunk/lib/htmldriver/README
   grass/trunk/lib/htmldriver/Text.c
   grass/trunk/lib/pngdriver/Box.c
   grass/trunk/lib/pngdriver/Color.c
   grass/trunk/lib/pngdriver/Color_table.c
   grass/trunk/lib/pngdriver/Draw.c
   grass/trunk/lib/pngdriver/Draw_bitmap.c
   grass/trunk/lib/pngdriver/Draw_line.c
   grass/trunk/lib/pngdriver/Draw_point.c
   grass/trunk/lib/pngdriver/Driver.c
   grass/trunk/lib/pngdriver/Erase.c
   grass/trunk/lib/pngdriver/Graph_close.c
   grass/trunk/lib/pngdriver/Graph_set.c
   grass/trunk/lib/pngdriver/Line_width.c
   grass/trunk/lib/pngdriver/Makefile
   grass/trunk/lib/pngdriver/Point.c
   grass/trunk/lib/pngdriver/Polygon.c
   grass/trunk/lib/pngdriver/Raster.c
   grass/trunk/lib/pngdriver/Set_window.c
   grass/trunk/lib/psdriver/Box.c
   grass/trunk/lib/psdriver/Color.c
   grass/trunk/lib/psdriver/Draw.c
   grass/trunk/lib/psdriver/Draw_bitmap.c
   grass/trunk/lib/psdriver/Driver.c
   grass/trunk/lib/psdriver/Erase.c
   grass/trunk/lib/psdriver/Graph_close.c
   grass/trunk/lib/psdriver/Graph_set.c
   grass/trunk/lib/psdriver/Line_width.c
   grass/trunk/lib/psdriver/Makefile
   grass/trunk/lib/psdriver/Raster.c
   grass/trunk/lib/psdriver/Set_window.c
Log:
display drivers, rename files to lowercase


Deleted: grass/trunk/lib/cairodriver/Box.c
===================================================================
--- grass/trunk/lib/cairodriver/Box.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,31 +0,0 @@
-/*!
-  \file cairodriver/Box.c
-
-  \brief GRASS cairo display driver - draw box
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-/*!
-  \brief Draw a (filled) rectangle
-
-  \param x1,y1,x2,y2 rectangle coordinates
-*/
-void Cairo_Box(double x1, double y1, double x2, double y2)
-{
-    G_debug(3, "Cairo_Box %f %f %f %f\n", x1, y1, x2, y2);
-
-    cairo_rectangle(cairo, x1, y1, x2 - x1, y2 - y1);
-    cairo_fill(cairo);
-    ca.modified = 1;
-
-    return;
-}

Deleted: grass/trunk/lib/cairodriver/Color.c
===================================================================
--- grass/trunk/lib/cairodriver/Color.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Color.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,36 +0,0 @@
-/*!
-  \file cairodriver/Color.c
-
-  \brief GRASS cairo display driver - colors management
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements 
-*/  
-
-#include "cairodriver.h"
-
-/*!
-  \brief Set source color (opaque)
-  
-  This color will then be used for any subsequent drawing operation
-  until a new source pattern is set.
-  
-  \param r red color value
-  \param g green color value
-  \param b blue color value
-*/
-void Cairo_Color(int r, int g, int b)
-{
-    G_debug(3, "Cairo_Color: %d,%d,%d", r, g, b);
-
-    cairo_set_source_rgba(cairo,
-			  CAIROCOLOR(r), CAIROCOLOR(g), CAIROCOLOR(b), 1.0);
-
-    G_debug(3, "Set color to: %g %g %g",
-	    CAIROCOLOR(r), CAIROCOLOR(g), CAIROCOLOR(b));
-}

Deleted: grass/trunk/lib/cairodriver/Draw.c
===================================================================
--- grass/trunk/lib/cairodriver/Draw.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,61 +0,0 @@
-/*!
-  \file cairodriver/Draw.c
-
-  \brief GRASS cairo display driver
-
-  (C) 2007-2008 by Lars Ahlzen, Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-void Cairo_Begin(void)
-{
-    cairo_new_path(cairo);
-}
-
-void Cairo_Move(double x, double y)
-{
-    cairo_move_to(cairo, x, y);
-}
-
-void Cairo_Cont(double x, double y)
-{
-    cairo_line_to(cairo, x, y);
-}
-
-void Cairo_Close(void)
-{
-    cairo_close_path(cairo);
-}
-
-void Cairo_Stroke(void)
-{
-    cairo_stroke(cairo);
-    ca.modified = 1;
-}
-
-void Cairo_Fill(void)
-{
-    cairo_fill(cairo);
-    ca.modified = 1;
-}
-
-void Cairo_Point(double x, double y)
-{
-    static double point_size = 1.0;
-    double half_point_size = point_size / 2;
-
-    cairo_new_path(cairo);
-    cairo_rectangle(cairo,
-		    x - half_point_size, y - half_point_size,
-		    point_size, point_size);
-    cairo_fill(cairo);
-    ca.modified = 1;
-}
-

Deleted: grass/trunk/lib/cairodriver/Draw_bitmap.c
===================================================================
--- grass/trunk/lib/cairodriver/Draw_bitmap.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Draw_bitmap.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,58 +0,0 @@
-/*!
-  \file cairodriver/Draw_bitmap.c
-
-  \brief GRASS cairo display driver - draw bitmap
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include <grass/glocale.h>
-
-#include "cairodriver.h"
-
-/*!
-  \brief Draw bitmap
-
-  \param ncols,nrows number of columns and rows
-  \param threshold threshold value
-  \param buf data buffer
-*/
-void Cairo_Bitmap(int ncols, int nrows, int threshold,
-		  const unsigned char *buf)
-{
-    cairo_surface_t *surf;
-    int stride;
-    unsigned char *data;
-    int i;
-
-    G_debug(1, "Cairo_Bitmap: %d %d %d", ncols, nrows, threshold);
-
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,8)
-    stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
-#else
-#define MULTIPLE 4
-    stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE;
-#endif
-    data = malloc(stride * nrows);
-    surf = cairo_image_surface_create_for_data(
-	data, CAIRO_FORMAT_A8, ncols, nrows, stride);
-
-    if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
-	G_fatal_error(_("Cairo_Bitmap: Failed to create source"));
-
-    for (i = 0; i < nrows; i++)
-	memcpy(&data[i * stride], &buf[i * ncols], ncols);
-
-    cairo_surface_mark_dirty(surf);
-    cairo_mask_surface(cairo, surf, cur_x, cur_y);
-
-    cairo_surface_destroy(surf);
-    ca.modified = 1;
-}
-

Deleted: grass/trunk/lib/cairodriver/Driver.c
===================================================================
--- grass/trunk/lib/cairodriver/Driver.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,58 +0,0 @@
-/*!
-  \file lib/cairodriver/Driver.c
-
-  \brief GRASS cairo display driver - driver initialization
-
-  (C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-/*!
-  \brief Initialize display driver
-
-  \return pointer driver structure
-*/
-const struct driver *Cairo_Driver(void)
-{
-    static struct driver drv;
-    static int initialized;
-
-    if (initialized)
-	return &drv;
-
-    drv.name = "cairo";
-    drv.Box = Cairo_Box;
-    drv.Erase = Cairo_Erase;
-    drv.Graph_set = Cairo_Graph_set;
-    drv.Graph_close = Cairo_Graph_close;
-    drv.Line_width = Cairo_Line_width;
-    drv.Set_window = Cairo_Set_window;
-    drv.Begin_raster = Cairo_begin_raster;
-    drv.Raster = Cairo_raster;
-    drv.End_raster = Cairo_end_raster;
-    drv.Begin = Cairo_Begin;
-    drv.Move = Cairo_Move;
-    drv.Cont = Cairo_Cont;
-    drv.Close = Cairo_Close;
-    drv.Stroke = Cairo_Stroke;
-    drv.Fill = Cairo_Fill;
-    drv.Point = Cairo_Point;
-    drv.Color = Cairo_Color;
-    drv.Bitmap = Cairo_Bitmap;
-    drv.Text = Cairo_Text;
-    drv.Text_box = Cairo_text_box;
-    drv.Set_font = Cairo_set_font;
-    drv.Font_list = Cairo_font_list;
-    drv.Font_info = Cairo_font_info;
-
-    initialized = 1;
-
-    return &drv;
-}

Deleted: grass/trunk/lib/cairodriver/Erase.c
===================================================================
--- grass/trunk/lib/cairodriver/Erase.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Erase.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,33 +0,0 @@
-/*!
-  \file cairodriver/Erase.c
-
-  \brief GRASS cairo display driver - erase screen
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-/*!
-  \brief Erase screen
-*/
-void Cairo_Erase(void)
-{
-    G_debug(1, "Cairo_Erase");
-
-    cairo_save(cairo);
-    cairo_set_source_rgba(cairo, ca.bgcolor_r, ca.bgcolor_g, ca.bgcolor_b, ca.bgcolor_a);
-    cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
-    cairo_paint(cairo);
-    cairo_restore(cairo);
-
-    ca.modified = 1;
-
-    return;
-}

Deleted: grass/trunk/lib/cairodriver/Graph.c
===================================================================
--- grass/trunk/lib/cairodriver/Graph.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Graph.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,400 +0,0 @@
-/*!
-  \file lib/cairodriver/Graph.c
-
-  \brief GRASS cairo display driver - driver settings
-
-  (C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-#if CAIRO_HAS_PS_SURFACE
-#include <cairo-ps.h>
-#endif
-#if CAIRO_HAS_PDF_SURFACE
-#include <cairo-pdf.h>
-#endif
-#if CAIRO_HAS_SVG_SURFACE
-#include <cairo-svg.h>
-#endif
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-#include <cairo-xlib.h>
-#include <cairo-xlib-xrender.h>
-#endif
-
-#include <unistd.h>
-#ifndef __MINGW32__
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#endif
-
-#include <grass/colors.h>
-#include <grass/glocale.h>
-
-struct cairo_state ca;
-
-/* cairo objects */
-cairo_surface_t *surface;
-cairo_t *cairo;
-
-static void init_cairo(void);
-static int ends_with(const char *string, const char *suffix);
-static void map_file(void);
-
-static void init_xlib(void)
-{
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    char *p;
-    unsigned long xid;
-    XVisualInfo templ;
-    XVisualInfo *vinfo;
-    int count;
-    Visual *visual;
-    int scrn;
-    Pixmap pix;
-    cairo_surface_t *s1, *s2;
-
-    ca.dpy = XOpenDisplay(NULL);
-    if (!ca.dpy)
-	G_fatal_error(_("Unable to open display"));
-
-    p = getenv("GRASS_RENDER_CAIRO_SCREEN");
-    if (!p || sscanf(p, "%i", &scrn) != 1)
-	scrn = DefaultScreen(ca.dpy);
-
-    p = getenv("GRASS_RENDER_CAIRO_VISUAL");
-    if (!p || sscanf(p, "%li", &xid) != 1)
-	xid = DefaultVisual(ca.dpy, scrn)->visualid;
-
-    templ.visualid = xid;
-    templ.screen = scrn;
-
-    vinfo = XGetVisualInfo(ca.dpy, VisualIDMask|VisualScreenMask, &templ, &count);
-    if (!vinfo || !count)
-	G_fatal_error(_("Unable to obtain visual"));
-    visual = vinfo[0].visual;
-
-    ca.screen = ScreenOfDisplay(ca.dpy, scrn);
-    pix = XCreatePixmap(ca.dpy, RootWindow(ca.dpy, scrn), 1, 1, vinfo[0].depth);
-    s1 = cairo_xlib_surface_create(ca.dpy, pix, visual, 1, 1);
-    s2 = cairo_surface_create_similar(s1, CAIRO_CONTENT_COLOR_ALPHA, 1, 1);
-    ca.format = cairo_xlib_surface_get_xrender_format(s2);
-    ca.depth = cairo_xlib_surface_get_depth(s2);
-    cairo_surface_destroy(s2);
-    cairo_surface_destroy(s1);
-    XFreePixmap(ca.dpy, pix);
-
-    if (!ca.win)
-	ca.win = XCreatePixmap(
-	    ca.dpy, RootWindow(ca.dpy, scrn),
-	    ca.width, ca.height, ca.depth);
-#endif
-}
-
-static void fini_xlib(void)
-{
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    XSetCloseDownMode(ca.dpy, RetainTemporary);
-    XCloseDisplay(ca.dpy);
-#endif
-}
-
-static void init_file(void)
-{
-    int is_vector = 0;
-    int is_xlib = 0;
-    int do_read = 0;
-    int do_map = 0;
-    char *p;
-
-    /* set image properties */
-    ca.width = screen_width;
-    ca.height = screen_height;
-    ca.stride = ca.width * 4;
-
-    /* get file name */
-    p = getenv("GRASS_RENDER_FILE");
-    if (!p || strlen(p) == 0)
-	p = DEFAULT_FILE_NAME;
-
-    ca.file_name = p;
-
-    /* get file type (from extension) */
-    if (ends_with(ca.file_name, ".ppm"))
-	ca.file_type = FTYPE_PPM;
-    else if (ends_with(ca.file_name, ".bmp"))
-	ca.file_type = FTYPE_BMP;
-#if CAIRO_HAS_PNG_FUNCTIONS
-    else if (ends_with(ca.file_name, ".png"))
-	ca.file_type = FTYPE_PNG;
-#endif
-#if CAIRO_HAS_PDF_SURFACE
-    else if (ends_with(ca.file_name, ".pdf"))
-	ca.file_type = FTYPE_PDF;
-#endif
-#if CAIRO_HAS_PS_SURFACE
-    else if (ends_with(ca.file_name, ".ps"))
-	ca.file_type = FTYPE_PS;
-#endif
-#if CAIRO_HAS_SVG_SURFACE
-    else if (ends_with(ca.file_name, ".svg"))
-	ca.file_type = FTYPE_SVG;
-#endif
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    else if (ends_with(ca.file_name, ".xid"))
-	ca.file_type = FTYPE_X11;
-#endif
-    else
-	G_fatal_error(_("Unknown file extension: %s"), p);
-    G_debug(1, "File type: %s (%d)", ca.file_name, ca.file_type);
-
-    switch (ca.file_type) {
-    case FTYPE_PDF:
-    case FTYPE_PS:
-    case FTYPE_SVG:
-	is_vector = 1;
-	break;
-    case FTYPE_X11:
-	is_xlib = 1;
-	break;
-    }
-
-    p = getenv("GRASS_RENDER_FILE_MAPPED");
-    do_map = p && strcmp(p, "TRUE") == 0 && ends_with(ca.file_name, ".bmp");
-
-    p = getenv("GRASS_RENDER_FILE_READ");
-    do_read = p && strcmp(p, "TRUE") == 0;
-
-    if (is_vector) {
-	do_read = do_map = 0;
-	ca.bgcolor_a = 1.0;
-    }
-
-    if (do_read && access(ca.file_name, 0) != 0)
-	do_read = 0;
-
-    G_verbose_message(_("cairo: collecting to file '%s'"),
-		      ca.file_name);
-    G_verbose_message(_("cairo: image size %dx%d"),
-		      ca.width, ca.height);
-    
-    if (do_read && do_map)
-	map_file();
-
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    if (is_xlib) {
-	if (do_read)
-	    cairo_read_xid();
-	else
-	    ca.win = 0;
-	init_xlib();
-	ca.mapped = 1;
-    }
-#endif
-
-    if (!ca.mapped && !is_vector)
-	ca.grid = G_malloc(ca.height * ca.stride);
-
-    init_cairo();
-
-    if (!do_read && !is_vector) {
-	Cairo_Erase();
-	ca.modified = 1;
-    }
-
-    if (do_read && !ca.mapped)
-	cairo_read_image();
-
-    if (do_map && !ca.mapped) {
-	cairo_write_image();
-	map_file();
-	init_cairo();
-    }
-}
-
-/*!
-  \brief Initialize driver
-
-  Set background color, transparency, drawable, antialias mode, etc.
-
-  \return 0
-*/
-int Cairo_Graph_set(void)
-{
-    cairo_antialias_t antialias;
-    char *p;
-
-    G_gisinit("Cairo driver");
-    G_debug(1, "Cairo_Graph_set");
-
-    /* get background color */
-    p = getenv("GRASS_RENDER_BACKGROUNDCOLOR");
-    if (p && *p) {
-	unsigned int red, green, blue;
-
-	if (sscanf(p, "%02x%02x%02x", &red, &green, &blue) == 3 ||
-	    G_str_to_color(p, (int *)&red, (int *)&green, (int *)&blue) == 1) {
-	    ca.bgcolor_r = CAIROCOLOR(red);
-	    ca.bgcolor_g = CAIROCOLOR(green);
-	    ca.bgcolor_b = CAIROCOLOR(blue);
-	}
-	else
-	    G_fatal_error("Unknown background color: %s", p);
-    }
-    else
-	ca.bgcolor_r = ca.bgcolor_g = ca.bgcolor_b = 1.0;
-
-    /* get background transparency setting */
-    p = getenv("GRASS_RENDER_TRANSPARENT");
-    if (p && strcmp(p, "TRUE") == 0)
-	ca.bgcolor_a = 0.0;
-    else
-	ca.bgcolor_a = 1.0;
-
-    antialias = CAIRO_ANTIALIAS_DEFAULT;
-    p = getenv("GRASS_RENDER_ANTIALIAS");
-    if (p && G_strcasecmp(p, "default") == 0)
-	antialias = CAIRO_ANTIALIAS_DEFAULT;
-    if (p && G_strcasecmp(p, "none") == 0)
-	antialias = CAIRO_ANTIALIAS_NONE;
-    if (p && G_strcasecmp(p, "gray") == 0)
-	antialias = CAIRO_ANTIALIAS_GRAY;
-    if (p && G_strcasecmp(p, "subpixel") == 0)
-	antialias = CAIRO_ANTIALIAS_SUBPIXEL;
-
-    init_file();
-
-    cairo_set_antialias(cairo, antialias);
-
-    return 0;
-}
-
-/*!
-  \brief Close driver
-*/
-void Cairo_Graph_close(void)
-{
-    G_debug(1, "Cairo_Graph_close");
-
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    if (ca.file_type == FTYPE_X11) {
-	XFlush(cairo_xlib_surface_get_display(surface));
-	ca.mapped = 0;
-    }
-#endif
-
-    cairo_write_image();
-
-    if (cairo) {
-	cairo_destroy(cairo);
-	cairo = NULL;
-    }
-    if (surface) {
-	cairo_surface_destroy(surface);
-	surface = NULL;
-    }
-
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    if (ca.file_type == FTYPE_X11)
-	fini_xlib();
-#endif
-}
-
-static void init_cairo(void)
-{
-    G_debug(1, "init_cairo");
-
-    /* create cairo surface */
-    switch (ca.file_type) {
-    case FTYPE_PPM:
-    case FTYPE_BMP:
-    case FTYPE_PNG:
-	surface =
-	    (cairo_surface_t *) cairo_image_surface_create_for_data(
-		ca.grid, CAIRO_FORMAT_ARGB32, ca.width, ca.height, ca.stride);
-	break;
-#if CAIRO_HAS_PDF_SURFACE
-    case FTYPE_PDF:
-	surface =
-	    (cairo_surface_t *) cairo_pdf_surface_create(
-		ca.file_name, (double) ca.width, (double) ca.height);
-	break;
-#endif
-#if CAIRO_HAS_PS_SURFACE
-    case FTYPE_PS:
-	surface =
-	    (cairo_surface_t *) cairo_ps_surface_create(
-		ca.file_name, (double) ca.width, (double) ca.height);
-	break;
-#endif
-#if CAIRO_HAS_SVG_SURFACE
-    case FTYPE_SVG:
-	surface =
-	    (cairo_surface_t *) cairo_svg_surface_create(
-		ca.file_name, (double) ca.width, (double) ca.height);
-	break;
-#endif
-#if CAIRO_HAS_XLIB_XRENDER_SURFACE
-    case FTYPE_X11:
-	surface =
-	    (cairo_surface_t *) cairo_xlib_surface_create_with_xrender_format(
-		ca.dpy, ca.win, ca.screen, ca.format, ca.width, ca.height);
-	break;
-#endif
-    default:
-	G_fatal_error(_("Unknown Cairo surface type"));
-	break;
-    }
-
-    if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS)
-	G_fatal_error(_("Failed to initialize Cairo surface"));
-
-    cairo = cairo_create(surface);
-}
-
-/* Returns TRUE if string ends with suffix (case insensitive) */
-static int ends_with(const char *string, const char *suffix)
-{
-    if (strlen(string) < strlen(suffix))
-	return FALSE;
-
-    return G_strcasecmp(suffix,
-			string + strlen(string) - strlen(suffix)) == 0;
-}
-
-static void map_file(void)
-{
-#ifndef __MINGW32__
-    size_t size = HEADER_SIZE + ca.width * ca.height * sizeof(unsigned int);
-    void *ptr;
-    int fd;
-
-    fd = open(ca.file_name, O_RDWR);
-    if (fd < 0)
-	return;
-
-    ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
-    if (ptr == MAP_FAILED)
-	return;
-
-    if (ca.grid) {
-	cairo_destroy(cairo);
-	cairo_surface_destroy(surface);
-	G_free(ca.grid);
-    }
-    ca.grid = (unsigned char *) ptr + HEADER_SIZE;
-
-    close(fd);
-
-    ca.mapped = 1;
-#endif
-}
-

Deleted: grass/trunk/lib/cairodriver/Line_width.c
===================================================================
--- grass/trunk/lib/cairodriver/Line_width.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Line_width.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,39 +0,0 @@
-/*!
-  \file cairodriver/Line_width.c
-
-  \brief GRASS cairo display driver - set line width
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-#define MIN_WIDTH 1
-
-#ifndef MAX
-#define MAX(a,b) ((a)>(b)?(a):(b))
-#endif
-
-static double previous_width = -1;
-
-/*!
-  \brief Set line width
-
-  \param width line width (double precision)
-*/
-void Cairo_Line_width(double width)
-{
-    G_debug(1, "Cairo_Line_width: %f", width);
-
-    width = MAX(MIN_WIDTH, width);
-    if (width != previous_width)
-	cairo_set_line_width(cairo, width);
-
-    return;
-}

Deleted: grass/trunk/lib/cairodriver/Makefile
===================================================================
--- grass/trunk/lib/cairodriver/Makefile	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,18 +0,0 @@
-MODULE_TOPDIR = ../..
-
-EXTRA_CFLAGS=-I../driver $(CAIROINC) $(FTINC)
-
-# added constant to /include/Make/Grass.make.in
-LIB = CAIRODRIVER
-PGM = cairodriver
-
-include $(MODULE_TOPDIR)/include/Make/Lib.make
-
-ifneq ($(USE_X11),)
-EXTRA_CFLAGS += $(XCFLAGS) -DUSE_X11=1
-endif
-
-ifneq ($(USE_CAIRO),)
-default: lib
-endif
-

Deleted: grass/trunk/lib/cairodriver/Raster.c
===================================================================
--- grass/trunk/lib/cairodriver/Raster.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Raster.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,134 +0,0 @@
-/*!
-  \file cairodriver/Raster.c
-
-  \brief GRASS cairo display driver - draw raster
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-
-#include "cairodriver.h"
-#include <grass/glocale.h>
-
-static int src_t, src_b, src_l, src_r, src_w, src_h;
-static double dst_t, dst_b, dst_l, dst_r, dst_w, dst_h;
-
-static cairo_surface_t *src_surf;
-static unsigned char *src_data;
-static int src_stride;
-
-static int masked;
-
-/*!
-  \brief Start drawing raster
-
-  \param mask
-  \param s
-  \param d
-*/
-void Cairo_begin_raster(int mask, int s[2][2], double d[2][2])
-{
-    cairo_status_t status;
-    
-    G_debug(1, "Cairo_begin_raster: %d, %d %d %d %d, %f %f %f %f",
-	    mask,
-	    s[0][0], s[0][1], s[1][0], s[1][1],
-	    d[0][0], d[0][1], d[1][0], d[1][1]);
-
-    masked = mask;
-
-    /* TODO: are top and left swapped? */
-
-    src_l = s[0][0];
-    src_r = s[0][1];
-    src_t = s[1][0];
-    src_b = s[1][1];
-
-    src_w = src_r - src_l;
-    src_h = src_b - src_t;
-
-    dst_l = d[0][0];
-    dst_r = d[0][1];
-    dst_t = d[1][0];
-    dst_b = d[1][1];
-
-    dst_w = dst_r - dst_l;
-    dst_h = dst_b - dst_t;
-
-    G_debug(1, " src (TBLR): %d %d %d %d, dst (TBLR) %f %f %f %f",
-	    src_t, src_b, src_l, src_r, dst_t, dst_b, dst_l, dst_r);
-
-    /* create source surface */
-    src_surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, src_w, src_h);
-    status = cairo_surface_status(src_surf);
-    if (status != CAIRO_STATUS_SUCCESS)
-	G_fatal_error("Cairo_begin_raster(): %s (%s). Using rows: %d, cols: %d ",
-                      _("Failed to create surface"),
-                      cairo_status_to_string (status), src_b, src_r);
-
-    src_data = cairo_image_surface_get_data(src_surf);
-    src_stride = cairo_image_surface_get_stride(src_surf);
-}
-
-/*!
-  \brief Draw raster row
-
-  \param n number of cell
-  \param row raster row
-  \param red,grn,blu,nul red,green,blue and null value
-
-  \return next row
-*/
-int Cairo_raster(int n, int row,
-		 const unsigned char *red, const unsigned char *grn,
-		 const unsigned char *blu, const unsigned char *nul)
-{
-    unsigned int *dst =
-	(unsigned int *)(src_data + (row - src_t) * src_stride);
-    int i;
-
-    G_debug(3, "Cairo_raster: %d %d", n, row);
-
-    for (i = 0; i < n; i++) {
-	if (masked && nul && nul[i])
-	    *dst++ = 0;
-	else {
-	    unsigned int r = red[i];
-	    unsigned int g = grn[i];
-	    unsigned int b = blu[i];
-	    unsigned int a = 0xFF;
-
-	    *dst++ = (a << 24) + (r << 16) + (g << 8) + (b << 0);
-	}
-    }
-
-    return row + 1;
-}
-
-/*!
-  \brief Finish drawing raster
-*/
-void Cairo_end_raster(void)
-{
-    G_debug(1, "Cairo_end_raster");
-
-    /* paint source surface onto dstination (scaled) */
-    cairo_save(cairo);
-    cairo_translate(cairo, dst_l, dst_t);
-    cairo_scale(cairo, dst_w / src_w, dst_h / src_h);
-    cairo_surface_mark_dirty(src_surf);
-    cairo_set_source_surface(cairo, src_surf, 0, 0);
-    cairo_pattern_set_filter(cairo_get_source(cairo), CAIRO_FILTER_NEAREST);
-    cairo_paint(cairo);
-    cairo_restore(cairo);
-
-    /* cleanup */
-    cairo_surface_destroy(src_surf);
-    ca.modified = 1;
-}

Deleted: grass/trunk/lib/cairodriver/Set_window.c
===================================================================
--- grass/trunk/lib/cairodriver/Set_window.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Set_window.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,31 +0,0 @@
-/*!
-  \file cairodriver/Set_window.c
-
-  \brief GRASS cairo display driver - set window
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include "cairodriver.h"
-
-/*!
-  \brief Set window
-  
-  \param t,b,l,r top, bottom, left, right
-*/
-void Cairo_Set_window(double t, double b, double l, double r)
-{
-    G_debug(1, "Cairo_Set_window: %f %f %f %f", t, b, l, r);
-
-    cairo_reset_clip(cairo);
-    cairo_rectangle(cairo, l, t, r - l, b - t);
-    cairo_clip(cairo);
-
-    return;
-}

Deleted: grass/trunk/lib/cairodriver/Text.c
===================================================================
--- grass/trunk/lib/cairodriver/Text.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/cairodriver/Text.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,343 +0,0 @@
-/*!
-  \file cairodriver/Text.c
-
-  \brief GRASS cairo display driver - text subroutines
-
-  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
-  \author Glynn Clements  
-*/
-
-#include <grass/glocale.h>
-#include "cairodriver.h"
-
-#if CAIRO_HAS_FT_FONT
-#include <cairo-ft.h>
-#include <fontconfig/fontconfig.h>
-#endif
-
-#ifdef HAVE_ICONV_H
-#include <iconv.h>
-#endif
-
-static char *convert(const char *in)
-{
-    size_t ilen, olen;
-    char *out;
-
-    ilen = strlen(in);
-    olen = 3 * ilen + 1;
-
-    out = G_malloc(olen);
-
-#ifdef HAVE_ICONV_H
-    {
-	const char *encoding = font_get_encoding();
-	char *p1 = (char *) in;
-	char *p2 = out;
-	size_t ret;
-	iconv_t cd;
-
-	if ((cd = iconv_open("UTF-8", encoding)) < 0)
-	    G_fatal_error(_("Unable to convert from <%s> to UTF-8"),
-			  encoding);
-
-	ret = iconv(cd, &p1, &ilen, &p2, &olen);
-
-	iconv_close(cd);
-
-	*p2++ = '\0';
-
-	if (ret > 0)
-	    G_warning(_("Some characters could not be converted to UTF-8"));
-    }
-#else
-    {
-	const unsigned char *p1 = (const unsigned char *) in;
-	unsigned char *p2 = (unsigned char *) out;
-	int i, j;
-
-	for (i = j = 0; i < ilen; i++) {
-	    int c = p1[i];
-	    if (c < 0x80)
-		p2[j++] = c;
-	    else {
-		p2[j++] = 0xC0 + (c >> 6);
-		p2[j++] = 0x80 + (c & 0x3F);
-	    }
-	}
-
-	p2[j++] = '\0';
-    }
-#endif
-
-    return out;
-}
-
-static void set_matrix(void)
-{
-    static cairo_matrix_t mat;
-
-    if (matrix_valid)
-	return;
-
-    cairo_matrix_init_identity(&mat);
-    cairo_matrix_scale(&mat, text_size_x, text_size_y);
-    cairo_matrix_rotate(&mat, -text_rotation * M_PI / 180);
-
-    cairo_set_font_matrix(cairo, &mat);
-
-    matrix_valid = 1;
-}
-
-/*!
-  \brief Draw text
-  
-  \param str string to be drawn
-*/
-void Cairo_Text(const char *str)
-{
-    char *utf8 = convert(str);
-
-    if (!utf8)
-	return;
-
-    set_matrix();
-
-    cairo_move_to(cairo, cur_x, cur_y);
-    cairo_show_text(cairo, utf8);
-
-    G_free(utf8);
-
-    ca.modified = 1;
-}
-
-/*
-  \brief Get text bounding box
-
-  \param str string
-  \param[out] t,b,l,r top, bottom, left, right corner
-*/
-void Cairo_text_box(const char *str, double *t, double *b, double *l, double *r)
-{
-    char *utf8 = convert(str);
-    cairo_text_extents_t ext;
-
-    if (!utf8)
-	return;
-
-    set_matrix();
-
-    cairo_text_extents(cairo, utf8, &ext);
-
-    G_free(utf8);
-
-    *l = cur_x + ext.x_bearing;
-    *r = cur_x + ext.x_bearing + ext.width;
-    *t = cur_y + ext.y_bearing;
-    *b = cur_y + ext.y_bearing + ext.height;
-}
-
-static void set_font_toy(const char *name)
-{
-    char *font = G_store(name);
-    cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
-    cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
-
-    for (;;) {
-	char *p = strrchr(font, '-');
-	if (!p)
-	    break;
-
-	if (G_strcasecmp(p, "-bold") == 0)
-	    weight = CAIRO_FONT_WEIGHT_BOLD;
-	else if (strcasecmp(p, "-italic") == 0)
-	    slant = CAIRO_FONT_SLANT_ITALIC;
-	else if (G_strcasecmp(p, "-oblique") == 0)
-	    slant = CAIRO_FONT_SLANT_OBLIQUE;
-	else
-	    break;
-
-	*p = '\0';
-    }
-
-    cairo_select_font_face(cairo, font, slant, weight);
-
-    G_free(font);
-}
-
-#if CAIRO_HAS_FT_FONT
-
-static void fc_init(void)
-{
-    static int initialized;
-
-    if (!initialized) {
-	FcInit();
-	initialized = 1;
-    }
-}
-
-static void set_font_fc(const char *name)
-{
-    static cairo_font_face_t *face;
-    FcPattern *pattern;
-    FcResult result;
-
-    fc_init();
-
-    if (face) {
-	cairo_font_face_destroy(face);
-	face = NULL;
-    }
-
-    pattern = FcNameParse(name);
-    FcDefaultSubstitute(pattern);
-    FcConfigSubstitute(FcConfigGetCurrent(), pattern, FcMatchPattern);
-    pattern = FcFontMatch(FcConfigGetCurrent(), pattern, &result);
-    face = cairo_ft_font_face_create_for_pattern(pattern);
-    cairo_set_font_face(cairo, face);
-}
-
-static void font_list_fc(char ***list, int *count, int verbose)
-{
-    FcPattern *pattern;
-    FcObjectSet *objset;
-    FcFontSet *fontset;
-    char **fonts = *list;
-    int num_fonts = *count;
-    int i;
-
-    fc_init();
-
-    pattern = FcPatternCreate();
-    objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (char *) NULL);
-    fontset = FcFontList(NULL, pattern, objset);
-
-    fonts = G_realloc(fonts, (num_fonts + fontset->nfont) * sizeof(char *));
-
-    for (i = 0; i < fontset->nfont; i++) {
-	char buf[1024];
-	FcPattern *pat = fontset->fonts[i];
-	FcChar8 *family = "", *style = "";
-
-	FcPatternGetString(pat, FC_FAMILY, 0, &family);
-	FcPatternGetString(pat, FC_STYLE , 0, &style );
-
-	if (verbose)
-	    sprintf(buf, "%s:%s|%s:%s|%d|%s|%d|%s|",
-		    family, style, family, style, GFONT_DRIVER, "", 0, "utf-8");
-	else
-	    sprintf(buf, "%s:%s", family, style);
-
-	fonts[num_fonts++] = G_store(buf);
-    }
-
-    FcObjectSetDestroy(objset);
-    FcPatternDestroy(pattern);
-    FcFontSetDestroy (fontset);
-
-    *list = fonts;
-    *count = num_fonts;
-}
-
-#endif
-
-static const char *toy_fonts[12] = {
-    "sans",
-    "sans-italic",
-    "sans-bold",
-    "sans-bold-italic",
-    "serif",
-    "serif-italic",
-    "serif-bold",
-    "serif-bold-italic",
-    "mono",
-    "mono-italic",
-    "mono-bold",
-    "mono-bold-italic",
-};
-static const int num_toy_fonts = 12;
-
-static int is_toy_font(const char *name)
-{
-    int i;
-
-    for (i = 0; i < num_toy_fonts; i++)
-	if (G_strcasecmp(name, toy_fonts[i]) == 0)
-	    return 1;
-
-    return 0;
-}
-
-/*!
-  \brief Set font
-
-  \param name font name
-*/
-void Cairo_set_font(const char *name)
-{
-#if CAIRO_HAS_FT_FONT
-    if (is_toy_font(name))
-	set_font_toy(name);
-    else
-	set_font_fc(name);
-#else
-    set_font_toy(name);
-#endif
-}
-
-static void font_list_toy(char ***list, int *count, int verbose)
-{
-    char **fonts = *list;
-    int num_fonts = *count;
-    int i;
-
-    fonts = G_realloc(fonts, (num_fonts + num_toy_fonts) * sizeof(char *));
-
-    for (i = 0; i < num_toy_fonts; i++) {
-	char buf[256];
-	if (verbose)
-	    sprintf(buf, "%s|%s|%d|%s|%d|%s|",
-		    toy_fonts[i], toy_fonts[i], GFONT_DRIVER, "", 0, "utf-8");
-	else
-	    strcpy(buf, toy_fonts[i]);
-	fonts[num_fonts++] = G_store(buf);
-    }
-
-    *list = fonts;
-    *count = num_fonts;
-}
-
-/*!
-  \brief Get list of fonts
-
-  \param[out] list font list
-  \param[out] count number of items in the list
-*/
-void Cairo_font_list(char ***list, int *count)
-{
-    font_list_toy(list, count, 0);
-#if CAIRO_HAS_FT_FONT
-    font_list_fc(list, count, 0);
-#endif
-}
-
-/*!
-  \brief Get fonts into
-
-  \param[out] list font list
-  \param[out] count number of items in the list
-*/
-void Cairo_font_info(char ***list, int *count)
-{
-    font_list_toy(list, count, 1);
-#if CAIRO_HAS_FT_FONT
-    font_list_fc(list, count, 1);
-#endif
-}
-

Copied: grass/trunk/lib/cairodriver/box.c (from rev 62429, grass/trunk/lib/cairodriver/Box.c)
===================================================================
--- grass/trunk/lib/cairodriver/box.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,31 @@
+/*!
+  \file cairodriver/Box.c
+
+  \brief GRASS cairo display driver - draw box
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+/*!
+  \brief Draw a (filled) rectangle
+
+  \param x1,y1,x2,y2 rectangle coordinates
+*/
+void Cairo_Box(double x1, double y1, double x2, double y2)
+{
+    G_debug(3, "Cairo_Box %f %f %f %f\n", x1, y1, x2, y2);
+
+    cairo_rectangle(cairo, x1, y1, x2 - x1, y2 - y1);
+    cairo_fill(cairo);
+    ca.modified = 1;
+
+    return;
+}

Copied: grass/trunk/lib/cairodriver/color.c (from rev 62429, grass/trunk/lib/cairodriver/Color.c)
===================================================================
--- grass/trunk/lib/cairodriver/color.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/color.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,36 @@
+/*!
+  \file cairodriver/Color.c
+
+  \brief GRASS cairo display driver - colors management
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements 
+*/  
+
+#include "cairodriver.h"
+
+/*!
+  \brief Set source color (opaque)
+  
+  This color will then be used for any subsequent drawing operation
+  until a new source pattern is set.
+  
+  \param r red color value
+  \param g green color value
+  \param b blue color value
+*/
+void Cairo_Color(int r, int g, int b)
+{
+    G_debug(3, "Cairo_Color: %d,%d,%d", r, g, b);
+
+    cairo_set_source_rgba(cairo,
+			  CAIROCOLOR(r), CAIROCOLOR(g), CAIROCOLOR(b), 1.0);
+
+    G_debug(3, "Set color to: %g %g %g",
+	    CAIROCOLOR(r), CAIROCOLOR(g), CAIROCOLOR(b));
+}

Copied: grass/trunk/lib/cairodriver/draw.c (from rev 62429, grass/trunk/lib/cairodriver/Draw.c)
===================================================================
--- grass/trunk/lib/cairodriver/draw.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,61 @@
+/*!
+  \file cairodriver/Draw.c
+
+  \brief GRASS cairo display driver
+
+  (C) 2007-2008 by Lars Ahlzen, Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+void Cairo_Begin(void)
+{
+    cairo_new_path(cairo);
+}
+
+void Cairo_Move(double x, double y)
+{
+    cairo_move_to(cairo, x, y);
+}
+
+void Cairo_Cont(double x, double y)
+{
+    cairo_line_to(cairo, x, y);
+}
+
+void Cairo_Close(void)
+{
+    cairo_close_path(cairo);
+}
+
+void Cairo_Stroke(void)
+{
+    cairo_stroke(cairo);
+    ca.modified = 1;
+}
+
+void Cairo_Fill(void)
+{
+    cairo_fill(cairo);
+    ca.modified = 1;
+}
+
+void Cairo_Point(double x, double y)
+{
+    static double point_size = 1.0;
+    double half_point_size = point_size / 2;
+
+    cairo_new_path(cairo);
+    cairo_rectangle(cairo,
+		    x - half_point_size, y - half_point_size,
+		    point_size, point_size);
+    cairo_fill(cairo);
+    ca.modified = 1;
+}
+

Copied: grass/trunk/lib/cairodriver/draw_bitmap.c (from rev 62429, grass/trunk/lib/cairodriver/Draw_bitmap.c)
===================================================================
--- grass/trunk/lib/cairodriver/draw_bitmap.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/draw_bitmap.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,58 @@
+/*!
+  \file cairodriver/Draw_bitmap.c
+
+  \brief GRASS cairo display driver - draw bitmap
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include <grass/glocale.h>
+
+#include "cairodriver.h"
+
+/*!
+  \brief Draw bitmap
+
+  \param ncols,nrows number of columns and rows
+  \param threshold threshold value
+  \param buf data buffer
+*/
+void Cairo_Bitmap(int ncols, int nrows, int threshold,
+		  const unsigned char *buf)
+{
+    cairo_surface_t *surf;
+    int stride;
+    unsigned char *data;
+    int i;
+
+    G_debug(1, "Cairo_Bitmap: %d %d %d", ncols, nrows, threshold);
+
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,8)
+    stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
+#else
+#define MULTIPLE 4
+    stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE;
+#endif
+    data = malloc(stride * nrows);
+    surf = cairo_image_surface_create_for_data(
+	data, CAIRO_FORMAT_A8, ncols, nrows, stride);
+
+    if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
+	G_fatal_error(_("Cairo_Bitmap: Failed to create source"));
+
+    for (i = 0; i < nrows; i++)
+	memcpy(&data[i * stride], &buf[i * ncols], ncols);
+
+    cairo_surface_mark_dirty(surf);
+    cairo_mask_surface(cairo, surf, cur_x, cur_y);
+
+    cairo_surface_destroy(surf);
+    ca.modified = 1;
+}
+

Copied: grass/trunk/lib/cairodriver/driver.c (from rev 62429, grass/trunk/lib/cairodriver/Driver.c)
===================================================================
--- grass/trunk/lib/cairodriver/driver.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,58 @@
+/*!
+  \file lib/cairodriver/Driver.c
+
+  \brief GRASS cairo display driver - driver initialization
+
+  (C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+/*!
+  \brief Initialize display driver
+
+  \return pointer driver structure
+*/
+const struct driver *Cairo_Driver(void)
+{
+    static struct driver drv;
+    static int initialized;
+
+    if (initialized)
+	return &drv;
+
+    drv.name = "cairo";
+    drv.Box = Cairo_Box;
+    drv.Erase = Cairo_Erase;
+    drv.Graph_set = Cairo_Graph_set;
+    drv.Graph_close = Cairo_Graph_close;
+    drv.Line_width = Cairo_Line_width;
+    drv.Set_window = Cairo_Set_window;
+    drv.Begin_raster = Cairo_begin_raster;
+    drv.Raster = Cairo_raster;
+    drv.End_raster = Cairo_end_raster;
+    drv.Begin = Cairo_Begin;
+    drv.Move = Cairo_Move;
+    drv.Cont = Cairo_Cont;
+    drv.Close = Cairo_Close;
+    drv.Stroke = Cairo_Stroke;
+    drv.Fill = Cairo_Fill;
+    drv.Point = Cairo_Point;
+    drv.Color = Cairo_Color;
+    drv.Bitmap = Cairo_Bitmap;
+    drv.Text = Cairo_Text;
+    drv.Text_box = Cairo_text_box;
+    drv.Set_font = Cairo_set_font;
+    drv.Font_list = Cairo_font_list;
+    drv.Font_info = Cairo_font_info;
+
+    initialized = 1;
+
+    return &drv;
+}

Copied: grass/trunk/lib/cairodriver/erase.c (from rev 62429, grass/trunk/lib/cairodriver/Erase.c)
===================================================================
--- grass/trunk/lib/cairodriver/erase.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/erase.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,33 @@
+/*!
+  \file cairodriver/Erase.c
+
+  \brief GRASS cairo display driver - erase screen
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+/*!
+  \brief Erase screen
+*/
+void Cairo_Erase(void)
+{
+    G_debug(1, "Cairo_Erase");
+
+    cairo_save(cairo);
+    cairo_set_source_rgba(cairo, ca.bgcolor_r, ca.bgcolor_g, ca.bgcolor_b, ca.bgcolor_a);
+    cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
+    cairo_paint(cairo);
+    cairo_restore(cairo);
+
+    ca.modified = 1;
+
+    return;
+}

Copied: grass/trunk/lib/cairodriver/graph.c (from rev 62429, grass/trunk/lib/cairodriver/Graph.c)
===================================================================
--- grass/trunk/lib/cairodriver/graph.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/graph.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,400 @@
+/*!
+  \file lib/cairodriver/Graph.c
+
+  \brief GRASS cairo display driver - driver settings
+
+  (C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+#if CAIRO_HAS_PS_SURFACE
+#include <cairo-ps.h>
+#endif
+#if CAIRO_HAS_PDF_SURFACE
+#include <cairo-pdf.h>
+#endif
+#if CAIRO_HAS_SVG_SURFACE
+#include <cairo-svg.h>
+#endif
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+#include <cairo-xlib.h>
+#include <cairo-xlib-xrender.h>
+#endif
+
+#include <unistd.h>
+#ifndef __MINGW32__
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#endif
+
+#include <grass/colors.h>
+#include <grass/glocale.h>
+
+struct cairo_state ca;
+
+/* cairo objects */
+cairo_surface_t *surface;
+cairo_t *cairo;
+
+static void init_cairo(void);
+static int ends_with(const char *string, const char *suffix);
+static void map_file(void);
+
+static void init_xlib(void)
+{
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    char *p;
+    unsigned long xid;
+    XVisualInfo templ;
+    XVisualInfo *vinfo;
+    int count;
+    Visual *visual;
+    int scrn;
+    Pixmap pix;
+    cairo_surface_t *s1, *s2;
+
+    ca.dpy = XOpenDisplay(NULL);
+    if (!ca.dpy)
+	G_fatal_error(_("Unable to open display"));
+
+    p = getenv("GRASS_RENDER_CAIRO_SCREEN");
+    if (!p || sscanf(p, "%i", &scrn) != 1)
+	scrn = DefaultScreen(ca.dpy);
+
+    p = getenv("GRASS_RENDER_CAIRO_VISUAL");
+    if (!p || sscanf(p, "%li", &xid) != 1)
+	xid = DefaultVisual(ca.dpy, scrn)->visualid;
+
+    templ.visualid = xid;
+    templ.screen = scrn;
+
+    vinfo = XGetVisualInfo(ca.dpy, VisualIDMask|VisualScreenMask, &templ, &count);
+    if (!vinfo || !count)
+	G_fatal_error(_("Unable to obtain visual"));
+    visual = vinfo[0].visual;
+
+    ca.screen = ScreenOfDisplay(ca.dpy, scrn);
+    pix = XCreatePixmap(ca.dpy, RootWindow(ca.dpy, scrn), 1, 1, vinfo[0].depth);
+    s1 = cairo_xlib_surface_create(ca.dpy, pix, visual, 1, 1);
+    s2 = cairo_surface_create_similar(s1, CAIRO_CONTENT_COLOR_ALPHA, 1, 1);
+    ca.format = cairo_xlib_surface_get_xrender_format(s2);
+    ca.depth = cairo_xlib_surface_get_depth(s2);
+    cairo_surface_destroy(s2);
+    cairo_surface_destroy(s1);
+    XFreePixmap(ca.dpy, pix);
+
+    if (!ca.win)
+	ca.win = XCreatePixmap(
+	    ca.dpy, RootWindow(ca.dpy, scrn),
+	    ca.width, ca.height, ca.depth);
+#endif
+}
+
+static void fini_xlib(void)
+{
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    XSetCloseDownMode(ca.dpy, RetainTemporary);
+    XCloseDisplay(ca.dpy);
+#endif
+}
+
+static void init_file(void)
+{
+    int is_vector = 0;
+    int is_xlib = 0;
+    int do_read = 0;
+    int do_map = 0;
+    char *p;
+
+    /* set image properties */
+    ca.width = screen_width;
+    ca.height = screen_height;
+    ca.stride = ca.width * 4;
+
+    /* get file name */
+    p = getenv("GRASS_RENDER_FILE");
+    if (!p || strlen(p) == 0)
+	p = DEFAULT_FILE_NAME;
+
+    ca.file_name = p;
+
+    /* get file type (from extension) */
+    if (ends_with(ca.file_name, ".ppm"))
+	ca.file_type = FTYPE_PPM;
+    else if (ends_with(ca.file_name, ".bmp"))
+	ca.file_type = FTYPE_BMP;
+#if CAIRO_HAS_PNG_FUNCTIONS
+    else if (ends_with(ca.file_name, ".png"))
+	ca.file_type = FTYPE_PNG;
+#endif
+#if CAIRO_HAS_PDF_SURFACE
+    else if (ends_with(ca.file_name, ".pdf"))
+	ca.file_type = FTYPE_PDF;
+#endif
+#if CAIRO_HAS_PS_SURFACE
+    else if (ends_with(ca.file_name, ".ps"))
+	ca.file_type = FTYPE_PS;
+#endif
+#if CAIRO_HAS_SVG_SURFACE
+    else if (ends_with(ca.file_name, ".svg"))
+	ca.file_type = FTYPE_SVG;
+#endif
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    else if (ends_with(ca.file_name, ".xid"))
+	ca.file_type = FTYPE_X11;
+#endif
+    else
+	G_fatal_error(_("Unknown file extension: %s"), p);
+    G_debug(1, "File type: %s (%d)", ca.file_name, ca.file_type);
+
+    switch (ca.file_type) {
+    case FTYPE_PDF:
+    case FTYPE_PS:
+    case FTYPE_SVG:
+	is_vector = 1;
+	break;
+    case FTYPE_X11:
+	is_xlib = 1;
+	break;
+    }
+
+    p = getenv("GRASS_RENDER_FILE_MAPPED");
+    do_map = p && strcmp(p, "TRUE") == 0 && ends_with(ca.file_name, ".bmp");
+
+    p = getenv("GRASS_RENDER_FILE_READ");
+    do_read = p && strcmp(p, "TRUE") == 0;
+
+    if (is_vector) {
+	do_read = do_map = 0;
+	ca.bgcolor_a = 1.0;
+    }
+
+    if (do_read && access(ca.file_name, 0) != 0)
+	do_read = 0;
+
+    G_verbose_message(_("cairo: collecting to file '%s'"),
+		      ca.file_name);
+    G_verbose_message(_("cairo: image size %dx%d"),
+		      ca.width, ca.height);
+    
+    if (do_read && do_map)
+	map_file();
+
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    if (is_xlib) {
+	if (do_read)
+	    cairo_read_xid();
+	else
+	    ca.win = 0;
+	init_xlib();
+	ca.mapped = 1;
+    }
+#endif
+
+    if (!ca.mapped && !is_vector)
+	ca.grid = G_malloc(ca.height * ca.stride);
+
+    init_cairo();
+
+    if (!do_read && !is_vector) {
+	Cairo_Erase();
+	ca.modified = 1;
+    }
+
+    if (do_read && !ca.mapped)
+	cairo_read_image();
+
+    if (do_map && !ca.mapped) {
+	cairo_write_image();
+	map_file();
+	init_cairo();
+    }
+}
+
+/*!
+  \brief Initialize driver
+
+  Set background color, transparency, drawable, antialias mode, etc.
+
+  \return 0
+*/
+int Cairo_Graph_set(void)
+{
+    cairo_antialias_t antialias;
+    char *p;
+
+    G_gisinit("Cairo driver");
+    G_debug(1, "Cairo_Graph_set");
+
+    /* get background color */
+    p = getenv("GRASS_RENDER_BACKGROUNDCOLOR");
+    if (p && *p) {
+	unsigned int red, green, blue;
+
+	if (sscanf(p, "%02x%02x%02x", &red, &green, &blue) == 3 ||
+	    G_str_to_color(p, (int *)&red, (int *)&green, (int *)&blue) == 1) {
+	    ca.bgcolor_r = CAIROCOLOR(red);
+	    ca.bgcolor_g = CAIROCOLOR(green);
+	    ca.bgcolor_b = CAIROCOLOR(blue);
+	}
+	else
+	    G_fatal_error("Unknown background color: %s", p);
+    }
+    else
+	ca.bgcolor_r = ca.bgcolor_g = ca.bgcolor_b = 1.0;
+
+    /* get background transparency setting */
+    p = getenv("GRASS_RENDER_TRANSPARENT");
+    if (p && strcmp(p, "TRUE") == 0)
+	ca.bgcolor_a = 0.0;
+    else
+	ca.bgcolor_a = 1.0;
+
+    antialias = CAIRO_ANTIALIAS_DEFAULT;
+    p = getenv("GRASS_RENDER_ANTIALIAS");
+    if (p && G_strcasecmp(p, "default") == 0)
+	antialias = CAIRO_ANTIALIAS_DEFAULT;
+    if (p && G_strcasecmp(p, "none") == 0)
+	antialias = CAIRO_ANTIALIAS_NONE;
+    if (p && G_strcasecmp(p, "gray") == 0)
+	antialias = CAIRO_ANTIALIAS_GRAY;
+    if (p && G_strcasecmp(p, "subpixel") == 0)
+	antialias = CAIRO_ANTIALIAS_SUBPIXEL;
+
+    init_file();
+
+    cairo_set_antialias(cairo, antialias);
+
+    return 0;
+}
+
+/*!
+  \brief Close driver
+*/
+void Cairo_Graph_close(void)
+{
+    G_debug(1, "Cairo_Graph_close");
+
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    if (ca.file_type == FTYPE_X11) {
+	XFlush(cairo_xlib_surface_get_display(surface));
+	ca.mapped = 0;
+    }
+#endif
+
+    cairo_write_image();
+
+    if (cairo) {
+	cairo_destroy(cairo);
+	cairo = NULL;
+    }
+    if (surface) {
+	cairo_surface_destroy(surface);
+	surface = NULL;
+    }
+
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    if (ca.file_type == FTYPE_X11)
+	fini_xlib();
+#endif
+}
+
+static void init_cairo(void)
+{
+    G_debug(1, "init_cairo");
+
+    /* create cairo surface */
+    switch (ca.file_type) {
+    case FTYPE_PPM:
+    case FTYPE_BMP:
+    case FTYPE_PNG:
+	surface =
+	    (cairo_surface_t *) cairo_image_surface_create_for_data(
+		ca.grid, CAIRO_FORMAT_ARGB32, ca.width, ca.height, ca.stride);
+	break;
+#if CAIRO_HAS_PDF_SURFACE
+    case FTYPE_PDF:
+	surface =
+	    (cairo_surface_t *) cairo_pdf_surface_create(
+		ca.file_name, (double) ca.width, (double) ca.height);
+	break;
+#endif
+#if CAIRO_HAS_PS_SURFACE
+    case FTYPE_PS:
+	surface =
+	    (cairo_surface_t *) cairo_ps_surface_create(
+		ca.file_name, (double) ca.width, (double) ca.height);
+	break;
+#endif
+#if CAIRO_HAS_SVG_SURFACE
+    case FTYPE_SVG:
+	surface =
+	    (cairo_surface_t *) cairo_svg_surface_create(
+		ca.file_name, (double) ca.width, (double) ca.height);
+	break;
+#endif
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+    case FTYPE_X11:
+	surface =
+	    (cairo_surface_t *) cairo_xlib_surface_create_with_xrender_format(
+		ca.dpy, ca.win, ca.screen, ca.format, ca.width, ca.height);
+	break;
+#endif
+    default:
+	G_fatal_error(_("Unknown Cairo surface type"));
+	break;
+    }
+
+    if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS)
+	G_fatal_error(_("Failed to initialize Cairo surface"));
+
+    cairo = cairo_create(surface);
+}
+
+/* Returns TRUE if string ends with suffix (case insensitive) */
+static int ends_with(const char *string, const char *suffix)
+{
+    if (strlen(string) < strlen(suffix))
+	return FALSE;
+
+    return G_strcasecmp(suffix,
+			string + strlen(string) - strlen(suffix)) == 0;
+}
+
+static void map_file(void)
+{
+#ifndef __MINGW32__
+    size_t size = HEADER_SIZE + ca.width * ca.height * sizeof(unsigned int);
+    void *ptr;
+    int fd;
+
+    fd = open(ca.file_name, O_RDWR);
+    if (fd < 0)
+	return;
+
+    ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
+    if (ptr == MAP_FAILED)
+	return;
+
+    if (ca.grid) {
+	cairo_destroy(cairo);
+	cairo_surface_destroy(surface);
+	G_free(ca.grid);
+    }
+    ca.grid = (unsigned char *) ptr + HEADER_SIZE;
+
+    close(fd);
+
+    ca.mapped = 1;
+#endif
+}
+

Copied: grass/trunk/lib/cairodriver/line_width.c (from rev 62429, grass/trunk/lib/cairodriver/Line_width.c)
===================================================================
--- grass/trunk/lib/cairodriver/line_width.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/line_width.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,39 @@
+/*!
+  \file cairodriver/Line_width.c
+
+  \brief GRASS cairo display driver - set line width
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+#define MIN_WIDTH 1
+
+#ifndef MAX
+#define MAX(a,b) ((a)>(b)?(a):(b))
+#endif
+
+static double previous_width = -1;
+
+/*!
+  \brief Set line width
+
+  \param width line width (double precision)
+*/
+void Cairo_Line_width(double width)
+{
+    G_debug(1, "Cairo_Line_width: %f", width);
+
+    width = MAX(MIN_WIDTH, width);
+    if (width != previous_width)
+	cairo_set_line_width(cairo, width);
+
+    return;
+}

Copied: grass/trunk/lib/cairodriver/makefile (from rev 62429, grass/trunk/lib/cairodriver/Makefile)
===================================================================
--- grass/trunk/lib/cairodriver/makefile	                        (rev 0)
+++ grass/trunk/lib/cairodriver/makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,18 @@
+MODULE_TOPDIR = ../..
+
+EXTRA_CFLAGS=-I../driver $(CAIROINC) $(FTINC)
+
+# added constant to /include/Make/Grass.make.in
+LIB = CAIRODRIVER
+PGM = cairodriver
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+ifneq ($(USE_X11),)
+EXTRA_CFLAGS += $(XCFLAGS) -DUSE_X11=1
+endif
+
+ifneq ($(USE_CAIRO),)
+default: lib
+endif
+

Copied: grass/trunk/lib/cairodriver/raster.c (from rev 62429, grass/trunk/lib/cairodriver/Raster.c)
===================================================================
--- grass/trunk/lib/cairodriver/raster.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/raster.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,134 @@
+/*!
+  \file cairodriver/Raster.c
+
+  \brief GRASS cairo display driver - draw raster
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+
+#include "cairodriver.h"
+#include <grass/glocale.h>
+
+static int src_t, src_b, src_l, src_r, src_w, src_h;
+static double dst_t, dst_b, dst_l, dst_r, dst_w, dst_h;
+
+static cairo_surface_t *src_surf;
+static unsigned char *src_data;
+static int src_stride;
+
+static int masked;
+
+/*!
+  \brief Start drawing raster
+
+  \param mask
+  \param s
+  \param d
+*/
+void Cairo_begin_raster(int mask, int s[2][2], double d[2][2])
+{
+    cairo_status_t status;
+    
+    G_debug(1, "Cairo_begin_raster: %d, %d %d %d %d, %f %f %f %f",
+	    mask,
+	    s[0][0], s[0][1], s[1][0], s[1][1],
+	    d[0][0], d[0][1], d[1][0], d[1][1]);
+
+    masked = mask;
+
+    /* TODO: are top and left swapped? */
+
+    src_l = s[0][0];
+    src_r = s[0][1];
+    src_t = s[1][0];
+    src_b = s[1][1];
+
+    src_w = src_r - src_l;
+    src_h = src_b - src_t;
+
+    dst_l = d[0][0];
+    dst_r = d[0][1];
+    dst_t = d[1][0];
+    dst_b = d[1][1];
+
+    dst_w = dst_r - dst_l;
+    dst_h = dst_b - dst_t;
+
+    G_debug(1, " src (TBLR): %d %d %d %d, dst (TBLR) %f %f %f %f",
+	    src_t, src_b, src_l, src_r, dst_t, dst_b, dst_l, dst_r);
+
+    /* create source surface */
+    src_surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, src_w, src_h);
+    status = cairo_surface_status(src_surf);
+    if (status != CAIRO_STATUS_SUCCESS)
+	G_fatal_error("Cairo_begin_raster(): %s (%s). Using rows: %d, cols: %d ",
+                      _("Failed to create surface"),
+                      cairo_status_to_string (status), src_b, src_r);
+
+    src_data = cairo_image_surface_get_data(src_surf);
+    src_stride = cairo_image_surface_get_stride(src_surf);
+}
+
+/*!
+  \brief Draw raster row
+
+  \param n number of cell
+  \param row raster row
+  \param red,grn,blu,nul red,green,blue and null value
+
+  \return next row
+*/
+int Cairo_raster(int n, int row,
+		 const unsigned char *red, const unsigned char *grn,
+		 const unsigned char *blu, const unsigned char *nul)
+{
+    unsigned int *dst =
+	(unsigned int *)(src_data + (row - src_t) * src_stride);
+    int i;
+
+    G_debug(3, "Cairo_raster: %d %d", n, row);
+
+    for (i = 0; i < n; i++) {
+	if (masked && nul && nul[i])
+	    *dst++ = 0;
+	else {
+	    unsigned int r = red[i];
+	    unsigned int g = grn[i];
+	    unsigned int b = blu[i];
+	    unsigned int a = 0xFF;
+
+	    *dst++ = (a << 24) + (r << 16) + (g << 8) + (b << 0);
+	}
+    }
+
+    return row + 1;
+}
+
+/*!
+  \brief Finish drawing raster
+*/
+void Cairo_end_raster(void)
+{
+    G_debug(1, "Cairo_end_raster");
+
+    /* paint source surface onto dstination (scaled) */
+    cairo_save(cairo);
+    cairo_translate(cairo, dst_l, dst_t);
+    cairo_scale(cairo, dst_w / src_w, dst_h / src_h);
+    cairo_surface_mark_dirty(src_surf);
+    cairo_set_source_surface(cairo, src_surf, 0, 0);
+    cairo_pattern_set_filter(cairo_get_source(cairo), CAIRO_FILTER_NEAREST);
+    cairo_paint(cairo);
+    cairo_restore(cairo);
+
+    /* cleanup */
+    cairo_surface_destroy(src_surf);
+    ca.modified = 1;
+}

Copied: grass/trunk/lib/cairodriver/set_window.c (from rev 62429, grass/trunk/lib/cairodriver/Set_window.c)
===================================================================
--- grass/trunk/lib/cairodriver/set_window.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/set_window.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,31 @@
+/*!
+  \file cairodriver/Set_window.c
+
+  \brief GRASS cairo display driver - set window
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include "cairodriver.h"
+
+/*!
+  \brief Set window
+  
+  \param t,b,l,r top, bottom, left, right
+*/
+void Cairo_Set_window(double t, double b, double l, double r)
+{
+    G_debug(1, "Cairo_Set_window: %f %f %f %f", t, b, l, r);
+
+    cairo_reset_clip(cairo);
+    cairo_rectangle(cairo, l, t, r - l, b - t);
+    cairo_clip(cairo);
+
+    return;
+}

Copied: grass/trunk/lib/cairodriver/text.c (from rev 62429, grass/trunk/lib/cairodriver/Text.c)
===================================================================
--- grass/trunk/lib/cairodriver/text.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/text.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,343 @@
+/*!
+  \file cairodriver/Text.c
+
+  \brief GRASS cairo display driver - text subroutines
+
+  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
+  \author Glynn Clements  
+*/
+
+#include <grass/glocale.h>
+#include "cairodriver.h"
+
+#if CAIRO_HAS_FT_FONT
+#include <cairo-ft.h>
+#include <fontconfig/fontconfig.h>
+#endif
+
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
+
+static char *convert(const char *in)
+{
+    size_t ilen, olen;
+    char *out;
+
+    ilen = strlen(in);
+    olen = 3 * ilen + 1;
+
+    out = G_malloc(olen);
+
+#ifdef HAVE_ICONV_H
+    {
+	const char *encoding = font_get_encoding();
+	char *p1 = (char *) in;
+	char *p2 = out;
+	size_t ret;
+	iconv_t cd;
+
+	if ((cd = iconv_open("UTF-8", encoding)) < 0)
+	    G_fatal_error(_("Unable to convert from <%s> to UTF-8"),
+			  encoding);
+
+	ret = iconv(cd, &p1, &ilen, &p2, &olen);
+
+	iconv_close(cd);
+
+	*p2++ = '\0';
+
+	if (ret > 0)
+	    G_warning(_("Some characters could not be converted to UTF-8"));
+    }
+#else
+    {
+	const unsigned char *p1 = (const unsigned char *) in;
+	unsigned char *p2 = (unsigned char *) out;
+	int i, j;
+
+	for (i = j = 0; i < ilen; i++) {
+	    int c = p1[i];
+	    if (c < 0x80)
+		p2[j++] = c;
+	    else {
+		p2[j++] = 0xC0 + (c >> 6);
+		p2[j++] = 0x80 + (c & 0x3F);
+	    }
+	}
+
+	p2[j++] = '\0';
+    }
+#endif
+
+    return out;
+}
+
+static void set_matrix(void)
+{
+    static cairo_matrix_t mat;
+
+    if (matrix_valid)
+	return;
+
+    cairo_matrix_init_identity(&mat);
+    cairo_matrix_scale(&mat, text_size_x, text_size_y);
+    cairo_matrix_rotate(&mat, -text_rotation * M_PI / 180);
+
+    cairo_set_font_matrix(cairo, &mat);
+
+    matrix_valid = 1;
+}
+
+/*!
+  \brief Draw text
+  
+  \param str string to be drawn
+*/
+void Cairo_Text(const char *str)
+{
+    char *utf8 = convert(str);
+
+    if (!utf8)
+	return;
+
+    set_matrix();
+
+    cairo_move_to(cairo, cur_x, cur_y);
+    cairo_show_text(cairo, utf8);
+
+    G_free(utf8);
+
+    ca.modified = 1;
+}
+
+/*
+  \brief Get text bounding box
+
+  \param str string
+  \param[out] t,b,l,r top, bottom, left, right corner
+*/
+void Cairo_text_box(const char *str, double *t, double *b, double *l, double *r)
+{
+    char *utf8 = convert(str);
+    cairo_text_extents_t ext;
+
+    if (!utf8)
+	return;
+
+    set_matrix();
+
+    cairo_text_extents(cairo, utf8, &ext);
+
+    G_free(utf8);
+
+    *l = cur_x + ext.x_bearing;
+    *r = cur_x + ext.x_bearing + ext.width;
+    *t = cur_y + ext.y_bearing;
+    *b = cur_y + ext.y_bearing + ext.height;
+}
+
+static void set_font_toy(const char *name)
+{
+    char *font = G_store(name);
+    cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
+    cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
+
+    for (;;) {
+	char *p = strrchr(font, '-');
+	if (!p)
+	    break;
+
+	if (G_strcasecmp(p, "-bold") == 0)
+	    weight = CAIRO_FONT_WEIGHT_BOLD;
+	else if (strcasecmp(p, "-italic") == 0)
+	    slant = CAIRO_FONT_SLANT_ITALIC;
+	else if (G_strcasecmp(p, "-oblique") == 0)
+	    slant = CAIRO_FONT_SLANT_OBLIQUE;
+	else
+	    break;
+
+	*p = '\0';
+    }
+
+    cairo_select_font_face(cairo, font, slant, weight);
+
+    G_free(font);
+}
+
+#if CAIRO_HAS_FT_FONT
+
+static void fc_init(void)
+{
+    static int initialized;
+
+    if (!initialized) {
+	FcInit();
+	initialized = 1;
+    }
+}
+
+static void set_font_fc(const char *name)
+{
+    static cairo_font_face_t *face;
+    FcPattern *pattern;
+    FcResult result;
+
+    fc_init();
+
+    if (face) {
+	cairo_font_face_destroy(face);
+	face = NULL;
+    }
+
+    pattern = FcNameParse(name);
+    FcDefaultSubstitute(pattern);
+    FcConfigSubstitute(FcConfigGetCurrent(), pattern, FcMatchPattern);
+    pattern = FcFontMatch(FcConfigGetCurrent(), pattern, &result);
+    face = cairo_ft_font_face_create_for_pattern(pattern);
+    cairo_set_font_face(cairo, face);
+}
+
+static void font_list_fc(char ***list, int *count, int verbose)
+{
+    FcPattern *pattern;
+    FcObjectSet *objset;
+    FcFontSet *fontset;
+    char **fonts = *list;
+    int num_fonts = *count;
+    int i;
+
+    fc_init();
+
+    pattern = FcPatternCreate();
+    objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (char *) NULL);
+    fontset = FcFontList(NULL, pattern, objset);
+
+    fonts = G_realloc(fonts, (num_fonts + fontset->nfont) * sizeof(char *));
+
+    for (i = 0; i < fontset->nfont; i++) {
+	char buf[1024];
+	FcPattern *pat = fontset->fonts[i];
+	FcChar8 *family = "", *style = "";
+
+	FcPatternGetString(pat, FC_FAMILY, 0, &family);
+	FcPatternGetString(pat, FC_STYLE , 0, &style );
+
+	if (verbose)
+	    sprintf(buf, "%s:%s|%s:%s|%d|%s|%d|%s|",
+		    family, style, family, style, GFONT_DRIVER, "", 0, "utf-8");
+	else
+	    sprintf(buf, "%s:%s", family, style);
+
+	fonts[num_fonts++] = G_store(buf);
+    }
+
+    FcObjectSetDestroy(objset);
+    FcPatternDestroy(pattern);
+    FcFontSetDestroy (fontset);
+
+    *list = fonts;
+    *count = num_fonts;
+}
+
+#endif
+
+static const char *toy_fonts[12] = {
+    "sans",
+    "sans-italic",
+    "sans-bold",
+    "sans-bold-italic",
+    "serif",
+    "serif-italic",
+    "serif-bold",
+    "serif-bold-italic",
+    "mono",
+    "mono-italic",
+    "mono-bold",
+    "mono-bold-italic",
+};
+static const int num_toy_fonts = 12;
+
+static int is_toy_font(const char *name)
+{
+    int i;
+
+    for (i = 0; i < num_toy_fonts; i++)
+	if (G_strcasecmp(name, toy_fonts[i]) == 0)
+	    return 1;
+
+    return 0;
+}
+
+/*!
+  \brief Set font
+
+  \param name font name
+*/
+void Cairo_set_font(const char *name)
+{
+#if CAIRO_HAS_FT_FONT
+    if (is_toy_font(name))
+	set_font_toy(name);
+    else
+	set_font_fc(name);
+#else
+    set_font_toy(name);
+#endif
+}
+
+static void font_list_toy(char ***list, int *count, int verbose)
+{
+    char **fonts = *list;
+    int num_fonts = *count;
+    int i;
+
+    fonts = G_realloc(fonts, (num_fonts + num_toy_fonts) * sizeof(char *));
+
+    for (i = 0; i < num_toy_fonts; i++) {
+	char buf[256];
+	if (verbose)
+	    sprintf(buf, "%s|%s|%d|%s|%d|%s|",
+		    toy_fonts[i], toy_fonts[i], GFONT_DRIVER, "", 0, "utf-8");
+	else
+	    strcpy(buf, toy_fonts[i]);
+	fonts[num_fonts++] = G_store(buf);
+    }
+
+    *list = fonts;
+    *count = num_fonts;
+}
+
+/*!
+  \brief Get list of fonts
+
+  \param[out] list font list
+  \param[out] count number of items in the list
+*/
+void Cairo_font_list(char ***list, int *count)
+{
+    font_list_toy(list, count, 0);
+#if CAIRO_HAS_FT_FONT
+    font_list_fc(list, count, 0);
+#endif
+}
+
+/*!
+  \brief Get fonts into
+
+  \param[out] list font list
+  \param[out] count number of items in the list
+*/
+void Cairo_font_info(char ***list, int *count)
+{
+    font_list_toy(list, count, 1);
+#if CAIRO_HAS_FT_FONT
+    font_list_fc(list, count, 1);
+#endif
+}
+

Deleted: grass/trunk/lib/htmldriver/Box.c
===================================================================
--- grass/trunk/lib/htmldriver/Box.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,12 +0,0 @@
-#include "htmlmap.h"
-
-void HTML_Box(double x1, double y1, double x2, double y2)
-{
-    HTML_Begin();
-    HTML_Move(x1, y1);
-    HTML_Cont(x1, y2);
-    HTML_Cont(x2, y2);
-    HTML_Cont(x2, y1);
-    HTML_Fill();
-}
-

Deleted: grass/trunk/lib/htmldriver/Draw.c
===================================================================
--- grass/trunk/lib/htmldriver/Draw.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,37 +0,0 @@
-
-#include <grass/gis.h>
-#include "path.h"
-#include "htmlmap.h"
-
-static struct path path;
-
-void HTML_Begin(void)
-{
-    path_begin(&path);
-}
-
-void HTML_Move(double x, double y)
-{
-    path_move(&path, x, y);
-}
-
-void HTML_Cont(double x, double y)
-{
-    path_cont(&path, x, y);
-}
-
-void HTML_Close(void)
-{
-    path_close(&path);
-}
-
-void HTML_Fill(void)
-{
-    html_polygon(&path);
-}
-
-void HTML_Stroke(void)
-{
-    path_reset(&path);
-}
-

Deleted: grass/trunk/lib/htmldriver/Driver.c
===================================================================
--- grass/trunk/lib/htmldriver/Driver.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,56 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       HTMLMAP
- * AUTHOR(S):    Glynn Clements <glynn gclements.plus.com> (original contributor)
- *               
- * PURPOSE:      driver to allow HTML image maps
- * COPYRIGHT:    (C) 2007-2007 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- *****************************************************************************/
-
-#include <stdio.h>
-#include "driver.h"
-#include "htmlmap.h"
-
-const struct driver *HTML_Driver(void)
-{
-    static struct driver drv;
-    static int initialized;
-
-    if (initialized)
-	return &drv;
-
-    drv.name = "html";
-    drv.Box = HTML_Box;
-    drv.Erase = NULL;
-    drv.Graph_set = HTML_Graph_set;
-    drv.Graph_close = HTML_Graph_close;
-    drv.Line_width = NULL;
-    drv.Set_window = NULL;
-    drv.Begin_raster = NULL;
-    drv.Raster = NULL;
-    drv.End_raster = NULL;
-    drv.Begin = HTML_Begin;
-    drv.Move = HTML_Move;
-    drv.Cont = HTML_Cont;
-    drv.Close = HTML_Close;
-    drv.Stroke = HTML_Stroke;
-    drv.Fill = HTML_Fill;
-    drv.Point = NULL;
-    drv.Color = NULL;
-    drv.Bitmap = NULL;
-    drv.Text = HTML_Text;
-    drv.Text_box = NULL;
-    drv.Set_font = NULL;
-    drv.Font_list = NULL;
-    drv.Font_info = NULL;
-
-    initialized = 1;
-
-    return &drv;
-}

Deleted: grass/trunk/lib/htmldriver/Graph_Clse.c
===================================================================
--- grass/trunk/lib/htmldriver/Graph_Clse.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Graph_Clse.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,161 +0,0 @@
-/*
- * Close down the graphics processing.  This gets called only at driver
- * termination time.
- */
-
-
-#include <grass/gis.h>
-#include "driverlib.h"
-#include "htmlmap.h"
-
-/* sreen dimensions defined in Graph_Set.c */
-
-/* point in polygon test by Randolph Franklin */
-/* http://www.ecse.rpi.edu/Homepages/wrf/     */
-/* adapted for integer coordinates            */
-
-static int pnpoly(int npol, int *xp, int *yp, int x, int y)
-{
-    int i, j, c = 0;
-
-    for (i = 0, j = npol - 1; i < npol; j = i++) {
-	if ((((yp[i] <= y) && (y < yp[j])) ||
-	     ((yp[j] <= y) && (y < yp[i]))) &&
-	    (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
-	    c = !c;
-    }
-    return c;
-}
-
-
-
-void HTML_Graph_close(void)
-{
-    struct MapPoly *poly, *test_poly;
-
-    int i;
-    int inside;
-
-    /* 
-     * exmaine the list of polygons, if a polygon wholly exists inside of
-     * another polygon, then remove it.
-     *
-     */
-
-    for (poly = html.head; poly != NULL; poly = poly->next_poly) {
-
-	for (test_poly = html.head; test_poly != NULL;
-	     test_poly = test_poly->next_poly) {
-	    if (poly == test_poly) {
-		continue;	/* don't check ourselves */
-	    }
-
-	    inside = 1;
-	    for (i = 0; i < poly->num_pts && inside; i++) {
-		inside = pnpoly(test_poly->num_pts,
-				test_poly->x_pts, test_poly->y_pts,
-				poly->x_pts[i], poly->y_pts[i]);
-	    }
-	    if (inside) {
-		poly->num_pts = 0;	/* mark polygon as having no points */
-		break;
-	    }
-	}
-
-    }
-
-
-    /*
-     * write any beginning prologue appropriate for the map type
-     */
-
-    switch (html.type) {
-
-    case APACHE:
-	fprintf(html.output, "#base _base_\n#default _default_\n");
-	break;
-
-    case RAW:
-	break;
-
-    case CLIENT:
-	fprintf(html.output, "<MAP NAME=\"map\">\n");
-	break;
-    }
-
-    /*
-     * write the polygons in a specific format
-     */
-
-    for (poly = html.head; poly != NULL; poly = poly->next_poly) {
-	if (poly->num_pts >= 3) {
-
-	    switch (html.type) {
-
-	    case APACHE:
-		fprintf(html.output, "poly %s", poly->url);
-		for (i = 0; i < poly->num_pts; i++) {
-		    fprintf(html.output, " %d,%d", poly->x_pts[i], poly->y_pts[i]);
-		}
-		fprintf(html.output, " %d,%d", poly->x_pts[0], poly->y_pts[0]);
-		fprintf(html.output, "\n");
-		break;
-
-	    case RAW:
-		fprintf(html.output, "%s", poly->url);
-		for (i = 0; i < poly->num_pts; i++) {
-		    fprintf(html.output, " %d %d", poly->x_pts[i], poly->y_pts[i]);
-		}
-		fprintf(html.output, " %d %d", poly->x_pts[0], poly->y_pts[0]);
-		fprintf(html.output, "\n");
-		break;
-
-	    case CLIENT:
-		fprintf(html.output,
-			"<AREA SHAPE=\"POLY\"\n HREF=\"%s\"\n  ALT=\"%s\"\n  COORDS=\"",
-			poly->url, poly->url);
-		for (i = 0; i < poly->num_pts; i++) {
-		    if (i > 0)
-			fprintf(html.output, ", ");
-		    /* 
-		     * don't add newlines, which confuses the weak-minded
-		     * i.e., ms internet exploder :-(
-		     * was: if (i % 8 == 0 && i != 0) fprintf(html.output,"\n  ");
-		     */
-		    fprintf(html.output, "%d,%d", poly->x_pts[i], poly->y_pts[i]);
-		}
-		fprintf(html.output, ", %d,%d", poly->x_pts[0], poly->y_pts[0]);
-		fprintf(html.output, "\">\n");
-		break;
-
-	    }
-
-	}
-
-    }
-
-    /* final stuff, if needed */
-
-    switch (html.type) {
-
-    case APACHE:
-	break;
-
-    case RAW:
-	break;
-
-    case CLIENT:
-	fprintf(html.output,
-		"<AREA SHAPE=\"RECT\" NOHREF COORDS=\"%d,%d %d,%d\">\n",
-		0, 0, screen_width, screen_height);
-	fprintf(html.output, "</MAP>\n");
-	break;
-
-    }
-
-    /*
-     * close file 
-     */
-
-    fclose(html.output);
-}

Deleted: grass/trunk/lib/htmldriver/Graph_Set.c
===================================================================
--- grass/trunk/lib/htmldriver/Graph_Set.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Graph_Set.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,134 +0,0 @@
-/*
- * Start up graphics processing.  Anything that needs to be assigned, set up,
- * started-up, or otherwise initialized happens here.  This is called only at
- * the startup of the graphics driver.
- *
- * The external variables define the pixle limits of the graphics surface.  The
- * coordinate system used by the applications programs has the (0,0) origin
- * in the upper left-hand corner.  Hence,
- *    screen_left < screen_right
- *    screen_top  < screen_bottom 
- *
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-#include "driverlib.h"
-#include "driver.h"
-#include "htmlmap.h"
-
-struct html_state html;
-
-int HTML_Graph_set(void)
-{
-    char *file_name;
-    char *p;
-
-    G_gisinit("HTMLMAP driver");
-
-    /*
-     * set the minimum bounding box dimensions 
-     */
-
-    if (NULL != (p = getenv("GRASS_RENDER_HTMLMINBBOX"))) {
-	html.BBOX_MINIMUM = atoi(p);
-	if (html.BBOX_MINIMUM <= 0) {
-	    html.BBOX_MINIMUM = DEF_MINBBOX;
-	}
-    }
-    else {
-	html.BBOX_MINIMUM = DEF_MINBBOX;
-    }
-
-    /*
-     * set the maximum number of points
-     */
-
-    if (NULL != (p = getenv("GRASS_RENDER_HTMLMAXPOINTS"))) {
-	html.MAX_POINTS = atoi(p);
-	if (html.MAX_POINTS <= 0) {
-	    html.MAX_POINTS = DEF_MAXPTS;
-	}
-    }
-    else {
-	html.MAX_POINTS = DEF_MAXPTS;
-    }
-
-    /*
-     * set the minimum difference to keep a point
-     */
-
-    if (NULL != (p = getenv("GRASS_RENDER_HTMLMINDIST"))) {
-	html.MINIMUM_DIST = atoi(p);
-	if (html.MINIMUM_DIST <= 0) {
-	    html.MINIMUM_DIST = DEF_MINDIST;
-	}
-    }
-    else {
-	html.MINIMUM_DIST = DEF_MINDIST;
-    }
-
-
-    /*
-     * open the output file
-     */
-
-    if (NULL != (p = getenv("GRASS_RENDER_FILE"))) {
-	if (strlen(p) == 0) {
-	    p = FILE_NAME;
-	}
-    }
-    else {
-	p = FILE_NAME;
-    }
-    file_name = p;
-
-    html.output = fopen(file_name, "w");
-    if (html.output == NULL) {
-	G_fatal_error("HTMLMAP: couldn't open output file %s", file_name);
-	exit(EXIT_FAILURE);
-    }
-
-
-    G_verbose_message(_("html: collecting to file '%s'"), file_name);
-    G_verbose_message(_("html: image size %dx%d"),
-		      screen_width, screen_height);
-
-    /*
-     * check type of map wanted
-     */
-
-    if (NULL == (p = getenv("GRASS_RENDER_HTMLTYPE"))) {
-	p = "CLIENT";
-    }
-    
-    if (strcmp(p, "APACHE") == 0) {
-	html.type = APACHE;
-	G_verbose_message(_("html: type '%s'"), "apache");
-    }
-    else if (strcmp(p, "RAW") == 0) {
-	html.type = RAW;
-	G_verbose_message(_("html: type '%s'"), "raw");
-    }
-    else {
-	html.type = CLIENT;
-	G_verbose_message(_("html: type '%s'"), "client");
-    }
-
-    /*
-     * initialize text memory and list pointers
-     */
-    
-    html.last_text = (char *)G_malloc(INITIAL_TEXT + 1);
-    html.last_text[0] = '\0';
-    html.last_text_len = INITIAL_TEXT;
-
-    html.head = NULL;
-    html.tail = &html.head;
-
-    return 0;
-}

Deleted: grass/trunk/lib/htmldriver/Makefile
===================================================================
--- grass/trunk/lib/htmldriver/Makefile	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,10 +0,0 @@
-MODULE_TOPDIR = ../..
-
-EXTRA_CFLAGS=-I../driver
-
-LIB = HTMLDRIVER
-PGM = htmldriver
-
-include $(MODULE_TOPDIR)/include/Make/Lib.make
-
-default: lib

Deleted: grass/trunk/lib/htmldriver/Polygon.c
===================================================================
--- grass/trunk/lib/htmldriver/Polygon.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Polygon.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,208 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include "driverlib.h"
-#include "htmlmap.h"
-
-#define RAD_DEG 57.29578
-
-static void delete_point(int *x, int *y, int count)
-{
-    int i;
-
-    for (i = 0; i < count; i++) {
-	x[i] = x[i + 1];
-	y[i] = y[i + 1];
-    }
-
-
-}
-
-static double find_azimuth(double x1, double y1, double x2, double y2)
-{
-    double xx, yy;
-
-    xx = x1 - x2;
-    yy = y1 - y2;
-
-    if (x1 == x2) {
-	return (y2 > y1) ? 90.0 : 270.0;
-    }
-    else {
-	if (y2 < y1) {
-	    if (x2 > x1) {
-		return 360.0 + (RAD_DEG * atan(yy / xx));
-	    }
-	    else {
-		return 180.0 + (RAD_DEG * atan(yy / xx));
-	    }
-	}
-	else {
-	    if (x2 > x1) {
-		return (RAD_DEG * atan(yy / xx));
-	    }
-	    else {
-		return 180.0 + (RAD_DEG * atan(yy / xx));
-	    }
-	}
-    }
-}
-
-
-void html_polygon(const struct path *p)
-{
-    int n = p->count;
-    struct MapPoly *new;
-    int i;
-    int delta_x, delta_y;
-    int min_x, max_x, min_y, max_y;
-
-    double min_azimuth = 1.0;
-    double azimuth1, azimuth2, diff1, diff2;
-    int *x = G_malloc(n * sizeof(int));
-    int *y = G_malloc(n * sizeof(int));
-
-    for (i = 0; i < n; i++) {
-	x[i] = (int) floor(p->vertices[i].x + 0.5);
-	y[i] = (int) floor(p->vertices[i].y + 0.5);
-    }
-
-    /* 
-     * remove points that have adjacent duplicates or have differences of
-     * less the the minimum allowed.  remove end points that are same as
-     * the begin point (ending point = starting point is added 
-     * during Graph_Clse)
-     */
-
-    i = 0;
-    while (i < (n - 1)) {
-	delta_x = x[i] - x[i + 1];
-	if (delta_x < 0)
-	    delta_x = -delta_x;
-	delta_y = y[i] - y[i + 1];
-	if (delta_y < 0)
-	    delta_y = -delta_y;
-
-	if ((x[i] == x[i + 1] && y[i] == y[i + 1]) ||
-	    (delta_x <= html.MINIMUM_DIST && delta_y <= html.MINIMUM_DIST)) {
-	    delete_point(&x[i + 1], &y[i + 1], n - i - 1);
-	    --n;
-	}
-	else {
-	    ++i;
-	}
-    }
-
-    /* perform same checks for last point & first point */
-    while (1) {
-	delta_x = x[0] - x[n - 1];
-	if (delta_x < 0)
-	    delta_x = -delta_x;
-	delta_y = y[0] - y[n - 1];
-	if (delta_y < 0)
-	    delta_y = -delta_y;
-
-	if ((x[0] == x[n - 1] && y[0] == y[n - 1]) ||
-	    (delta_x <= html.MINIMUM_DIST && delta_y <= html.MINIMUM_DIST)) {
-	    --n;
-	}
-	else {
-	    break;
-	}
-    }
-
-
-
-    /* 
-     * if a polygon has either x or y extents less than the bounding box 
-     * minimum, ignore it
-     *
-     */
-
-    min_x = max_x = x[0];
-    min_y = max_y = y[0];
-    for (i = 0; i < n; i++) {
-	if (x[i] < min_x)
-	    min_x = x[i];
-	if (x[i] > max_x)
-	    max_x = x[i];
-	if (y[i] < min_y)
-	    min_y = y[i];
-	if (y[i] > max_y)
-	    max_y = y[i];
-    }
-    delta_x = max_x - min_x;
-    delta_y = max_y - min_y;
-    if (delta_x < html.BBOX_MINIMUM || delta_y < html.BBOX_MINIMUM) {
-	n = 0;
-    }
-
-
-    /* 
-     * remove points in excess of MAX_POINTS vertices
-     */
-
-    while (n > html.MAX_POINTS) {
-
-	for (i = 0; i < (n - 2); i++) {
-
-	    /* 
-	     * see if middle point can be removed, by checking if the
-	     * relative bearing to the middle is less than our current tolerance
-	     */
-
-	    azimuth1 = find_azimuth((double)x[i], (double)y[i],
-				    (double)x[i + 1], (double)y[i + 1]);
-	    azimuth2 = find_azimuth((double)x[i], (double)y[i],
-				    (double)x[i + 2], (double)y[i + 2]);
-
-	    diff1 = fmod(fabs((azimuth2 + 360.0) - azimuth1), 360.0);
-	    diff2 = fmod(fabs((azimuth1 + 360.0) - azimuth2), 360.0);
-
-	    if (diff1 <= min_azimuth || diff2 <= min_azimuth) {
-
-		delete_point(&x[i + 1], &y[i + 1], n - i - 1);
-		--n;
-		++i;
-		/* either stop deleting points because we're less than 100,
-		   or keep deleting points with the same difference as this 
-		   one (which might make a smaller polygon yet).  
-		   if (n <= 100) {
-		   break;
-		   }
-		 */
-	    }
-
-	}
-
-	/* increase minimum azimuth difference for next round */
-	min_azimuth += 1.0;
-    }
-
-    /*
-     * copy remaining points into a new MapPoly
-     */
-
-    if (n >= 3) {
-
-	new = (struct MapPoly *)G_malloc(sizeof(struct MapPoly));
-
-	/* grab the last text string written as url */
-	new->url = G_store(html.last_text);
-
-	/* hook up new MapPoly into list */
-	new->next_poly = NULL;
-	*html.tail = new;
-	html.tail = &(new->next_poly);
-
-	new->num_pts = n;
-	new->x_pts = x;
-	new->y_pts = y;
-    }
-    else {
-	G_free(x);
-	G_free(y);
-    }
-}

Deleted: grass/trunk/lib/htmldriver/README
===================================================================
--- grass/trunk/lib/htmldriver/README	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/README	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,172 +0,0 @@
-                                  HTMLMAP driver
-
-                                  Tom Poindexter
-                                 tpoindex at nyx.net
-
-  This display driver is to allow the generation of HTML image maps for
-area vector data.  HTML image maps are used in conjunction with images
-to provide unique URL targets for different portions of an image.  The HTMLMAP
-driver can create both client-side image maps embedded into HTML files, or
-server-side image maps used by web server software.
-
-  Note that commands that require the MOUSE will NOT work correctly (or
-at all!)
-
-  Polygons can at most have 100 vertices (this limit imposed by HTML image map 
-formats.)  The driver will attempt to trim polygons that have more that 100 
-vertices (also see GRASS_RENDER_HTMLMAXPOINTS, below.)  Also, any polygon that is 
-entirely bounded by another polygon will be discarded.
-
-  Text written to the driver before polygons are used as the HREF tag for
-all subsequent polygons written.  It is intended that all polygons 
-that exists in a vector file will have the same HREF tag.
-
-  The only GRASS display commands that should be used with this driver are:
-	d.text	 - pass href information for resulting image maps.
-	d.vect.area	 - draw polygons from a vector file.
-    
-
-    0. Set environment variables:
-
-       GRASS_RENDER_WIDTH=xxx   #if you want another size than the default 640
-       export GRASS_RENDER_WIDTH
-       GRASS_RENDER_HEIGHT=xxx  #if you want another size than the default 480
-       export GRASS_RENDER_WIDTH
-
-       Additionally, HTMLMAP driver recognizes:
-
-       export GRASS_RENDER_HTMLTYPE
-       GRASS_RENDER_HTMLTYPE=xxx  
-            specifies the type of Html map to create:
-	    CLIENT  - Netscape client-side image map (default).  (NAME="map")
-	    APACHE  - Apache/NCSA server-side image map
-	    RAW     - Raw url and polygon vertices ("url x1 y1 x2 y2 .....")
-                      suitable for conversion to CERN server format, or
-                      any other format with user supplied conversion program.
-
-       export GRASS_RENDER_FILE
-       GRASS_RENDER_FILE=xxxxxx
-	    specifies the resulting file to store the html image map,
-	    default is 'htmlmap'.  Files without absolute path names are
-            written in the current directory where the driver was started.
-
-            Any existing file is overwritten without warning.
-
-
-	export GRASS_RENDER_HTMLMINDIST
-	GRASS_RENDER_HTMLMINDIST=xx
-	    specifies the minimum distance (in pixels) that a point must
-	    change from the previous one to keep in the list of vertices
-            for a polygon.  The default is '2', which means that a point's
-	    x or y difference from the previous point must change by a number
-	    of pixels greate than this value.  This parameters helps
-	    to eliminate points closely spaced points.
-
-
-	export GRASS_RENDER_HTMLMINBBOX
-	GRASS_RENDER_HTMLMINBBOX=xx
-	    specifies the minimum bounding box dimenions (both width and
-	    height) in order to store a polygon.  The default is '2', which
-	    means any polygon having bounding box width or height extent
-	    of less than 2 pixels will not be output as a clickable area.  
-            This parameter helps to eliminate clickable areas that are one 
-	    pixel in height or width, typically a single point or line.
-	
-
-	export GRASS_RENDER_HTMLMAXPOINTS
-	GRASS_RENDER_HTMLMAXPOINTS=xx
-	    specifies the maxiumum number of vertices that a polygon can 
-	    have.  The default is 99.  Some browser can only handle
-	    image map polygons of less that 100 vertices.
-
-
-    1. Start it up.
-
-         # set the environment variables (above) if desired, or use defaults
-
-         d.mon start=HTMLMAP
-         d.mon select=HTMLMAP
-
-    2. Display text strings (href's) and area polygons:
-
-         echo "http://www.no-such-place.net/area51/" | d.text
-	 d.vect.area map=area51
-         echo "http://www.roswell-nm.net/little/green/men.html" | d.text
-	 d.vect.area map=roswell
-
-    3. When done displaying stuff to HTMLMAP driver, use
-
-         d.mon stop=HTMLMAP
-
-       This will write the image map file file. A new file called 'htmlmap' 
-       (or whatever you specified with GRASS_RENDER_FILE) will be created  
-       in your current directory.  
-
-    4. In practice, you'll want to create gif/jpg/png images that correspond 
-       with your newly created image map:
-
-         # using previous GRASS_RENDER_WIDTH & GRASS_RENDER_HEIGHT
-         d.mon start=CELL
-         d.mon select=CELL
-         d.rast map=terrain
-         d.vect.area map=area51  fillcolor=white  linecolor=blue
-         d.vect.area map=roswell fillcolor=yellow linecolor=blue
-         d.vect map=states  color=green
-         d.vect map=roads   color=blue
-         d.mon stop=CELL
-         # make the region the same as the newly created cell for ppm export
-         g.pushregion.sh  # or g.region save=saved.reg
-         g.region raster=D_cell
-         r.out.ppm -q input=D_cell output=alien.ppm
-         # use the netpbm utilities to create a gif (quantize if needed)
-         ppmquant 128 <alien.ppm |  ppmtogif >alien.gif	
-         # assemble some html with the image and the image map
-         echo '<html><body><img src="alien.gif" usemap="#map">' >alien.html
-         cat htmlmap                                           >>alien.html
-         echo '</body></html>'                                 >>alien.html
-         # don't forget to reset your region
-         g.popregion.sh   # or g.region region=saved.reg
-	 # take a look and test it out
-	 netscape file:`pwd`/alien.html &
-
-
-
-  Building the HTMLMAP driver:
-
-    Change to the HTMLMAP directory, and make it:
-
-	cd src/display/devices/HTMLMAP
-	gmake5
-    
-    If all goes well, the HTMLMAP driver will be compiled and moved into
-    your device driver directory ($GISBASE/driver) and "etc/monitorcap"
-    will be modified.
-
-
-  Other:  
-
-    Don't forget to add the HTMLMAP driver in your monitorcap file!
-    Your monitorcap file exists as $GISBASE/etc/monitorcap.
-
-        HTMLMAP:driver/HTMLMAP:Create HTML Image Map: \
-             /usr/local/grass43/dev/fifo.9a /usr/local/grass43/dev/fifo.9b \
-             ::any terminal
-
-    Note: This job will be done by the Gmakefile.    
-
-    HTMLMAP was adapted from the CELL driver in GRASS 4.3.  Point-in-
-    polygon-test code was lifted from Randolph Franklin's web page, see 
-
-	http://www.ecse.rpi.edu/Homepages/wrf/
-	http://www.ecse.rpi.edu/Homepages/wrf/research/geom/pnpoly.html
-
-
-    If you create an HTML file with two or more images & image maps, you 
-    will need to edit the map names.  The HTMLMAP driver creates its map
-    with the name 'map'.  A small sed script can easily change the map name:
-
-	sed -e 's/NAME="map"/NAME="foomap"/' <htmlmap >foomap.html
-
-
------------------------------
-http://www.nyx.net/~tpoindex/grass-stuff/

Deleted: grass/trunk/lib/htmldriver/Text.c
===================================================================
--- grass/trunk/lib/htmldriver/Text.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/htmldriver/Text.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,30 +0,0 @@
-
-/* Text.c - save text string into last_text buffer */
-
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include "driverlib.h"
-#include "htmlmap.h"
-
-void HTML_Text(const char *text)
-{
-    int len = strlen(text);
-    const char *s;
-    char *d;
-
-    if (len > html.last_text_len) {
-	G_free(html.last_text);
-	html.last_text = (char *)G_malloc(len + 1);
-	html.last_text_len = len;
-    }
-
-    /* copy string to last_text area, make sure we don't copy \n */
-    for (d = html.last_text, s = text; *s != '\0'; s++) {
-	if (*s != '\n') {
-	    *d = *s;
-	    d++;
-	}
-    }
-    *d = '\0';
-}

Copied: grass/trunk/lib/htmldriver/box.c (from rev 62429, grass/trunk/lib/htmldriver/Box.c)
===================================================================
--- grass/trunk/lib/htmldriver/box.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,12 @@
+#include "htmlmap.h"
+
+void HTML_Box(double x1, double y1, double x2, double y2)
+{
+    HTML_Begin();
+    HTML_Move(x1, y1);
+    HTML_Cont(x1, y2);
+    HTML_Cont(x2, y2);
+    HTML_Cont(x2, y1);
+    HTML_Fill();
+}
+

Copied: grass/trunk/lib/htmldriver/draw.c (from rev 62429, grass/trunk/lib/htmldriver/Draw.c)
===================================================================
--- grass/trunk/lib/htmldriver/draw.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,37 @@
+
+#include <grass/gis.h>
+#include "path.h"
+#include "htmlmap.h"
+
+static struct path path;
+
+void HTML_Begin(void)
+{
+    path_begin(&path);
+}
+
+void HTML_Move(double x, double y)
+{
+    path_move(&path, x, y);
+}
+
+void HTML_Cont(double x, double y)
+{
+    path_cont(&path, x, y);
+}
+
+void HTML_Close(void)
+{
+    path_close(&path);
+}
+
+void HTML_Fill(void)
+{
+    html_polygon(&path);
+}
+
+void HTML_Stroke(void)
+{
+    path_reset(&path);
+}
+

Copied: grass/trunk/lib/htmldriver/driver.c (from rev 62429, grass/trunk/lib/htmldriver/Driver.c)
===================================================================
--- grass/trunk/lib/htmldriver/driver.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,56 @@
+
+/****************************************************************************
+ *
+ * MODULE:       HTMLMAP
+ * AUTHOR(S):    Glynn Clements <glynn gclements.plus.com> (original contributor)
+ *               
+ * PURPOSE:      driver to allow HTML image maps
+ * COPYRIGHT:    (C) 2007-2007 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the file COPYING that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include "driver.h"
+#include "htmlmap.h"
+
+const struct driver *HTML_Driver(void)
+{
+    static struct driver drv;
+    static int initialized;
+
+    if (initialized)
+	return &drv;
+
+    drv.name = "html";
+    drv.Box = HTML_Box;
+    drv.Erase = NULL;
+    drv.Graph_set = HTML_Graph_set;
+    drv.Graph_close = HTML_Graph_close;
+    drv.Line_width = NULL;
+    drv.Set_window = NULL;
+    drv.Begin_raster = NULL;
+    drv.Raster = NULL;
+    drv.End_raster = NULL;
+    drv.Begin = HTML_Begin;
+    drv.Move = HTML_Move;
+    drv.Cont = HTML_Cont;
+    drv.Close = HTML_Close;
+    drv.Stroke = HTML_Stroke;
+    drv.Fill = HTML_Fill;
+    drv.Point = NULL;
+    drv.Color = NULL;
+    drv.Bitmap = NULL;
+    drv.Text = HTML_Text;
+    drv.Text_box = NULL;
+    drv.Set_font = NULL;
+    drv.Font_list = NULL;
+    drv.Font_info = NULL;
+
+    initialized = 1;
+
+    return &drv;
+}

Copied: grass/trunk/lib/htmldriver/graph_clse.c (from rev 62429, grass/trunk/lib/htmldriver/Graph_Clse.c)
===================================================================
--- grass/trunk/lib/htmldriver/graph_clse.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/graph_clse.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,161 @@
+/*
+ * Close down the graphics processing.  This gets called only at driver
+ * termination time.
+ */
+
+
+#include <grass/gis.h>
+#include "driverlib.h"
+#include "htmlmap.h"
+
+/* sreen dimensions defined in Graph_Set.c */
+
+/* point in polygon test by Randolph Franklin */
+/* http://www.ecse.rpi.edu/Homepages/wrf/     */
+/* adapted for integer coordinates            */
+
+static int pnpoly(int npol, int *xp, int *yp, int x, int y)
+{
+    int i, j, c = 0;
+
+    for (i = 0, j = npol - 1; i < npol; j = i++) {
+	if ((((yp[i] <= y) && (y < yp[j])) ||
+	     ((yp[j] <= y) && (y < yp[i]))) &&
+	    (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
+	    c = !c;
+    }
+    return c;
+}
+
+
+
+void HTML_Graph_close(void)
+{
+    struct MapPoly *poly, *test_poly;
+
+    int i;
+    int inside;
+
+    /* 
+     * exmaine the list of polygons, if a polygon wholly exists inside of
+     * another polygon, then remove it.
+     *
+     */
+
+    for (poly = html.head; poly != NULL; poly = poly->next_poly) {
+
+	for (test_poly = html.head; test_poly != NULL;
+	     test_poly = test_poly->next_poly) {
+	    if (poly == test_poly) {
+		continue;	/* don't check ourselves */
+	    }
+
+	    inside = 1;
+	    for (i = 0; i < poly->num_pts && inside; i++) {
+		inside = pnpoly(test_poly->num_pts,
+				test_poly->x_pts, test_poly->y_pts,
+				poly->x_pts[i], poly->y_pts[i]);
+	    }
+	    if (inside) {
+		poly->num_pts = 0;	/* mark polygon as having no points */
+		break;
+	    }
+	}
+
+    }
+
+
+    /*
+     * write any beginning prologue appropriate for the map type
+     */
+
+    switch (html.type) {
+
+    case APACHE:
+	fprintf(html.output, "#base _base_\n#default _default_\n");
+	break;
+
+    case RAW:
+	break;
+
+    case CLIENT:
+	fprintf(html.output, "<MAP NAME=\"map\">\n");
+	break;
+    }
+
+    /*
+     * write the polygons in a specific format
+     */
+
+    for (poly = html.head; poly != NULL; poly = poly->next_poly) {
+	if (poly->num_pts >= 3) {
+
+	    switch (html.type) {
+
+	    case APACHE:
+		fprintf(html.output, "poly %s", poly->url);
+		for (i = 0; i < poly->num_pts; i++) {
+		    fprintf(html.output, " %d,%d", poly->x_pts[i], poly->y_pts[i]);
+		}
+		fprintf(html.output, " %d,%d", poly->x_pts[0], poly->y_pts[0]);
+		fprintf(html.output, "\n");
+		break;
+
+	    case RAW:
+		fprintf(html.output, "%s", poly->url);
+		for (i = 0; i < poly->num_pts; i++) {
+		    fprintf(html.output, " %d %d", poly->x_pts[i], poly->y_pts[i]);
+		}
+		fprintf(html.output, " %d %d", poly->x_pts[0], poly->y_pts[0]);
+		fprintf(html.output, "\n");
+		break;
+
+	    case CLIENT:
+		fprintf(html.output,
+			"<AREA SHAPE=\"POLY\"\n HREF=\"%s\"\n  ALT=\"%s\"\n  COORDS=\"",
+			poly->url, poly->url);
+		for (i = 0; i < poly->num_pts; i++) {
+		    if (i > 0)
+			fprintf(html.output, ", ");
+		    /* 
+		     * don't add newlines, which confuses the weak-minded
+		     * i.e., ms internet exploder :-(
+		     * was: if (i % 8 == 0 && i != 0) fprintf(html.output,"\n  ");
+		     */
+		    fprintf(html.output, "%d,%d", poly->x_pts[i], poly->y_pts[i]);
+		}
+		fprintf(html.output, ", %d,%d", poly->x_pts[0], poly->y_pts[0]);
+		fprintf(html.output, "\">\n");
+		break;
+
+	    }
+
+	}
+
+    }
+
+    /* final stuff, if needed */
+
+    switch (html.type) {
+
+    case APACHE:
+	break;
+
+    case RAW:
+	break;
+
+    case CLIENT:
+	fprintf(html.output,
+		"<AREA SHAPE=\"RECT\" NOHREF COORDS=\"%d,%d %d,%d\">\n",
+		0, 0, screen_width, screen_height);
+	fprintf(html.output, "</MAP>\n");
+	break;
+
+    }
+
+    /*
+     * close file 
+     */
+
+    fclose(html.output);
+}

Copied: grass/trunk/lib/htmldriver/graph_set.c (from rev 62429, grass/trunk/lib/htmldriver/Graph_Set.c)
===================================================================
--- grass/trunk/lib/htmldriver/graph_set.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/graph_set.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,134 @@
+/*
+ * Start up graphics processing.  Anything that needs to be assigned, set up,
+ * started-up, or otherwise initialized happens here.  This is called only at
+ * the startup of the graphics driver.
+ *
+ * The external variables define the pixle limits of the graphics surface.  The
+ * coordinate system used by the applications programs has the (0,0) origin
+ * in the upper left-hand corner.  Hence,
+ *    screen_left < screen_right
+ *    screen_top  < screen_bottom 
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "driverlib.h"
+#include "driver.h"
+#include "htmlmap.h"
+
+struct html_state html;
+
+int HTML_Graph_set(void)
+{
+    char *file_name;
+    char *p;
+
+    G_gisinit("HTMLMAP driver");
+
+    /*
+     * set the minimum bounding box dimensions 
+     */
+
+    if (NULL != (p = getenv("GRASS_RENDER_HTMLMINBBOX"))) {
+	html.BBOX_MINIMUM = atoi(p);
+	if (html.BBOX_MINIMUM <= 0) {
+	    html.BBOX_MINIMUM = DEF_MINBBOX;
+	}
+    }
+    else {
+	html.BBOX_MINIMUM = DEF_MINBBOX;
+    }
+
+    /*
+     * set the maximum number of points
+     */
+
+    if (NULL != (p = getenv("GRASS_RENDER_HTMLMAXPOINTS"))) {
+	html.MAX_POINTS = atoi(p);
+	if (html.MAX_POINTS <= 0) {
+	    html.MAX_POINTS = DEF_MAXPTS;
+	}
+    }
+    else {
+	html.MAX_POINTS = DEF_MAXPTS;
+    }
+
+    /*
+     * set the minimum difference to keep a point
+     */
+
+    if (NULL != (p = getenv("GRASS_RENDER_HTMLMINDIST"))) {
+	html.MINIMUM_DIST = atoi(p);
+	if (html.MINIMUM_DIST <= 0) {
+	    html.MINIMUM_DIST = DEF_MINDIST;
+	}
+    }
+    else {
+	html.MINIMUM_DIST = DEF_MINDIST;
+    }
+
+
+    /*
+     * open the output file
+     */
+
+    if (NULL != (p = getenv("GRASS_RENDER_FILE"))) {
+	if (strlen(p) == 0) {
+	    p = FILE_NAME;
+	}
+    }
+    else {
+	p = FILE_NAME;
+    }
+    file_name = p;
+
+    html.output = fopen(file_name, "w");
+    if (html.output == NULL) {
+	G_fatal_error("HTMLMAP: couldn't open output file %s", file_name);
+	exit(EXIT_FAILURE);
+    }
+
+
+    G_verbose_message(_("html: collecting to file '%s'"), file_name);
+    G_verbose_message(_("html: image size %dx%d"),
+		      screen_width, screen_height);
+
+    /*
+     * check type of map wanted
+     */
+
+    if (NULL == (p = getenv("GRASS_RENDER_HTMLTYPE"))) {
+	p = "CLIENT";
+    }
+    
+    if (strcmp(p, "APACHE") == 0) {
+	html.type = APACHE;
+	G_verbose_message(_("html: type '%s'"), "apache");
+    }
+    else if (strcmp(p, "RAW") == 0) {
+	html.type = RAW;
+	G_verbose_message(_("html: type '%s'"), "raw");
+    }
+    else {
+	html.type = CLIENT;
+	G_verbose_message(_("html: type '%s'"), "client");
+    }
+
+    /*
+     * initialize text memory and list pointers
+     */
+    
+    html.last_text = (char *)G_malloc(INITIAL_TEXT + 1);
+    html.last_text[0] = '\0';
+    html.last_text_len = INITIAL_TEXT;
+
+    html.head = NULL;
+    html.tail = &html.head;
+
+    return 0;
+}

Copied: grass/trunk/lib/htmldriver/makefile (from rev 62429, grass/trunk/lib/htmldriver/Makefile)
===================================================================
--- grass/trunk/lib/htmldriver/makefile	                        (rev 0)
+++ grass/trunk/lib/htmldriver/makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+EXTRA_CFLAGS=-I../driver
+
+LIB = HTMLDRIVER
+PGM = htmldriver
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+default: lib

Copied: grass/trunk/lib/htmldriver/polygon.c (from rev 62429, grass/trunk/lib/htmldriver/Polygon.c)
===================================================================
--- grass/trunk/lib/htmldriver/polygon.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/polygon.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,208 @@
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include "driverlib.h"
+#include "htmlmap.h"
+
+#define RAD_DEG 57.29578
+
+static void delete_point(int *x, int *y, int count)
+{
+    int i;
+
+    for (i = 0; i < count; i++) {
+	x[i] = x[i + 1];
+	y[i] = y[i + 1];
+    }
+
+
+}
+
+static double find_azimuth(double x1, double y1, double x2, double y2)
+{
+    double xx, yy;
+
+    xx = x1 - x2;
+    yy = y1 - y2;
+
+    if (x1 == x2) {
+	return (y2 > y1) ? 90.0 : 270.0;
+    }
+    else {
+	if (y2 < y1) {
+	    if (x2 > x1) {
+		return 360.0 + (RAD_DEG * atan(yy / xx));
+	    }
+	    else {
+		return 180.0 + (RAD_DEG * atan(yy / xx));
+	    }
+	}
+	else {
+	    if (x2 > x1) {
+		return (RAD_DEG * atan(yy / xx));
+	    }
+	    else {
+		return 180.0 + (RAD_DEG * atan(yy / xx));
+	    }
+	}
+    }
+}
+
+
+void html_polygon(const struct path *p)
+{
+    int n = p->count;
+    struct MapPoly *new;
+    int i;
+    int delta_x, delta_y;
+    int min_x, max_x, min_y, max_y;
+
+    double min_azimuth = 1.0;
+    double azimuth1, azimuth2, diff1, diff2;
+    int *x = G_malloc(n * sizeof(int));
+    int *y = G_malloc(n * sizeof(int));
+
+    for (i = 0; i < n; i++) {
+	x[i] = (int) floor(p->vertices[i].x + 0.5);
+	y[i] = (int) floor(p->vertices[i].y + 0.5);
+    }
+
+    /* 
+     * remove points that have adjacent duplicates or have differences of
+     * less the the minimum allowed.  remove end points that are same as
+     * the begin point (ending point = starting point is added 
+     * during Graph_Clse)
+     */
+
+    i = 0;
+    while (i < (n - 1)) {
+	delta_x = x[i] - x[i + 1];
+	if (delta_x < 0)
+	    delta_x = -delta_x;
+	delta_y = y[i] - y[i + 1];
+	if (delta_y < 0)
+	    delta_y = -delta_y;
+
+	if ((x[i] == x[i + 1] && y[i] == y[i + 1]) ||
+	    (delta_x <= html.MINIMUM_DIST && delta_y <= html.MINIMUM_DIST)) {
+	    delete_point(&x[i + 1], &y[i + 1], n - i - 1);
+	    --n;
+	}
+	else {
+	    ++i;
+	}
+    }
+
+    /* perform same checks for last point & first point */
+    while (1) {
+	delta_x = x[0] - x[n - 1];
+	if (delta_x < 0)
+	    delta_x = -delta_x;
+	delta_y = y[0] - y[n - 1];
+	if (delta_y < 0)
+	    delta_y = -delta_y;
+
+	if ((x[0] == x[n - 1] && y[0] == y[n - 1]) ||
+	    (delta_x <= html.MINIMUM_DIST && delta_y <= html.MINIMUM_DIST)) {
+	    --n;
+	}
+	else {
+	    break;
+	}
+    }
+
+
+
+    /* 
+     * if a polygon has either x or y extents less than the bounding box 
+     * minimum, ignore it
+     *
+     */
+
+    min_x = max_x = x[0];
+    min_y = max_y = y[0];
+    for (i = 0; i < n; i++) {
+	if (x[i] < min_x)
+	    min_x = x[i];
+	if (x[i] > max_x)
+	    max_x = x[i];
+	if (y[i] < min_y)
+	    min_y = y[i];
+	if (y[i] > max_y)
+	    max_y = y[i];
+    }
+    delta_x = max_x - min_x;
+    delta_y = max_y - min_y;
+    if (delta_x < html.BBOX_MINIMUM || delta_y < html.BBOX_MINIMUM) {
+	n = 0;
+    }
+
+
+    /* 
+     * remove points in excess of MAX_POINTS vertices
+     */
+
+    while (n > html.MAX_POINTS) {
+
+	for (i = 0; i < (n - 2); i++) {
+
+	    /* 
+	     * see if middle point can be removed, by checking if the
+	     * relative bearing to the middle is less than our current tolerance
+	     */
+
+	    azimuth1 = find_azimuth((double)x[i], (double)y[i],
+				    (double)x[i + 1], (double)y[i + 1]);
+	    azimuth2 = find_azimuth((double)x[i], (double)y[i],
+				    (double)x[i + 2], (double)y[i + 2]);
+
+	    diff1 = fmod(fabs((azimuth2 + 360.0) - azimuth1), 360.0);
+	    diff2 = fmod(fabs((azimuth1 + 360.0) - azimuth2), 360.0);
+
+	    if (diff1 <= min_azimuth || diff2 <= min_azimuth) {
+
+		delete_point(&x[i + 1], &y[i + 1], n - i - 1);
+		--n;
+		++i;
+		/* either stop deleting points because we're less than 100,
+		   or keep deleting points with the same difference as this 
+		   one (which might make a smaller polygon yet).  
+		   if (n <= 100) {
+		   break;
+		   }
+		 */
+	    }
+
+	}
+
+	/* increase minimum azimuth difference for next round */
+	min_azimuth += 1.0;
+    }
+
+    /*
+     * copy remaining points into a new MapPoly
+     */
+
+    if (n >= 3) {
+
+	new = (struct MapPoly *)G_malloc(sizeof(struct MapPoly));
+
+	/* grab the last text string written as url */
+	new->url = G_store(html.last_text);
+
+	/* hook up new MapPoly into list */
+	new->next_poly = NULL;
+	*html.tail = new;
+	html.tail = &(new->next_poly);
+
+	new->num_pts = n;
+	new->x_pts = x;
+	new->y_pts = y;
+    }
+    else {
+	G_free(x);
+	G_free(y);
+    }
+}

Copied: grass/trunk/lib/htmldriver/readme (from rev 62429, grass/trunk/lib/htmldriver/README)
===================================================================
--- grass/trunk/lib/htmldriver/readme	                        (rev 0)
+++ grass/trunk/lib/htmldriver/readme	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,172 @@
+                                  HTMLMAP driver
+
+                                  Tom Poindexter
+                                 tpoindex at nyx.net
+
+  This display driver is to allow the generation of HTML image maps for
+area vector data.  HTML image maps are used in conjunction with images
+to provide unique URL targets for different portions of an image.  The HTMLMAP
+driver can create both client-side image maps embedded into HTML files, or
+server-side image maps used by web server software.
+
+  Note that commands that require the MOUSE will NOT work correctly (or
+at all!)
+
+  Polygons can at most have 100 vertices (this limit imposed by HTML image map 
+formats.)  The driver will attempt to trim polygons that have more that 100 
+vertices (also see GRASS_RENDER_HTMLMAXPOINTS, below.)  Also, any polygon that is 
+entirely bounded by another polygon will be discarded.
+
+  Text written to the driver before polygons are used as the HREF tag for
+all subsequent polygons written.  It is intended that all polygons 
+that exists in a vector file will have the same HREF tag.
+
+  The only GRASS display commands that should be used with this driver are:
+	d.text	 - pass href information for resulting image maps.
+	d.vect.area	 - draw polygons from a vector file.
+    
+
+    0. Set environment variables:
+
+       GRASS_RENDER_WIDTH=xxx   #if you want another size than the default 640
+       export GRASS_RENDER_WIDTH
+       GRASS_RENDER_HEIGHT=xxx  #if you want another size than the default 480
+       export GRASS_RENDER_WIDTH
+
+       Additionally, HTMLMAP driver recognizes:
+
+       export GRASS_RENDER_HTMLTYPE
+       GRASS_RENDER_HTMLTYPE=xxx  
+            specifies the type of Html map to create:
+	    CLIENT  - Netscape client-side image map (default).  (NAME="map")
+	    APACHE  - Apache/NCSA server-side image map
+	    RAW     - Raw url and polygon vertices ("url x1 y1 x2 y2 .....")
+                      suitable for conversion to CERN server format, or
+                      any other format with user supplied conversion program.
+
+       export GRASS_RENDER_FILE
+       GRASS_RENDER_FILE=xxxxxx
+	    specifies the resulting file to store the html image map,
+	    default is 'htmlmap'.  Files without absolute path names are
+            written in the current directory where the driver was started.
+
+            Any existing file is overwritten without warning.
+
+
+	export GRASS_RENDER_HTMLMINDIST
+	GRASS_RENDER_HTMLMINDIST=xx
+	    specifies the minimum distance (in pixels) that a point must
+	    change from the previous one to keep in the list of vertices
+            for a polygon.  The default is '2', which means that a point's
+	    x or y difference from the previous point must change by a number
+	    of pixels greate than this value.  This parameters helps
+	    to eliminate points closely spaced points.
+
+
+	export GRASS_RENDER_HTMLMINBBOX
+	GRASS_RENDER_HTMLMINBBOX=xx
+	    specifies the minimum bounding box dimenions (both width and
+	    height) in order to store a polygon.  The default is '2', which
+	    means any polygon having bounding box width or height extent
+	    of less than 2 pixels will not be output as a clickable area.  
+            This parameter helps to eliminate clickable areas that are one 
+	    pixel in height or width, typically a single point or line.
+	
+
+	export GRASS_RENDER_HTMLMAXPOINTS
+	GRASS_RENDER_HTMLMAXPOINTS=xx
+	    specifies the maxiumum number of vertices that a polygon can 
+	    have.  The default is 99.  Some browser can only handle
+	    image map polygons of less that 100 vertices.
+
+
+    1. Start it up.
+
+         # set the environment variables (above) if desired, or use defaults
+
+         d.mon start=HTMLMAP
+         d.mon select=HTMLMAP
+
+    2. Display text strings (href's) and area polygons:
+
+         echo "http://www.no-such-place.net/area51/" | d.text
+	 d.vect.area map=area51
+         echo "http://www.roswell-nm.net/little/green/men.html" | d.text
+	 d.vect.area map=roswell
+
+    3. When done displaying stuff to HTMLMAP driver, use
+
+         d.mon stop=HTMLMAP
+
+       This will write the image map file file. A new file called 'htmlmap' 
+       (or whatever you specified with GRASS_RENDER_FILE) will be created  
+       in your current directory.  
+
+    4. In practice, you'll want to create gif/jpg/png images that correspond 
+       with your newly created image map:
+
+         # using previous GRASS_RENDER_WIDTH & GRASS_RENDER_HEIGHT
+         d.mon start=CELL
+         d.mon select=CELL
+         d.rast map=terrain
+         d.vect.area map=area51  fillcolor=white  linecolor=blue
+         d.vect.area map=roswell fillcolor=yellow linecolor=blue
+         d.vect map=states  color=green
+         d.vect map=roads   color=blue
+         d.mon stop=CELL
+         # make the region the same as the newly created cell for ppm export
+         g.pushregion.sh  # or g.region save=saved.reg
+         g.region raster=D_cell
+         r.out.ppm -q input=D_cell output=alien.ppm
+         # use the netpbm utilities to create a gif (quantize if needed)
+         ppmquant 128 <alien.ppm |  ppmtogif >alien.gif	
+         # assemble some html with the image and the image map
+         echo '<html><body><img src="alien.gif" usemap="#map">' >alien.html
+         cat htmlmap                                           >>alien.html
+         echo '</body></html>'                                 >>alien.html
+         # don't forget to reset your region
+         g.popregion.sh   # or g.region region=saved.reg
+	 # take a look and test it out
+	 netscape file:`pwd`/alien.html &
+
+
+
+  Building the HTMLMAP driver:
+
+    Change to the HTMLMAP directory, and make it:
+
+	cd src/display/devices/HTMLMAP
+	gmake5
+    
+    If all goes well, the HTMLMAP driver will be compiled and moved into
+    your device driver directory ($GISBASE/driver) and "etc/monitorcap"
+    will be modified.
+
+
+  Other:  
+
+    Don't forget to add the HTMLMAP driver in your monitorcap file!
+    Your monitorcap file exists as $GISBASE/etc/monitorcap.
+
+        HTMLMAP:driver/HTMLMAP:Create HTML Image Map: \
+             /usr/local/grass43/dev/fifo.9a /usr/local/grass43/dev/fifo.9b \
+             ::any terminal
+
+    Note: This job will be done by the Gmakefile.    
+
+    HTMLMAP was adapted from the CELL driver in GRASS 4.3.  Point-in-
+    polygon-test code was lifted from Randolph Franklin's web page, see 
+
+	http://www.ecse.rpi.edu/Homepages/wrf/
+	http://www.ecse.rpi.edu/Homepages/wrf/research/geom/pnpoly.html
+
+
+    If you create an HTML file with two or more images & image maps, you 
+    will need to edit the map names.  The HTMLMAP driver creates its map
+    with the name 'map'.  A small sed script can easily change the map name:
+
+	sed -e 's/NAME="map"/NAME="foomap"/' <htmlmap >foomap.html
+
+
+-----------------------------
+http://www.nyx.net/~tpoindex/grass-stuff/

Copied: grass/trunk/lib/htmldriver/text.c (from rev 62429, grass/trunk/lib/htmldriver/Text.c)
===================================================================
--- grass/trunk/lib/htmldriver/text.c	                        (rev 0)
+++ grass/trunk/lib/htmldriver/text.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,30 @@
+
+/* Text.c - save text string into last_text buffer */
+
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include "driverlib.h"
+#include "htmlmap.h"
+
+void HTML_Text(const char *text)
+{
+    int len = strlen(text);
+    const char *s;
+    char *d;
+
+    if (len > html.last_text_len) {
+	G_free(html.last_text);
+	html.last_text = (char *)G_malloc(len + 1);
+	html.last_text_len = len;
+    }
+
+    /* copy string to last_text area, make sure we don't copy \n */
+    for (d = html.last_text, s = text; *s != '\0'; s++) {
+	if (*s != '\n') {
+	    *d = *s;
+	    d++;
+	}
+    }
+    *d = '\0';
+}

Deleted: grass/trunk/lib/pngdriver/Box.c
===================================================================
--- grass/trunk/lib/pngdriver/Box.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,65 +0,0 @@
-/*!
-  \file pngdriver/Box.c
-
-  \brief GRASS png display driver - draw box
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include <math.h>
-#include "pngdriver.h"
-
-/*!
-  \brief Draw a (filled) rectangle
-
-  \param fx1,fy1,fx2,fy2 rectangle coordinates
-*/
-
-void PNG_Box(double fx1, double fy1, double fx2, double fy2)
-{
-    int x1 = (int) floor(fx1 + 0.5);
-    int y1 = (int) floor(fy1 + 0.5);
-    int x2 = (int) floor(fx2 + 0.5);
-    int y2 = (int) floor(fy2 + 0.5);
-    int tmp;
-    int x, y;
-
-    if (x1 > x2)
-	tmp = x1, x1 = x2, x2 = tmp;
-
-    if (y1 > y2)
-	tmp = y1, y1 = y2, y2 = tmp;
-
-    if (x2 < 0 || x1 > png.width)
-	return;
-
-    if (y2 < 0 || y1 > png.height)
-	return;
-
-    if (x1 < png.clip_left)
-	x1 = png.clip_left;
-
-    if (x2 > png.clip_rite)
-	x2 = png.clip_rite;
-
-    if (y1 < png.clip_top)
-	y1 = png.clip_top;
-
-    if (y2 > png.clip_bot)
-	y2 = png.clip_bot;
-
-    for (y = y1; y < y2; y++) {
-	unsigned int *p = &png.grid[y * png.width + x1];
-
-	for (x = x1; x < x2; x++)
-	    *p++ = png.current_color;
-    }
-
-    png.modified = 1;
-}

Deleted: grass/trunk/lib/pngdriver/Color.c
===================================================================
--- grass/trunk/lib/pngdriver/Color.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Color.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,35 +0,0 @@
-/*!
-  \file pngdriver/Color.c
-
-  \brief GRASS png display driver - PNG_color_rgb
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include <grass/gis.h>
-#include "pngdriver.h"
-
-/*!
-  \brief  Identify a color 
-
-  Identify a color that has been set in the reset_color() (found in Reset_clr.c
-  file in this directory).  Subsequent graphics calls will use this color.
- 
-  Called by:
-       Color() in ../lib/Color.c
-
-  \param r red color value
-  \param g green color value
-  \param b blue color value
-*/
-
-void PNG_color_rgb(int r, int g, int b)
-{
-    png.current_color = png_get_color(r, g, b, 0);
-}

Deleted: grass/trunk/lib/pngdriver/Color_table.c
===================================================================
--- grass/trunk/lib/pngdriver/Color_table.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Color_table.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,126 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/colors.h>
-#include "pngdriver.h"
-
-static int r_shift, g_shift, b_shift, a_shift;
-static int Red[256], Grn[256], Blu[256];
-
-static void set_color(int i, int red, int grn, int blu)
-{
-    png.palette[i][0] = red;
-    png.palette[i][1] = grn;
-    png.palette[i][2] = blu;
-    png.palette[i][3] = 0;
-}
-
-static void init_colors_rgb(void)
-{
-    if (G_is_little_endian()) {
-	b_shift = 0;
-	g_shift = 8;
-	r_shift = 16;
-	a_shift = 24;
-    }
-    else {
-	b_shift = 24;
-	g_shift = 16;
-	r_shift = 8;
-	a_shift = 0;
-    }
-}
-
-static void init_colors_indexed(void)
-{
-    int n_pixels;
-    int r, g, b;
-    int i;
-
-    n_pixels = 0;
-
-    if (png.has_alpha)
-	/* transparent color should be the first!
-	 * Its RGB value doesn't matter since we fake RGB-to-index. */
-	set_color(n_pixels++, 0, 0, 0);
-
-    for (r = 0; r < 6; r++) {
-	for (g = 0; g < 6; g++) {
-	    for (b = 0; b < 6; b++) {
-		int red = r * 0xFF / 5;
-		int grn = g * 0xFF / 5;
-		int blu = b * 0xFF / 5;
-
-		set_color(n_pixels++, red, grn, blu);
-	    }
-	}
-    }
-
-    while (n_pixels < 256)
-	set_color(n_pixels++, 0, 0, 0);
-
-    for (i = 0; i < 256; i++) {
-	int k = i * 6 / 256;
-
-	Red[i] = k * 6 * 6;
-	Grn[i] = k * 6;
-	Blu[i] = k;
-    }
-}
-
-void png_init_color_table(void)
-{
-    if (png.true_color)
-	init_colors_rgb();
-    else
-	init_colors_indexed();
-}
-
-static int get_color_rgb(int r, int g, int b, int a)
-{
-    return (r << r_shift) + (g << g_shift) + (b << b_shift) + (a << a_shift);
-}
-
-static int get_color_indexed(int r, int g, int b, int a)
-{
-    if (png.has_alpha && a >= 128)
-	return 0;
-
-    return Red[r] + Grn[g] + Blu[b] + png.has_alpha;
-}
-
-static void get_pixel_rgb(unsigned int pixel, int *r, int *g, int *b, int *a)
-{
-    *r = (pixel >> r_shift) & 0xFF;
-    *g = (pixel >> g_shift) & 0xFF;
-    *b = (pixel >> b_shift) & 0xFF;
-    *a = (pixel >> a_shift) & 0xFF;
-}
-
-static void get_pixel_indexed(unsigned int pixel, int *r, int *g, int *b,
-			      int *a)
-{
-    *r = png.palette[pixel][0];
-    *g = png.palette[pixel][1];
-    *b = png.palette[pixel][2];
-    *a = png.palette[pixel][3];
-}
-
-
-void png_get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
-{
-    if (png.true_color)
-	get_pixel_rgb(pixel, r, g, b, a);
-    else
-	get_pixel_indexed(pixel, r, g, b, a);
-}
-
-unsigned int png_get_color(int r, int g, int b, int a)
-{
-    return png.true_color
-	? get_color_rgb(r, g, b, a)
-	: get_color_indexed(r, g, b, a);
-}
-

Deleted: grass/trunk/lib/pngdriver/Draw.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,50 +0,0 @@
-/*!
-  \file pngdriver/Draw.c
-
-  \brief GRASS PNG display driver
-
-  (C) 2008 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Glynn Clements  
-*/
-
-#include <grass/gis.h>
-#include "driverlib.h"
-#include "path.h"
-#include "pngdriver.h"
-
-static struct path path;
-
-void PNG_Begin(void)
-{
-    path_begin(&path);
-}
-
-void PNG_Move(double x, double y)
-{
-    path_move(&path, x, y);
-}
-
-void PNG_Cont(double x, double y)
-{
-    path_cont(&path, x, y);
-}
-
-void PNG_Close(void)
-{
-    path_close(&path);
-}
-
-void PNG_Stroke(void)
-{
-    path_stroke(&path, png_draw_line);
-}
-
-void PNG_Fill(void)
-{
-    png_polygon(&path);
-}
-

Deleted: grass/trunk/lib/pngdriver/Draw_bitmap.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw_bitmap.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Draw_bitmap.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,86 +0,0 @@
-/*!
-  \file pngdriver/Draw_bitmap.c
-
-  \brief GRASS png display driver - draw bitmap
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include <math.h>
-#include "pngdriver.h"
-
-#ifndef min
-#define min(a,b) ((a)<(b)?(a):(b))
-#endif
-#ifndef max
-#define max(a,b) ((a)>(b)?(a):(b))
-#endif
-
-/*!
-  \brief Draw bitmap
-
-  \param ncols,nrows number of columns and rows
-  \param threshold threshold value
-  \param buf data buffer
-*/
-
-void PNG_draw_bitmap(int ncols, int nrows, int threshold,
-		     const unsigned char *buf)
-{
-    int i0 = max(png.clip_left - cur_x, 0);
-    int i1 = min(png.clip_rite - cur_x, ncols);
-    int j0 = max(png.clip_top - cur_y, 0);
-    int j1 = min(png.clip_bot - cur_y, nrows);
-
-    if (!png.true_color) {
-	int i, j;
-
-	for (j = j0; j < j1; j++) {
-	    int y = cur_y + j;
-
-	    for (i = i0; i < i1; i++) {
-		int x = cur_x + i;
-		unsigned int k = buf[j * ncols + i];
-		unsigned int *p = &png.grid[y * png.width + x];
-
-		if (k > threshold)
-		    *p = png.current_color;
-	    }
-	}
-    }
-    else {
-	int r1, g1, b1, a1;
-	int i, j;
-
-	png_get_pixel(png.current_color, &r1, &g1, &b1, &a1);
-
-	for (j = j0; j < j1; j++) {
-	    int y = cur_y + j;
-
-	    for (i = i0; i < i1; i++) {
-		int x = cur_x + i;
-		unsigned int k = buf[j * ncols + i];
-		unsigned int *p = &png.grid[y * png.width + x];
-		unsigned int a0, r0, g0, b0;
-		unsigned int a, r, g, b;
-
-		png_get_pixel(*p, &r0, &g0, &b0, &a0);
-
-		a = (a0 * (255 - k) + a1 * k) / 255;
-		r = (r0 * (255 - k) + r1 * k) / 255;
-		g = (g0 * (255 - k) + g1 * k) / 255;
-		b = (b0 * (255 - k) + b1 * k) / 255;
-
-		*p = png_get_color(r, g, b, a);
-	    }
-	}
-    }
-
-    png.modified = 1;
-}

Deleted: grass/trunk/lib/pngdriver/Draw_line.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw_line.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Draw_line.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,104 +0,0 @@
-
-/*
- * draw a line between two given points in the current color.
- *
- * Called by:
- *     Cont_abs() in ../lib/Cont_abs.c
- */
-
-#include <stdlib.h>
-#include <math.h>
-
-#include "pngdriver.h"
-
-static void store_xy(double x, double y)
-{
-    int xi = (int) floor(x);
-    int yi = (int) floor(y);
-
-    if (x < png.clip_left || x >= png.clip_rite || y < png.clip_top || y >= png.clip_bot)
-	return;
-
-    png.grid[yi * png.width + xi] = png.current_color;
-}
-
-static void swap(double *a, double *b)
-{
-    double t = *a; *a = *b; *b = t;
-}
-
-static void draw_line(double x1, double y1, double x2, double y2)
-{
-    double x, y;
-    double dx, dy;
-
-    if (fabs(y1 - y2) > fabs(x1 - x2)) {
-	if (y1 > y2) {
-	    swap(&y1, &y2);
-	    swap(&x1, &x2);
-	}
-
-	dy = y2 - y1;
-	dx = x2 - x1;
-
-	for (y = floor(y1) + 0.5; y < y2; y++) {
-	    x = x1 + (y - y1) * dx / dy;
-	    store_xy(x, y);
-	}
-    }
-    else {
-	if (x1 > x2) {
-	    swap(&x1, &x2);
-	    swap(&y1, &y2);
-	}
-
-	dx = x2 - x1;
-	dy = y2 - y1;
-
-	for (x = floor(x1) + 0.5; x < x2; x++) {
-	    y = y1 + (x - x1) * dy / dx;
-	    store_xy(x, y);
-	}
-    }
-}
-
-void png_draw_line(double x1, double y1, double x2, double y2)
-{
-    struct path path;
-    struct vertex vertices[5];
-    double k = png.linewidth / 2;
-    double dx, dy;
-
-    if (png.linewidth <= 1) {
-	draw_line(x1, y1, x2, y2);
-	png.modified = 1;
-	return;
-    }
-
-    path.vertices = vertices;
-    path.count = 0;
-    path.alloc = 5;
-    path.start = -1;
-
-    /* FIXME: rendering issues (#1283) */
-    dx = fabs(x2 - x1);
-    dy = fabs(y2 - y1);
-
-    if (dy > dx) {
-	path_move(&path, x1 - k, y1);
-	path_cont(&path, x1 + k, y1);
-	path_cont(&path, x2 + k, y2);
-	path_cont(&path, x2 - k, y2);
-	path_close(&path);
-    }
-    else {
-	path_move(&path, x1, y1 - k);
-	path_cont(&path, x1, y1 + k);
-	path_cont(&path, x2, y2 + k);
-	path_cont(&path, x2, y2 - k);
-	path_close(&path);
-    }
-
-    png_polygon(&path);
-}
-

Deleted: grass/trunk/lib/pngdriver/Draw_point.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw_point.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Draw_point.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,15 +0,0 @@
-#include <math.h>
-#include "pngdriver.h"
-
-void PNG_draw_point(double fx, double fy)
-{
-    int x = (int) floor(fx + 0.5);
-    int y = (int) floor(fy + 0.5);
-
-    if (x < png.clip_left || x >= png.clip_rite || y < png.clip_top || y >= png.clip_bot)
-	return;
-
-    png.grid[y * png.width + x] = png.current_color;
-
-    png.modified = 1;
-}

Deleted: grass/trunk/lib/pngdriver/Driver.c
===================================================================
--- grass/trunk/lib/pngdriver/Driver.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,57 +0,0 @@
-/*!
-  \file pngdriver/Driver.c
-
-  \brief GRASS png display driver - driver initialization
-
-  (C) 2007 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Glynn Clements  
-*/
-
-#include "pngdriver.h"
-
-/*!
-  \brief Initialize display driver
-
-  \return pointer driver structure
-*/
-const struct driver *PNG_Driver(void)
-{
-    static struct driver drv;
-    static int initialized;
-
-    if (initialized)
-	return &drv;
-
-    drv.name = "png";
-    drv.Box = PNG_Box;
-    drv.Erase = PNG_Erase;
-    drv.Graph_set = PNG_Graph_set;
-    drv.Graph_close = PNG_Graph_close;
-    drv.Line_width = PNG_Line_width;
-    drv.Set_window = PNG_Set_window;
-    drv.Begin_raster = PNG_begin_raster;
-    drv.Raster = PNG_raster;
-    drv.End_raster = NULL;
-    drv.Begin = PNG_Begin;
-    drv.Move = PNG_Move;
-    drv.Cont = PNG_Cont;
-    drv.Close = PNG_Close;
-    drv.Stroke = PNG_Stroke;
-    drv.Fill = PNG_Fill;
-    drv.Point = PNG_Point;
-    drv.Color = PNG_color_rgb;
-    drv.Bitmap = PNG_draw_bitmap;
-    drv.Text = NULL;
-    drv.Text_box = NULL;
-    drv.Set_font = NULL;
-    drv.Font_list = NULL;
-    drv.Font_info = NULL;
-
-    initialized = 1;
-
-    return &drv;
-}

Deleted: grass/trunk/lib/pngdriver/Erase.c
===================================================================
--- grass/trunk/lib/pngdriver/Erase.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Erase.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,29 +0,0 @@
-/*!
-  \file pngdriver/Erase.c
-
-  \brief GRASS png display driver - erase screen
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include "pngdriver.h"
-
-/*!
-  \brief Erase screen
-*/
-void PNG_Erase(void)
-{
-    int n = png.width * png.height;
-    int i;
-
-    for (i = 0; i < n; i++)
-	png.grid[i] = png.background;
-
-    png.modified = 1;
-}

Deleted: grass/trunk/lib/pngdriver/Graph_close.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_close.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Graph_close.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,58 +0,0 @@
-/*!
-  \file pngdriver/Graph_close.c
-
-  \brief GRASS png display driver - close graphics processing
-
-  (C) 2003-2014 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements
-*/
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef __MINGW32__
-#include <windows.h>
-#else
-#include <sys/mman.h>
-#endif
-
-#include <grass/gis.h>
-#include "pngdriver.h"
-
-static void unmap_file(void)
-{
-    size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
-    void *ptr = (char *)png.grid - HEADER_SIZE;
-
-    if (!png.mapped)
-	return;
-
-#ifdef __MINGW32__
-    UnmapViewOfFile(ptr);
-    CloseHandle(png.handle);
-#else
-    munmap(ptr, size);
-#endif
-
-    png.mapped = 0;
-}
-
-/*!
-  \brief Close down the graphics processing. This gets called only at driver
-         termination time.
-*/
-void PNG_Graph_close(void)
-{
-    write_image();
-
-    if (png.mapped)
-	unmap_file();
-    else
-	G_free(png.grid);
-}

Deleted: grass/trunk/lib/pngdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_set.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Graph_set.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,172 +0,0 @@
-/*!
-  \file pngdriver/Graph_set.c
-
-  \brief GRASS png display driver - set graphics processing
-
-  (C) 2003-2014 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements
-*/
-
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef __MINGW32__
-#include <windows.h>
-#else
-#include <sys/mman.h>
-#endif
-
-#include <grass/gis.h>
-#include <grass/colors.h>
-#include <grass/glocale.h>
-#include "pngdriver.h"
-
-struct png_state png;
-
-static void map_file(void)
-{
-    size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
-    void *ptr;
-    int fd;
-
-    fd = open(png.file_name, O_RDWR);
-    if (fd < 0)
-	return;
-
-#ifdef __MINGW32__
-    png.handle = CreateFileMapping((HANDLE) _get_osfhandle(fd),
-				   NULL, PAGE_READWRITE,
-				   0, size, NULL);
-    if (!png.handle)
-	return;
-    ptr = MapViewOfFile(png.handle, FILE_MAP_WRITE, 0, 0, size);
-    if (!ptr)
-	return;
-#else
-    ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
-    if (ptr == MAP_FAILED)
-	return;
-#endif
-
-    if (png.grid)
-	G_free(png.grid);
-    png.grid = (unsigned int *)((char *) ptr + HEADER_SIZE);
-
-    close(fd);
-
-    png.mapped = 1;
-}
-
-/*!
-  \brief Start up graphics processing
-
-   Anything that needs to be assigned, set up,
-   started-up, or otherwise initialized happens here.  This is called only at
-   the startup of the graphics driver.
- 
-   The external variables define the pixle limits of the graphics surface.  The
-   coordinate system used by the applications programs has the (0,0) origin
-   in the upper left-hand corner.  Hence,
-     screen_left < screen_right
-     screen_top  < screen_bottom 
-*/
-
-int PNG_Graph_set(void)
-{
-    unsigned int red, grn, blu;
-    int do_read = 0;
-    int do_map = 0;
-    char *p;
-
-    G_gisinit("PNG driver");
-
-    p = getenv("GRASS_RENDER_FILE");
-    if (!p || strlen(p) == 0)
-	p = FILE_NAME;
-
-    png.file_name = p;
-
-    p = getenv("GRASS_RENDER_TRUECOLOR");
-    png.true_color = !p || strcmp(p, "FALSE") != 0;
-
-    G_verbose_message(_("png: truecolor status %s"),
-		      png.true_color ? _("enabled") : _("disabled"));
-
-    p = getenv("GRASS_RENDER_FILE_MAPPED");
-    do_map = p && strcmp(p, "TRUE") == 0;
-
-    if (do_map) {
-	char *ext = png.file_name + strlen(png.file_name) - 4;
-
-	if (G_strcasecmp(ext, ".bmp") != 0)
-	    do_map = 0;
-    }
-
-    p = getenv("GRASS_RENDER_FILE_READ");
-    do_read = p && strcmp(p, "TRUE") == 0;
-
-    if (do_read && access(png.file_name, 0) != 0)
-	do_read = 0;
-
-    png.width = screen_width;
-    png.height = screen_height;
-
-    png.clip_top = 0;
-    png.clip_bot = png.height;
-    png.clip_left = 0;
-    png.clip_rite = png.width;
-
-    p = getenv("GRASS_RENDER_TRANSPARENT");
-    png.has_alpha = p && strcmp(p, "TRUE") == 0;
-
-    png_init_color_table();
-
-    p = getenv("GRASS_RENDER_BACKGROUNDCOLOR");
-    if (p && *p && 
-	(sscanf(p, "%02x%02x%02x", &red, &grn, &blu) == 3 ||
-	 G_str_to_color(p, (int *)&red, (int *)&grn, (int *)&blu) == 1)) {
-	png.background = png_get_color(red, grn, blu, png.has_alpha ? 255 : 0);
-    }
-    else {
-	/* 0xffffff = white, 0x000000 = black */
-	if (strcmp(DEFAULT_FG_COLOR, "white") == 0)
-	    /* foreground: white, background: black */
-	    png.background = png_get_color(0, 0, 0, png.has_alpha ? 255 : 0);
-	else
-	    /* foreground: black, background: white */
-	    png.background = png_get_color(255, 255, 255, png.has_alpha ? 255 : 0);
-    }
-    
-    G_verbose_message(_("png: collecting to file '%s'"), png.file_name);
-    G_verbose_message(_("png: image size %dx%d"),
-		      png.width, png.height);
-
-    if (do_read && do_map)
-	map_file();
-
-    if (!png.mapped)
-	png.grid = G_malloc(png.width * png.height * sizeof(unsigned int));
-
-    if (!do_read) {
-	PNG_Erase();
-	png.modified = 1;
-    }
-
-    if (do_read && !png.mapped)
-	read_image();
-
-    if (do_map && !png.mapped) {
-	write_image();
-	map_file();
-    }
-
-    return 0;
-}

Deleted: grass/trunk/lib/pngdriver/Line_width.c
===================================================================
--- grass/trunk/lib/pngdriver/Line_width.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Line_width.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,26 +0,0 @@
-/*!
-  \file pngdriver/Line_width.c
-
-  \brief GRASS png display driver - set line width
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include <math.h>
-#include "pngdriver.h"
-
-/*!
-  \brief Set line width
-
-  \param width line width (double precision)
-*/
-void PNG_Line_width(double width)
-{
-    png.linewidth = (width < 0 ? 0 : (int) floor(width + 0.5));
-}

Deleted: grass/trunk/lib/pngdriver/Makefile
===================================================================
--- grass/trunk/lib/pngdriver/Makefile	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,18 +0,0 @@
-MODULE_TOPDIR = ../..
-
-include $(MODULE_TOPDIR)/include/Make/Vars.make
-
-ifeq ($(USE_PNG),)
-  MOD_OBJS := $(filter-out read_png.o write_png.o,$(AUTO_OBJS))
-endif
-
-LIB = PNGDRIVER
-PGM = pngdriver
-include $(MODULE_TOPDIR)/include/Make/Lib.make
-include $(MODULE_TOPDIR)/include/Make/Doxygen.make
-
-EXTRA_CFLAGS=$(ZLIBINCPATH) $(PNGINC) -I../driver
-
-default: lib
-
-DOXNAME = pngdriver

Deleted: grass/trunk/lib/pngdriver/Point.c
===================================================================
--- grass/trunk/lib/pngdriver/Point.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Point.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,28 +0,0 @@
-/*!
-  \file pngdriver/Point.c
-
-  \brief GRASS png display driver - draw point
-
-  (C) 2007-2014 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Glynn Clements  
-*/
-
-#include <grass/gis.h>
-#include "pngdriver.h"
-
-/*!
-  \brief Draw point
-*/
-void PNG_Point(double x, double y)
-{
-    static double point_size = 1.0;
-    double half_point_size = point_size / 2;
-
-    PNG_Box(x - half_point_size, y - half_point_size,
-	    point_size, point_size);
-}
-

Deleted: grass/trunk/lib/pngdriver/Polygon.c
===================================================================
--- grass/trunk/lib/pngdriver/Polygon.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Polygon.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,147 +0,0 @@
-/*!
-  \file pngdriver/Polygon.c
-
-  \brief GRASS png display driver - draw polygon
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include <stdlib.h>
-#include <math.h>
-#include <grass/gis.h>
-
-#include "path.h"
-#include "pngdriver.h"
-
-static int cmp_double(const void *aa, const void *bb)
-{
-    const double *a = aa;
-    const double *b = bb;
-
-    return
-	*a > *b ?  1 :
-	*a < *b ? -1 :
-	0;
-}
-
-static void fill(double x0, double x1, double y)
-{
-    int yi = (int) floor(y);
-    int xi0 = (int) floor(x0 + 0.5);
-    int xi1 = (int) floor(x1 + 0.5);
-    unsigned int *p;
-    int x;
-
-    if (yi >= png.clip_bot || yi < png.clip_top)
-	return;
-
-    if (xi0 > png.clip_rite)
-	return;
-
-    if (xi1 < png.clip_left)
-	return;
-
-    if (xi0 < png.clip_left)
-	xi0 = png.clip_left;
-
-    if (xi1 > png.clip_rite)
-	xi1 = png.clip_rite;
-
-    p = &png.grid[yi * png.width + xi0];
-
-    for (x = xi0; x < xi1; x++)
-	*p++ = png.current_color;
-}
-
-static void line(const struct vertex *p, int n, double y)
-{
-    static double *xs;
-    static int max_x;
-    int num_x = 0;
-    int i;
-
-    for (i = 1; i < n; i++) {
-	const struct vertex *p0 = &p[i - 1];
-	const struct vertex *p1 = &p[i];
-	const struct vertex *tmp;
-	double x;
-
-	if (p0->y == p1->y)
-	    continue;
-
-	if (p0->y > p1->y)
-	    tmp = p0, p0 = p1, p1 = tmp;
-
-	if (p0->y > y)
-	    continue;
-
-	if (p1->y <= y)
-	    continue;
-
-	x = p1->x * (y - p0->y) + p0->x * (p1->y - y);
-	x /= p1->y - p0->y;
-
-	if (num_x >= max_x) {
-	    max_x += 20;
-	    xs = G_realloc(xs, max_x * sizeof(double));
-	}
-
-	xs[num_x++] = x;
-    }
-
-    qsort(xs, num_x, sizeof(double), cmp_double);
-
-    for (i = 0; i + 1 < num_x; i += 2)
-	fill(xs[i], xs[i + 1], y);
-}
-
-static void poly(const struct vertex *p, int n)
-{
-    double y0, y1, y;
-    int i;
-
-    if (n < 3)
-	return;
-
-    y0 = y1 = p[0].y;
-
-    for (i = 1; i < n; i++) {
-	if (y0 > p[i].y)
-	    y0 = p[i].y;
-
-	if (y1 < p[i].y)
-	    y1 = p[i].y;
-    }
-
-    if (y0 > png.clip_bot || y1 < png.clip_top)
-	return;
-
-    if (y0 < png.clip_top)
-	y0 = png.clip_top;
-
-    if (y1 > png.clip_bot)
-	y1 = png.clip_bot;
-
-    for (y = floor(y0 + 0.5) + 0.5; y < y1; y++)
-	line(p, n, y);
-}
-
-/*!
-  \brief Draw polygon
-*/
-void png_polygon(struct path *p)
-{
-    if (p->vertices[p->count - 1].mode != P_CLOSE)
-	path_close(p);
-
-    poly(p->vertices, p->count);
-
-    png.modified = 1;
-}
-

Deleted: grass/trunk/lib/pngdriver/Raster.c
===================================================================
--- grass/trunk/lib/pngdriver/Raster.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Raster.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,147 +0,0 @@
-/*!
-  \file pngdriver/Raster.c
-
-  \brief GRASS png display driver - draw raster
-
-  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements  
-*/
-
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include "driver.h"
-#include "pngdriver.h"
-
-#ifndef min
-#define min(a,b) ((a)<(b)?(a):(b))
-#endif
-#ifndef max
-#define max(a,b) ((a)>(b)?(a):(b))
-#endif
-
-static int *trans;
-static int ncols;
-static int nalloc;
-static int masked;
-static int src[2][2];
-static int dst[2][2];
-
-static double scale(double k, const int src[2], const int dst[2])
-{
-    return dst[0] + (double)(k - src[0]) * (dst[1] - dst[0]) / (src[1] -
-								src[0]);
-}
-
-static int scale_fwd_y(int sy)
-{
-    return (int)floor(scale(sy, src[1], dst[1]) + 0.5);
-}
-
-static int scale_rev_x(int dx)
-{
-    return (int)floor(scale(dx + 0.5, dst[0], src[0]));
-}
-
-static int next_row(int sy, int dy)
-{
-    sy++;
-
-    for (;;) {
-	int y = scale_fwd_y(sy);
-
-	if (y > dy)
-	    return sy - 1;
-	sy++;
-    }
-}
-
-static void alloc_buffers(void)
-{
-    if (nalloc >= ncols)
-	return;
-
-    nalloc = ncols;
-    trans = G_realloc(trans, nalloc * sizeof(int));
-}
-
-/*!
-  \brief Start drawing raster
-
-  \param mask
-  \param s
-  \param d
-*/
-void PNG_begin_raster(int mask, int s[2][2], double fd[2][2])
-{
-    int d[2][2];
-    int i;
-
-    d[0][0] = (int) floor(fd[0][0] + 0.5);
-    d[0][1] = (int) floor(fd[0][1] + 0.5);
-    d[1][0] = (int) floor(fd[1][0] + 0.5);
-    d[1][1] = (int) floor(fd[1][1] + 0.5);
-
-    ncols = d[0][1] - d[0][0];
-
-    memcpy(src, s, sizeof(src));
-    memcpy(dst, d, sizeof(dst));
-    masked = mask;
-
-    alloc_buffers();
-
-    for (i = 0; i < ncols; i++)
-	trans[i] = scale_rev_x(d[0][0] + i);
-}
-
-/*!
-  \brief Draw raster row
-
-  \param n number of cell
-  \param row raster row
-  \param red,grn,blu,nul red,green,blue and null value
-
-  \return next row
-*/
-int PNG_raster(int n, int row,
-	       const unsigned char *red, const unsigned char *grn,
-	       const unsigned char *blu, const unsigned char *nul)
-{
-    int d_y0 = scale_fwd_y(row + 0);
-    int d_y1 = scale_fwd_y(row + 1);
-    int d_rows = d_y1 - d_y0;
-    int x0 = max(png.clip_left - dst[0][0], 0);
-    int x1 = min(png.clip_rite - dst[0][0], ncols);
-    int y0 = max(png.clip_top - d_y0, 0);
-    int y1 = min(png.clip_bot - d_y0, d_rows);
-    int x, y;
-
-    if (y1 <= y0)
-	return next_row(row, d_y1);
-
-    for (x = x0; x < x1; x++) {
-	int xx = dst[0][0] + x;
-	int j = trans[x];
-	int c;
-
-	if (masked && nul && nul[j])
-	    continue;
-
-	c = png_get_color(red[j], grn[j], blu[j], 0);
-
-	for (y = y0; y < y1; y++) {
-	    int yy = d_y0 + y;
-
-	    png.grid[yy * png.width + xx] = c;
-	}
-    }
-
-    png.modified = 1;
-
-    return next_row(row, d_y1);
-}

Deleted: grass/trunk/lib/pngdriver/Set_window.c
===================================================================
--- grass/trunk/lib/pngdriver/Set_window.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/pngdriver/Set_window.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,29 +0,0 @@
-/*!
-  \file pngdriver/Set_window.c
-
-  \brief GRASS png display driver - set window
-
-  (C) 2007-2014 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Per Henrik Johansen (original contributor)
-  \author Glynn Clements
-*/
-
-#include <math.h>
-#include "pngdriver.h"
-
-/*!
-  \brief Set window
-  
-  \param t,b,l,r top, bottom, left, right
-*/
-void PNG_Set_window(double t, double b, double l, double r)
-{
-    png.clip_top  = t > 0          ? t : 0;
-    png.clip_bot  = b < png.height ? b : png.height;
-    png.clip_left = l > 0          ? l : 0;
-    png.clip_rite = r < png.width  ? r : png.width;
-}

Copied: grass/trunk/lib/pngdriver/box.c (from rev 62429, grass/trunk/lib/pngdriver/Box.c)
===================================================================
--- grass/trunk/lib/pngdriver/box.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,65 @@
+/*!
+  \file pngdriver/Box.c
+
+  \brief GRASS png display driver - draw box
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include <math.h>
+#include "pngdriver.h"
+
+/*!
+  \brief Draw a (filled) rectangle
+
+  \param fx1,fy1,fx2,fy2 rectangle coordinates
+*/
+
+void PNG_Box(double fx1, double fy1, double fx2, double fy2)
+{
+    int x1 = (int) floor(fx1 + 0.5);
+    int y1 = (int) floor(fy1 + 0.5);
+    int x2 = (int) floor(fx2 + 0.5);
+    int y2 = (int) floor(fy2 + 0.5);
+    int tmp;
+    int x, y;
+
+    if (x1 > x2)
+	tmp = x1, x1 = x2, x2 = tmp;
+
+    if (y1 > y2)
+	tmp = y1, y1 = y2, y2 = tmp;
+
+    if (x2 < 0 || x1 > png.width)
+	return;
+
+    if (y2 < 0 || y1 > png.height)
+	return;
+
+    if (x1 < png.clip_left)
+	x1 = png.clip_left;
+
+    if (x2 > png.clip_rite)
+	x2 = png.clip_rite;
+
+    if (y1 < png.clip_top)
+	y1 = png.clip_top;
+
+    if (y2 > png.clip_bot)
+	y2 = png.clip_bot;
+
+    for (y = y1; y < y2; y++) {
+	unsigned int *p = &png.grid[y * png.width + x1];
+
+	for (x = x1; x < x2; x++)
+	    *p++ = png.current_color;
+    }
+
+    png.modified = 1;
+}

Copied: grass/trunk/lib/pngdriver/color.c (from rev 62429, grass/trunk/lib/pngdriver/Color.c)
===================================================================
--- grass/trunk/lib/pngdriver/color.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/color.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,35 @@
+/*!
+  \file pngdriver/Color.c
+
+  \brief GRASS png display driver - PNG_color_rgb
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include <grass/gis.h>
+#include "pngdriver.h"
+
+/*!
+  \brief  Identify a color 
+
+  Identify a color that has been set in the reset_color() (found in Reset_clr.c
+  file in this directory).  Subsequent graphics calls will use this color.
+ 
+  Called by:
+       Color() in ../lib/Color.c
+
+  \param r red color value
+  \param g green color value
+  \param b blue color value
+*/
+
+void PNG_color_rgb(int r, int g, int b)
+{
+    png.current_color = png_get_color(r, g, b, 0);
+}

Copied: grass/trunk/lib/pngdriver/color_table.c (from rev 62429, grass/trunk/lib/pngdriver/Color_table.c)
===================================================================
--- grass/trunk/lib/pngdriver/color_table.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/color_table.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,126 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/colors.h>
+#include "pngdriver.h"
+
+static int r_shift, g_shift, b_shift, a_shift;
+static int Red[256], Grn[256], Blu[256];
+
+static void set_color(int i, int red, int grn, int blu)
+{
+    png.palette[i][0] = red;
+    png.palette[i][1] = grn;
+    png.palette[i][2] = blu;
+    png.palette[i][3] = 0;
+}
+
+static void init_colors_rgb(void)
+{
+    if (G_is_little_endian()) {
+	b_shift = 0;
+	g_shift = 8;
+	r_shift = 16;
+	a_shift = 24;
+    }
+    else {
+	b_shift = 24;
+	g_shift = 16;
+	r_shift = 8;
+	a_shift = 0;
+    }
+}
+
+static void init_colors_indexed(void)
+{
+    int n_pixels;
+    int r, g, b;
+    int i;
+
+    n_pixels = 0;
+
+    if (png.has_alpha)
+	/* transparent color should be the first!
+	 * Its RGB value doesn't matter since we fake RGB-to-index. */
+	set_color(n_pixels++, 0, 0, 0);
+
+    for (r = 0; r < 6; r++) {
+	for (g = 0; g < 6; g++) {
+	    for (b = 0; b < 6; b++) {
+		int red = r * 0xFF / 5;
+		int grn = g * 0xFF / 5;
+		int blu = b * 0xFF / 5;
+
+		set_color(n_pixels++, red, grn, blu);
+	    }
+	}
+    }
+
+    while (n_pixels < 256)
+	set_color(n_pixels++, 0, 0, 0);
+
+    for (i = 0; i < 256; i++) {
+	int k = i * 6 / 256;
+
+	Red[i] = k * 6 * 6;
+	Grn[i] = k * 6;
+	Blu[i] = k;
+    }
+}
+
+void png_init_color_table(void)
+{
+    if (png.true_color)
+	init_colors_rgb();
+    else
+	init_colors_indexed();
+}
+
+static int get_color_rgb(int r, int g, int b, int a)
+{
+    return (r << r_shift) + (g << g_shift) + (b << b_shift) + (a << a_shift);
+}
+
+static int get_color_indexed(int r, int g, int b, int a)
+{
+    if (png.has_alpha && a >= 128)
+	return 0;
+
+    return Red[r] + Grn[g] + Blu[b] + png.has_alpha;
+}
+
+static void get_pixel_rgb(unsigned int pixel, int *r, int *g, int *b, int *a)
+{
+    *r = (pixel >> r_shift) & 0xFF;
+    *g = (pixel >> g_shift) & 0xFF;
+    *b = (pixel >> b_shift) & 0xFF;
+    *a = (pixel >> a_shift) & 0xFF;
+}
+
+static void get_pixel_indexed(unsigned int pixel, int *r, int *g, int *b,
+			      int *a)
+{
+    *r = png.palette[pixel][0];
+    *g = png.palette[pixel][1];
+    *b = png.palette[pixel][2];
+    *a = png.palette[pixel][3];
+}
+
+
+void png_get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
+{
+    if (png.true_color)
+	get_pixel_rgb(pixel, r, g, b, a);
+    else
+	get_pixel_indexed(pixel, r, g, b, a);
+}
+
+unsigned int png_get_color(int r, int g, int b, int a)
+{
+    return png.true_color
+	? get_color_rgb(r, g, b, a)
+	: get_color_indexed(r, g, b, a);
+}
+

Copied: grass/trunk/lib/pngdriver/draw.c (from rev 62429, grass/trunk/lib/pngdriver/Draw.c)
===================================================================
--- grass/trunk/lib/pngdriver/draw.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,50 @@
+/*!
+  \file pngdriver/Draw.c
+
+  \brief GRASS PNG display driver
+
+  (C) 2008 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Glynn Clements  
+*/
+
+#include <grass/gis.h>
+#include "driverlib.h"
+#include "path.h"
+#include "pngdriver.h"
+
+static struct path path;
+
+void PNG_Begin(void)
+{
+    path_begin(&path);
+}
+
+void PNG_Move(double x, double y)
+{
+    path_move(&path, x, y);
+}
+
+void PNG_Cont(double x, double y)
+{
+    path_cont(&path, x, y);
+}
+
+void PNG_Close(void)
+{
+    path_close(&path);
+}
+
+void PNG_Stroke(void)
+{
+    path_stroke(&path, png_draw_line);
+}
+
+void PNG_Fill(void)
+{
+    png_polygon(&path);
+}
+

Copied: grass/trunk/lib/pngdriver/draw_bitmap.c (from rev 62429, grass/trunk/lib/pngdriver/Draw_bitmap.c)
===================================================================
--- grass/trunk/lib/pngdriver/draw_bitmap.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/draw_bitmap.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,86 @@
+/*!
+  \file pngdriver/Draw_bitmap.c
+
+  \brief GRASS png display driver - draw bitmap
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include <math.h>
+#include "pngdriver.h"
+
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+#ifndef max
+#define max(a,b) ((a)>(b)?(a):(b))
+#endif
+
+/*!
+  \brief Draw bitmap
+
+  \param ncols,nrows number of columns and rows
+  \param threshold threshold value
+  \param buf data buffer
+*/
+
+void PNG_draw_bitmap(int ncols, int nrows, int threshold,
+		     const unsigned char *buf)
+{
+    int i0 = max(png.clip_left - cur_x, 0);
+    int i1 = min(png.clip_rite - cur_x, ncols);
+    int j0 = max(png.clip_top - cur_y, 0);
+    int j1 = min(png.clip_bot - cur_y, nrows);
+
+    if (!png.true_color) {
+	int i, j;
+
+	for (j = j0; j < j1; j++) {
+	    int y = cur_y + j;
+
+	    for (i = i0; i < i1; i++) {
+		int x = cur_x + i;
+		unsigned int k = buf[j * ncols + i];
+		unsigned int *p = &png.grid[y * png.width + x];
+
+		if (k > threshold)
+		    *p = png.current_color;
+	    }
+	}
+    }
+    else {
+	int r1, g1, b1, a1;
+	int i, j;
+
+	png_get_pixel(png.current_color, &r1, &g1, &b1, &a1);
+
+	for (j = j0; j < j1; j++) {
+	    int y = cur_y + j;
+
+	    for (i = i0; i < i1; i++) {
+		int x = cur_x + i;
+		unsigned int k = buf[j * ncols + i];
+		unsigned int *p = &png.grid[y * png.width + x];
+		unsigned int a0, r0, g0, b0;
+		unsigned int a, r, g, b;
+
+		png_get_pixel(*p, &r0, &g0, &b0, &a0);
+
+		a = (a0 * (255 - k) + a1 * k) / 255;
+		r = (r0 * (255 - k) + r1 * k) / 255;
+		g = (g0 * (255 - k) + g1 * k) / 255;
+		b = (b0 * (255 - k) + b1 * k) / 255;
+
+		*p = png_get_color(r, g, b, a);
+	    }
+	}
+    }
+
+    png.modified = 1;
+}

Copied: grass/trunk/lib/pngdriver/draw_line.c (from rev 62429, grass/trunk/lib/pngdriver/Draw_line.c)
===================================================================
--- grass/trunk/lib/pngdriver/draw_line.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/draw_line.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,104 @@
+
+/*
+ * draw a line between two given points in the current color.
+ *
+ * Called by:
+ *     Cont_abs() in ../lib/Cont_abs.c
+ */
+
+#include <stdlib.h>
+#include <math.h>
+
+#include "pngdriver.h"
+
+static void store_xy(double x, double y)
+{
+    int xi = (int) floor(x);
+    int yi = (int) floor(y);
+
+    if (x < png.clip_left || x >= png.clip_rite || y < png.clip_top || y >= png.clip_bot)
+	return;
+
+    png.grid[yi * png.width + xi] = png.current_color;
+}
+
+static void swap(double *a, double *b)
+{
+    double t = *a; *a = *b; *b = t;
+}
+
+static void draw_line(double x1, double y1, double x2, double y2)
+{
+    double x, y;
+    double dx, dy;
+
+    if (fabs(y1 - y2) > fabs(x1 - x2)) {
+	if (y1 > y2) {
+	    swap(&y1, &y2);
+	    swap(&x1, &x2);
+	}
+
+	dy = y2 - y1;
+	dx = x2 - x1;
+
+	for (y = floor(y1) + 0.5; y < y2; y++) {
+	    x = x1 + (y - y1) * dx / dy;
+	    store_xy(x, y);
+	}
+    }
+    else {
+	if (x1 > x2) {
+	    swap(&x1, &x2);
+	    swap(&y1, &y2);
+	}
+
+	dx = x2 - x1;
+	dy = y2 - y1;
+
+	for (x = floor(x1) + 0.5; x < x2; x++) {
+	    y = y1 + (x - x1) * dy / dx;
+	    store_xy(x, y);
+	}
+    }
+}
+
+void png_draw_line(double x1, double y1, double x2, double y2)
+{
+    struct path path;
+    struct vertex vertices[5];
+    double k = png.linewidth / 2;
+    double dx, dy;
+
+    if (png.linewidth <= 1) {
+	draw_line(x1, y1, x2, y2);
+	png.modified = 1;
+	return;
+    }
+
+    path.vertices = vertices;
+    path.count = 0;
+    path.alloc = 5;
+    path.start = -1;
+
+    /* FIXME: rendering issues (#1283) */
+    dx = fabs(x2 - x1);
+    dy = fabs(y2 - y1);
+
+    if (dy > dx) {
+	path_move(&path, x1 - k, y1);
+	path_cont(&path, x1 + k, y1);
+	path_cont(&path, x2 + k, y2);
+	path_cont(&path, x2 - k, y2);
+	path_close(&path);
+    }
+    else {
+	path_move(&path, x1, y1 - k);
+	path_cont(&path, x1, y1 + k);
+	path_cont(&path, x2, y2 + k);
+	path_cont(&path, x2, y2 - k);
+	path_close(&path);
+    }
+
+    png_polygon(&path);
+}
+

Copied: grass/trunk/lib/pngdriver/draw_point.c (from rev 62429, grass/trunk/lib/pngdriver/Draw_point.c)
===================================================================
--- grass/trunk/lib/pngdriver/draw_point.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/draw_point.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,15 @@
+#include <math.h>
+#include "pngdriver.h"
+
+void PNG_draw_point(double fx, double fy)
+{
+    int x = (int) floor(fx + 0.5);
+    int y = (int) floor(fy + 0.5);
+
+    if (x < png.clip_left || x >= png.clip_rite || y < png.clip_top || y >= png.clip_bot)
+	return;
+
+    png.grid[y * png.width + x] = png.current_color;
+
+    png.modified = 1;
+}

Copied: grass/trunk/lib/pngdriver/driver.c (from rev 62429, grass/trunk/lib/pngdriver/Driver.c)
===================================================================
--- grass/trunk/lib/pngdriver/driver.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,57 @@
+/*!
+  \file pngdriver/Driver.c
+
+  \brief GRASS png display driver - driver initialization
+
+  (C) 2007 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Glynn Clements  
+*/
+
+#include "pngdriver.h"
+
+/*!
+  \brief Initialize display driver
+
+  \return pointer driver structure
+*/
+const struct driver *PNG_Driver(void)
+{
+    static struct driver drv;
+    static int initialized;
+
+    if (initialized)
+	return &drv;
+
+    drv.name = "png";
+    drv.Box = PNG_Box;
+    drv.Erase = PNG_Erase;
+    drv.Graph_set = PNG_Graph_set;
+    drv.Graph_close = PNG_Graph_close;
+    drv.Line_width = PNG_Line_width;
+    drv.Set_window = PNG_Set_window;
+    drv.Begin_raster = PNG_begin_raster;
+    drv.Raster = PNG_raster;
+    drv.End_raster = NULL;
+    drv.Begin = PNG_Begin;
+    drv.Move = PNG_Move;
+    drv.Cont = PNG_Cont;
+    drv.Close = PNG_Close;
+    drv.Stroke = PNG_Stroke;
+    drv.Fill = PNG_Fill;
+    drv.Point = PNG_Point;
+    drv.Color = PNG_color_rgb;
+    drv.Bitmap = PNG_draw_bitmap;
+    drv.Text = NULL;
+    drv.Text_box = NULL;
+    drv.Set_font = NULL;
+    drv.Font_list = NULL;
+    drv.Font_info = NULL;
+
+    initialized = 1;
+
+    return &drv;
+}

Copied: grass/trunk/lib/pngdriver/erase.c (from rev 62429, grass/trunk/lib/pngdriver/Erase.c)
===================================================================
--- grass/trunk/lib/pngdriver/erase.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/erase.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,29 @@
+/*!
+  \file pngdriver/Erase.c
+
+  \brief GRASS png display driver - erase screen
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include "pngdriver.h"
+
+/*!
+  \brief Erase screen
+*/
+void PNG_Erase(void)
+{
+    int n = png.width * png.height;
+    int i;
+
+    for (i = 0; i < n; i++)
+	png.grid[i] = png.background;
+
+    png.modified = 1;
+}

Copied: grass/trunk/lib/pngdriver/graph_close.c (from rev 62429, grass/trunk/lib/pngdriver/Graph_close.c)
===================================================================
--- grass/trunk/lib/pngdriver/graph_close.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/graph_close.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,58 @@
+/*!
+  \file pngdriver/Graph_close.c
+
+  \brief GRASS png display driver - close graphics processing
+
+  (C) 2003-2014 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements
+*/
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef __MINGW32__
+#include <windows.h>
+#else
+#include <sys/mman.h>
+#endif
+
+#include <grass/gis.h>
+#include "pngdriver.h"
+
+static void unmap_file(void)
+{
+    size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
+    void *ptr = (char *)png.grid - HEADER_SIZE;
+
+    if (!png.mapped)
+	return;
+
+#ifdef __MINGW32__
+    UnmapViewOfFile(ptr);
+    CloseHandle(png.handle);
+#else
+    munmap(ptr, size);
+#endif
+
+    png.mapped = 0;
+}
+
+/*!
+  \brief Close down the graphics processing. This gets called only at driver
+         termination time.
+*/
+void PNG_Graph_close(void)
+{
+    write_image();
+
+    if (png.mapped)
+	unmap_file();
+    else
+	G_free(png.grid);
+}

Copied: grass/trunk/lib/pngdriver/graph_set.c (from rev 62429, grass/trunk/lib/pngdriver/Graph_set.c)
===================================================================
--- grass/trunk/lib/pngdriver/graph_set.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/graph_set.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,172 @@
+/*!
+  \file pngdriver/Graph_set.c
+
+  \brief GRASS png display driver - set graphics processing
+
+  (C) 2003-2014 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef __MINGW32__
+#include <windows.h>
+#else
+#include <sys/mman.h>
+#endif
+
+#include <grass/gis.h>
+#include <grass/colors.h>
+#include <grass/glocale.h>
+#include "pngdriver.h"
+
+struct png_state png;
+
+static void map_file(void)
+{
+    size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
+    void *ptr;
+    int fd;
+
+    fd = open(png.file_name, O_RDWR);
+    if (fd < 0)
+	return;
+
+#ifdef __MINGW32__
+    png.handle = CreateFileMapping((HANDLE) _get_osfhandle(fd),
+				   NULL, PAGE_READWRITE,
+				   0, size, NULL);
+    if (!png.handle)
+	return;
+    ptr = MapViewOfFile(png.handle, FILE_MAP_WRITE, 0, 0, size);
+    if (!ptr)
+	return;
+#else
+    ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
+    if (ptr == MAP_FAILED)
+	return;
+#endif
+
+    if (png.grid)
+	G_free(png.grid);
+    png.grid = (unsigned int *)((char *) ptr + HEADER_SIZE);
+
+    close(fd);
+
+    png.mapped = 1;
+}
+
+/*!
+  \brief Start up graphics processing
+
+   Anything that needs to be assigned, set up,
+   started-up, or otherwise initialized happens here.  This is called only at
+   the startup of the graphics driver.
+ 
+   The external variables define the pixle limits of the graphics surface.  The
+   coordinate system used by the applications programs has the (0,0) origin
+   in the upper left-hand corner.  Hence,
+     screen_left < screen_right
+     screen_top  < screen_bottom 
+*/
+
+int PNG_Graph_set(void)
+{
+    unsigned int red, grn, blu;
+    int do_read = 0;
+    int do_map = 0;
+    char *p;
+
+    G_gisinit("PNG driver");
+
+    p = getenv("GRASS_RENDER_FILE");
+    if (!p || strlen(p) == 0)
+	p = FILE_NAME;
+
+    png.file_name = p;
+
+    p = getenv("GRASS_RENDER_TRUECOLOR");
+    png.true_color = !p || strcmp(p, "FALSE") != 0;
+
+    G_verbose_message(_("png: truecolor status %s"),
+		      png.true_color ? _("enabled") : _("disabled"));
+
+    p = getenv("GRASS_RENDER_FILE_MAPPED");
+    do_map = p && strcmp(p, "TRUE") == 0;
+
+    if (do_map) {
+	char *ext = png.file_name + strlen(png.file_name) - 4;
+
+	if (G_strcasecmp(ext, ".bmp") != 0)
+	    do_map = 0;
+    }
+
+    p = getenv("GRASS_RENDER_FILE_READ");
+    do_read = p && strcmp(p, "TRUE") == 0;
+
+    if (do_read && access(png.file_name, 0) != 0)
+	do_read = 0;
+
+    png.width = screen_width;
+    png.height = screen_height;
+
+    png.clip_top = 0;
+    png.clip_bot = png.height;
+    png.clip_left = 0;
+    png.clip_rite = png.width;
+
+    p = getenv("GRASS_RENDER_TRANSPARENT");
+    png.has_alpha = p && strcmp(p, "TRUE") == 0;
+
+    png_init_color_table();
+
+    p = getenv("GRASS_RENDER_BACKGROUNDCOLOR");
+    if (p && *p && 
+	(sscanf(p, "%02x%02x%02x", &red, &grn, &blu) == 3 ||
+	 G_str_to_color(p, (int *)&red, (int *)&grn, (int *)&blu) == 1)) {
+	png.background = png_get_color(red, grn, blu, png.has_alpha ? 255 : 0);
+    }
+    else {
+	/* 0xffffff = white, 0x000000 = black */
+	if (strcmp(DEFAULT_FG_COLOR, "white") == 0)
+	    /* foreground: white, background: black */
+	    png.background = png_get_color(0, 0, 0, png.has_alpha ? 255 : 0);
+	else
+	    /* foreground: black, background: white */
+	    png.background = png_get_color(255, 255, 255, png.has_alpha ? 255 : 0);
+    }
+    
+    G_verbose_message(_("png: collecting to file '%s'"), png.file_name);
+    G_verbose_message(_("png: image size %dx%d"),
+		      png.width, png.height);
+
+    if (do_read && do_map)
+	map_file();
+
+    if (!png.mapped)
+	png.grid = G_malloc(png.width * png.height * sizeof(unsigned int));
+
+    if (!do_read) {
+	PNG_Erase();
+	png.modified = 1;
+    }
+
+    if (do_read && !png.mapped)
+	read_image();
+
+    if (do_map && !png.mapped) {
+	write_image();
+	map_file();
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/pngdriver/line_width.c (from rev 62429, grass/trunk/lib/pngdriver/Line_width.c)
===================================================================
--- grass/trunk/lib/pngdriver/line_width.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/line_width.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,26 @@
+/*!
+  \file pngdriver/Line_width.c
+
+  \brief GRASS png display driver - set line width
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include <math.h>
+#include "pngdriver.h"
+
+/*!
+  \brief Set line width
+
+  \param width line width (double precision)
+*/
+void PNG_Line_width(double width)
+{
+    png.linewidth = (width < 0 ? 0 : (int) floor(width + 0.5));
+}

Copied: grass/trunk/lib/pngdriver/makefile (from rev 62429, grass/trunk/lib/pngdriver/Makefile)
===================================================================
--- grass/trunk/lib/pngdriver/makefile	                        (rev 0)
+++ grass/trunk/lib/pngdriver/makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,18 @@
+MODULE_TOPDIR = ../..
+
+include $(MODULE_TOPDIR)/include/Make/Vars.make
+
+ifeq ($(USE_PNG),)
+  MOD_OBJS := $(filter-out read_png.o write_png.o,$(AUTO_OBJS))
+endif
+
+LIB = PNGDRIVER
+PGM = pngdriver
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+
+EXTRA_CFLAGS=$(ZLIBINCPATH) $(PNGINC) -I../driver
+
+default: lib
+
+DOXNAME = pngdriver

Copied: grass/trunk/lib/pngdriver/point.c (from rev 62429, grass/trunk/lib/pngdriver/Point.c)
===================================================================
--- grass/trunk/lib/pngdriver/point.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/point.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,28 @@
+/*!
+  \file pngdriver/Point.c
+
+  \brief GRASS png display driver - draw point
+
+  (C) 2007-2014 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Glynn Clements  
+*/
+
+#include <grass/gis.h>
+#include "pngdriver.h"
+
+/*!
+  \brief Draw point
+*/
+void PNG_Point(double x, double y)
+{
+    static double point_size = 1.0;
+    double half_point_size = point_size / 2;
+
+    PNG_Box(x - half_point_size, y - half_point_size,
+	    point_size, point_size);
+}
+

Copied: grass/trunk/lib/pngdriver/polygon.c (from rev 62429, grass/trunk/lib/pngdriver/Polygon.c)
===================================================================
--- grass/trunk/lib/pngdriver/polygon.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/polygon.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,147 @@
+/*!
+  \file pngdriver/Polygon.c
+
+  \brief GRASS png display driver - draw polygon
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+
+#include "path.h"
+#include "pngdriver.h"
+
+static int cmp_double(const void *aa, const void *bb)
+{
+    const double *a = aa;
+    const double *b = bb;
+
+    return
+	*a > *b ?  1 :
+	*a < *b ? -1 :
+	0;
+}
+
+static void fill(double x0, double x1, double y)
+{
+    int yi = (int) floor(y);
+    int xi0 = (int) floor(x0 + 0.5);
+    int xi1 = (int) floor(x1 + 0.5);
+    unsigned int *p;
+    int x;
+
+    if (yi >= png.clip_bot || yi < png.clip_top)
+	return;
+
+    if (xi0 > png.clip_rite)
+	return;
+
+    if (xi1 < png.clip_left)
+	return;
+
+    if (xi0 < png.clip_left)
+	xi0 = png.clip_left;
+
+    if (xi1 > png.clip_rite)
+	xi1 = png.clip_rite;
+
+    p = &png.grid[yi * png.width + xi0];
+
+    for (x = xi0; x < xi1; x++)
+	*p++ = png.current_color;
+}
+
+static void line(const struct vertex *p, int n, double y)
+{
+    static double *xs;
+    static int max_x;
+    int num_x = 0;
+    int i;
+
+    for (i = 1; i < n; i++) {
+	const struct vertex *p0 = &p[i - 1];
+	const struct vertex *p1 = &p[i];
+	const struct vertex *tmp;
+	double x;
+
+	if (p0->y == p1->y)
+	    continue;
+
+	if (p0->y > p1->y)
+	    tmp = p0, p0 = p1, p1 = tmp;
+
+	if (p0->y > y)
+	    continue;
+
+	if (p1->y <= y)
+	    continue;
+
+	x = p1->x * (y - p0->y) + p0->x * (p1->y - y);
+	x /= p1->y - p0->y;
+
+	if (num_x >= max_x) {
+	    max_x += 20;
+	    xs = G_realloc(xs, max_x * sizeof(double));
+	}
+
+	xs[num_x++] = x;
+    }
+
+    qsort(xs, num_x, sizeof(double), cmp_double);
+
+    for (i = 0; i + 1 < num_x; i += 2)
+	fill(xs[i], xs[i + 1], y);
+}
+
+static void poly(const struct vertex *p, int n)
+{
+    double y0, y1, y;
+    int i;
+
+    if (n < 3)
+	return;
+
+    y0 = y1 = p[0].y;
+
+    for (i = 1; i < n; i++) {
+	if (y0 > p[i].y)
+	    y0 = p[i].y;
+
+	if (y1 < p[i].y)
+	    y1 = p[i].y;
+    }
+
+    if (y0 > png.clip_bot || y1 < png.clip_top)
+	return;
+
+    if (y0 < png.clip_top)
+	y0 = png.clip_top;
+
+    if (y1 > png.clip_bot)
+	y1 = png.clip_bot;
+
+    for (y = floor(y0 + 0.5) + 0.5; y < y1; y++)
+	line(p, n, y);
+}
+
+/*!
+  \brief Draw polygon
+*/
+void png_polygon(struct path *p)
+{
+    if (p->vertices[p->count - 1].mode != P_CLOSE)
+	path_close(p);
+
+    poly(p->vertices, p->count);
+
+    png.modified = 1;
+}
+

Copied: grass/trunk/lib/pngdriver/raster.c (from rev 62429, grass/trunk/lib/pngdriver/Raster.c)
===================================================================
--- grass/trunk/lib/pngdriver/raster.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/raster.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,147 @@
+/*!
+  \file pngdriver/Raster.c
+
+  \brief GRASS png display driver - draw raster
+
+  (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements  
+*/
+
+#include <string.h>
+#include <math.h>
+#include <grass/gis.h>
+#include "driver.h"
+#include "pngdriver.h"
+
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+#ifndef max
+#define max(a,b) ((a)>(b)?(a):(b))
+#endif
+
+static int *trans;
+static int ncols;
+static int nalloc;
+static int masked;
+static int src[2][2];
+static int dst[2][2];
+
+static double scale(double k, const int src[2], const int dst[2])
+{
+    return dst[0] + (double)(k - src[0]) * (dst[1] - dst[0]) / (src[1] -
+								src[0]);
+}
+
+static int scale_fwd_y(int sy)
+{
+    return (int)floor(scale(sy, src[1], dst[1]) + 0.5);
+}
+
+static int scale_rev_x(int dx)
+{
+    return (int)floor(scale(dx + 0.5, dst[0], src[0]));
+}
+
+static int next_row(int sy, int dy)
+{
+    sy++;
+
+    for (;;) {
+	int y = scale_fwd_y(sy);
+
+	if (y > dy)
+	    return sy - 1;
+	sy++;
+    }
+}
+
+static void alloc_buffers(void)
+{
+    if (nalloc >= ncols)
+	return;
+
+    nalloc = ncols;
+    trans = G_realloc(trans, nalloc * sizeof(int));
+}
+
+/*!
+  \brief Start drawing raster
+
+  \param mask
+  \param s
+  \param d
+*/
+void PNG_begin_raster(int mask, int s[2][2], double fd[2][2])
+{
+    int d[2][2];
+    int i;
+
+    d[0][0] = (int) floor(fd[0][0] + 0.5);
+    d[0][1] = (int) floor(fd[0][1] + 0.5);
+    d[1][0] = (int) floor(fd[1][0] + 0.5);
+    d[1][1] = (int) floor(fd[1][1] + 0.5);
+
+    ncols = d[0][1] - d[0][0];
+
+    memcpy(src, s, sizeof(src));
+    memcpy(dst, d, sizeof(dst));
+    masked = mask;
+
+    alloc_buffers();
+
+    for (i = 0; i < ncols; i++)
+	trans[i] = scale_rev_x(d[0][0] + i);
+}
+
+/*!
+  \brief Draw raster row
+
+  \param n number of cell
+  \param row raster row
+  \param red,grn,blu,nul red,green,blue and null value
+
+  \return next row
+*/
+int PNG_raster(int n, int row,
+	       const unsigned char *red, const unsigned char *grn,
+	       const unsigned char *blu, const unsigned char *nul)
+{
+    int d_y0 = scale_fwd_y(row + 0);
+    int d_y1 = scale_fwd_y(row + 1);
+    int d_rows = d_y1 - d_y0;
+    int x0 = max(png.clip_left - dst[0][0], 0);
+    int x1 = min(png.clip_rite - dst[0][0], ncols);
+    int y0 = max(png.clip_top - d_y0, 0);
+    int y1 = min(png.clip_bot - d_y0, d_rows);
+    int x, y;
+
+    if (y1 <= y0)
+	return next_row(row, d_y1);
+
+    for (x = x0; x < x1; x++) {
+	int xx = dst[0][0] + x;
+	int j = trans[x];
+	int c;
+
+	if (masked && nul && nul[j])
+	    continue;
+
+	c = png_get_color(red[j], grn[j], blu[j], 0);
+
+	for (y = y0; y < y1; y++) {
+	    int yy = d_y0 + y;
+
+	    png.grid[yy * png.width + xx] = c;
+	}
+    }
+
+    png.modified = 1;
+
+    return next_row(row, d_y1);
+}

Copied: grass/trunk/lib/pngdriver/set_window.c (from rev 62429, grass/trunk/lib/pngdriver/Set_window.c)
===================================================================
--- grass/trunk/lib/pngdriver/set_window.c	                        (rev 0)
+++ grass/trunk/lib/pngdriver/set_window.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,29 @@
+/*!
+  \file pngdriver/Set_window.c
+
+  \brief GRASS png display driver - set window
+
+  (C) 2007-2014 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Per Henrik Johansen (original contributor)
+  \author Glynn Clements
+*/
+
+#include <math.h>
+#include "pngdriver.h"
+
+/*!
+  \brief Set window
+  
+  \param t,b,l,r top, bottom, left, right
+*/
+void PNG_Set_window(double t, double b, double l, double r)
+{
+    png.clip_top  = t > 0          ? t : 0;
+    png.clip_bot  = b < png.height ? b : png.height;
+    png.clip_left = l > 0          ? l : 0;
+    png.clip_rite = r < png.width  ? r : png.width;
+}

Deleted: grass/trunk/lib/psdriver/Box.c
===================================================================
--- grass/trunk/lib/psdriver/Box.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,7 +0,0 @@
-
-#include "psdriver.h"
-
-void PS_Box(double x1, double y1, double x2, double y2)
-{
-    output("%f %f %f %f BOX\n", x1, y1, x2, y2);
-}

Deleted: grass/trunk/lib/psdriver/Color.c
===================================================================
--- grass/trunk/lib/psdriver/Color.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Color.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,11 +0,0 @@
-
-#include <grass/gis.h>
-#include "psdriver.h"
-
-void PS_Color(int r, int g, int b)
-{
-    if (ps.true_color)
-	output("%d %d %d COLOR\n", r, g, b);
-    else
-	output("%d GRAY\n", (int)(r * 0.299 + g * 0.587 + b * 0.114));
-}

Deleted: grass/trunk/lib/psdriver/Draw.c
===================================================================
--- grass/trunk/lib/psdriver/Draw.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,50 +0,0 @@
-/*!
-  \file psdriver/Draw.c
-
-  \brief GRASS PS display driver
-
-  (C) 2007-2008 by Glynn Clements and the GRASS Development Team
-  
-  This program is free software under the GNU General Public License
-  (>=v2). Read the file COPYING that comes with GRASS for details.
-  
-  \author Glynn Clements  
-*/
-
-#include "psdriver.h"
-
-void PS_Begin(void)
-{
-    output("NEW\n");
-}
-
-void PS_Move(double x, double y)
-{
-    output("%f %f MOVE\n", x, y);
-}
-
-void PS_Cont(double x, double y)
-{
-    output("%f %f CONT\n", x, y);
-}
-
-void PS_Close(void)
-{
-    output("CLOSE\n");
-}
-
-void PS_Stroke(void)
-{
-    output("STROKE\n");
-}
-
-void PS_Fill(void)
-{
-    output("FILL\n");
-}
-
-void PS_Point(double x, double y)
-{
-    output("%f %f POINT\n", x, y);
-}
-

Deleted: grass/trunk/lib/psdriver/Draw_bitmap.c
===================================================================
--- grass/trunk/lib/psdriver/Draw_bitmap.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Draw_bitmap.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,35 +0,0 @@
-
-#include "psdriver.h"
-
-void PS_Bitmap(int ncols, int nrows, int threshold,
-	       const unsigned char *buf)
-{
-    int i, j;
-
-    output("%d %d %d %d BITMAP\n", cur_x, cur_y, ncols, nrows);
-
-    for (j = 0; j < nrows; j++) {
-	unsigned int bit = 0x80;
-	unsigned int acc = 0;
-
-	for (i = 0; i < ncols; i++) {
-	    unsigned int k = buf[j * ncols + i];
-
-	    if (k > threshold)
-		acc |= bit;
-
-	    bit >>= 1;
-
-	    if (!bit) {
-		output("%02X", acc);
-		bit = 0x80;
-		acc = 0;
-	    }
-	}
-
-	if (bit != 0x80)
-	    output("%02X", acc);
-
-	output("\n");
-    }
-}

Deleted: grass/trunk/lib/psdriver/Driver.c
===================================================================
--- grass/trunk/lib/psdriver/Driver.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,58 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       PS driver
- * AUTHOR(S):    Glynn Clements <glynn at gclements.plus.com>
- * COPYRIGHT:    (C) 2007 Glynn Clements
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *****************************************************************************/
-
-#include "psdriver.h"
-
-const struct driver *PS_Driver(void)
-{
-    static struct driver drv;
-    static int initialized;
-
-    if (initialized)
-	return &drv;
-
-    drv.name = "ps";
-    drv.Box = PS_Box;
-    drv.Erase = PS_Erase;
-    drv.Graph_set = PS_Graph_set;
-    drv.Graph_close = PS_Graph_close;
-    drv.Line_width = PS_Line_width;
-    drv.Set_window = PS_Set_window;
-    drv.Begin_raster = PS_begin_raster;
-    drv.Raster = PS_raster;
-    drv.End_raster = PS_end_raster;
-    drv.Begin = PS_Begin;
-    drv.Move = PS_Move;
-    drv.Cont = PS_Cont;
-    drv.Close = PS_Close;
-    drv.Stroke = PS_Stroke;
-    drv.Fill = PS_Fill;
-    drv.Point = PS_Point;
-    drv.Color = PS_Color;
-    drv.Bitmap = PS_Bitmap;
-    drv.Text = NULL;
-    drv.Text_box = NULL;
-    drv.Set_font = NULL;
-    drv.Font_list = NULL;
-    drv.Font_info = NULL;
-
-    initialized = 1;
-
-    return &drv;
-}

Deleted: grass/trunk/lib/psdriver/Erase.c
===================================================================
--- grass/trunk/lib/psdriver/Erase.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Erase.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,9 +0,0 @@
-#include "psdriver.h"
-
-void PS_Erase(void)
-{
-    if (ps.encapsulated)
-	output("%d %d %d %d BOX\n", ps.left, ps.top, ps.right, ps.bot);
-    else
-	output("ERASE\n");
-}

Deleted: grass/trunk/lib/psdriver/Graph_close.c
===================================================================
--- grass/trunk/lib/psdriver/Graph_close.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Graph_close.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,17 +0,0 @@
-/*
- * Close down the graphics processing.  This gets called only at driver
- * termination time.
- */
-
-#include "psdriver.h"
-
-void PS_Graph_close(void)
-{
-    if (!ps.no_trailer) {
-	output("%%%%BeginTrailer\n");
-	output("END\n");
-	output("%%%%EndTrailer\n");
-    }
-
-    fclose(ps.outfp);
-}

Deleted: grass/trunk/lib/psdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/psdriver/Graph_set.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Graph_set.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,230 +0,0 @@
-/*
- * Start up graphics processing.  Anything that needs to be assigned, set up,
- * started-up, or otherwise initialized happens here.  This is called only at
- * the startup of the graphics driver.
- *
- * The external variables define the pixle limits of the graphics surface.  The
- * coordinate system used by the applications programs has the (0,0) origin
- * in the upper left-hand corner.  Hence,
- *    screen_left < screen_right
- *    screen_top  < screen_bottom 
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <time.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "psdriver.h"
-
-#define DATE_FORMAT "%c"
-
-struct ps_state ps;
-
-static const char *file_name;
-
-static double width, height;
-static int landscape;
-
-struct paper
-{
-    const char *name;
-    double width, height;
-    double left, right, bot, top;
-};
-
-static const struct paper papers[] = {
-    /* name         width   height  left    right   bottom  top */
-    {"a4", 8.268, 11.693, 0.5, 0.5, 1.0, 1.0},
-    {"a3", 11.693, 16.535, 0.5, 0.5, 1.0, 1.0},
-    {"a2", 16.54, 23.39, 1.0, 1.0, 1.0, 1.0},
-    {"a1", 23.39, 33.07, 1.0, 1.0, 1.0, 1.0},
-    {"a0", 33.07, 46.77, 1.0, 1.0, 1.0, 1.0},
-    {"us-legal", 8.5, 14.0, 1.0, 1.0, 1.0, 1.0},
-    {"us-letter", 8.5, 11.0, 1.0, 1.0, 1.0, 1.0},
-    {"us-tabloid", 11.0, 17.0, 1.0, 1.0, 1.0, 1.0},
-    {NULL, 0, 0, 0, 0, 0, 0}
-};
-
-static void write_prolog(void)
-{
-    char prolog_file[GPATH_MAX];
-    char date_str[256];
-    FILE *prolog_fp;
-    time_t t = time(NULL);
-    struct tm *tm = localtime(&t);
-
-    strftime(date_str, sizeof(date_str), DATE_FORMAT, tm);
-
-    sprintf(prolog_file, "%s/etc/psdriver.ps", G_gisbase());
-
-    prolog_fp = fopen(prolog_file, "r");
-    if (!prolog_fp)
-	G_fatal_error("Unable to open prolog file");
-
-    if (ps.encapsulated)
-	output("%%!PS-Adobe-3.0 EPSF-3.0\n");
-    else
-	output("%%!PS-Adobe-3.0\n");
-
-    output("%%%%LanguageLevel: %d\n", 3);
-    output("%%%%Creator: GRASS PS Driver\n");
-    output("%%%%Title: %s\n", file_name);
-    output("%%%%For: %s\n", G_whoami());
-    output("%%%%Orientation: %s\n", landscape ? "Landscape" : "Portrait");
-    output("%%%%BoundingBox: %d %d %d %d\n",
-	   (int)floor(ps.left), (int)floor(ps.bot),
-	   (int)ceil(ps.right), (int)ceil(ps.top));
-    output("%%%%CreationDate: %s\n", date_str);
-    output("%%%%EndComments\n");
-
-    output("%%%%BeginProlog\n");
-    while (!feof(prolog_fp)) {
-	char buf[256];
-
-	if (!fgets(buf, sizeof(buf), prolog_fp))
-	    break;
-
-	fputs(buf, ps.outfp);
-    }
-    output("%%%%EndProlog\n");
-
-    fclose(prolog_fp);
-}
-
-void write_setup(void)
-{
-    output("%%%%BeginSetup\n");
-
-    output("%.1f %.1f translate\n", ps.left, ps.bot);
-
-    if (landscape)
-	output("90 rotate 0 1 -1 scale\n");
-    else
-	output("0 %.1f translate 1 -1 scale\n", height);
-
-    output("%.1f %.1f BEGIN\n", width, height);
-
-    output("%%%%EndSetup\n");
-    output("%%%%Page: 1 1\n");
-}
-
-static double in2pt(double x)
-{
-    return x * 72;
-}
-
-static void swap(double *x, double *y)
-{
-    double tmp = *x;
-
-    *x = *y;
-    *y = tmp;
-}
-
-static void get_paper(void)
-{
-    const char *name = getenv("GRASS_RENDER_PS_PAPER");
-    const struct paper *paper;
-    int i;
-
-    width = screen_width;
-    height = screen_height;
-
-    ps.left = 0;
-    ps.right = width;
-    ps.bot = 0;
-    ps.top = height;
-
-    if (landscape)
-	swap(&ps.right, &ps.top);
-
-    if (!name)
-	return;
-
-    for (i = 0;; i++) {
-	paper = &papers[i];
-
-	if (!paper->name)
-	    return;
-
-	if (G_strcasecmp(name, paper->name) == 0)
-	    break;
-    }
-
-    ps.left = in2pt(paper->left);
-    ps.right = in2pt(paper->width) - in2pt(paper->right);
-    ps.bot = in2pt(paper->bot);
-    ps.top = in2pt(paper->height) - in2pt(paper->top);
-
-    width = ps.right - ps.left;
-    height = in2pt(paper->height) - in2pt(paper->top) - in2pt(paper->bot);
-
-    if (landscape)
-	swap(&width, &height);
-
-    ps.right = ps.left + width;
-    ps.bot = ps.top + height;
-}
-
-int PS_Graph_set(void)
-{
-    const char *p;
-
-    G_gisinit("PS driver");
-
-    p = getenv("GRASS_RENDER_FILE");
-    if (!p || strlen(p) == 0)
-	p = FILE_NAME;
-
-    file_name = p;
-    p = file_name + strlen(file_name) - 4;
-    ps.encapsulated = (G_strcasecmp(p, ".eps") == 0);
-
-    p = getenv("GRASS_RENDER_TRUECOLOR");
-    ps.true_color = p && strcmp(p, "TRUE") == 0;
-
-    p = getenv("GRASS_RENDER_PS_LANDSCAPE");
-    landscape = p && strcmp(p, "TRUE") == 0;
-
-    p = getenv("GRASS_RENDER_PS_HEADER");
-    ps.no_header = p && strcmp(p, "FALSE") == 0;
-
-    p = getenv("GRASS_RENDER_PS_TRAILER");
-    ps.no_trailer = p && strcmp(p, "FALSE") == 0;
-
-    G_verbose_message(_("ps: truecolor status %s"),
-		      ps.true_color ? _("enabled") : _("disabled"));
-
-    get_paper();
-
-    ps.outfp = fopen(file_name, ps.no_header ? "a" : "w");
-
-    if (!ps.outfp)
-	G_fatal_error("Unable to open output file: %s", file_name);
-
-    if (!ps.no_header) {
-	write_prolog();
-	write_setup();
-    }
-
-    G_verbose_message(_("ps: collecting to file '%s'"), file_name);
-    G_verbose_message(_("ps: image size %dx%d"),
-		      screen_width, screen_height);
-
-    fflush(ps.outfp);
-
-    return 0;
-}
-
-void output(const char *fmt, ...)
-{
-    va_list va;
-
-    va_start(va, fmt);
-    vfprintf(ps.outfp, fmt, va);
-    va_end(va);
-}

Deleted: grass/trunk/lib/psdriver/Line_width.c
===================================================================
--- grass/trunk/lib/psdriver/Line_width.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Line_width.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,9 +0,0 @@
-#include "psdriver.h"
-
-void PS_Line_width(double width)
-{
-    if (width < 0)
-	width = 0;
-
-    output("%f WIDTH\n", width);
-}

Deleted: grass/trunk/lib/psdriver/Makefile
===================================================================
--- grass/trunk/lib/psdriver/Makefile	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,16 +0,0 @@
-MODULE_TOPDIR = ../..
-
-EXTRA_CFLAGS = -I../driver
-
-LIB = PSDRIVER
-PGM = psdriver
-
-include $(MODULE_TOPDIR)/include/Make/Lib.make
-include $(MODULE_TOPDIR)/include/Make/Doxygen.make
-
-default: lib $(ETC)/psdriver.ps
-
-$(ETC)/psdriver.ps: psdriver.ps
-	$(INSTALL_DATA) $< $@
-
-DOXNAME = psdriver

Deleted: grass/trunk/lib/psdriver/Raster.c
===================================================================
--- grass/trunk/lib/psdriver/Raster.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Raster.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,65 +0,0 @@
-
-#include <string.h>
-
-#include "psdriver.h"
-
-static int masked;
-
-void PS_begin_raster(int mask, int src[2][2], double dst[2][2])
-{
-    const char *type = ps.true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
-	: (mask ? "RASTERGRAYMASK" : "RASTERGRAY");
-
-    int ssx = src[0][1] - src[0][0];
-    int ssy = src[1][1] - src[1][0];
-    int sox = src[0][0];
-    int soy = src[1][0];
-
-    double dsx = dst[0][1] - dst[0][0];
-    double dsy = dst[1][1] - dst[1][0];
-    double dox = dst[0][0];
-    double doy = dst[1][0];
-
-    masked = mask;
-
-    output("gsave\n");
-    output("%f %f translate %f %f scale\n", dox, doy, dsx, dsy);
-    output("%d %d [%d 0 0 %d %d %d] %s\n", ssx, ssy, ssx, ssy, sox, soy,
-	   type);
-}
-
-int PS_raster(int n, int row,
-	      const unsigned char *red, const unsigned char *grn,
-	      const unsigned char *blu, const unsigned char *nul)
-{
-    int i;
-
-    for (i = 0; i < n; i++) {
-	if (ps.true_color) {
-	    if (masked)
-		output("%02X%02X%02X%02X", (nul && nul[i]) ? 0xFF : 0x00,
-		       red[i], grn[i], blu[i]);
-	    else
-		output("%02X%02X%02X", red[i], grn[i], blu[i]);
-	}
-	else {
-	    unsigned int gray =
-		(unsigned int)(red[i] * 0.299 + grn[i] * 0.587 +
-			       blu[i] * 0.114);
-
-	    if (masked)
-		output("%02X%02X", (nul && nul[i]) ? 0xFF : 0x00, gray);
-	    else
-		output("%02X", gray);
-	}
-    }
-
-    output("\n");
-
-    return row + 1;
-}
-
-void PS_end_raster(void)
-{
-    output("grestore\n");
-}

Deleted: grass/trunk/lib/psdriver/Set_window.c
===================================================================
--- grass/trunk/lib/psdriver/Set_window.c	2014-10-28 12:46:44 UTC (rev 62430)
+++ grass/trunk/lib/psdriver/Set_window.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -1,26 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       PNG driver
- * AUTHOR(S):    Glynn Clements <glynn at gclements.plus.com>
- * COPYRIGHT:    (C) 2007 Glynn Clements
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *****************************************************************************/
-
-#include "psdriver.h"
-
-void PS_Set_window(double t, double b, double l, double r)
-{
-    output("%.1f %.1f %.1f %.1f %s\n", t, b, l, r,
-	   ps.encapsulated ? "EPSWINDOW" : "WINDOW");
-}

Copied: grass/trunk/lib/psdriver/box.c (from rev 62429, grass/trunk/lib/psdriver/Box.c)
===================================================================
--- grass/trunk/lib/psdriver/box.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/box.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,7 @@
+
+#include "psdriver.h"
+
+void PS_Box(double x1, double y1, double x2, double y2)
+{
+    output("%f %f %f %f BOX\n", x1, y1, x2, y2);
+}

Copied: grass/trunk/lib/psdriver/color.c (from rev 62429, grass/trunk/lib/psdriver/Color.c)
===================================================================
--- grass/trunk/lib/psdriver/color.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/color.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,11 @@
+
+#include <grass/gis.h>
+#include "psdriver.h"
+
+void PS_Color(int r, int g, int b)
+{
+    if (ps.true_color)
+	output("%d %d %d COLOR\n", r, g, b);
+    else
+	output("%d GRAY\n", (int)(r * 0.299 + g * 0.587 + b * 0.114));
+}

Copied: grass/trunk/lib/psdriver/draw.c (from rev 62429, grass/trunk/lib/psdriver/Draw.c)
===================================================================
--- grass/trunk/lib/psdriver/draw.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/draw.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,50 @@
+/*!
+  \file psdriver/Draw.c
+
+  \brief GRASS PS display driver
+
+  (C) 2007-2008 by Glynn Clements and the GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Glynn Clements  
+*/
+
+#include "psdriver.h"
+
+void PS_Begin(void)
+{
+    output("NEW\n");
+}
+
+void PS_Move(double x, double y)
+{
+    output("%f %f MOVE\n", x, y);
+}
+
+void PS_Cont(double x, double y)
+{
+    output("%f %f CONT\n", x, y);
+}
+
+void PS_Close(void)
+{
+    output("CLOSE\n");
+}
+
+void PS_Stroke(void)
+{
+    output("STROKE\n");
+}
+
+void PS_Fill(void)
+{
+    output("FILL\n");
+}
+
+void PS_Point(double x, double y)
+{
+    output("%f %f POINT\n", x, y);
+}
+

Copied: grass/trunk/lib/psdriver/draw_bitmap.c (from rev 62429, grass/trunk/lib/psdriver/Draw_bitmap.c)
===================================================================
--- grass/trunk/lib/psdriver/draw_bitmap.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/draw_bitmap.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,35 @@
+
+#include "psdriver.h"
+
+void PS_Bitmap(int ncols, int nrows, int threshold,
+	       const unsigned char *buf)
+{
+    int i, j;
+
+    output("%d %d %d %d BITMAP\n", cur_x, cur_y, ncols, nrows);
+
+    for (j = 0; j < nrows; j++) {
+	unsigned int bit = 0x80;
+	unsigned int acc = 0;
+
+	for (i = 0; i < ncols; i++) {
+	    unsigned int k = buf[j * ncols + i];
+
+	    if (k > threshold)
+		acc |= bit;
+
+	    bit >>= 1;
+
+	    if (!bit) {
+		output("%02X", acc);
+		bit = 0x80;
+		acc = 0;
+	    }
+	}
+
+	if (bit != 0x80)
+	    output("%02X", acc);
+
+	output("\n");
+    }
+}

Copied: grass/trunk/lib/psdriver/driver.c (from rev 62429, grass/trunk/lib/psdriver/Driver.c)
===================================================================
--- grass/trunk/lib/psdriver/driver.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/driver.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,58 @@
+
+/****************************************************************************
+ *
+ * MODULE:       PS driver
+ * AUTHOR(S):    Glynn Clements <glynn at gclements.plus.com>
+ * COPYRIGHT:    (C) 2007 Glynn Clements
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *****************************************************************************/
+
+#include "psdriver.h"
+
+const struct driver *PS_Driver(void)
+{
+    static struct driver drv;
+    static int initialized;
+
+    if (initialized)
+	return &drv;
+
+    drv.name = "ps";
+    drv.Box = PS_Box;
+    drv.Erase = PS_Erase;
+    drv.Graph_set = PS_Graph_set;
+    drv.Graph_close = PS_Graph_close;
+    drv.Line_width = PS_Line_width;
+    drv.Set_window = PS_Set_window;
+    drv.Begin_raster = PS_begin_raster;
+    drv.Raster = PS_raster;
+    drv.End_raster = PS_end_raster;
+    drv.Begin = PS_Begin;
+    drv.Move = PS_Move;
+    drv.Cont = PS_Cont;
+    drv.Close = PS_Close;
+    drv.Stroke = PS_Stroke;
+    drv.Fill = PS_Fill;
+    drv.Point = PS_Point;
+    drv.Color = PS_Color;
+    drv.Bitmap = PS_Bitmap;
+    drv.Text = NULL;
+    drv.Text_box = NULL;
+    drv.Set_font = NULL;
+    drv.Font_list = NULL;
+    drv.Font_info = NULL;
+
+    initialized = 1;
+
+    return &drv;
+}

Copied: grass/trunk/lib/psdriver/erase.c (from rev 62429, grass/trunk/lib/psdriver/Erase.c)
===================================================================
--- grass/trunk/lib/psdriver/erase.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/erase.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,9 @@
+#include "psdriver.h"
+
+void PS_Erase(void)
+{
+    if (ps.encapsulated)
+	output("%d %d %d %d BOX\n", ps.left, ps.top, ps.right, ps.bot);
+    else
+	output("ERASE\n");
+}

Copied: grass/trunk/lib/psdriver/graph_close.c (from rev 62429, grass/trunk/lib/psdriver/Graph_close.c)
===================================================================
--- grass/trunk/lib/psdriver/graph_close.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/graph_close.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,17 @@
+/*
+ * Close down the graphics processing.  This gets called only at driver
+ * termination time.
+ */
+
+#include "psdriver.h"
+
+void PS_Graph_close(void)
+{
+    if (!ps.no_trailer) {
+	output("%%%%BeginTrailer\n");
+	output("END\n");
+	output("%%%%EndTrailer\n");
+    }
+
+    fclose(ps.outfp);
+}

Copied: grass/trunk/lib/psdriver/graph_set.c (from rev 62429, grass/trunk/lib/psdriver/Graph_set.c)
===================================================================
--- grass/trunk/lib/psdriver/graph_set.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/graph_set.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,230 @@
+/*
+ * Start up graphics processing.  Anything that needs to be assigned, set up,
+ * started-up, or otherwise initialized happens here.  This is called only at
+ * the startup of the graphics driver.
+ *
+ * The external variables define the pixle limits of the graphics surface.  The
+ * coordinate system used by the applications programs has the (0,0) origin
+ * in the upper left-hand corner.  Hence,
+ *    screen_left < screen_right
+ *    screen_top  < screen_bottom 
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <time.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "psdriver.h"
+
+#define DATE_FORMAT "%c"
+
+struct ps_state ps;
+
+static const char *file_name;
+
+static double width, height;
+static int landscape;
+
+struct paper
+{
+    const char *name;
+    double width, height;
+    double left, right, bot, top;
+};
+
+static const struct paper papers[] = {
+    /* name         width   height  left    right   bottom  top */
+    {"a4", 8.268, 11.693, 0.5, 0.5, 1.0, 1.0},
+    {"a3", 11.693, 16.535, 0.5, 0.5, 1.0, 1.0},
+    {"a2", 16.54, 23.39, 1.0, 1.0, 1.0, 1.0},
+    {"a1", 23.39, 33.07, 1.0, 1.0, 1.0, 1.0},
+    {"a0", 33.07, 46.77, 1.0, 1.0, 1.0, 1.0},
+    {"us-legal", 8.5, 14.0, 1.0, 1.0, 1.0, 1.0},
+    {"us-letter", 8.5, 11.0, 1.0, 1.0, 1.0, 1.0},
+    {"us-tabloid", 11.0, 17.0, 1.0, 1.0, 1.0, 1.0},
+    {NULL, 0, 0, 0, 0, 0, 0}
+};
+
+static void write_prolog(void)
+{
+    char prolog_file[GPATH_MAX];
+    char date_str[256];
+    FILE *prolog_fp;
+    time_t t = time(NULL);
+    struct tm *tm = localtime(&t);
+
+    strftime(date_str, sizeof(date_str), DATE_FORMAT, tm);
+
+    sprintf(prolog_file, "%s/etc/psdriver.ps", G_gisbase());
+
+    prolog_fp = fopen(prolog_file, "r");
+    if (!prolog_fp)
+	G_fatal_error("Unable to open prolog file");
+
+    if (ps.encapsulated)
+	output("%%!PS-Adobe-3.0 EPSF-3.0\n");
+    else
+	output("%%!PS-Adobe-3.0\n");
+
+    output("%%%%LanguageLevel: %d\n", 3);
+    output("%%%%Creator: GRASS PS Driver\n");
+    output("%%%%Title: %s\n", file_name);
+    output("%%%%For: %s\n", G_whoami());
+    output("%%%%Orientation: %s\n", landscape ? "Landscape" : "Portrait");
+    output("%%%%BoundingBox: %d %d %d %d\n",
+	   (int)floor(ps.left), (int)floor(ps.bot),
+	   (int)ceil(ps.right), (int)ceil(ps.top));
+    output("%%%%CreationDate: %s\n", date_str);
+    output("%%%%EndComments\n");
+
+    output("%%%%BeginProlog\n");
+    while (!feof(prolog_fp)) {
+	char buf[256];
+
+	if (!fgets(buf, sizeof(buf), prolog_fp))
+	    break;
+
+	fputs(buf, ps.outfp);
+    }
+    output("%%%%EndProlog\n");
+
+    fclose(prolog_fp);
+}
+
+void write_setup(void)
+{
+    output("%%%%BeginSetup\n");
+
+    output("%.1f %.1f translate\n", ps.left, ps.bot);
+
+    if (landscape)
+	output("90 rotate 0 1 -1 scale\n");
+    else
+	output("0 %.1f translate 1 -1 scale\n", height);
+
+    output("%.1f %.1f BEGIN\n", width, height);
+
+    output("%%%%EndSetup\n");
+    output("%%%%Page: 1 1\n");
+}
+
+static double in2pt(double x)
+{
+    return x * 72;
+}
+
+static void swap(double *x, double *y)
+{
+    double tmp = *x;
+
+    *x = *y;
+    *y = tmp;
+}
+
+static void get_paper(void)
+{
+    const char *name = getenv("GRASS_RENDER_PS_PAPER");
+    const struct paper *paper;
+    int i;
+
+    width = screen_width;
+    height = screen_height;
+
+    ps.left = 0;
+    ps.right = width;
+    ps.bot = 0;
+    ps.top = height;
+
+    if (landscape)
+	swap(&ps.right, &ps.top);
+
+    if (!name)
+	return;
+
+    for (i = 0;; i++) {
+	paper = &papers[i];
+
+	if (!paper->name)
+	    return;
+
+	if (G_strcasecmp(name, paper->name) == 0)
+	    break;
+    }
+
+    ps.left = in2pt(paper->left);
+    ps.right = in2pt(paper->width) - in2pt(paper->right);
+    ps.bot = in2pt(paper->bot);
+    ps.top = in2pt(paper->height) - in2pt(paper->top);
+
+    width = ps.right - ps.left;
+    height = in2pt(paper->height) - in2pt(paper->top) - in2pt(paper->bot);
+
+    if (landscape)
+	swap(&width, &height);
+
+    ps.right = ps.left + width;
+    ps.bot = ps.top + height;
+}
+
+int PS_Graph_set(void)
+{
+    const char *p;
+
+    G_gisinit("PS driver");
+
+    p = getenv("GRASS_RENDER_FILE");
+    if (!p || strlen(p) == 0)
+	p = FILE_NAME;
+
+    file_name = p;
+    p = file_name + strlen(file_name) - 4;
+    ps.encapsulated = (G_strcasecmp(p, ".eps") == 0);
+
+    p = getenv("GRASS_RENDER_TRUECOLOR");
+    ps.true_color = p && strcmp(p, "TRUE") == 0;
+
+    p = getenv("GRASS_RENDER_PS_LANDSCAPE");
+    landscape = p && strcmp(p, "TRUE") == 0;
+
+    p = getenv("GRASS_RENDER_PS_HEADER");
+    ps.no_header = p && strcmp(p, "FALSE") == 0;
+
+    p = getenv("GRASS_RENDER_PS_TRAILER");
+    ps.no_trailer = p && strcmp(p, "FALSE") == 0;
+
+    G_verbose_message(_("ps: truecolor status %s"),
+		      ps.true_color ? _("enabled") : _("disabled"));
+
+    get_paper();
+
+    ps.outfp = fopen(file_name, ps.no_header ? "a" : "w");
+
+    if (!ps.outfp)
+	G_fatal_error("Unable to open output file: %s", file_name);
+
+    if (!ps.no_header) {
+	write_prolog();
+	write_setup();
+    }
+
+    G_verbose_message(_("ps: collecting to file '%s'"), file_name);
+    G_verbose_message(_("ps: image size %dx%d"),
+		      screen_width, screen_height);
+
+    fflush(ps.outfp);
+
+    return 0;
+}
+
+void output(const char *fmt, ...)
+{
+    va_list va;
+
+    va_start(va, fmt);
+    vfprintf(ps.outfp, fmt, va);
+    va_end(va);
+}

Copied: grass/trunk/lib/psdriver/line_width.c (from rev 62429, grass/trunk/lib/psdriver/Line_width.c)
===================================================================
--- grass/trunk/lib/psdriver/line_width.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/line_width.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,9 @@
+#include "psdriver.h"
+
+void PS_Line_width(double width)
+{
+    if (width < 0)
+	width = 0;
+
+    output("%f WIDTH\n", width);
+}

Copied: grass/trunk/lib/psdriver/makefile (from rev 62429, grass/trunk/lib/psdriver/Makefile)
===================================================================
--- grass/trunk/lib/psdriver/makefile	                        (rev 0)
+++ grass/trunk/lib/psdriver/makefile	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,16 @@
+MODULE_TOPDIR = ../..
+
+EXTRA_CFLAGS = -I../driver
+
+LIB = PSDRIVER
+PGM = psdriver
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+
+default: lib $(ETC)/psdriver.ps
+
+$(ETC)/psdriver.ps: psdriver.ps
+	$(INSTALL_DATA) $< $@
+
+DOXNAME = psdriver

Copied: grass/trunk/lib/psdriver/raster.c (from rev 62429, grass/trunk/lib/psdriver/Raster.c)
===================================================================
--- grass/trunk/lib/psdriver/raster.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/raster.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,65 @@
+
+#include <string.h>
+
+#include "psdriver.h"
+
+static int masked;
+
+void PS_begin_raster(int mask, int src[2][2], double dst[2][2])
+{
+    const char *type = ps.true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
+	: (mask ? "RASTERGRAYMASK" : "RASTERGRAY");
+
+    int ssx = src[0][1] - src[0][0];
+    int ssy = src[1][1] - src[1][0];
+    int sox = src[0][0];
+    int soy = src[1][0];
+
+    double dsx = dst[0][1] - dst[0][0];
+    double dsy = dst[1][1] - dst[1][0];
+    double dox = dst[0][0];
+    double doy = dst[1][0];
+
+    masked = mask;
+
+    output("gsave\n");
+    output("%f %f translate %f %f scale\n", dox, doy, dsx, dsy);
+    output("%d %d [%d 0 0 %d %d %d] %s\n", ssx, ssy, ssx, ssy, sox, soy,
+	   type);
+}
+
+int PS_raster(int n, int row,
+	      const unsigned char *red, const unsigned char *grn,
+	      const unsigned char *blu, const unsigned char *nul)
+{
+    int i;
+
+    for (i = 0; i < n; i++) {
+	if (ps.true_color) {
+	    if (masked)
+		output("%02X%02X%02X%02X", (nul && nul[i]) ? 0xFF : 0x00,
+		       red[i], grn[i], blu[i]);
+	    else
+		output("%02X%02X%02X", red[i], grn[i], blu[i]);
+	}
+	else {
+	    unsigned int gray =
+		(unsigned int)(red[i] * 0.299 + grn[i] * 0.587 +
+			       blu[i] * 0.114);
+
+	    if (masked)
+		output("%02X%02X", (nul && nul[i]) ? 0xFF : 0x00, gray);
+	    else
+		output("%02X", gray);
+	}
+    }
+
+    output("\n");
+
+    return row + 1;
+}
+
+void PS_end_raster(void)
+{
+    output("grestore\n");
+}

Copied: grass/trunk/lib/psdriver/set_window.c (from rev 62429, grass/trunk/lib/psdriver/Set_window.c)
===================================================================
--- grass/trunk/lib/psdriver/set_window.c	                        (rev 0)
+++ grass/trunk/lib/psdriver/set_window.c	2014-10-28 13:15:16 UTC (rev 62431)
@@ -0,0 +1,26 @@
+
+/****************************************************************************
+ *
+ * MODULE:       PNG driver
+ * AUTHOR(S):    Glynn Clements <glynn at gclements.plus.com>
+ * COPYRIGHT:    (C) 2007 Glynn Clements
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *****************************************************************************/
+
+#include "psdriver.h"
+
+void PS_Set_window(double t, double b, double l, double r)
+{
+    output("%.1f %.1f %.1f %.1f %s\n", t, b, l, r,
+	   ps.encapsulated ? "EPSWINDOW" : "WINDOW");
+}



More information about the grass-commit mailing list