COMMIT sjt-xft
Gr.  Xft/fontconfig is typical X code: absolutely no argument
checking, but no documentation of what's acceptable, either.
Index: src/ChangeLog
===================================================================
RCS file: /Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/src/ChangeLog,v
retrieving revision 1.758
diff -u -r1.758 ChangeLog
--- src/ChangeLog	2004/11/14 12:19:59	1.758
+++ src/ChangeLog	2004/11/27 02:38:38
@@ -1,3 +1,23 @@
+2004-11-27  Stephen J. Turnbull  <stephen(a)xemacs.org>
+
+	* xft-fonts.h: Declare debug_xft.
+
+	* objects-x.c (x_font_instance_truename):
+	Convert Xft* identifiers to Fc* versions.
+
+	(x_initialize_font_instance):
+	(x_find_charset_font):
+	Condition debugging on debug_xft.  Get rid of unneeded "####
+	debug" markers.  Change fprintf to stderr_out.
+
+	(x_find_charset_font): Restore missing argument to
+	DebugFcTypeOfValue.  Remove nonworking debug cruft.
+
+	(FcResultToString):
+	(FcTypeOfValueToString):
+	(x_find_charset_font):
+	Change DebugFc* to Fc*ToString.
+
 2004-11-12  Marcus Crestani  <crestani(a)informatik.uni-tuebingen.de>
 
 	* Makefile.in.in: Fix pdump build for Cygwin.
Index: src/objects-x.c
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/src/objects-x.c,v
retrieving revision 1.26.2.1
diff -u -r1.26.2.1 objects-x.c
--- src/objects-x.c	2004/11/25 12:44:15	1.26.2.1
+++ src/objects-x.c	2004/11/27 02:36:53
@@ -212,8 +212,8 @@
 
   LISP_STRING_TO_EXTERNAL (f->name, extname, Qx_font_name_encoding);
 
-  /* #### debug */
-  stderr_out ("attempting to initialize font spec %s\n", extname);
+  if (debug_xft > 0)
+    stderr_out ("attempting to initialize font spec %s\n", extname);
   /* #### serialize (optimize) these later... */
 #ifdef USE_XFT
   rf = xft_open_font_by_name (dpy, extname);
@@ -225,8 +225,8 @@
       /* #### should this refer to X and/or Xft? */
       maybe_signal_error (Qgui_error, "Couldn't load font", f->name,
 			  Qfont, errb);
-      /* #### debug */
-      stderr_out ("failed to initialize font spec %s\n", extname);
+      if (debug_xft > 0)
+	stderr_out ("failed to initialize font spec %s\n", extname);
       return 0;
     }
 
@@ -265,8 +265,8 @@
 	f->height = rf->height;
       /* #### is this right?  See comment on proportional_p below. */
       f->proportional_p = 1; /* we can't recognize monospaced fonts! */
-      /* #### debug */
-      stderr_out ("initialized Xft font %s\n", extname);
+      if (debug_xft > 0)
+	stderr_out ("initialized Xft font %s\n", extname);
     } 
       
   else if (fs)
@@ -332,14 +332,15 @@
       f->proportional_p = (fs->min_bounds.width != fs->max_bounds.width ||
 			   (x_handle_non_fully_specified_fonts &&
 			    !fs->all_chars_exist));
-      /* #### debug */
-      stderr_out ("initialized Xft font %s\n", extname);
+      if (debug_xft > 0)
+	stderr_out ("initialized Xft font %s\n", extname);
     }
 
-  /* #### debug: check for weirdness */
+  /* #### check for weirdness */
   if (f->height < f->width)
-    stderr_out ("width of font %s is %d, larger than its height %d\n",
-		extname, f->width, f->height);
+    if (debug_xft > 0)
+      stderr_out ("width of font %s is %d, larger than its height %d\n",
+		  extname, f->width, f->height);
 
   return 1;
 }
@@ -689,27 +690,30 @@
     {
 #ifdef USE_XFT
       int core;
-      XftPattern *pat = FONT_INSTANCE_X_XFTFONT (f)->pattern;
-      XftResult res_xlfd = XftPatternGetString(pat, XFT_XLFD, 0, &xlfd);
-      XftResult res_core = XftPatternGetBool(pat, XFT_CORE, 0, &core);
-      
-      if (res_xlfd == XftResultTypeMismatch || res_core == XftResultTypeMismatch)
+      FcPattern *pat = FONT_INSTANCE_X_XFTFONT (f)->pattern;
+      FcResult res_xlfd = FcPatternGetString (pat, XFT_XLFD, 0, &xlfd);
+      FcResult res_core = FcPatternGetBool (pat, XFT_CORE, 0, &core);
+
+      if (res_xlfd == FcResultTypeMismatch || res_core == FcResultTypeMismatch)
 	{
 	  /* we've got an Xft font! */
-	  char temp[FCSTRLEN];
-	  int res = XftNameUnparse(pat, temp, FCSTRLEN-1);
-	  Lisp_Object name = (res ? make_string(temp, strlen(temp)) : Qnil);
+	  FcChar8 *res = FcNameUnparse (pat);
+	  Lisp_Object name = (res ? make_string (res, strlen (res)) : Qnil);
+	  /* #### huh?  device?  Fc don' need no steekin' device! */
 	  Lisp_Object real_pat = Ffc_font_real_pattern (name, f->device);
-	  
-	  res = XftNameUnparse(XFCPATTERN_PTR(real_pat), temp, FCSTRLEN-1);
-	  if (res) 
+	  free (res);
+
+	  res = FcNameUnparse (XFCPATTERN_PTR(real_pat));
+	  if (res)
 	    {
-	      FONT_INSTANCE_TRUENAME (f) = make_string (temp, strlen(temp));
+	      FONT_INSTANCE_TRUENAME (f) = make_string (res, strlen (res));
+	      free (res);
 	      return FONT_INSTANCE_TRUENAME (f);
 	    }
 	  else
 	    { /* Now we're f.... */
-	      maybe_signal_error (Qgui_error, "Couldn't determine font truename",
+	      maybe_signal_error (Qgui_error,
+				  "Couldn't determine font truename",
 				  Qnil, Qfont, errb);
 	      return Qnil;
 	    }
@@ -912,7 +916,9 @@
 }
 
 /* #### debug functions: find a better place for us */
-const char *DebugFcResult (FcResult r)
+const char *FcResultToString (FcResult r);
+const char *
+FcResultToString (FcResult r)
 {
   static char buffer[256];
   switch (r)
@@ -931,7 +937,9 @@
     }
 }
 
-const char *DebugFcTypeOfValue (FcValue v)
+const char *FcTypeOfValueToString (FcValue v);
+const char *
+FcTypeOfValueToString (FcValue v)
 {
   static char buffer[256];
   switch (v.type)
@@ -985,61 +993,65 @@
   if (stage)
     return Qnil;
 
-  /* #### does Xft permit/require a different encoding?
-     #### Xft or not, this is bogus: suppose the encoding is widechar? */
+  /* #### does Xft permit/require a different encoding? */
   LISP_STRING_TO_EXTERNAL (font, patternext, Qx_font_name_encoding);
+  if (debug_xft > 0)
+    stderr_out ("confirming charset for font instance %s\n", patternext);
 
-  /* #### debug */
-  stderr_out ("confirming charset for font instance %s\n", patternext);
-
 #ifdef USE_XFT
   /* #### totally lazy, let's just get something out the door */
   waste = FcInit ();
-  /* #### debug */
-  stderr_out ("%s fontconfig initialization\n",
-	      waste ? "Successful" : "Failed");
+  if (debug_xft > 1)		/* I don't think this can fail */
+    stderr_out ("%s fontconfig initialization\n",
+		waste ? "Successful" : "Failed");
   if (waste)		/* #### should we init in xft_fonts_init()
 				   and FcInitBringUpToDate() here? */
     {
-      FcChar8 *lang;
+      FcChar8 *lang = "en";
       fcc = FcConfigGetCurrent ();
       patternxft = FcNameParse (patternext);
       /* #### Next four return FcBool, but what does the return mean? */
       /* #### There's probably a way to do this with FcCharsets, but isn't
 	 the language approach better in the long run? */
       /* #### can we regression test this, or does it break too early? */
-      stderr_out ("FcNameParse'ed name is %s\n", FcNameUnparse
(patternxft));
+      if (debug_xft > 0)
+	stderr_out ("FcNameParse'ed name is %s\n",
+		    FcNameUnparse (patternxft));
       FcConfigSubstitute (fcc, patternxft, FcMatchFont);
-      stderr_out ("FcConfigSubstitute'ed name is %s\n", FcNameUnparse
(patternxft));
+      if (debug_xft > 0)
+	stderr_out ("FcConfigSubstitute'ed name is %s\n",
+		    FcNameUnparse (patternxft));
       FcDefaultSubstitute (patternxft);
-      stderr_out ("FcDefaultSubstitute'ed name is %s\n", FcNameUnparse
(patternxft));
+      if (debug_xft > 0)
+	stderr_out ("FcDefaultSubstitute'ed name is %s\n",
+		    FcNameUnparse (patternxft));
       if (EQ (charset, Fget_charset (intern ("katakana-jisx0201")))
 	  || EQ (charset, Fget_charset (intern ("japanese-jisx0208")))
 	  || EQ (charset, Fget_charset (intern ("japanese-jisx0212"))))
 	{
-	  /* #### debug */
-	  stderr_out ("checking if %s handles Japanese\n", patternext);
+	  if (debug_xft > 0)
+	    stderr_out ("checking if %s handles Japanese\n", patternext);
 	  lang = "ja";
 	}
       else if (EQ (charset, Fget_charset (intern ("ascii"))))
 	{
-	  /* #### debug */
-	  stderr_out ("checking if %s handles English\n", patternext);
+	  if (debug_xft > 0)
+	    stderr_out ("checking if %s handles English\n", patternext);
 	  lang = "en";
 	}
-#if 0
-      {
-	/* #### debug stuff */
-	/* NOTE: This will return IDENTICALLY ZERO most of the time because
-	   most fonts support multiple languages, but this is an exact test */
-	FcObjectSet *fcos = FcObjectSetBuild (FC_FAMILY, FC_LANG, NULL);
-	FcFontSet *fcfs = FcFontList (NULL, patternxft, fcos);
-	stderr_out ("There are %d matches\n", fcfs->nfont);
-	/* #### is *fcfs a memory leak? */
-	FcObjectSetDestroy (fcos);
-      }
-#endif
+      else
+	{
+	  /* #### is this the right way to make a warning? */
+	  warn_when_safe_lispobj (intern ("xft"), Qwarning,
+				  list2 (build_string ("unknown charset"),
+					 charset));
+	  /* default to "en" */
+	}
+
       patternxft = FcFontMatch (fcc, patternxft, &fcresult);
+      /* #### stderr_out crashed in the next block; why?
+	 probably because FcTypeOfValueToString below didn't get
+	 an argument!!  Fixed now, but watch for crashes. */
       {
 	int i = 0;
 	FcValue v;
@@ -1050,9 +1062,8 @@
 	    if (v.type == FcTypeLangSet && /* #### excessive paranoia */
 		FcLangSetHasLang (v.u.l, lang) != FcLangDifferentLang)
 	      {
-		/* #### debug */
-		/* stderr_out crashed here; why? */
-		fprintf (stderr, "Xft font %s supports %s\n", patternext, lang);
+		if (debug_xft > 0)
+		  stderr_out ("Xft font %s supports %s\n", patternext, lang);
 		/* heuristic to give reasonable names */
 		FcPatternDel (patternxft, FC_CHARSET);
 		FcPatternDel (patternxft, FC_LANG);
@@ -1061,13 +1072,15 @@
 	    /* #### this is wrong, we should pass to X? */
 	    else
 	      {
-		fprintf (stderr, "Unexpected type of lang value (%s)\n",
-			    DebugFcTypeOfValue);
+		if (debug_xft > 0)
+		  stderr_out ("Unexpected type of lang value (%s)\n",
+			      FcTypeOfValueToString (v));
 		return Qnil;
 	      }
 	  }
-	fprintf (stderr, "Unexpected result getting lang (%s)\n",
-		    DebugFcResult (r));
+	if (debug_xft > 0)
+	  stderr_out ("Unexpected result getting lang (%s)\n",
+		      FcResultToString (r));
       }
     }
 #endif
@@ -1076,8 +1089,8 @@
 		      patternext, MAX_FONT_COUNT, &count);
   /* #### This code seems awfully bogus -- mrb */
   /* #### fontconfig does it better -- sjt */
-  /* #### debug */
-  stderr_out ("shit happend, try X11 charset match for %s\n", patternext);
+  if (debug_xft > 0)
+    stderr_out ("shit happens, try X11 charset match for %s\n", patternext);
   for (i = 0; i < count; i ++)
     {
       const Ibyte *intname;
Index: src/xft-fonts.h
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/src/Attic/xft-fonts.h,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 xft-fonts.h
--- src/xft-fonts.h	2004/11/25 12:44:18	1.1.2.1
+++ src/xft-fonts.h	2004/11/26 13:17:58
@@ -44,6 +44,8 @@
 #include "../lwlib/lwlib-fonts.h"
 #include "../lwlib/lwlib-colors.h"
 
+extern int debug_xft;
+
 /* #### new in xft reloaded #3; where is this used? */
 XftColor xft_get_color (Display *dpy, Colormap cmap, Lisp_Object c, int dim);
 
-- 
Institute of Policy and Planning Sciences     
http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.