[GRASS-SVN] r32866 - in grass/trunk: display/d.erase display/d.info
include lib/cairodriver lib/display lib/driver lib/htmldriver
lib/pngdriver lib/psdriver lib/raster
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 18 16:24:15 EDT 2008
Author: glynn
Date: 2008-08-18 16:24:15 -0400 (Mon, 18 Aug 2008)
New Revision: 32866
Added:
grass/trunk/lib/pngdriver/Polygon.c
Removed:
grass/trunk/lib/display/list.c
Modified:
grass/trunk/display/d.erase/main.c
grass/trunk/display/d.info/main.c
grass/trunk/include/display.h
grass/trunk/include/raster.h
grass/trunk/lib/cairodriver/Graph.c
grass/trunk/lib/display/setup.c
grass/trunk/lib/display/window.c
grass/trunk/lib/driver/Erase.c
grass/trunk/lib/driver/Polygon.c
grass/trunk/lib/driver/Returns.c
grass/trunk/lib/driver/Set_window.c
grass/trunk/lib/driver/driver.h
grass/trunk/lib/driver/init.c
grass/trunk/lib/driver/text3.c
grass/trunk/lib/htmldriver/Graph_Clse.c
grass/trunk/lib/htmldriver/Graph_Set.c
grass/trunk/lib/pngdriver/Driver.c
grass/trunk/lib/pngdriver/Graph_set.c
grass/trunk/lib/pngdriver/Makefile
grass/trunk/lib/pngdriver/Set_window.c
grass/trunk/lib/pngdriver/pngdriver.h
grass/trunk/lib/psdriver/Erase.c
grass/trunk/lib/psdriver/Graph_set.c
grass/trunk/lib/psdriver/Set_window.c
grass/trunk/lib/psdriver/psdriver.h
grass/trunk/lib/raster/raster.c
Log:
Replace screen_{left,right,top,bottom} with screen_{width,height}
Replace R_screen_{left,rite,top,bot} with R_get_window()
Move polygon filler into PNG driver
Add GRASS_{LINE_WIDTH,TEXT_SIZE,FRAME} env variables
Remove unused functions from lib/display
Modified: grass/trunk/display/d.erase/main.c
===================================================================
--- grass/trunk/display/d.erase/main.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/display/d.erase/main.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -52,9 +52,8 @@
D_erase(color->answer);
- if (eraseframe->answer) {
- D_full_screen();
- }
+ if (eraseframe->answer)
+ R_erase();
R_close_driver();
Modified: grass/trunk/display/d.info/main.c
===================================================================
--- grass/trunk/display/d.info/main.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/display/d.info/main.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -71,12 +71,8 @@
if (R_open_driver() != 0)
G_fatal_error(_("No graphics device selected"));
- if (rflag->answer || dflag->answer) {
- l = R_screen_left();
- r = R_screen_rite();
- t = R_screen_top();
- b = R_screen_bot();
- }
+ if (rflag->answer || dflag->answer)
+ R_get_window(&t, &b, &l, &r);
if (rflag->answer)
fprintf(stdout, "rectangle: %f %f %f %f\n", l, r, t, b);
Modified: grass/trunk/include/display.h
===================================================================
--- grass/trunk/include/display.h 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/include/display.h 2008-08-18 20:24:15 UTC (rev 32866)
@@ -72,11 +72,6 @@
/* icon.c */
void D_plot_icon(double, double, int, double, double);
-/* list.c */
-void D_clear_window(void);
-void D_set_erase_color(const char *);
-void D_get_erase_color(char *);
-
/* raster.c */
int D_draw_raster(int, const void *, struct Colors *, RASTER_MAP_TYPE);
int D_draw_d_raster(int, const DCELL *, struct Colors *);
@@ -98,7 +93,7 @@
int D_color_of_type(const void *, struct Colors *, RASTER_MAP_TYPE);
/* setup.c */
-int D_setup(int);
+void D_setup(int);
/* symbol.c */
void D_symbol(const SYMBOL *, double, double, const RGBA_Color *,
@@ -115,16 +110,9 @@
int D_color_number_to_RGB(int, int *, int *, int *);
/* window.c */
-void D_new_window(char *, double, double, double, double);
-void D_new_window_percent(char *, double, double, double, double);
-void D_show_window(int);
-int D_get_screen_window(double *, double *, double *, double *);
+void D_set_window(double, double, double, double);
+void D_get_screen_window(double *, double *, double *, double *);
void D_check_map_window(struct Cell_head *);
-void D_reset_screen_window(double, double, double, double);
-void D_remove_window(void);
-void D_erase_window(void);
void D_erase(const char *);
-void D_remove_windows(void);
-void D_full_screen(void);
#endif /* GRASS_DISPLAY_H */
Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/include/raster.h 2008-08-18 20:24:15 UTC (rev 32866)
@@ -5,12 +5,9 @@
int R_open_driver(void);
void R_close_driver(void);
-double R_screen_left(void);
-double R_screen_rite(void);
-double R_screen_bot(void);
-double R_screen_top(void);
-
int R_get_num_colors(void);
+void R_set_window(double, double, double, double);
+void R_get_window(double *, double *, double *, double *);
void R_standard_color(int);
void R_RGB_color(int, int, int);
@@ -33,7 +30,6 @@
void R_text_size(double, double);
void R_text_rotation(double);
-void R_set_window(double, double, double, double);
void R_text(const char *);
void R_get_text_box(const char *, double *, double *, double *, double *);
Modified: grass/trunk/lib/cairodriver/Graph.c
===================================================================
--- grass/trunk/lib/cairodriver/Graph.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/cairodriver/Graph.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -104,8 +104,8 @@
char *p;
/* set image properties */
- width = screen_right - screen_left;
- height = screen_bottom - screen_top;
+ width = screen_width;
+ height = screen_height;
stride = width * 4;
/* get file name */
Deleted: grass/trunk/lib/display/list.c
===================================================================
--- grass/trunk/lib/display/list.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/display/list.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -1,48 +0,0 @@
-/* Routines to manage the graphics window contents list
- *
- * D_set_erase_color(color)
- * sets the color name of the current erase color for the window
- *
- * D_get_erase_color(color)
- * returns the current erase color name for window
- *
- */
-
-#include <string.h>
-#include <stdio.h>
-#include <grass/display.h>
-#include <grass/raster.h>
-
-
-/*!
- * \brief clears information about current frame
- *
- * Removes all information about the current frame. This includes the map region and the
- * frame content lists.
- *
- * \param ~
- * \return int
- */
-
-void D_clear_window(void)
-{
-}
-
-static char *erase_color;
-
-void D_set_erase_color(const char *colorname)
-{
- if (erase_color)
- G_free(erase_color);
-
- erase_color = G_store(colorname);
-}
-
-
-void D_get_erase_color(char *colorname)
-{
- if (!erase_color)
- erase_color = G_store(DEFAULT_BG_COLOR);
-
- strcpy(colorname, erase_color);
-}
Modified: grass/trunk/lib/display/setup.c
===================================================================
--- grass/trunk/lib/display/setup.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/display/setup.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -56,25 +56,16 @@
* \return int
*/
-int D_setup(int clear)
+void D_setup(int clear)
{
struct Cell_head region;
double t, b, l, r;
- t = R_screen_top();
- b = R_screen_bot();
- l = R_screen_left();
- r = R_screen_rite();
- D_new_window("full_screen", t, b, l, r);
-
D_get_screen_window(&t, &b, &l, &r);
/* clear the frame, if requested to do so */
- if (clear) {
- D_clear_window();
- R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
- R_box_abs(l, t, r, b);
- }
+ if (clear)
+ D_erase(DEFAULT_BG_COLOR);
/* Set the map region associated with graphics frame */
G_get_set_window(®ion);
@@ -88,7 +79,4 @@
/* set text clipping, for good measure */
R_set_window(t, b, l, r);
- R_move_abs(0, 0);
- D_move_abs(0, 0);
- return 0;
}
Modified: grass/trunk/lib/display/window.c
===================================================================
--- grass/trunk/lib/display/window.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/display/window.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -4,9 +4,6 @@
* if "name" is an empty string, the routine returns a unique
* string in "name"
*
- * D_reset_screen_window(t, b, l, r)
- * resets the edges of the current window
- *
* D_show_window(color)
* outlines current window in color (from ../colors.h)
*
@@ -19,9 +16,6 @@
* else
* struct "wind" is written to map window (m_win)
*
- * D_remove_window()
- * remove any trace of window
- *
* D_erase_window()
* Erases the window on scree. Does not affect window contents list.
*/
@@ -40,13 +34,14 @@
static struct Cell_head map_window;
static int map_window_set;
-static void D_set_window(double t, double b, double l, double r)
+void D_set_window(double t, double b, double l, double r)
{
screen_window.t = t;
screen_window.b = b;
screen_window.l = l;
screen_window.r = r;
screen_window_set = 1;
+ R_set_window(t, b, l, r);
}
/*!
@@ -62,14 +57,12 @@
* \return int
*/
-int D_get_screen_window(double *t, double *b, double *l, double *r)
+void D_get_screen_window(double *t, double *b, double *l, double *r)
{
- if (!screen_window_set)
- {
- screen_window.t = R_screen_top();
- screen_window.b = R_screen_bot();
- screen_window.l = R_screen_left();
- screen_window.r = R_screen_rite();
+ if (!screen_window_set) {
+ R_get_window(
+ &screen_window.t, &screen_window.b,
+ &screen_window.l, &screen_window.r);
screen_window_set = 1;
}
@@ -77,105 +70,10 @@
*b = screen_window.b;
*l = screen_window.l;
*r = screen_window.r;
-
- return 0;
}
/*!
- * \brief create new graphics frame
- *
- * Creates a new frame <b>name</b> with
- * coordinates <b>top, bottom, left</b>, and <b>right.</b> If <b>name</b>
- * is the empty string '''' (i.e., *<b>name</b> = = 0), the routine returns a
- * unique string in <b>name.</b>
- *
- * \param name
- * \param top
- * \param bottom
- * \param left
- * \param right
- * \return void
- */
-
-void D_new_window(char *name, double t, double b, double l, double r)
-{
- screen_window_set = 0;
- map_window_set = 0;
- D_set_window(t, b, l, r);
-}
-
-
-/*!
- * \brief create new graphics frame, with coordinates in percent
- *
- * Creates a new frame <b>name</b> with coordinates <b>top, bottom,
- * left</b>, and <b>right</b> as percentages of the screen size.
- * If <b>name</b> is the empty string "" (i.e., *<b>name</b> == 0),
- * the routine returns a unique string in <b>name.</b>
- *
- * \param name
- * \param bottom
- * \param top
- * \param left
- * \param right
- * \return void
- */
-
-void D_new_window_percent(char *name, double b, double t, double l, double r)
-{
- double scr_t = R_screen_top();
- double scr_b = R_screen_bot();
- double scr_l = R_screen_left();
- double scr_r = R_screen_rite();
-
- double win_t = 0.5 + scr_t + (scr_b - scr_t) * (100. - t) / 100.0;
- double win_b = 0.5 + scr_t + (scr_b - scr_t) * (100. - b) / 100.0;
- double win_l = 0.5 + scr_l + (scr_r - scr_l) * l / 100.0;
- double win_r = 0.5 + scr_l + (scr_r - scr_l) * r / 100.0;
-
- if (win_t < scr_t)
- win_t = scr_t;
- if (win_b > scr_b)
- win_b = scr_b;
- if (win_l < scr_l)
- win_l = scr_l;
- if (win_r > scr_r)
- win_r = scr_r;
-
- D_new_window(name, win_t, win_b, win_l, win_r);
-}
-
-
-/*!
- * \brief outlines current frame
- *
- * Outlines
- * current frame in <b>color.</b> Appropriate colors are found in
- * $GISBASE/src/D/libes/colors.h\remarks{$GISBASE is the directory where GRASS
- * is installed. See UNIX_Environment for details.} and are spelled
- * with lowercase letters.
- *
- * \param color
- * \return void
- */
-
-void D_show_window(int color)
-{
- double t, b, l, r;
-
- D_get_screen_window(&t, &b, &l, &r);
-
- R_standard_color(color);
- R_move_abs(l, b);
- R_cont_abs(l, t);
- R_cont_abs(r, t);
- R_cont_abs(r, b);
- R_cont_abs(l, b);
-}
-
-
-/*!
* \brief assign/retrieve current map region
*
* Graphics frames can have GRASS map regions associated with
@@ -200,41 +98,7 @@
}
}
-
/*!
- * \brief resets current frame position
- *
- * Re-establishes the screen position of a
- * frame at the location specified by <b>top, bottom, left, and right.</b>
- *
- * \param top
- * \param bottom
- * \param left
- * \param right
- * \return void
- */
-
-void D_reset_screen_window(double t, double b, double l, double r)
-{
- D_set_window(t, b, l, r);
-}
-
-/*!
- * \brief remove a frame
- *
- * Removes any trace of the
- * current frame.
- *
- * \param ~
- */
-
-void D_remove_window(void)
-{
- screen_window_set = 0;
- map_window_set = 0;
-}
-
-/*!
* \brief erase current frame
*
* Erases the frame on the
@@ -243,22 +107,12 @@
* \param ~
*/
-void D_erase_window(void)
-{
- double t, b, l, r;
-
- D_get_screen_window(&t, &b, &l, &r);
- R_box_abs(l, t, r, b);
- R_flush();
-}
-
void D_erase(const char *color)
{
double t, b, l, r;
int colorindex;
D_get_screen_window(&t, &b, &l, &r);
- D_clear_window();
/* Parse and select background color */
colorindex = D_parse_color(color, 0);
@@ -266,24 +120,5 @@
/* Do the plotting */
R_box_abs(l, t, r, b);
-
- /* Add erase item to the pad */
- D_set_erase_color(color);
}
-void D_remove_windows(void)
-{
- screen_window_set = 0;
- map_window_set = 0;
-}
-
-void D_full_screen(void)
-{
- D_remove_windows();
-
- D_new_window_percent("full_screen", 0.0, 100.0, 0.0, 100.0);
-
- R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
- R_erase();
-}
-
Modified: grass/trunk/lib/driver/Erase.c
===================================================================
--- grass/trunk/lib/driver/Erase.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/Erase.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -10,10 +10,7 @@
return;
}
- top = COM_Screen_top();
- bot = COM_Screen_bot();
- rite = COM_Screen_rite();
- left = COM_Screen_left();
+ COM_Get_window(&top, &bot, &left, &rite);
COM_Box_abs(left, top, rite, bot);
}
Modified: grass/trunk/lib/driver/Polygon.c
===================================================================
--- grass/trunk/lib/driver/Polygon.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/Polygon.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -3,133 +3,10 @@
#include "driver.h"
#include "driverlib.h"
-struct point
-{
- double x, y;
-};
-
-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)
-{
- COM_Box_abs(x0, y, x1, y + 1);
-}
-
-static void line(const struct point *p, int n, double y)
-{
- static double *xs;
- static double max_x;
- int num_x = 0;
- int i;
-
- for (i = 0; i < n; i++) {
- const struct point *p0 = &p[i];
- const struct point *p1 = &p[i + 1];
- const struct point *tmp;
- double fx;
- long 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;
-
- fx = (double)p1->x * (y - p0->y) + (double)p0->x * (p1->y - y);
- fx /= p1->y - p0->y;
- x = fx < -0x7fffffff ? -0x7fffffff :
- fx > 0x7fffffff ? 0x7fffffff : (long)fx;
-
- 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 point *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 > screen_bottom || y1 < screen_top)
- return;
-
- if (y0 < screen_top)
- y0 = screen_top;
-
- if (y1 > screen_bottom)
- y1 = screen_bottom;
-
- for (y = y0; y < y1; y++)
- line(p, n, y);
-}
-
-static void fill_polygon(const double *xarray, const double *yarray, int count)
-{
- static struct point *points;
- static int max_points;
- int i;
-
- if (max_points < count + 1) {
- max_points = count + 1;
- points = G_realloc(points, sizeof(struct point) * max_points);
- }
-
- for (i = 0; i < count; i++) {
- points[i].x = xarray[i];
- points[i].y = yarray[i];
- }
-
- points[count].x = xarray[0];
- points[count].y = yarray[0];
-
- poly(points, count);
-}
-
void COM_Polygon_abs(const double *xarray, const double *yarray, int number)
{
- if (driver->Polygon) {
+ if (driver->Polygon)
(*driver->Polygon) (xarray, yarray, number);
- return;
- }
-
- fill_polygon(xarray, yarray, number);
}
void COM_Polygon_rel(const double *xarray, const double *yarray, int number)
Modified: grass/trunk/lib/driver/Returns.c
===================================================================
--- grass/trunk/lib/driver/Returns.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/Returns.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -1,26 +1,6 @@
#include "driver.h"
#include "driverlib.h"
-double COM_Screen_left(void)
-{
- return screen_left;
-}
-
-double COM_Screen_rite(void)
-{
- return screen_right;
-}
-
-double COM_Screen_bot(void)
-{
- return screen_bottom;
-}
-
-double COM_Screen_top(void)
-{
- return screen_top;
-}
-
int COM_Number_of_colors(void)
{
return NCOLORS;
Modified: grass/trunk/lib/driver/Set_window.c
===================================================================
--- grass/trunk/lib/driver/Set_window.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/Set_window.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -1,8 +1,25 @@
#include "driver.h"
#include "driverlib.h"
+static struct {
+ double t, b, l, r;
+} window;
+
void COM_Set_window(double t, double b, double l, double r)
{
+ window.t = t;
+ window.b = b;
+ window.l = l;
+ window.r = r;
+
if (driver->Set_window)
(*driver->Set_window) (t, b, l, r);
}
+
+void COM_Get_window(double *t, double *b, double *l, double *r)
+{
+ *t = window.t;
+ *b = window.b;
+ *l = window.l;
+ *r = window.r;
+}
Modified: grass/trunk/lib/driver/driver.h
===================================================================
--- grass/trunk/lib/driver/driver.h 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/driver.h 2008-08-18 20:24:15 UTC (rev 32866)
@@ -6,10 +6,8 @@
extern int NCOLORS;
-extern int screen_left;
-extern int screen_right;
-extern int screen_bottom;
-extern int screen_top;
+extern int screen_width;
+extern int screen_height;
extern double cur_x;
extern double cur_y;
@@ -56,7 +54,7 @@
/* Library Functions */
/* init.c */
-extern int LIB_init(const struct driver *drv);
+extern void LIB_init(const struct driver *drv);
/* Commands */
@@ -121,14 +119,11 @@
extern void COM_Respond(void);
/* Returns.c */
-extern double COM_Screen_left(void);
-extern double COM_Screen_rite(void);
-extern double COM_Screen_bot(void);
-extern double COM_Screen_top(void);
extern int COM_Number_of_colors(void);
/* Set_window.c */
extern void COM_Set_window(double, double, double, double);
+extern void COM_Get_window(double *, double *, double *, double *);
/* Text.c */
extern void COM_Text(const char *);
Modified: grass/trunk/lib/driver/init.c
===================================================================
--- grass/trunk/lib/driver/init.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/init.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -28,10 +28,8 @@
int NCOLORS;
-int screen_left;
-int screen_right;
-int screen_bottom;
-int screen_top;
+int screen_width;
+int screen_height;
double cur_x;
double cur_y;
@@ -41,7 +39,7 @@
double text_rotation;
int matrix_valid;
-int LIB_init(const struct driver *drv)
+void LIB_init(const struct driver *drv)
{
const char *p;
@@ -51,15 +49,13 @@
/* initialize graphics */
p = getenv("GRASS_WIDTH");
- screen_left = 0;
- screen_right = (p && atoi(p)) ? atoi(p) : DEF_WIDTH;
+ screen_width = (p && atoi(p)) ? atoi(p) : DEF_WIDTH;
p = getenv("GRASS_HEIGHT");
- screen_top = 0;
- screen_bottom = (p && atoi(p)) ? atoi(p) : DEF_HEIGHT;
+ screen_height = (p && atoi(p)) ? atoi(p) : DEF_HEIGHT;
if (COM_Graph_set() < 0)
exit(1);
- return 0;
+ COM_Set_window(0, screen_height, 0, screen_width);
}
Modified: grass/trunk/lib/driver/text3.c
===================================================================
--- grass/trunk/lib/driver/text3.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/driver/text3.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -111,7 +111,7 @@
/* init point */
pen.x = x * 64;
/* pen.y = 0; */
- pen.y = (screen_bottom - y) * 64;
+ pen.y = (screen_height - y) * 64;
/* convert string to:shift-jis from:encoding */
outlen = convert_str(encoding, string, &out);
@@ -207,10 +207,10 @@
/* draw bitmap */
if (!fdont_draw)
draw_bitmap(&slot->bitmap, slot->bitmap_left,
- screen_bottom - slot->bitmap_top);
+ screen_height - slot->bitmap_top);
else
set_text_box(&slot->bitmap, slot->bitmap_left,
- screen_bottom - slot->bitmap_top);
+ screen_height - slot->bitmap_top);
/* increment pen position */
pen->x += slot->advance.x;
Modified: grass/trunk/lib/htmldriver/Graph_Clse.c
===================================================================
--- grass/trunk/lib/htmldriver/Graph_Clse.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/htmldriver/Graph_Clse.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -147,7 +147,7 @@
case CLIENT:
fprintf(output,
"<AREA SHAPE=\"RECT\" NOHREF COORDS=\"%d,%d %d,%d\">\n",
- screen_left, screen_top, screen_right, screen_bottom);
+ 0, 0, screen_width, screen_height);
fprintf(output, "</MAP>\n");
break;
Modified: grass/trunk/lib/htmldriver/Graph_Set.c
===================================================================
--- grass/trunk/lib/htmldriver/Graph_Set.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/htmldriver/Graph_Set.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -105,7 +105,7 @@
G_message("HTMLMAP: collecting to file: %s\n width = %d, height = %d, ",
- file_name, screen_right, screen_bottom);
+ file_name, screen_width, screen_height);
/*
* check type of map wanted
Modified: grass/trunk/lib/pngdriver/Driver.c
===================================================================
--- grass/trunk/lib/pngdriver/Driver.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/pngdriver/Driver.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -34,7 +34,7 @@
drv.Line_width = PNG_Line_width;
drv.Polydots = NULL;
drv.Polyline = NULL;
- drv.Polygon = NULL;
+ drv.Polygon = PNG_Polygon;
drv.Set_window = PNG_Set_window;
drv.Begin_scaled_raster = PNG_begin_scaled_raster;
drv.Scaled_raster = PNG_scaled_raster;
Modified: grass/trunk/lib/pngdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_set.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/pngdriver/Graph_set.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -30,7 +30,7 @@
int has_alpha;
int mapped;
-int clip_top, clip_bot, clip_left, clip_rite;
+double clip_top, clip_bot, clip_left, clip_rite;
int width, height;
void *image;
unsigned int *grid;
@@ -103,13 +103,13 @@
if (do_read && access(file_name, 0) != 0)
do_read = 0;
- width = screen_right - screen_left;
- height = screen_bottom - screen_top;
+ width = screen_width;
+ height = screen_height;
- clip_top = screen_top;
- clip_bot = screen_bottom;
- clip_left = screen_left;
- clip_rite = screen_right;
+ clip_top = 0;
+ clip_bot = height;
+ clip_left = 0;
+ clip_rite = width;
p = getenv("GRASS_TRANSPARENT");
has_alpha = p && strcmp(p, "TRUE") == 0;
Modified: grass/trunk/lib/pngdriver/Makefile
===================================================================
--- grass/trunk/lib/pngdriver/Makefile 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/pngdriver/Makefile 2008-08-18 20:24:15 UTC (rev 32866)
@@ -20,6 +20,7 @@
Graph_close.o \
Graph_set.o \
Line_width.o \
+ Polygon.o \
Raster.o \
Respond.o \
Set_window.o \
Added: grass/trunk/lib/pngdriver/Polygon.c
===================================================================
--- grass/trunk/lib/pngdriver/Polygon.c (rev 0)
+++ grass/trunk/lib/pngdriver/Polygon.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -0,0 +1,147 @@
+
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+
+#include "pngdriver.h"
+
+struct point
+{
+ double x, y;
+};
+
+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 = &grid[yi * width + xi1];
+ int x;
+
+ if (yi < clip_bot || yi >= clip_top)
+ return;
+
+ if (xi0 > clip_rite)
+ return;
+
+ if (xi1 < clip_left)
+ return;
+
+ if (xi0 < clip_left)
+ xi0 = clip_left;
+
+ if (xi1 > clip_rite)
+ xi1 = clip_rite;
+
+ p = &grid[yi * width + xi1];
+
+ for (x = xi0; x < xi1; x++)
+ *p++ = currentColor;
+}
+
+static void line(const struct point *p, int n, double y)
+{
+ static double *xs;
+ static double max_x;
+ int num_x = 0;
+ int i;
+
+ for (i = 0; i < n; i++) {
+ const struct point *p0 = &p[i];
+ const struct point *p1 = &p[i + 1];
+ const struct point *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 point *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 > clip_bot || y1 < clip_top)
+ return;
+
+ if (y0 < clip_top)
+ y0 = clip_top;
+
+ if (y1 > clip_bot)
+ y1 = clip_bot;
+
+ for (y = y0; y < y1; y++)
+ line(p, n, y + 0.5);
+}
+
+void PNG_Polygon(const double *xarray, const double *yarray, int count)
+{
+ static struct point *points;
+ static int max_points;
+ int i;
+
+ if (max_points < count + 1) {
+ max_points = count + 1;
+ points = G_realloc(points, sizeof(struct point) * max_points);
+ }
+
+ for (i = 0; i < count; i++) {
+ points[i].x = xarray[i];
+ points[i].y = yarray[i];
+ }
+
+ points[count].x = xarray[0];
+ points[count].y = yarray[0];
+
+ poly(points, count);
+}
+
Modified: grass/trunk/lib/pngdriver/Set_window.c
===================================================================
--- grass/trunk/lib/pngdriver/Set_window.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/pngdriver/Set_window.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -20,15 +20,11 @@
#include <math.h>
#include "pngdriver.h"
-void PNG_Set_window(double ft, double fb, double fl, double fr)
+void PNG_Set_window(double t, double b, double l, double r)
{
- int t = (int) floor(ft + 0.5);
- int b = (int) floor(fb + 0.5);
- int l = (int) floor(fl + 0.5);
- int r = (int) floor(fr + 0.5);
-
- clip_top = t > screen_top ? t : screen_top;
- clip_bot = b < screen_bottom ? b : screen_bottom;
- clip_left = l > screen_left ? l : screen_left;
- clip_rite = r < screen_right ? r : screen_right;
+ clip_top = t > 0 ? t : 0;
+ clip_bot = b < height ? b : height;
+ clip_left = l > 0 ? l : 0;
+ clip_rite = r < width ? r : width;
}
+
Modified: grass/trunk/lib/pngdriver/pngdriver.h
===================================================================
--- grass/trunk/lib/pngdriver/pngdriver.h 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/pngdriver/pngdriver.h 2008-08-18 20:24:15 UTC (rev 32866)
@@ -17,7 +17,7 @@
extern int has_alpha;
extern int mapped;
-extern int clip_top, clip_bot, clip_left, clip_rite;
+extern double clip_top, clip_bot, clip_left, clip_rite;
extern int width, height;
extern unsigned int *grid;
extern unsigned char png_palette[256][4];
@@ -50,6 +50,7 @@
extern void PNG_Graph_close(void);
extern int PNG_Graph_set(void);
extern void PNG_Line_width(double);
+extern void PNG_Polygon(const double *, const double *, int);
extern void PNG_begin_scaled_raster(int, int[2][2], double[2][2]);
extern int PNG_scaled_raster(int, int, const unsigned char *,
const unsigned char *, const unsigned char *,
Modified: grass/trunk/lib/psdriver/Erase.c
===================================================================
--- grass/trunk/lib/psdriver/Erase.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/psdriver/Erase.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -3,8 +3,7 @@
void PS_Erase(void)
{
if (encapsulated)
- output("%d %d %d %d BOX\n", screen_left, screen_top, screen_right,
- screen_bottom);
+ output("%d %d %d %d BOX\n", left, top, right, bot);
else
output("ERASE\n");
}
Modified: grass/trunk/lib/psdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/psdriver/Graph_set.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/psdriver/Graph_set.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
+#include <math.h>
#include <grass/gis.h>
#include "psdriver.h"
@@ -23,12 +24,12 @@
const char *file_name;
FILE *outfp;
int true_color;
-int width, height;
int encapsulated;
int no_header, no_trailer;
+double left, right, bot, top;
+static double width, height;
static int landscape;
-static int left, right, bot, top;
struct paper
{
@@ -76,7 +77,9 @@
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", left, bot, right, top);
+ output("%%%%BoundingBox: %d %d %d %d\n",
+ (int)floor(left), (int)floor(bot),
+ (int)ceil(right), (int)ceil(top));
output("%%%%CreationDate: %s\n", date_str);
output("%%%%EndComments\n");
@@ -98,27 +101,27 @@
{
output("%%%%BeginSetup\n");
- output("%d %d translate\n", left, bot);
+ output("%.1f %.1f translate\n", left, bot);
if (landscape)
output("90 rotate 0 1 -1 scale\n");
else
- output("0 %d translate 1 -1 scale\n", height);
+ output("0 %.1f translate 1 -1 scale\n", height);
- output("%d %d BEGIN\n", width, height);
+ output("%.1f %.1f BEGIN\n", width, height);
output("%%%%EndSetup\n");
output("%%%%Page: 1 1\n");
}
-static int in2pt(double x)
+static double in2pt(double x)
{
- return (int)(x * 72);
+ return x * 72;
}
-static void swap(int *x, int *y)
+static void swap(double *x, double *y)
{
- int tmp = *x;
+ double tmp = *x;
*x = *y;
*y = tmp;
@@ -130,8 +133,8 @@
const struct paper *paper;
int i;
- width = screen_right - screen_left;
- height = screen_bottom - screen_top;
+ width = screen_width;
+ height = screen_height;
left = 0;
right = width;
@@ -165,8 +168,8 @@
if (landscape)
swap(&width, &height);
- screen_right = screen_left + width;
- screen_bottom = screen_top + height;
+ right = left + width;
+ bot = top + height;
}
int PS_Graph_set(void)
@@ -212,8 +215,8 @@
write_setup();
}
- G_message
- ("PS: collecting to file: %s,\n GRASS_WIDTH=%d, GRASS_HEIGHT=%d",
+ G_message(
+ "PS: collecting to file: %s,\nGRASS_WIDTH=%.1f, GRASS_HEIGHT=%.1f",
file_name, width, height);
fflush(outfp);
Modified: grass/trunk/lib/psdriver/Set_window.c
===================================================================
--- grass/trunk/lib/psdriver/Set_window.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/psdriver/Set_window.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -21,6 +21,6 @@
void PS_Set_window(double t, double b, double l, double r)
{
- output("%f %f %f %f %s\n", t, b, l, r,
+ output("%.1f %.1f %.1f %.1f %s\n", t, b, l, r,
encapsulated ? "EPSWINDOW" : "WINDOW");
}
Modified: grass/trunk/lib/psdriver/psdriver.h
===================================================================
--- grass/trunk/lib/psdriver/psdriver.h 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/psdriver/psdriver.h 2008-08-18 20:24:15 UTC (rev 32866)
@@ -11,9 +11,9 @@
extern const char *file_name;
extern FILE *outfp;
extern int true_color;
-extern int width, height;
extern int encapsulated;
extern int no_header, no_trailer;
+extern double left, right, bot, top;
extern void output(const char *, ...);
Modified: grass/trunk/lib/raster/raster.c
===================================================================
--- grass/trunk/lib/raster/raster.c 2008-08-18 20:19:33 UTC (rev 32865)
+++ grass/trunk/lib/raster/raster.c 2008-08-18 20:24:15 UTC (rev 32866)
@@ -26,17 +26,28 @@
{
const char *fenc = getenv("GRASS_ENCODING");
const char *font = getenv("GRASS_FONT");
- int t = R_screen_top();
- int b = R_screen_bot();
- int l = R_screen_left();
- int r = R_screen_rite();
+ const char *line_width = getenv("GRASS_LINE_WIDTH");
+ const char *text_size = getenv("GRASS_TEXT_SIZE");
+ const char *frame = getenv("GRASS_FRAME");
R_font(font ? font : "romans");
if (fenc)
R_encoding(fenc);
- R_set_window(t, b, l, r);
+ if (line_width)
+ R_line_width(atof(line_width));
+
+ if (text_size) {
+ double s = atof(text_size);
+ R_text_size(s, s);
+ }
+
+ if (frame) {
+ double t, b, l, r;
+ sscanf(frame, "%lf,%lf,%lf,%lf", &t, &b, &l, &r);
+ R_set_window(t, b, l, r);
+ }
}
int R_open_driver(void)
@@ -76,63 +87,6 @@
system(cmd);
}
-/*!
- * \brief screen left edge
- *
- * Returns the coordinate of the left edge of the screen.
- *
- * \param void
- * \return double
- */
-
-double R_screen_left(void)
-{
- return COM_Screen_left();
-}
-
-/*!
- * \brief screen right edge
- *
- * Returns the coordinate of the right edge of the screen.
- *
- * \param void
- * \return double
- */
-
-double R_screen_rite(void)
-{
- return COM_Screen_rite();
-}
-
-/*!
- * \brief bottom of screen
- *
- * Returns the coordinate of the bottom of the screen.
- *
- * \param void
- * \return double
- */
-
-double R_screen_bot(void)
-{
- return COM_Screen_bot();
-}
-
-
-/*!
- * \brief top of screen
- *
- * Returns the coordinate of the top of the screen.
- *
- * \param void
- * \return double
- */
-
-double R_screen_top(void)
-{
- return COM_Screen_top();
-}
-
int R_get_num_colors(void)
{
return COM_Number_of_colors();
@@ -454,10 +408,10 @@
}
/*!
- * \brief set text clipping frame
+ * \brief set clipping frame
*
- * Subsequent calls to <i>R_text</i> will have text strings
- * clipped to the screen frame defined by <b>top, bottom, left, right.</b>
+ * Subsequent drawing operations will be clipped to the screen frame
+ * defined by <b>top, bottom, left, right.</b>
*
* \param t top
* \param b bottom
@@ -472,6 +426,23 @@
}
/*!
+ * \brief get clipping frame
+ *
+ * Retrieve clipping frame
+ *
+ * \param t top
+ * \param b bottom
+ * \param l left
+ * \param r right
+ * \return void
+ */
+
+void R_get_window(double *t, double *b, double *l, double *r)
+{
+ return COM_Get_window(t, b, l, r);
+}
+
+/*!
* \brief write text
*
* Writes <b>text</b> in the current color and font, at the current text
More information about the grass-commit
mailing list