[GRASS-SVN] r32662 - in grass/trunk: display/d.font display/d.text.new display/d.vect include lib/cairodriver lib/driver lib/htmldriver lib/pngdriver lib/psdriver lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 10 05:37:05 EDT 2008


Author: glynn
Date: 2008-08-10 05:37:04 -0400 (Sun, 10 Aug 2008)
New Revision: 32662

Added:
   grass/trunk/lib/cairodriver/Text.c
Modified:
   grass/trunk/display/d.font/main.c
   grass/trunk/display/d.text.new/main.c
   grass/trunk/display/d.vect/attr.c
   grass/trunk/display/d.vect/label.c
   grass/trunk/display/d.vect/topo.c
   grass/trunk/display/d.vect/zcoor.c
   grass/trunk/include/raster.h
   grass/trunk/lib/cairodriver/Driver.c
   grass/trunk/lib/cairodriver/Graph.c
   grass/trunk/lib/cairodriver/Poly.c
   grass/trunk/lib/cairodriver/Respond.c
   grass/trunk/lib/cairodriver/cairodriver.h
   grass/trunk/lib/cairodriver/read.c
   grass/trunk/lib/cairodriver/read_bmp.c
   grass/trunk/lib/cairodriver/read_ppm.c
   grass/trunk/lib/cairodriver/write.c
   grass/trunk/lib/cairodriver/write_bmp.c
   grass/trunk/lib/cairodriver/write_ppm.c
   grass/trunk/lib/driver/Font.c
   grass/trunk/lib/driver/Get_t_box.c
   grass/trunk/lib/driver/Text_size.c
   grass/trunk/lib/driver/driver.h
   grass/trunk/lib/driver/driverlib.h
   grass/trunk/lib/driver/font_freetype.c
   grass/trunk/lib/driver/init.c
   grass/trunk/lib/driver/text3.c
   grass/trunk/lib/htmldriver/Driver.c
   grass/trunk/lib/pngdriver/Driver.c
   grass/trunk/lib/psdriver/Driver.c
   grass/trunk/lib/raster/raster.c
Log:
Allow drivers to override font and text operations
Add native text rendering to cairo driver
Rename R_charset() to R_encoding()
Change default driver to cairo
Change cairo environment variables to GRASS_PNG*
Add cairo_ prefix to image read/write functions to prevent conflict with PNG driver
Add Polydots method to cairo driver



Modified: grass/trunk/display/d.font/main.c
===================================================================
--- grass/trunk/display/d.font/main.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/display/d.font/main.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -128,7 +128,7 @@
     }
 
     if (opt3->answer)		/* Set character encoding */
-	R_charset(opt3->answer);
+	R_encoding(opt3->answer);
 
     /* add this command to the list */
     R_close_driver();

Modified: grass/trunk/display/d.text.new/main.c
===================================================================
--- grass/trunk/display/d.text.new/main.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/display/d.text.new/main.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -287,7 +287,7 @@
 	R_font(opt.path->answer);
 
     if (opt.charset->answer)
-	R_charset(opt.charset->answer);
+	R_encoding(opt.charset->answer);
 
     D_setup(0);
 
@@ -384,7 +384,7 @@
 		    *ptr = 0;
 		R_font(buf_ptr);
 		if (ptr)
-		    R_charset(ptr + 1);
+		    R_encoding(ptr + 1);
 		break;
 	    case 'C':
 		/* color */

Modified: grass/trunk/display/d.vect/attr.c
===================================================================
--- grass/trunk/display/d.vect/attr.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/display/d.vect/attr.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -65,7 +65,7 @@
 	if (lattr->font)
 	    R_font(lattr->font);
 	if (lattr->enc)
-	    R_charset(lattr->enc);
+	    R_encoding(lattr->enc);
 
 	if (chcat) {
 	    int found = 0;

Modified: grass/trunk/display/d.vect/label.c
===================================================================
--- grass/trunk/display/d.vect/label.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/display/d.vect/label.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -40,7 +40,7 @@
 	if (lattr->font)
 	    R_font(lattr->font);
 	if (lattr->enc)
-	    R_charset(lattr->enc);
+	    R_encoding(lattr->enc);
 
 	if (chcat) {
 	    int found = 0;

Modified: grass/trunk/display/d.vect/topo.c
===================================================================
--- grass/trunk/display/d.vect/topo.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/display/d.vect/topo.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -23,7 +23,7 @@
     if (lattr->font)
 	R_font(lattr->font);
     if (lattr->enc)
-	R_charset(lattr->enc);
+	R_encoding(lattr->enc);
 
     Vect_rewind(Map);
 

Modified: grass/trunk/display/d.vect/zcoor.c
===================================================================
--- grass/trunk/display/d.vect/zcoor.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/display/d.vect/zcoor.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -24,7 +24,7 @@
     if (lattr->font)
 	R_font(lattr->font);
     if (lattr->enc)
-	R_charset(lattr->enc);
+	R_encoding(lattr->enc);
 
     Vect_rewind(Map);
 

Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/include/raster.h	2008-08-10 09:37:04 UTC (rev 32662)
@@ -38,7 +38,7 @@
 void R_get_text_box(const char *, double *, double *, double *, double *);
 
 void R_font(const char *);
-void R_charset(const char *);
+void R_encoding(const char *);
 void R_font_list(char ***, int *);
 void R_font_info(char ***, int *);
 

Modified: grass/trunk/lib/cairodriver/Driver.c
===================================================================
--- grass/trunk/lib/cairodriver/Driver.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/Driver.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -32,7 +32,7 @@
     drv.Graph_set = Cairo_Graph_set;
     drv.Graph_close = Cairo_Graph_close;
     drv.Line_width = Cairo_Line_width;
-    drv.Polydots = NULL;
+    drv.Polydots = Cairo_Polydots;
     drv.Polyline = Cairo_Polyline;
     drv.Polygon = Cairo_Polygon;
     drv.Set_window = Cairo_Set_window;
@@ -45,7 +45,11 @@
     drv.draw_line = Cairo_draw_line;
     drv.draw_point = Cairo_draw_point;
     drv.draw_bitmap = Cairo_draw_bitmap;
-    drv.draw_text = NULL;
+    drv.draw_text = Cairo_draw_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;
 

Modified: grass/trunk/lib/cairodriver/Graph.c
===================================================================
--- grass/trunk/lib/cairodriver/Graph.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/Graph.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -109,7 +109,7 @@
     stride = width * 4;
 
     /* get file name */
-    p = getenv("GRASS_CAIROFILE");
+    p = getenv("GRASS_PNGFILE");
     if (!p || strlen(p) == 0)
 	p = DEFAULT_FILE_NAME;
 
@@ -149,10 +149,10 @@
 	break;
     }
 
-    p = getenv("GRASS_CAIRO_MAPPED");
+    p = getenv("GRASS_PNG_MAPPED");
     do_map = p && strcmp(p, "TRUE") == 0 && ends_with(file_name, ".bmp");
 
-    p = getenv("GRASS_CAIRO_READ");
+    p = getenv("GRASS_PNG_READ");
     do_read = p && strcmp(p, "TRUE") == 0;
 
     if (is_vector) {
@@ -181,10 +181,10 @@
     }
 
     if (do_read && !mapped)
-	read_image();
+	cairo_read_image();
 
     if (do_map && !mapped) {
-	write_image();
+	cairo_write_image();
 	map_file();
 	init_cairo();
     }
@@ -222,7 +222,7 @@
     else
 	bgcolor_a = 1.0;
 
-    p = getenv("GRASS_AUTO_WRITE");
+    p = getenv("GRASS_PNG_AUTO_WRITE");
     auto_write = p && strcmp(p, "TRUE") == 0;
 
 #if defined(USE_X11) && CAIRO_HAS_XLIB_SURFACE
@@ -237,7 +237,7 @@
 {
     G_debug(1, "Cairo_Graph_close");
 
-    write_image();
+    cairo_write_image();
 
     if (cairo) {
 	cairo_destroy(cairo);

Modified: grass/trunk/lib/cairodriver/Poly.c
===================================================================
--- grass/trunk/lib/cairodriver/Poly.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/Poly.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -22,3 +22,13 @@
     do_polygon(xarray, yarray, count);
     cairo_stroke(cairo);
 }
+
+void Cairo_Polydots(const double *xarray, const double *yarray, int count)
+{
+    int i;
+
+    G_debug(3, "Cairo_Polydots (%d points)", count);
+    for (i = 1; i < count; i++)
+	Cairo_draw_point(xarray[0], yarray[0]);
+}
+

Modified: grass/trunk/lib/cairodriver/Respond.c
===================================================================
--- grass/trunk/lib/cairodriver/Respond.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/Respond.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -4,5 +4,5 @@
 void Cairo_Respond(void)
 {
     if (auto_write)
-	write_image();
+	cairo_write_image();
 }

Added: grass/trunk/lib/cairodriver/Text.c
===================================================================
--- grass/trunk/lib/cairodriver/Text.c	                        (rev 0)
+++ grass/trunk/lib/cairodriver/Text.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -0,0 +1,191 @@
+#include <grass/glocale.h>
+#include "cairodriver.h"
+
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
+
+static cairo_matrix_t mat;
+
+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
+    {
+	char *p1 = (char *) in;
+	char *p2 = out;
+	size_t ret;
+	iconv_t cd;
+
+	if (!encoding)
+	    encoding = G_store("US-ASCII");
+
+	if ((cd = iconv_open("UTF-8", encoding)) < 0)
+	    G_fatal_error(_("Unable to convert from <%s> to UTF-8"));
+
+	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 < len; 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)
+{
+    if (matrix_valid)
+	return;
+
+    cairo_matrix_init_identity(&mat);
+    cairo_matrix_scale(&mat, text_size_x * 25, text_size_y * 25);
+    cairo_matrix_rotate(&mat, -text_rotation * M_PI / 180);
+
+    cairo_set_font_matrix(cairo, &mat);
+
+    matrix_valid = 1;
+}
+
+void Cairo_draw_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);
+
+    modified = 1;
+}
+
+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_x + ext.y_bearing;
+    *b = cur_x + ext.y_bearing + ext.height;
+}
+
+void Cairo_set_font(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);
+}
+
+void Cairo_set_encoding(const char *enc)
+{
+    if (encoding)
+	G_free(encoding);
+
+    encoding = G_store(enc);
+}
+
+void Cairo_text_size(double width, double height)
+{
+    text_size_x = width;
+    text_size_y = height;
+    matrix_valid = 0;
+}
+
+void Cairo_text_rotation(double angle)
+{
+    text_rotation = angle;
+    matrix_valid = 0;
+}
+
+void Cairo_font_list(char ***list, int *count)
+{
+    char **fonts;
+    int num_fonts;
+
+    num_fonts = 1;
+
+    fonts = G_malloc(num_fonts * sizeof(char *));
+    fonts[0] = G_store("serif");
+
+    *list = fonts;
+    *count = num_fonts;
+}
+
+void Cairo_font_info(char ***list, int *count)
+{
+    char **fonts;
+    int num_fonts;
+
+    num_fonts = 1;
+
+    fonts = G_malloc(num_fonts * sizeof(char *));
+    fonts[0] = G_store("serif|serif|1||0|utf-8|");
+
+    *list = fonts;
+    *count = num_fonts;
+}
+

Modified: grass/trunk/lib/cairodriver/cairodriver.h
===================================================================
--- grass/trunk/lib/cairodriver/cairodriver.h	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/cairodriver.h	2008-08-10 09:37:04 UTC (rev 32662)
@@ -65,16 +65,22 @@
 extern void Cairo_Line_width(double);
 extern void Cairo_Polygon(const double *, const double *, int);
 extern void Cairo_Polyline(const double *, const double *, int);
+extern void Cairo_Polydots(const double *, const double *, int);
 extern void Cairo_Respond(void);
+extern void Cairo_draw_text(const char *);
+extern void Cairo_text_box(const char *, double *, double *, double *, double *);
+extern void Cairo_set_font(const char *);
+extern void Cairo_font_list(char ***, int *);
+extern void Cairo_font_info(char ***, int *);
 
 /* read.c */
-extern void read_image(void);
-extern void read_ppm(void);
-extern void read_bmp(void);
+extern void cairo_read_image(void);
+extern void cairo_read_ppm(void);
+extern void cairo_read_bmp(void);
 
 /* write.c */
-extern void write_image(void);
-extern void write_ppm(void);
-extern void write_bmp(void);
+extern void cairo_write_image(void);
+extern void cairo_write_ppm(void);
+extern void cairo_write_bmp(void);
 
 #endif /* __CAIRODRIVER_H__ */

Modified: grass/trunk/lib/cairodriver/read.c
===================================================================
--- grass/trunk/lib/cairodriver/read.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/read.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -1,6 +1,6 @@
 #include "cairodriver.h"
 
-void read_image(void)
+void cairo_read_image(void)
 {
     G_debug(1, "read_image");
 
@@ -9,11 +9,11 @@
 
     if (file_type == FTYPE_PPM) {
 	G_debug(1, "Reading image from %s", file_name);
-	read_ppm();
+	cairo_read_ppm();
     }
     else if (file_type == FTYPE_BMP) {
 	G_debug(1, "Reading image from %s", file_name);
-	read_bmp();
+	cairo_read_bmp();
     }
 #if CAIRO_HAS_PNG_FUNCTIONS
     else if (file_type == FTYPE_PNG) {

Modified: grass/trunk/lib/cairodriver/read_bmp.c
===================================================================
--- grass/trunk/lib/cairodriver/read_bmp.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/read_bmp.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -64,7 +64,7 @@
     return 1;
 }
 
-void read_bmp(void)
+void cairo_read_bmp(void)
 {
     char header[HEADER_SIZE];
     FILE *input;

Modified: grass/trunk/lib/cairodriver/read_ppm.c
===================================================================
--- grass/trunk/lib/cairodriver/read_ppm.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/read_ppm.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -1,6 +1,6 @@
 #include "cairodriver.h"
 
-void read_ppm(void)
+void cairo_read_ppm(void)
 {
     char *mask_name = G_store(file_name);
     FILE *input, *mask;

Modified: grass/trunk/lib/cairodriver/write.c
===================================================================
--- grass/trunk/lib/cairodriver/write.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/write.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -5,7 +5,7 @@
 #include <cairo-xlib.h>
 #endif
 
-void write_image(void)
+void cairo_write_image(void)
 {
     G_debug(1, "write_image");
 
@@ -20,11 +20,11 @@
 
     if (file_type == FTYPE_PPM) {
 	G_debug(1, "Writing image to %s", file_name);
-	write_ppm();
+	cairo_write_ppm();
     }
     else if (file_type == FTYPE_BMP) {
 	G_debug(1, "Writing image to %s", file_name);
-	write_bmp();
+	cairo_write_bmp();
     }
 #if CAIRO_HAS_PNG_FUNCTIONS
     else if (file_type == FTYPE_PNG) {

Modified: grass/trunk/lib/cairodriver/write_bmp.c
===================================================================
--- grass/trunk/lib/cairodriver/write_bmp.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/write_bmp.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -48,7 +48,7 @@
     p = put_4(p, 0);
 }
 
-void write_bmp(void)
+void cairo_write_bmp(void)
 {
     char header[HEADER_SIZE];
     FILE *output;

Modified: grass/trunk/lib/cairodriver/write_ppm.c
===================================================================
--- grass/trunk/lib/cairodriver/write_ppm.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/cairodriver/write_ppm.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -1,6 +1,6 @@
 #include "cairodriver.h"
 
-void write_ppm(void)
+void cairo_write_ppm(void)
 {
     char *mask_name = G_store(file_name);
     FILE *output, *mask;

Modified: grass/trunk/lib/driver/Font.c
===================================================================
--- grass/trunk/lib/driver/Font.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/Font.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -5,6 +5,8 @@
 #include "driver.h"
 #include "driverlib.h"
 
+char *encoding;
+
 static int font_type = GFONT_STROKE;
 
 static void stroke_set(const char *filename)
@@ -19,8 +21,13 @@
 	font_type = GFONT_FREETYPE;
 }
 
-void COM_Font_get(const char *name)
+void COM_Set_font(const char *name)
 {
+    if (driver->Set_font) {
+	(*driver->Set_font)(name);
+	return;
+    }
+
     if (G_is_absolute_path(name)) {
 	if (!font_exists(name))
 	    return;
@@ -36,7 +43,7 @@
 		switch (ftcap[i].type) {
 		case GFONT_FREETYPE:
 		    freetype_set(ftcap[i].path, ftcap[i].index);
-		    font_init_charset(ftcap[i].encoding);
+		    COM_Set_encoding(ftcap[i].encoding);
 		    break;
 		case GFONT_STROKE:
 		    stroke_set(ftcap[i].name);
@@ -49,9 +56,12 @@
     }
 }
 
-void COM_Font_init_charset(const char *charset)
+void COM_Set_encoding(const char *enc)
 {
-    font_init_charset(charset);
+    if (encoding)
+	G_free(encoding);
+
+    encoding = G_store(enc);
 }
 
 int font_is_freetype(void)
@@ -93,11 +103,21 @@
 
 void COM_Font_list(char ***list, int *count)
 {
+    if (driver->Font_list) {
+	(*driver->Font_list)(list, count);
+	return;
+    }
+
     font_list(list, count, 0);
 }
 
 void COM_Font_info(char ***list, int *count)
 {
+    if (driver->Font_info) {
+	(*driver->Font_info)(list, count);
+	return;
+    }
+
     font_list(list, count, 1);
 }
 

Modified: grass/trunk/lib/driver/Get_t_box.c
===================================================================
--- grass/trunk/lib/driver/Get_t_box.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/Get_t_box.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -3,6 +3,11 @@
 
 void COM_Get_text_box(const char *text, double *t, double *b, double *l, double *r)
 {
+    if (driver->text_box) {
+	(*driver->text_box)(text, t, b, l, r);
+	return;
+    }
+
     if (!font_is_freetype()) {
 	soft_text_ext(cur_x, cur_y,
 		      text_size_x, text_size_y, text_rotation, text);

Modified: grass/trunk/lib/driver/Text_size.c
===================================================================
--- grass/trunk/lib/driver/Text_size.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/Text_size.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -5,9 +5,11 @@
 {
     text_size_x = x / 25.0;
     text_size_y = y / 25.0;
+    matrix_valid = 0;
 }
 
 void COM_Text_rotation(double val)
 {
     text_rotation = val;
+    matrix_valid = 0;
 }

Modified: grass/trunk/lib/driver/driver.h
===================================================================
--- grass/trunk/lib/driver/driver.h	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/driver.h	2008-08-10 09:37:04 UTC (rev 32662)
@@ -17,8 +17,10 @@
 extern double text_size_x;
 extern double text_size_y;
 extern double text_rotation;
+extern int matrix_valid;
 
 extern struct GFONT_CAP *ftcap;
+extern char *encoding;
 
 struct driver
 {
@@ -45,6 +47,10 @@
     void (*draw_point) (double, double);
     void (*draw_bitmap) (int, int, int, const unsigned char *);
     void (*draw_text) (const char *);
+    void (*text_box)(const char *, double *, double *, double *, double *);
+    void (*Set_font)(const char *);
+    void (*Font_list)(char ***, int *);
+    void (*Font_info)(char ***, int *);
 };
 
 /* Library Functions */
@@ -73,8 +79,8 @@
 extern void COM_Erase(void);
 
 /* Font.c */
-extern void COM_Font_get(const char *);
-extern void COM_Font_init_charset(const char *);
+extern void COM_Set_font(const char *);
+extern void COM_Set_encoding(const char *);
 extern void COM_Font_list(char ***, int *);
 extern void COM_Font_info(char ***, int *);
 

Modified: grass/trunk/lib/driver/driverlib.h
===================================================================
--- grass/trunk/lib/driver/driverlib.h	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/driverlib.h	2008-08-10 09:37:04 UTC (rev 32662)
@@ -29,9 +29,7 @@
 
 /* font_freetype.c */
 int font_init_freetype(const char *, int);
-int font_init_charset(const char *);
 const char *font_get_freetype_name(void);
-const char *font_get_charset(void);
 int font_get_index(void);
 
 /* parse_ftcap.c */

Modified: grass/trunk/lib/driver/font_freetype.c
===================================================================
--- grass/trunk/lib/driver/font_freetype.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/font_freetype.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -5,7 +5,6 @@
 
 static char *filename;
 static int font_index;
-static char *charset;
 
 int font_init_freetype(const char *name, int index)
 {
@@ -18,26 +17,11 @@
     return 0;
 }
 
-int font_init_charset(const char *str)
-{
-    if (charset)
-	G_free(charset);
-    charset = G_store(str);
-    return 0;
-}
-
 const char *font_get_freetype_name(void)
 {
     return filename;
 }
 
-const char *font_get_charset(void)
-{
-    if (!charset)
-	charset = G_store("ISO-8859-1");
-    return charset;
-}
-
 int font_get_index(void)
 {
     return font_index;

Modified: grass/trunk/lib/driver/init.c
===================================================================
--- grass/trunk/lib/driver/init.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/init.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -39,6 +39,7 @@
 double text_size_x;
 double text_size_y;
 double text_rotation;
+int matrix_valid;
 
 int LIB_init(const struct driver *drv)
 {

Modified: grass/trunk/lib/driver/text3.c
===================================================================
--- grass/trunk/lib/driver/text3.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/driver/text3.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -40,6 +40,13 @@
 static int fdont_draw = 0;
 static int ft, fb, fl, fr;
 
+static const char *font_get_encoding(void)
+{
+    if (!encoding)
+	encoding = G_store("ISO-8859-1");
+    return encoding;
+}
+
 static void draw_main(int x, int y,
 		      double text_size_x, double text_size_y,
 		      double text_rotation, const char *string)
@@ -53,14 +60,14 @@
     FT_Vector pen;
     FT_Error ans;
     const char *filename;
-    const char *charset;
+    const char *encoding;
     int font_index;
     unsigned char *out;
     int outlen;
 
     /* get file name */
     filename = font_get_freetype_name();
-    charset = font_get_charset();
+    encoding = font_get_encoding();
     font_index = font_get_index();
 
     /* set freetype */
@@ -106,8 +113,8 @@
     /* pen.y = 0; */
     pen.y = (screen_bottom - y) * 64;
 
-    /* convert string to:shift-jis from:charset */
-    outlen = convert_str(charset, string, &out);
+    /* convert string to:shift-jis from:encoding */
+    outlen = convert_str(encoding, string, &out);
 
     /* set matrix */
     set_matrix(&matrix, D2R(text_rotation));

Modified: grass/trunk/lib/htmldriver/Driver.c
===================================================================
--- grass/trunk/lib/htmldriver/Driver.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/htmldriver/Driver.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -44,6 +44,10 @@
     drv.draw_point = NULL;
     drv.draw_bitmap = NULL;
     drv.draw_text = HTML_Text;
+    drv.text_box = NULL;
+    drv.Set_font = NULL;
+    drv.Font_list = NULL;
+    drv.Font_info = NULL;
 
     initialized = 1;
 

Modified: grass/trunk/lib/pngdriver/Driver.c
===================================================================
--- grass/trunk/lib/pngdriver/Driver.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/pngdriver/Driver.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -46,6 +46,10 @@
     drv.draw_point = PNG_draw_point;
     drv.draw_bitmap = PNG_draw_bitmap;
     drv.draw_text = NULL;
+    drv.text_box = NULL;
+    drv.Set_font = NULL;
+    drv.Font_list = NULL;
+    drv.Font_info = NULL;
 
     initialized = 1;
 

Modified: grass/trunk/lib/psdriver/Driver.c
===================================================================
--- grass/trunk/lib/psdriver/Driver.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/psdriver/Driver.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -46,6 +46,10 @@
     drv.draw_point = PS_draw_point;
     drv.draw_bitmap = PS_draw_bitmap;
     drv.draw_text = NULL;
+    drv.text_box = NULL;
+    drv.Set_font = NULL;
+    drv.Font_list = NULL;
+    drv.Font_info = NULL;
 
     initialized = 1;
 

Modified: grass/trunk/lib/raster/raster.c
===================================================================
--- grass/trunk/lib/raster/raster.c	2008-08-10 02:53:17 UTC (rev 32661)
+++ grass/trunk/lib/raster/raster.c	2008-08-10 09:37:04 UTC (rev 32662)
@@ -34,7 +34,7 @@
     R_font(font ? font : "romans");
 
     if (fenc)
-	R_charset(fenc);
+	R_encoding(fenc);
 
     R_set_window(t, b, l, r);
 }
@@ -43,12 +43,15 @@
 {
     const char *p = getenv("GRASS_RENDER_IMMEDIATE");
     const struct driver *drv =
+	(p && G_strcasecmp(p, "PNG") == 0) ? PNG_Driver() :
 	(p && G_strcasecmp(p, "PS") == 0) ? PS_Driver() :
 	(p && G_strcasecmp(p, "HTML") == 0) ? HTML_Driver() :
 #ifdef USE_CAIRO
 	(p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
+	Cairo_Driver();
+#else
+	PNG_Driver();
 #endif
-	PNG_Driver();
 
     LIB_init(drv);
 
@@ -64,7 +67,7 @@
 
 void R_close_driver(void)
 {
-    char *cmd = getenv("GRASS_NOTIFY");
+    const char *cmd = getenv("GRASS_NOTIFY");
 
     COM_Respond();
     COM_Graph_close();
@@ -516,12 +519,12 @@
 
 void R_font(const char *name)
 {
-    COM_Font_get(name);
+    COM_Set_font(name);
 }
 
-void R_charset(const char *name)
+void R_encoding(const char *name)
 {
-    COM_Font_init_charset(name);
+    COM_Set_encoding(name);
 }
 
 void R_font_list(char ***list, int *count)



More information about the grass-commit mailing list