[gnome-print] PATCH: Fontconfig



Hello,

Here's a patch which makes gnome-print use fontconfig fonts and obsoletes gnome-print.fontmap files and gnome-font-installer. It does not however remove build instructions for gnome-font-installer.

I wrote a little test file fonts.c which prints out list of fonts gnome-print knows about.

This patch also fixes some build issues, without it transports and drivers didn't compile for me.

--
Tambet Ingo <tambet@ximian.com>
? autom4te-2.53.cache
? fontconfig.diff
? stamp-h1
? tests/fonts
? tests/fonts.c
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomeprint/ChangeLog,v
retrieving revision 1.174
diff -u -r1.174 ChangeLog
--- ChangeLog	19 Sep 2002 02:27:35 -0000	1.174
+++ ChangeLog	31 Oct 2002 14:32:12 -0000
@@ -1,3 +1,15 @@
+2002-10-31  Tambet Ingo  <tambet@ximian.com>
+
+	* tests/Makefile.am (SUBDIRS): Added build instructions for new test called fonts.c
+
+	* libgnomeprint/drivers/Makefile.am: s/libexec/plugin/
+
+	* libgnomeprint/transports/Makefile.am: ditto.
+
+	* configure.in: Add checks for fontconfig.
+
+	* libgnomeprint/gnome-fontmap.c: Use fontconfig to get fonts.
+
 2002-09-18  Chema Celorio  <chema@ximian.com>
 
 	* libgnomeprint/Makefile.am (libgnomeprintincdir): fix the second part of #93271
Index: configure.in
===================================================================
RCS file: /cvs/gnome/libgnomeprint/configure.in,v
retrieving revision 1.199
diff -u -r1.199 configure.in
--- configure.in	1 Sep 2002 16:20:55 -0000	1.199
+++ configure.in	31 Oct 2002 14:32:13 -0000
@@ -85,7 +85,8 @@
 libart_modules="libart-2.0 >= 2.3.7"
 pango_modules="pango >= 0.21"
 libxml2_modules="libxml-2.0 >= 2.4.23"
-PKG_CHECK_MODULES(GP, [ $glib_modules $libart_modules $pango_modules $libxml2_modules $libbonobo_modules ])
+fontconfig_modules="fontconfig >= 1.0"
+PKG_CHECK_MODULES(GP, [ $glib_modules $libart_modules $pango_modules $libxml2_modules $libbonobo_modules $fontconfig_modules ])
 
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
 
Index: libgnomeprint/gnome-fontmap.c
===================================================================
RCS file: /cvs/gnome/libgnomeprint/libgnomeprint/gnome-fontmap.c,v
retrieving revision 1.23
diff -u -r1.23 gnome-fontmap.c
--- libgnomeprint/gnome-fontmap.c	29 Aug 2002 17:12:47 -0000	1.23
+++ libgnomeprint/gnome-fontmap.c	31 Oct 2002 14:32:14 -0000
@@ -29,11 +29,7 @@
 #include <time.h>
 #include <stdlib.h>
 #include <string.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <libxml/parser.h>
-#include <libxml/xmlmemory.h>
+#include <fontconfig/fontconfig.h>
 #include "gnome-fontmap.h"
 
 /*
@@ -46,27 +42,15 @@
  */
 
 static GPFontMap *gp_fontmap_load (void);
-static void gp_fontmap_load_dir (GPFontMap *map, const guchar *dirname);
-static void gp_fontmap_load_file (GPFontMap *map, const guchar *filename);
-static void gp_fm_load_font_2_0_type1 (GPFontMap *map, xmlNodePtr node);
-static void gp_fm_load_font_2_0_type1alias (GPFontMap *map, xmlNodePtr node);
-static void gp_fm_load_font_2_0_truetype (GPFontMap *map, xmlNodePtr node);
-static void gp_font_entry_2_0_load_data (GPFontEntry *e, xmlNodePtr node);
-static void gp_font_entry_2_0_type1_load_files (GPFontEntryT1 *t1, xmlNodePtr node);
-static void gp_font_entry_2_0_truetype_load_files (GPFontEntryTT *tt, xmlNodePtr node);
-static void gp_fm_load_fonts_2_0 (GPFontMap * map, xmlNodePtr root);
 
 static void gp_fontmap_ref (GPFontMap * map);
 static void gp_fontmap_unref (GPFontMap * map);
 static void gp_family_entry_ref (GPFamilyEntry * entry);
 static void gp_family_entry_unref (GPFamilyEntry * entry);
 
-static gchar * gp_xmlGetPropString (xmlNodePtr node, const gchar * name);
 static gint gp_fe_sortname (gconstpointer a, gconstpointer b);
 static gint gp_fe_sortspecies (gconstpointer a, gconstpointer b);
 static gint gp_familyentry_sortname (gconstpointer a, gconstpointer b);
-static gchar * gp_fm_get_species_name (const gchar * fullname, const gchar * familyname);
-static gboolean gp_fm_is_changed (GPFontMap * map);
 
 /* Fontlist -> FontMap */
 static GHashTable * fontlist2map = NULL;
@@ -81,7 +65,7 @@
 
 	if (map) {
 		/* If > 1 sec is passed from last query, check timestamps */
-		if ((time (NULL) > lastaccess) && gp_fm_is_changed (map)) {
+		if ((time (NULL) > lastaccess)) {
 			/* Any directory is changed, so force rereading of map */
 			gp_fontmap_release (map);
 			map = NULL;
@@ -168,13 +152,161 @@
 	}
 }
 
+static GnomeFontWeight
+convert_fc_weight (gint i)
+{
+	if (i < FC_WEIGHT_LIGHT)
+		return GNOME_FONT_LIGHTEST;
+	if (i < (FC_WEIGHT_LIGHT + FC_WEIGHT_MEDIUM) / 2)
+		return GNOME_FONT_LIGHT;
+	if (i < (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2)
+		return GNOME_FONT_REGULAR;
+	if (i < (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2)
+		return GNOME_FONT_DEMI;
+	if (i < (FC_WEIGHT_BOLD + FC_WEIGHT_BLACK) / 2)
+		return GNOME_FONT_BOLD;
+
+	return GNOME_FONT_HEAVIEST;
+}
+
+static GPFontEntry *
+fcpattern_to_gp_font_entry (FcPattern *font)
+{
+	GPFontEntry *e;
+	GPFontEntryTT *tt;
+	FcResult result;
+	FcChar8 *str;
+	int i;
+
+	tt = g_new0 (GPFontEntryTT, 1);
+	e = (GPFontEntry *)tt;
+
+	e->type = GP_FONT_ENTRY_TRUETYPE;
+	e->refcount = 1;
+	e->face = NULL;
+
+	result = FcPatternGetString (font, FC_FAMILY, 0, &str);
+	if (result == FcResultMatch)
+		e->familyname = g_strdup (str);
+
+	result = FcPatternGetString (font, FC_STYLE, 0, &str);
+	if (result == FcResultMatch) {
+		e->speciesname = g_strdup (str);
+		e->weight = g_strdup (str);
+	}
+
+	result = FcPatternGetInteger (font, FC_WEIGHT, 0, &i);
+	if (result == FcResultMatch)
+		e->Weight = convert_fc_weight (i);
+	else
+		e->Weight = GNOME_FONT_REGULAR;
+
+	e->version = g_strdup ("1.0");
+
+	e->name = g_strdup_printf ("%s %s", e->familyname, e->weight);
+	e->psname = g_strdup_printf ("%s-%s", e->familyname, e->weight);
+
+	result = FcPatternGetInteger (font, FC_SLANT, 0, &i);
+	if (result == FcResultMatch)
+		e->ItalicAngle = i;
+
+	result = FcPatternGetString (font, FC_FILE, 0, &str);
+	if (result == FcResultMatch)
+		tt->ttf.name = g_strdup (str);
+
+	return e;
+}
+
+static GPFontEntry *
+fcpattern_to_gp_font_entry_alias (FcPattern *font, const gchar *family, const gchar *style)
+{
+	GPFontEntry *e;
+
+	e = fcpattern_to_gp_font_entry (font);
+
+	/* Override font name and style */
+	if (e->name)
+		g_free (e->name);
+	if (e->psname)
+		g_free (e->psname);
+
+	e->name = g_strdup_printf ("%s %s", family, style);
+	e->psname = g_strdup_printf ("%s-%s", family, style);
+
+	return e;
+}
+
+/* Add well-known aliases Sans Sans-Serif and Monospace */
+static void
+gp_fontmap_add_aliases (GPFontMap *map)
+{
+	FcPattern *match_pattern, *result_pattern;
+	GPFontEntry *e;
+	gchar *aliases[] = { "Sans", "Serif", "Monospace", NULL };
+	gchar *styles[] = { "Regular", "Bold", "Italic", "Bold Italic", NULL };
+	FcResult res;
+	gint i, j;
+
+	for (i = 0; aliases[i]; i++) {
+		for (j = 0; styles[j]; j++) {
+			match_pattern = FcPatternBuild (NULL,
+							FC_FAMILY, FcTypeString, aliases[i],
+							FC_STYLE,  FcTypeString, styles[j],
+							NULL);
+
+			FcConfigSubstitute (NULL, match_pattern, FcMatchPattern);
+			FcDefaultSubstitute (match_pattern);
+
+			g_assert (match_pattern);
+
+			result_pattern = FcFontMatch (NULL, match_pattern, &res);
+			if (result_pattern) {
+				e = fcpattern_to_gp_font_entry_alias (result_pattern, aliases[i], styles[j]);
+				if (e) {
+					g_hash_table_insert (map->fontdict, e->name, e);
+					map->num_fonts++;
+					map->fonts = g_slist_prepend (map->fonts, e);
+				}
+
+				FcPatternDestroy (result_pattern);
+			}
+
+			FcPatternDestroy (match_pattern);
+		}
+	}
+}
+
+static void
+gp_fontmap_load_fontconfig (GPFontMap *map)
+{
+	FcFontSet *fontset;
+	FcPattern *font;
+	GPFontEntry *e;
+	int i;
+
+	fontset = FcConfigGetFonts (NULL, FcSetSystem);
+	if (fontset == NULL) {
+		return;
+	}
+
+	for (i = 0; i < fontset->nfont; i++) {
+		font = fontset->fonts[i];
+
+		e = fcpattern_to_gp_font_entry (font);
+		if (e) {
+			g_hash_table_insert (map->fontdict, e->name, e);
+			map->num_fonts++;
+			map->fonts = g_slist_prepend (map->fonts, e);
+		}
+	}
+
+	gp_fontmap_add_aliases (map);
+}
+
 static GPFontMap *
 gp_fontmap_load (void)
 {
 	GPFontMap *map;
-	struct stat s;
-	const gchar *homedir;
-	gchar *mapdir;
 	GSList * l;
 
 	map = g_new (GPFontMap, 1);
@@ -194,42 +326,7 @@
 	map->defaults = NULL;
 	map->defaultsdict = g_hash_table_new (g_str_hash, g_str_equal);
 
-	/* User map */
-	homedir = g_get_home_dir ();
-	mapdir = g_strdup_printf ("%s/.gnome/fonts", homedir);
-	if (!stat (mapdir, &s) && S_ISDIR (s.st_mode)) {
-		map->mtime_user = s.st_mtime;
-		gp_fontmap_load_dir (map, mapdir);
-	}
-	g_free (mapdir);
-	/* Dynamic map */
-	if (!stat (FONTMAPDIR_DYNAMIC, &s) && S_ISDIR (s.st_mode)) {
-		map->mtime_dynamic = s.st_mtime;
-		gp_fontmap_load_dir (map, FONTMAPDIR_DYNAMIC);
-	}
-	/* Static map */
-	if (!stat (FONTMAPDIR_STATIC, &s) && S_ISDIR (s.st_mode)) {
-		map->mtime_static = s.st_mtime;
-		gp_fontmap_load_dir (map, FONTMAPDIR_STATIC);
-	}
-
-	/* Sanity check */
-	if (map->num_fonts < 24) {
-		/* Less than 24 fonts means, you do not have PS ones */
-		if (!stat (DATADIR "/fonts/fontmap2", &s) && S_ISREG (s.st_mode)) {
-			gp_fontmap_load_file (map, DATADIR "/fonts/fontmap2");
-		}
-	}
-	/* More sanity check */
-	if (map->num_fonts < 24) {
-		gchar *filename;
-		/* Less than 24 fonts means, you do not have PS ones */
-		filename = g_strdup_printf ("%s/.gnome/fonts/fontmap", homedir);
-		if (!stat (filename, &s) && S_ISREG (s.st_mode)) {
-			gp_fontmap_load_file (map, filename);
-		}
-		g_free (filename);
-	}
+	gp_fontmap_load_fontconfig (map);
 
 	/* Sort fonts alphabetically */
 	map->fonts = g_slist_sort (map->fonts, gp_fe_sortname);
@@ -319,369 +416,6 @@
 	return map;
 }
 
-static gint
-gp_fontmap_compare_names (gconstpointer a, gconstpointer b)
-{
-	if (!strcmp (a, "gnome-print.fontmap")) return -1;
-	if (!strcmp (b, "gnome-print.fontmap")) return 1;
-	return strcmp (a, b);
-}
-
-/* Tries to load all *.fontmap files from given directory */
-
-static void
-gp_fontmap_load_dir (GPFontMap *map, const guchar *dirname)
-{
-	DIR *dir;
-	struct dirent *dent;
-
-	dir = opendir (dirname);
-
-	if (dir) {
-		GSList *files;
-		files = NULL;
-		while ((dent = readdir (dir))) {
-			gint len;
-			len = strlen (dent->d_name);
-			if ((len > 8) && !strcmp (dent->d_name + len - 8, ".fontmap")) {
-				/* Seems to be what we are looking for */
-				files = g_slist_prepend (files, g_strdup (dent->d_name));
-			}
-		}
-		closedir (dir);
-		/* Sort names alphabetically */
-		files = g_slist_sort (files, gp_fontmap_compare_names);
-		while (files) {
-			struct stat s;
-			gchar *filename;
-			filename = g_strdup_printf ("%s/%s", dirname, (gchar *) files->data);
-			g_free (files->data);
-			if (!stat (filename, &s) && S_ISREG (s.st_mode)) {
-				gp_fontmap_load_file (map, filename);
-			}
-			g_free (filename);
-			files = g_slist_remove (files, files->data);
-		}
-	}
-}
-
-/* Parse file, and add fonts to map, if it is valid fontmap */
-
-static void
-gp_fontmap_load_file (GPFontMap *map, const guchar *filename)
-{
-	xmlDocPtr doc;
-
-	doc = xmlParseFile (filename);
-	if (doc) {
-		xmlNodePtr root;
-		/* In minimum we are valid xml file */
-		root = xmlDocGetRootElement (doc);
-		if (root && !strcmp (root->name, "fontmap")) {
-			xmlChar *version;
-			/* We are really fontmap */
-			version = xmlGetProp (root, "version");
-			if (version) {
-				if (!strcmp (version, "2.0")) {
-					xmlChar *test;
-					gboolean try;
-					/* We are even right version */
-					try = TRUE;
-					test = xmlGetProp (root, "test");
-					if (test) {
-						struct stat s;
-						if (stat (test, &s) || !S_ISREG (s.st_mode)) try = FALSE;
-						xmlFree (test);
-					}
-					if (try) gp_fm_load_fonts_2_0 (map, root);
-				}
-				xmlFree (version);
-			}
-		}
-		xmlFreeDoc (doc);
-	}
-}
-
-/* Parse root element and build fontmap step 1 */
-
-static void
-gp_fm_load_fonts_2_0 (GPFontMap * map, xmlNodePtr root)
-{
-	xmlNodePtr child;
-
-	for (child = root->xmlChildrenNode; child != NULL; child = child->next) {
-		if (!strcmp (child->name, "font")) {
-			xmlChar *format;
-			/* We are font */
-			format = xmlGetProp (child, "format");
-			if (format) {
-				if (!strcmp (format, "type1")) {
-					/* We are type1/type1alias entry */
-					gp_fm_load_font_2_0_type1 (map, child);
-				} else if (!strcmp (format, "type1alias")) {
-					/* We are type1/type1alias entry */
-					gp_fm_load_font_2_0_type1alias (map, child);
-				} else if (!strcmp (format, "truetype")) {
-					/* We are truetype entry */
-					gp_fm_load_font_2_0_truetype (map, child);
-				}
-				xmlFree (format);
-			}
-		} else if (!strcmp (child->name, "default")) {
-			xmlChar *font;
-			font = xmlGetProp (child, "font");
-			if (font) {
-				xmlChar *locales;
-				guchar *loc;
-				GSList *l;
-				locales = xmlGetProp (child, "locales");
-				loc = (locales) ? g_strdup (locales) : g_strdup ("C");
-				/* fixme: This is not nice (Lauris) */
-				l = g_slist_prepend (NULL, g_strdup (font));
-				l = g_slist_prepend (l, loc);
-				map->defaults = g_slist_prepend (map->defaults, l);
-				if (locales) xmlFree (locales);
-				xmlFree (font);
-			}
-		}
-	}
-}
-
-static void
-gp_fm_load_font_2_0_type1 (GPFontMap *map, xmlNodePtr node)
-{
-	GPFontEntryT1 *t1;
-	GPFontEntry *e;
-	xmlChar *xmlname, *t;
-
-	/* Get our unique name */
-	xmlname = xmlGetProp (node, "name");
-	/* Check, whether we are already registered */
-	if (g_hash_table_lookup (map->fontdict, xmlname)) {
-		xmlFree (xmlname);
-		return;
-	}
-
-	t1 = g_new0 (GPFontEntryT1, 1);
-	e = (GPFontEntry *) t1;
-
-	e->type = GP_FONT_ENTRY_TYPE1;
-	e->refcount = 1;
-	e->face = NULL;
-	e->name = g_strdup (xmlname);
-	xmlFree (xmlname);
-
-	gp_font_entry_2_0_load_data (e, node);
-	gp_font_entry_2_0_type1_load_files (t1, node);
-	if (!e->familyname || !e->psname || !t1->pfb.name) {
-		gp_font_entry_unref (e);
-		return;
-	}
-
-	e->Weight = gp_fontmap_lookup_weight (e->weight);
-
-	if (!e->speciesname) {
-		e->speciesname = gp_fm_get_species_name (e->name, e->familyname);
-	}
-
-	t = xmlGetProp (node, "italicangle");
-	if (t == NULL) {
-		gchar *p;
-		p = strstr (e->speciesname, "Italic");
-		if (!p) p = strstr (e->speciesname, "Oblique");
-		e->ItalicAngle = p ? -10.0 : 0.0;
-	} else {
-		e->ItalicAngle = atof (t);
-		xmlFree (t);
-	}
-
-	g_hash_table_insert (map->fontdict, e->name, e);
-	map->num_fonts++;
-	map->fonts = g_slist_prepend (map->fonts, e);
-}
-
-static void
-gp_fm_load_font_2_0_type1alias (GPFontMap *map, xmlNodePtr node)
-{
-	GPFontEntryT1Alias *t1a;
-	GPFontEntryT1 *t1;
-	GPFontEntry *e;
-	xmlChar *xmlname, *xmlalias, *t;
-
-	/* Get our unique name */
-	xmlname = xmlGetProp (node, "name");
-	/* Check, whether we are already registered */
-	if (g_hash_table_lookup (map->fontdict, xmlname)) {
-		xmlFree (xmlname);
-		return;
-	}
-	/* Get our alternate PS name */
-	xmlalias = xmlGetProp (node, "alias");
-	if (!xmlalias) {
-		xmlFree (xmlname);
-		return;
-	}
-
-	t1a = g_new0 (GPFontEntryT1Alias, 1);
-	t1 = (GPFontEntryT1 *) t1a;
-	e = (GPFontEntry *) t1a;
-
-	e->type = GP_FONT_ENTRY_TYPE1_ALIAS;
-	e->refcount = 1;
-	e->face = NULL;
-	e->name = g_strdup (xmlname);
-	xmlFree (xmlname);
-	t1a->alias = g_strdup (xmlalias);
-	xmlFree (xmlalias);
-
-	gp_font_entry_2_0_load_data (e, node);
-	gp_font_entry_2_0_type1_load_files (t1, node);
-	if (!e->familyname || !e->psname || !t1->pfb.name) {
-		gp_font_entry_unref (e);
-		return;
-	}
-
-	e->Weight = gp_fontmap_lookup_weight (e->weight);
-
-	if (!e->speciesname) {
-		e->speciesname = gp_fm_get_species_name (e->name, e->familyname);
-	}
-
-	t = xmlGetProp (node, "italicangle");
-	if (t == NULL) {
-		gchar *p;
-		p = strstr (e->speciesname, "Italic");
-		if (!p) p = strstr (e->speciesname, "Oblique");
-		e->ItalicAngle = p ? -10.0 : 0.0;
-	} else {
-		e->ItalicAngle = atof (t);
-		xmlFree (t);
-	}
-
-	g_hash_table_insert (map->fontdict, e->name, e);
-	map->num_fonts++;
-	map->fonts = g_slist_prepend (map->fonts, e);
-}
-
-static void
-gp_fm_load_font_2_0_truetype (GPFontMap *map, xmlNodePtr node)
-{
-	GPFontEntryTT *tt;
-	GPFontEntry *e;
-	xmlChar *xmlname, *t;
-
-	/* Get our unique name */
-	xmlname = xmlGetProp (node, "name");
-	/* Check, whether we are already registered */
-	if (g_hash_table_lookup (map->fontdict, xmlname)) {
-		xmlFree (xmlname);
-		return;
-	}
-
-	tt = g_new0 (GPFontEntryTT, 1);
-	e = (GPFontEntry *) tt;
-
-	e->type = GP_FONT_ENTRY_TRUETYPE;
-	e->refcount = 1;
-	e->face = NULL;
-	e->name = g_strdup (xmlname);
-	xmlFree (xmlname);
-
-	gp_font_entry_2_0_load_data (e, node);
-	gp_font_entry_2_0_truetype_load_files (tt, node);
-	if (!e->familyname || !e->psname || !tt->ttf.name) {
-		gp_font_entry_unref (e);
-		return;
-	}
-
-	e->Weight = gp_fontmap_lookup_weight (e->weight);
-
-	if (!e->speciesname) {
-		e->speciesname = gp_fm_get_species_name (e->name, e->familyname);
-	}
-
-	t = xmlGetProp (node, "italicangle");
-	if (t == NULL) {
-		gchar *p;
-		p = strstr (e->speciesname, "Italic");
-		if (!p) p = strstr (e->speciesname, "Oblique");
-		e->ItalicAngle = p ? -10.0 : 0.0;
-	} else {
-		e->ItalicAngle = atof (t);
-		xmlFree (t);
-	}
-
-	t = xmlGetProp (node, "subface");
-	tt->facenum = (t) ? atoi (t) : 0;
-	if (t) xmlFree (t);
-
-	g_hash_table_insert (map->fontdict, e->name, e);
-	map->num_fonts++;
-	map->fonts = g_slist_prepend (map->fonts, e);
-}
-
-/* Loads common font property data */
-
-static void
-gp_font_entry_2_0_load_data (GPFontEntry *e, xmlNodePtr node)
-{
-	/* fixme: We could do some checking here to save alloc/free calls */
-	/* name is parsed by parent */
-	e->version = gp_xmlGetPropString (node, "version");
-	e->familyname = gp_xmlGetPropString (node, "familyname");
-	e->speciesname = gp_xmlGetPropString (node, "speciesname");
-	e->psname = gp_xmlGetPropString (node, "psname");
-	/* Read Weight attribute */
-	e->weight = gp_xmlGetPropString (node, "weight");
-	if (!e->weight) e->weight = g_strdup ("Book");
-}
-
-/* Loads "afm" and "pfb" file nodes */
-
-static void
-gp_font_entry_2_0_type1_load_files (GPFontEntryT1 *t1, xmlNodePtr node)
-{
-	xmlNodePtr child;
-
-	for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
-		/* Scan all children nodes */
-		if (!strcmp (child->name, "file")) {
-			xmlChar *type;
-			/* We are <file> node */
-			type = xmlGetProp (child, "type");
-			if (type && !strcmp (type, "afm") && !t1->afm.name) {
-				t1->afm.name = gp_xmlGetPropString (child, "path");
-			} else if (type && !strcmp (type, "pfb") && !t1->pfb.name) {
-				t1->pfb.name = gp_xmlGetPropString (child, "path");
-			}
-			if (type) xmlFree (type);
-		}
-		if (t1->afm.name && t1->pfb.name) return;
-	}
-}
-
-/* Loads "afm" and "pfb" file nodes */
-
-static void
-gp_font_entry_2_0_truetype_load_files (GPFontEntryTT *tt, xmlNodePtr node)
-{
-	xmlNodePtr child;
-
-	for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
-		/* Scan all children nodes */
-		if (!strcmp (child->name, "file")) {
-			xmlChar *type;
-			/* We are <file> node */
-			type = xmlGetProp (child, "type");
-			if (type && !strcmp (type, "ttf") && !tt->ttf.name) {
-				tt->ttf.name = gp_xmlGetPropString (child, "path");
-			}
-			if (type) xmlFree (type);
-		}
-		if (tt->ttf.name) return;
-	}
-}
-
 /* This is experimental method (not public anyways) (Lauris) */
 
 GPFontEntry *gp_font_entry_from_files (GPFontMap *map,
@@ -761,6 +495,7 @@
 		GPFontEntryT1 *t1;
 		GPFontEntryT1Alias *t1a;
 		GPFontEntrySpecial *s;
+		GPFontEntryTT *tt;
 
 		g_return_if_fail (entry->face == NULL);
 
@@ -782,6 +517,10 @@
 			break;
 		case GP_FONT_ENTRY_ALIAS:
 			break;
+		case GP_FONT_ENTRY_TRUETYPE:
+			tt = (GPFontEntryTT *) entry;
+			if (tt->ttf.name) g_free (tt->ttf.name);
+			break;
 		case GP_FONT_ENTRY_SPECIAL:
 			s = (GPFontEntrySpecial *) entry;
 			if (s->file.name) g_free (s->file.name);
@@ -880,26 +619,6 @@
 	gp_fontmap_unref (map);
 }
 
-/*
- * Returns newly allocated string or NULL
- */
-
-static gchar *
-gp_xmlGetPropString (xmlNodePtr node, const gchar * name)
-{
-	xmlChar * prop;
-	gchar * str;
-
-	prop = xmlGetProp (node, name);
-	if (prop) {
-		str = g_strdup (prop);
-		xmlFree (prop);
-		return str;
-	}
-
-	return NULL;
-}
-
 static gint
 gp_fe_sortname (gconstpointer a, gconstpointer b)
 {
@@ -918,24 +637,6 @@
 	return strcasecmp (((GPFamilyEntry *) a)->name, ((GPFamilyEntry *) b)->name);
 }
 
-static gchar *
-gp_fm_get_species_name (const gchar * fullname, const gchar * familyname)
-{
-	gchar * p;
-
-	p = strstr (fullname, familyname);
-
-	if (!p) return g_strdup ("Normal");
-
-	p = p + strlen (familyname);
-
-	while (*p && (*p < 'A')) p++;
-
-	if (!*p) return g_strdup ("Normal");
-
-	return g_strdup (p);
-}
-
 GnomeFontWeight
 gp_fontmap_lookup_weight (const gchar * weight)
 {
@@ -980,43 +681,4 @@
 	wcode = GPOINTER_TO_INT (g_hash_table_lookup (weights, weight));
 
 	return wcode;
-}
-
-/*
- * This is not correct, if you only edit some file,
- * but I do not want to keep timestamps for all fontmaps
- * files. So please touch directory, after editing
- * files manually.
- */
-
-static gboolean
-gp_fm_is_changed (GPFontMap * map)
-{
-	struct stat s;
-	const gchar *homedir;
-	gchar *userdir;
-
-	homedir = g_get_home_dir ();
-	if (homedir) {
-		userdir = g_strdup_printf ("%s/.gnome/fonts", homedir);
-		if (!stat (userdir, &s) && !S_ISDIR (s.st_mode)) {
-			/* User dir does not exist */
-			g_free (userdir);
-			if (s.st_mtime != map->mtime_user) return TRUE;
-		} else {
-			g_free (userdir);
-		}
-	}
-
-	if (!stat (FONTMAPDIR_DYNAMIC, &s) && S_ISDIR (s.st_mode)) {
-		/* Dynamic dir exists */
-		if (s.st_mtime != map->mtime_dynamic) return TRUE;
-	}
-
-	if (!stat (FONTMAPDIR_STATIC, &s) && S_ISDIR (s.st_mode)) {
-		/* Static dir exists */
-		if (s.st_mtime != map->mtime_static) return TRUE;
-	}
-
-	return FALSE;
 }
Index: libgnomeprint/drivers/Makefile.am
===================================================================
RCS file: /cvs/gnome/libgnomeprint/libgnomeprint/drivers/Makefile.am,v
retrieving revision 1.8
diff -u -r1.8 Makefile.am
--- libgnomeprint/drivers/Makefile.am	26 Aug 2002 04:28:47 -0000	1.8
+++ libgnomeprint/drivers/Makefile.am	31 Oct 2002 14:32:23 -0000
@@ -11,7 +11,7 @@
 libgnomeprint_fax_la_LDFLAGS =  -version-info 0:0:0 -module
 libgnomeprint_fax_la_LIBADD =
 
-libexecdir = $(GNOME_PRINT_MODULES_DIR)/drivers
+plugindir = $(GNOME_PRINT_MODULES_DIR)/drivers
 
 if HAVE_OMNI
 omni_libraries = $(OMNI2_LIB)
@@ -23,7 +23,7 @@
 omni_libadd =
 endif
 
-libexec_LTLIBRARIES = \
+plugin_LTLIBRARIES = \
 	$(FAX_LIB) \
 	$(omni_libraries)
 noinst_LTLIBRARIES =
Index: libgnomeprint/transports/Makefile.am
===================================================================
RCS file: /cvs/gnome/libgnomeprint/libgnomeprint/transports/Makefile.am,v
retrieving revision 1.10
diff -u -r1.10 Makefile.am
--- libgnomeprint/transports/Makefile.am	29 Aug 2002 17:12:50 -0000	1.10
+++ libgnomeprint/transports/Makefile.am	31 Oct 2002 14:32:23 -0000
@@ -1,5 +1,5 @@
-libexecdir = $(GNOME_PRINT_MODULES_DIR)/transports
-libexec_LTLIBRARIES = \
+plugindir = $(GNOME_PRINT_MODULES_DIR)/transports
+plugin_LTLIBRARIES = \
 	$(FILE_LIB) \
 	$(LPR_LIB) \
 	$(CUSTOM_LIB)
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/gnome/libgnomeprint/tests/Makefile.am,v
retrieving revision 1.27
diff -u -r1.27 Makefile.am
--- tests/Makefile.am	29 Aug 2002 21:04:43 -0000	1.27
+++ tests/Makefile.am	31 Oct 2002 14:32:23 -0000
@@ -2,7 +2,7 @@
 
 CFLAGS=$(WARN_CFLAGS)
 
-noinst_PROGRAMS = generate gpa-test
+noinst_PROGRAMS = generate gpa-test fonts
 
 INCLUDES = \
 	-I$(top_srcdir) \
@@ -24,3 +24,7 @@
 gpa_test_LDFLAGS =
 gpa_test_DEPENDENCIES = $(DEPS)
 gpa_test_LDADD = $(print_libs)
+
+fonts_SOURCES = fonts.c
+fonts_LDFLAGS =
+fonts_LDADD = $(print_libs)
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  fonts.c: test functions for the libgpa config database
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Authors:
 *    Tambet Ingo <tambet@ximian.com>
 *
 *  Copyright (C) 2002 Ximian Inc. and authors
 *
 */

#include <popt.h>
#include <glib.h>
#include <libgnomeprint/gnome-font.h>

gboolean dump_list = FALSE;
gboolean dump_long_list = FALSE;

static struct poptOption options[] = {
	{ "list", 'l', POPT_ARG_NONE, &dump_list,   0,
	  "List fonts gnome-print knows about (Default action)", NULL},
	{ "list-full", 'f', POPT_ARG_NONE, &dump_long_list,   0,
	  "Dump full list of fonts and their properties",  NULL},
	POPT_AUTOHELP
	{ NULL }
};

static void
print_short_list (void)
{
	GList *list, *tmp;
	gchar *font;

	tmp = list = gnome_font_list ();

	while (tmp) {
		font = tmp->data;
		tmp = tmp->next;

		g_print ("%s\n", font);
	}

	gnome_font_list_free (list);
}

static void
print_long_list (void)
{
	g_print ("You think it's that easy? :)\n");
}

int
main (int argc, char *argv[])
{
	poptContext popt;

	popt = poptGetContext ("test", argc, argv, options, 0);
	poptGetNextOpt (popt);

	if (dump_long_list)
		print_long_list ();
	else
		print_short_list ();

	poptFreeContext (popt);

	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]