From http://www.jwz.org/xscreensaver/xscreensaver-5.15.tar.gz
[xscreensaver] / OSX / jwxyz.m
index 604caf50dafb066ea1689f4172250918790aed2d..7fce07d45e48c49e7c44bee83e03bc4a1f79a909 100644 (file)
@@ -963,8 +963,8 @@ XFillPolygon (Display *dpy, Drawable d, GC gc,
   int i;
   push_fg_gc (d, gc, YES);
   CGContextBeginPath (d->cgc);
+  float x = 0, y = 0;
   for (i = 0; i < npoints; i++) {
-    float x, y;
     if (i > 0 && mode == CoordModePrevious) {
       x += points[i].x;
       y -= points[i].y;
@@ -1265,7 +1265,7 @@ XParseColor (Display *dpy, Colormap cmap, const char *spec, XColor *ret)
     g = (hex[spec[3]] << 4) | hex[spec[4]];
     b = (hex[spec[5]] << 4) | hex[spec[6]];
   } else if (!strcasecmp(spec,"black")) {
-    r = g = b = 0;
+//  r = g = b = 0;
   } else if (!strcasecmp(spec,"white")) {
     r = g = b = 255;
   } else if (!strcasecmp(spec,"red")) {
@@ -2418,8 +2418,21 @@ XLoadFont (Display *dpy, const char *name)
   Font fid = (Font) calloc (1, sizeof(*fid));
 
   fid->nsfont = try_native_font (name, &fid->ps_name, &fid->size);
+
+  if (!fid->nsfont && name &&
+      strchr (name, ' ') &&
+      !strchr (name, '*')) {
+    // If name contains a space but no stars, it is a native font spec --
+    // return NULL so that we know it really didn't exist.  Else, it is an
+    //  XLFD font, so keep trying.
+    XUnloadFont (dpy, fid);
+    return 0;
+  }
+
   if (! fid->nsfont)
     fid->nsfont = try_xlfd_font (name, &fid->ps_name, &fid->size);
+
+  // We should never return NULL for XLFD fonts.
   if (!fid->nsfont) {
     NSLog(@"no NSFont for \"%s\"", name);
     abort();
@@ -2438,14 +2451,17 @@ XFontStruct *
 XLoadQueryFont (Display *dpy, const char *name)
 {
   Font fid = XLoadFont (dpy, name);
+  if (!fid) return 0;
   return XQueryFont (dpy, fid);
 }
 
 int
 XUnloadFont (Display *dpy, Font fid)
 {
-  free (fid->ps_name);
-  free (fid->metrics.per_char);
+  if (fid->ps_name)
+    free (fid->ps_name);
+  if (fid->metrics.per_char)
+    free (fid->metrics.per_char);
 
   // #### DAMMIT!  I can't tell what's going wrong here, but I keep getting
   //      crashes in [NSFont ascender] <- query_font, and it seems to go away