[GRASS-SVN] r34923 - in grass/trunk: general/g.mkfontcap include lib/cairodriver lib/driver vector/v.label.sa

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 17 16:04:58 EST 2008


Author: glynn
Date: 2008-12-17 16:04:58 -0500 (Wed, 17 Dec 2008)
New Revision: 34923

Added:
   grass/trunk/include/fontcap.h
Removed:
   grass/trunk/include/freetypecap.h
   grass/trunk/vector/v.label.sa/font.c
Modified:
   grass/trunk/general/g.mkfontcap/freetype_fonts.c
   grass/trunk/general/g.mkfontcap/main.c
   grass/trunk/general/g.mkfontcap/stroke_fonts.c
   grass/trunk/lib/cairodriver/Draw_bitmap.c
   grass/trunk/lib/cairodriver/Text.c
   grass/trunk/lib/driver/Font.c
   grass/trunk/lib/driver/Get_t_box.c
   grass/trunk/lib/driver/Text.c
   grass/trunk/lib/driver/Text_size.c
   grass/trunk/lib/driver/driver.h
   grass/trunk/lib/driver/driverlib.h
   grass/trunk/lib/driver/init.c
   grass/trunk/lib/driver/parse_ftcap.c
   grass/trunk/lib/driver/text2.c
   grass/trunk/lib/driver/text3.c
   grass/trunk/vector/v.label.sa/labels.h
Log:
Rename freetypecap -> fontcap
Fix/improve handling of driver-specific fonts
Driver fonts augment (not replace) FreeType/stroke fonts
Cairo driver now lists both FontConfig and "toy" fonts
Move stroke font scale factor into stroke font handling



Modified: grass/trunk/general/g.mkfontcap/freetype_fonts.c
===================================================================
--- grass/trunk/general/g.mkfontcap/freetype_fonts.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/general/g.mkfontcap/freetype_fonts.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -23,7 +23,7 @@
 
 #include <grass/config.h>
 #include <grass/gis.h>
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 
 #include "local_proto.h"
 

Modified: grass/trunk/general/g.mkfontcap/main.c
===================================================================
--- grass/trunk/general/g.mkfontcap/main.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/general/g.mkfontcap/main.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -23,7 +23,7 @@
 #include <errno.h>
 
 #include <grass/gis.h>
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 
 #include "local_proto.h"
 

Modified: grass/trunk/general/g.mkfontcap/stroke_fonts.c
===================================================================
--- grass/trunk/general/g.mkfontcap/stroke_fonts.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/general/g.mkfontcap/stroke_fonts.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -20,7 +20,7 @@
 #include <errno.h>
 
 #include <grass/gis.h>
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 
 #include "local_proto.h"
 

Copied: grass/trunk/include/fontcap.h (from rev 34915, grass/trunk/include/freetypecap.h)
===================================================================
--- grass/trunk/include/fontcap.h	                        (rev 0)
+++ grass/trunk/include/fontcap.h	2008-12-17 21:04:58 UTC (rev 34923)
@@ -0,0 +1,18 @@
+#ifndef _GRASS_FREETYPECAP_H
+#define _GRASS_FREETYPECAP_H
+
+struct GFONT_CAP
+{
+    char *name;	    /**< Short name for this font face */
+    char *longname; /**< Descriptive name for the font face */
+    char *path;	    /**< Full path to the file containing this font face */
+    int index;	    /**< Index within the file of this font face */
+    int type;	    /**< Type of this font face (currently stroke or freetype) */
+    char *encoding; /**< Encoding to be used with this font face. */
+};
+
+#define GFONT_STROKE 0
+#define GFONT_FREETYPE 1
+#define GFONT_DRIVER 2
+
+#endif


Property changes on: grass/trunk/include/fontcap.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Deleted: grass/trunk/include/freetypecap.h
===================================================================
--- grass/trunk/include/freetypecap.h	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/include/freetypecap.h	2008-12-17 21:04:58 UTC (rev 34923)
@@ -1,23 +0,0 @@
-#ifndef _GRASS_FREETYPECAP_H
-#define _GRASS_FREETYPECAP_H
-
-struct GFONT_CAP
-{
-
-    char *name;	    /**< Short name for this font face */
-
-    char *longname; /**< Descriptive name for the font face */
-
-    char *path;	    /**< Full path to the file containing this font face */
-
-    int index;	    /**< Index within the file of this font face */
-
-    int type;	    /**< Type of this font face (currently stroke or freetype) */
-
-    char *encoding; /**< Encoding to be used with this font face. */
-};
-
-#define GFONT_STROKE 0
-#define GFONT_FREETYPE 1
-
-#endif

Modified: grass/trunk/lib/cairodriver/Draw_bitmap.c
===================================================================
--- grass/trunk/lib/cairodriver/Draw_bitmap.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/cairodriver/Draw_bitmap.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -16,30 +16,6 @@
 
 #include "cairodriver.h"
 
-static cairo_surface_t *fix_surface(cairo_surface_t * src)
-{
-    int width = cairo_image_surface_get_width(src);
-    int height = cairo_image_surface_get_height(src);
-    int stride = cairo_image_surface_get_stride(src);
-    cairo_format_t format = cairo_image_surface_get_format(src);
-    unsigned char *data = cairo_image_surface_get_data(src);
-    cairo_surface_t *dst = cairo_image_surface_create(format, width, height);
-    int stride2 = cairo_image_surface_get_stride(dst);
-    unsigned char *data2 = cairo_image_surface_get_data(dst);
-    int i;
-
-    for (i = 0; i < height; i++) {
-	void *p = data + i * stride;
-	void *q = data2 + i * stride2;
-	int n = stride < stride2 ? stride : stride2;
-
-	memcpy(q, p, n);
-    }
-
-    cairo_surface_destroy(src);
-    return dst;
-}
-
 /*!
   \brief Draw bitmap
 
@@ -48,23 +24,29 @@
   \param buf data buffer
 */
 void Cairo_Bitmap(int ncols, int nrows, int threshold,
-		       const unsigned char *buf)
+		  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);
 
-    surf = cairo_image_surface_create_for_data((unsigned char *)buf,
-					       CAIRO_FORMAT_A8, ncols, nrows,
-					       ncols);
+    stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
+    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"));
 
-    surf = fix_surface(surf);
+    for (i = 0; i < nrows; i++)
+	memcpy(&data[i * stride], &buf[i * ncols], ncols);
 
     cairo_mask_surface(cairo, surf, cur_x, cur_y);
 
     cairo_surface_destroy(surf);
     ca.modified = 1;
 }
+

Modified: grass/trunk/lib/cairodriver/Text.c
===================================================================
--- grass/trunk/lib/cairodriver/Text.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/cairodriver/Text.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -36,14 +36,12 @@
 
 #ifdef HAVE_ICONV_H
     {
+	const char *encoding = font_get_encoding();
 	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"),
 			  encoding);
@@ -88,7 +86,7 @@
 	return;
 
     cairo_matrix_init_identity(&mat);
-    cairo_matrix_scale(&mat, text_size_x * 25, text_size_y * 25);
+    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);
@@ -174,18 +172,24 @@
 
 #if CAIRO_HAS_FT_FONT
 
-static void set_font_fc(const char *name)
+static void fc_init(void)
 {
-    static cairo_font_face_t *face;
     static int initialized;
-    FcPattern *pattern;
-    FcResult result;
 
     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;
@@ -199,6 +203,48 @@
     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] = {
@@ -255,9 +301,11 @@
 
     for (i = 0; i < num_toy_fonts; i++) {
 	char buf[256];
-	sprintf(buf, "%s%s",
-		toy_fonts[i],
-		verbose ? "||1||0|utf-8|" : "");
+	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);
     }
 
@@ -273,8 +321,10 @@
 */
 void Cairo_font_list(char ***list, int *count)
 {
-    font_list(list, count, 0);
     font_list_toy(list, count, 0);
+#if CAIRO_HAS_FT_FONT
+    font_list_fc(list, count, 0);
+#endif
 }
 
 /*!
@@ -285,7 +335,9 @@
 */
 void Cairo_font_info(char ***list, int *count)
 {
-    font_list(list, count, 1);
     font_list_toy(list, count, 1);
+#if CAIRO_HAS_FT_FONT
+    font_list_fc(list, count, 1);
+#endif
 }
 

Modified: grass/trunk/lib/driver/Font.c
===================================================================
--- grass/trunk/lib/driver/Font.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/Font.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -5,9 +5,8 @@
 #include "driver.h"
 #include "driverlib.h"
 
-char *encoding;
-
 static int font_type = GFONT_STROKE;
+static char *encoding;
 
 static void stroke_set(const char *filename)
 {
@@ -21,62 +20,32 @@
 	font_type = GFONT_FREETYPE;
 }
 
-void COM_Set_font(const char *name)
+static void driver_set(const char *name)
 {
-    if (driver->Set_font) {
-	(*driver->Set_font)(name);
-	return;
-    }
-
-    if (G_is_absolute_path(name)) {
-	if (!font_exists(name))
-	    return;
-
-	freetype_set(name, 0);
-    }
-    else {
-	int i;
-
-	/* check if freetype font is available in freetypecap */
-	for (i = 0; ftcap[i].name; i++)
-	    if (strcmp(name, ftcap[i].name) == 0) {
-		switch (ftcap[i].type) {
-		case GFONT_FREETYPE:
-		    freetype_set(ftcap[i].path, ftcap[i].index);
-		    COM_Set_encoding(ftcap[i].encoding);
-		    break;
-		case GFONT_STROKE:
-		    stroke_set(ftcap[i].name);
-		    break;
-		}
-		return;
-	    }
-
-	stroke_set("romans");
-    }
+    (*driver->Set_font)(name);
+    font_type = GFONT_DRIVER;
 }
 
-void COM_Set_encoding(const char *enc)
+int font_get_type(void)
 {
-    if (encoding)
-	G_free(encoding);
-
-    encoding = G_store(enc);
+    return font_type;
 }
 
-int font_is_freetype(void)
+const char *font_get_encoding(void)
 {
-    return font_type == GFONT_FREETYPE;
+    if (!encoding)
+	encoding = G_store("ISO-8859-1");
+    return encoding;
 }
 
-void font_list(char ***list, int *count, int verbose)
+static void font_list(char ***list, int *count, int verbose)
 {
     char **fonts;
     int num_fonts;
     int i;
 
-    for (i = 0; ftcap[i].name; i++) ;
-
+    for (i = 0; ftcap[i].name; i++)
+	;
     num_fonts = i;
 
     fonts = G_malloc(num_fonts * sizeof(const char *));
@@ -101,31 +70,91 @@
     *count = num_fonts;
 }
 
-void COM_Font_list(char ***list, int *count)
+static void free_font_list(char **fonts, int count)
 {
-    if (driver->Font_list) {
-	(*driver->Font_list)(list, count);
-	return;
-    }
+    int i;
 
-    font_list(list, count, 0);
+    for (i = 0; i < count; i++)
+	G_free(fonts[i]);
+
+    G_free(fonts);
 }
 
-void COM_Font_info(char ***list, int *count)
+void COM_Set_font(const char *name)
 {
-    if (driver->Font_info) {
-	(*driver->Font_info)(list, count);
+    int i;
+
+    if (G_is_absolute_path(name)) {
+	if (font_exists(name))
+	    freetype_set(name, 0);
 	return;
     }
 
-    font_list(list, count, 1);
+    for (i = 0; ftcap[i].name; i++) {
+	struct GFONT_CAP *cap = &ftcap[i];
+
+	if (strcmp(name, cap->name) != 0)
+	    continue;
+
+	switch (cap->type) {
+	case GFONT_FREETYPE:
+	    freetype_set(cap->path, cap->index);
+	    COM_Set_encoding(cap->encoding);
+	    break;
+	case GFONT_STROKE:
+	    stroke_set(cap->name);
+	    break;
+	}
+	return;
+    }
+
+
+    if (driver->Font_list && driver->Set_font) {
+	char **list = NULL;
+	int count = 0;
+
+	(*driver->Font_list)(&list, &count);
+
+	for (i = 0; i < count; i++) {
+	    struct GFONT_CAP cap;
+
+	    if (!parse_fontcap_entry(&cap, list[i]))
+		continue;
+
+	    if (cap.type != GFONT_DRIVER)
+		continue;
+
+	    driver_set(cap.name);
+	    COM_Set_encoding(cap.encoding);
+	    break;
+	}
+
+	free_font_list(list, count);
+	return;
+    }
+
+    stroke_set("romans");
 }
 
-void free_font_list(char **fonts, int count)
+void COM_Set_encoding(const char *enc)
 {
-    int i;
+    if (encoding)
+	G_free(encoding);
 
-    for (i = 0; i < count; i++)
-	G_free(fonts[i]);
-    G_free(fonts);
+    encoding = G_store(enc);
 }
+
+void COM_Font_list(char ***list, int *count)
+{
+    font_list(list, count, 0);
+    if (driver->Font_list)
+	(*driver->Font_list)(list, count);
+}
+
+void COM_Font_info(char ***list, int *count)
+{
+    font_list(list, count, 1);
+    if (driver->Font_info)
+	(*driver->Font_info)(list, count);
+}
+

Modified: grass/trunk/lib/driver/Get_t_box.c
===================================================================
--- grass/trunk/lib/driver/Get_t_box.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/Get_t_box.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -3,14 +3,17 @@
 
 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())
+    switch (font_get_type()) {
+    case GFONT_STROKE:
 	get_text_ext(text, t, b, l, r);
-    else
+	break;
+    case GFONT_FREETYPE:
 	get_text_ext_freetype(text, t, b, l, r);
+	break;
+    case GFONT_DRIVER:
+	if (driver->Text_box)
+	    (*driver->Text_box)(text, t, b, l, r);
+	break;
+    }
 }
 

Modified: grass/trunk/lib/driver/Text.c
===================================================================
--- grass/trunk/lib/driver/Text.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/Text.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -3,14 +3,17 @@
 
 void COM_Text(const char *text)
 {
-    if (driver->Text) {
-	(*driver->Text)(text);
-	return;
-    }
-
-    if (!font_is_freetype())
+    switch (font_get_type()) {
+    case GFONT_STROKE:
 	soft_text(text);
-    else
+	break;
+    case GFONT_FREETYPE:
 	soft_text_freetype(text);
+	break;
+    case GFONT_DRIVER:
+	if (driver->Text)
+	    (*driver->Text)(text);
+	break;
+    }
 }
 

Modified: grass/trunk/lib/driver/Text_size.c
===================================================================
--- grass/trunk/lib/driver/Text_size.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/Text_size.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -4,8 +4,8 @@
 
 void COM_Text_size(double x, double y)
 {
-    text_size_x = x / 25.0;
-    text_size_y = y / 25.0;
+    text_size_x = x;
+    text_size_y = y;
     matrix_valid = 0;
 }
 

Modified: grass/trunk/lib/driver/driver.h
===================================================================
--- grass/trunk/lib/driver/driver.h	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/driver.h	2008-12-17 21:04:58 UTC (rev 34923)
@@ -2,7 +2,7 @@
 #ifndef _DRIVER_H
 #define _DRIVER_H
 
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 
 extern int screen_width;
 extern int screen_height;

Modified: grass/trunk/lib/driver/driverlib.h
===================================================================
--- grass/trunk/lib/driver/driverlib.h	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/driverlib.h	2008-12-17 21:04:58 UTC (rev 34923)
@@ -9,8 +9,8 @@
 /* Utility Functions */
 
 /* Font.c */
-int font_is_freetype(void);
-void font_list(char ***, int *, int);
+int font_get_type(void);
+const char *font_get_encoding(void);
 
 /* Text2.c */
 void get_text_ext(const char *, double *, double *, double *, double *);
@@ -31,7 +31,6 @@
 
 /* parse_ftcap.c */
 extern int font_exists(const char *);
-extern struct GFONT_CAP *parse_freetypecap(void);
-extern void free_freetypecap(struct GFONT_CAP *);
-extern void free_font_list(char **, int);
-
+extern int parse_fontcap_entry(struct GFONT_CAP *, const char *);
+extern struct GFONT_CAP *parse_fontcap(void);
+extern void free_fontcap(struct GFONT_CAP *);

Modified: grass/trunk/lib/driver/init.c
===================================================================
--- grass/trunk/lib/driver/init.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/init.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -18,7 +18,7 @@
 #include <stdlib.h>
 
 #include <grass/gis.h>
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 #include "driverlib.h"
 #include "driver.h"
 
@@ -44,7 +44,7 @@
     const char *p;
 
     driver = drv;
-    ftcap = parse_freetypecap();
+    ftcap = parse_fontcap();
 
     /* initialize graphics */
 

Modified: grass/trunk/lib/driver/parse_ftcap.c
===================================================================
--- grass/trunk/lib/driver/parse_ftcap.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/parse_ftcap.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -1,24 +1,40 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 #include "driverlib.h"
 
 int font_exists(const char *name)
 {
-    FILE *fp;
+    return access(name, R_OK) >= 0;
+}
 
-    fp = fopen(name, "r");
-    if (!fp)
+int parse_fontcap_entry(struct GFONT_CAP *e, const char *str)
+{
+    char name[GNAME_MAX], longname[GNAME_MAX], path[GPATH_MAX], encoding[128];
+    int type, index;
+
+    if (sscanf(str, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
+	       name, longname, &type, path, &index, encoding) != 6)
 	return 0;
 
-    fclose(fp);
+    if (!font_exists(path))
+	return 0;
+
+    e->name = G_store(name);
+    e->longname = G_store(longname);
+    e->type = type;
+    e->path = G_store(path);
+    e->index = index;
+    e->encoding = G_store(encoding);
+
     return 1;
 }
 
-struct GFONT_CAP *parse_freetypecap(void)
+struct GFONT_CAP *parse_fontcap(void)
 {
     char *capfile, file[GPATH_MAX];
     char buf[GPATH_MAX];
@@ -40,49 +56,31 @@
 
     if (fp != NULL) {
 	while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
-	    char name[GNAME_MAX], longname[GNAME_MAX],
-		path[GPATH_MAX], encoding[128];
-	    int type, index;
+	    struct GFONT_CAP cap;
 	    char *p;
 
 	    p = strchr(buf, '#');
 	    if (p)
 		*p = 0;
 
-	    if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
-		       name, longname, &type, path, &index, encoding)
-		!= 6)
+	    if (!parse_fontcap_entry(&cap, buf))
 		continue;
 
-	    if (!font_exists(path))
-		continue;
-
-	    fonts = (struct GFONT_CAP *)G_realloc(fonts,
-						  (fonts_count +
-						   1) *
-						  sizeof(struct GFONT_CAP));
-
-	    fonts[fonts_count].name = G_store(name);
-	    fonts[fonts_count].longname = G_store(longname);
-	    fonts[fonts_count].type = type;
-	    fonts[fonts_count].path = G_store(path);
-	    fonts[fonts_count].index = index;
-	    fonts[fonts_count].encoding = G_store(encoding);
-
-	    fonts_count++;
+	    fonts = G_realloc(fonts, (fonts_count + 1) * sizeof(struct GFONT_CAP));
+	    fonts[fonts_count++] = cap;
 	}
+
 	fclose(fp);
     }
 
-    fonts = (struct GFONT_CAP *)G_realloc(fonts, (fonts_count + 1) *
-					  sizeof(struct GFONT_CAP));
+    fonts = G_realloc(fonts, (fonts_count + 1) * sizeof(struct GFONT_CAP));
     fonts[fonts_count].name = NULL;
     fonts[fonts_count].path = NULL;
 
     return fonts;
 }
 
-void free_freetypecap(struct GFONT_CAP *ftcap)
+void free_fontcap(struct GFONT_CAP *ftcap)
 {
     int i;
 
@@ -97,6 +95,5 @@
     }
 
     G_free(ftcap);
-
-    return;
 }
+

Modified: grass/trunk/lib/driver/text2.c
===================================================================
--- grass/trunk/lib/driver/text2.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/text2.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -25,8 +25,8 @@
 		      int ix, int iy,
 		      double orig_x, double orig_y)
 {
-    double ax = text_size_x * ix;
-    double ay = text_size_y * iy;
+    double ax = text_size_x * ix / 25;
+    double ay = text_size_y * iy / 25;
     double rx = ax * text_cosrot - ay * text_sinrot;
     double ry = ax * text_sinrot + ay * text_cosrot;
     *x = orig_x + rx;

Modified: grass/trunk/lib/driver/text3.c
===================================================================
--- grass/trunk/lib/driver/text3.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/lib/driver/text3.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -39,13 +39,6 @@
 static void set_text_box(FT_Bitmap *, FT_Int, FT_Int, struct rectangle *);
 #endif
 
-static const char *font_get_encoding(void)
-{
-    if (!encoding)
-	encoding = G_store("ISO-8859-1");
-    return encoding;
-}
-
 static void draw_main(double x, double y, const char *string,
 		      struct rectangle *box)
 {
@@ -90,11 +83,10 @@
     /* ans = FT_Set_Char_Size(face,text_size_x*64,text_size_y*64,0,0); */
     /* ans = FT_Set_Char_Size(face,10*64,0,72,0); */
     /* ans = FT_Set_Char_Size(face,text_size_x*64,text_size_y*64,72,72); */
-    ans =
-	FT_Set_Char_Size(face,
-			 (int)(text_size_x * 25 * 64),
-			 (int)(text_size_y * 25 * 64),
-			 100, 100);
+    ans = FT_Set_Char_Size(face,
+			   (int)(text_size_x * 64),
+			   (int)(text_size_y * 64),
+			   100, 100);
 
     if (ans) {
 	/* DEBUG_LOG("Text3 error: ft set size\n"); */

Deleted: grass/trunk/vector/v.label.sa/font.c
===================================================================
--- grass/trunk/vector/v.label.sa/font.c	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/vector/v.label.sa/font.c	2008-12-17 21:04:58 UTC (rev 34923)
@@ -1,97 +0,0 @@
-/*
- * from lib/driver/parse_ftcap.c
- * These functions are copied from the diplay driver lib,
- * so that we don't need to have an active display driver open,
- * to run this module.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/freetypecap.h>
-#include "labels.h"
-
-static int font_exists(const char *name);
-
-static int font_exists(const char *name)
-{
-    FILE *fp;
-
-    fp = fopen(name, "r");
-    if (!fp)
-	return 0;
-
-    fclose(fp);
-    return 1;
-}
-
-void free_freetypecap(struct GFONT_CAP *ftcap)
-{
-    if (ftcap == NULL)
-	return;
-    G_free(ftcap->name);
-    G_free(ftcap->longname);
-    G_free(ftcap->path);
-    G_free(ftcap->encoding);
-    G_free(ftcap);
-
-    return;
-}
-
-struct GFONT_CAP *find_font_from_freetypecap(const char *font)
-{
-    char *capfile, file[GPATH_MAX];
-    char buf[GPATH_MAX];
-    FILE *fp;
-    int fonts_count = 0;
-    struct GFONT_CAP *font_cap = NULL;
-
-    fp = NULL;
-    if ((capfile = getenv("GRASS_FONT_CAP"))) {
-	if ((fp = fopen(capfile, "r")) == NULL)
-	    G_warning(_("%s: Unable to read font definition file; use the default"),
-		      capfile);
-    }
-    if (fp == NULL) {
-	sprintf(file, "%s/etc/fontcap", G_gisbase());
-	if ((fp = fopen(file, "r")) == NULL)
-	    G_warning(_("%s: No font definition file"), file);
-    }
-
-    if (fp != NULL) {
-	while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
-	    char name[GNAME_MAX], longname[GNAME_MAX],
-		path[GPATH_MAX], encoding[128];
-	    int type, index;
-	    char *p;
-
-	    p = strchr(buf, '#');
-	    if (p)
-		*p = 0;
-
-	    if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
-		       name, longname, &type, path, &index, encoding)
-		!= 6)
-		continue;
-	    if (strcmp(name, font) != 0 && strcmp(longname, font) != 0)
-		continue;
-	    if (!font_exists(path))
-		continue;
-
-	    font_cap = (struct GFONT_CAP *)G_malloc(sizeof(struct GFONT_CAP));
-
-	    font_cap[fonts_count].name = G_store(name);
-	    font_cap[fonts_count].longname = G_store(longname);
-	    font_cap[fonts_count].type = type;
-	    font_cap[fonts_count].path = G_store(path);
-	    font_cap[fonts_count].index = index;
-	    font_cap[fonts_count].encoding = G_store(encoding);
-
-	}
-	fclose(fp);
-    }
-
-    return font_cap;
-}

Modified: grass/trunk/vector/v.label.sa/labels.h
===================================================================
--- grass/trunk/vector/v.label.sa/labels.h	2008-12-17 20:00:54 UTC (rev 34922)
+++ grass/trunk/vector/v.label.sa/labels.h	2008-12-17 21:04:58 UTC (rev 34923)
@@ -15,7 +15,7 @@
 #include <grass/Vect.h>
 #include <grass/dbmi.h>
 #include <grass/glocale.h>
-#include <grass/freetypecap.h>
+#include <grass/fontcap.h>
 
 #include <ft2build.h>
 #include FT_FREETYPE_H
@@ -179,7 +179,4 @@
 struct line_pnts *skyline_trans_rot(struct line_pnts *skyline,
 				    label_point_t * p, double angle);
 
-void free_freetypecap(struct GFONT_CAP *ftcap);
-struct GFONT_CAP *find_font_from_freetypecap(const char *font);
-
 #endif /* _LABELS_H */



More information about the grass-commit mailing list