static int
compare_font_names (const void *name1, const void *name2)
{
- return strcasecmp (*(const char **) name1, *(const char **) name2);
+ return xstrcasecmp (*(const unsigned char **) name1,
+ *(const unsigned char **) name2);
}
static Lisp_Object xfont_list_pattern P_ ((Lisp_Object, Display *, char *));
Lisp_Object entity;
int result;
- if (i > 0 && strcasecmp (indices[i - 1], indices[i]) == 0)
+ if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) == 0)
continue;
entity = font_make_entity ();
|| XINT (AREF (entity, FONT_AVGWIDTH_INDEX)) > 0))
list = Fcons (entity, list);
}
+ XFreeFontNames (names);
}
x_uncatch_errors ();
}
registry = AREF (spec, FONT_REGISTRY_INDEX);
- if (NILP (registry))
- ASET (spec, FONT_REGISTRY_INDEX, Qiso8859_1);
len = font_unparse_xlfd (spec, 0, name, 256);
ASET (spec, FONT_REGISTRY_INDEX, registry);
if (len < 0)
}
if (NILP (list) && ! NILP (registry))
{
+ /* Try alternate registries. */
Lisp_Object alter;
if ((alter = Fassoc (SYMBOL_NAME (registry),
}
}
}
+ if (NILP (list))
+ {
+ /* Try alias. */
+ val = assq_no_quit (QCname, AREF (spec, FONT_EXTRA_INDEX));
+ if (CONSP (val) && STRINGP (XCDR (val)))
+ list = xfont_list_pattern (frame, display, (char *) SDATA (XCDR (val)));
+ }
return list;
}
continue;
last_len = p1 - p0;
last_family = p0;
- family = make_unibyte_string (p0, last_len);
- if (NILP (Fassoc_string (family, list, Qt)))
+ family = font_intern_prop (p0, last_len, 1);
+ if (NILP (assq_no_quit (family, list)))
list = Fcons (family, list);
}
font. */
registry = AREF (entity, FONT_REGISTRY_INDEX);
if (font_registry_charsets (registry, &encoding, &repertory) < 0)
- return Qnil;
+ {
+ font_add_log (" x:unknown registry", registry, Qnil);
+ return Qnil;
+ }
if (XINT (AREF (entity, FONT_SIZE_INDEX)) != 0)
pixel_size = XINT (AREF (entity, FONT_SIZE_INDEX));
}
len = font_unparse_xlfd (entity, pixel_size, name, 256);
if (len <= 0)
- return Qnil;
+ {
+ font_add_log (" x:unparse failed", entity, Qnil);
+ return Qnil;
+ }
BLOCK_INPUT;
x_catch_errors (display);
x_clear_errors (display);
xfont = NULL;
}
+ else if (! xfont)
+ {
+ /* Some version of X lists:
+ -misc-fixed-medium-r-normal--20-*-75-75-c-100-iso8859-1
+ -misc-fixed-medium-r-normal--20-*-100-100-c-100-iso8859-1
+ but can open only:
+ -misc-fixed-medium-r-normal--20-*-100-100-c-100-iso8859-1
+ and
+ -misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1
+ So, we try again with wildcards in RESX and RESY. */
+ Lisp_Object temp;
+
+ temp = Fcopy_font_spec (entity);
+ ASET (temp, FONT_DPI_INDEX, Qnil);
+ len = font_unparse_xlfd (temp, pixel_size, name, 256);
+ if (len <= 0)
+ {
+ font_add_log (" x:unparse failed", temp, Qnil);
+ return Qnil;
+ }
+ xfont = XLoadQueryFont (display, name);
+ if (x_had_errors_p (display))
+ {
+ /* This error is perhaps due to insufficient memory on X server.
+ Let's just ignore it. */
+ x_clear_errors (display);
+ xfont = NULL;
+ }
+ }
fullname = Qnil;
/* Try to get the full name of FONT. */
if (xfont && XGetFontProperty (xfont, XA_FONT, &value))
UNBLOCK_INPUT;
if (! xfont)
- return Qnil;
+ {
+ font_add_log (" x:open failed", build_string (name), Qnil);
+ return Qnil;
+ }
- font_object = font_make_object (VECSIZE (struct xfont_info));
+ font_object = font_make_object (VECSIZE (struct xfont_info),
+ entity, pixel_size);
ASET (font_object, FONT_TYPE_INDEX, Qx);
if (STRINGP (fullname))
font_parse_xlfd ((char *) SDATA (fullname), font_object);
- for (i = 1; i < FONT_ENTITY_MAX; i++)
- ASET (font_object, i, AREF (entity, i));
- ASET (font_object, FONT_SIZE_INDEX, make_number (pixel_size));
if (STRINGP (fullname))
ASET (font_object, FONT_NAME_INDEX, fullname);
else
for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
if ((pcm = xfont_get_pcm (xfont, &char2b)) != NULL)
width += pcm->width, n++;
- font->average_width = width / n;
+ if (n > 0)
+ font->average_width = width / n;
}
+ if (font->average_width == 0)
+ /* No easy way other than this to get a reasonable
+ average_width. */
+ font->average_width
+ = (xfont->min_bounds.width + xfont->max_bounds.width) / 2;
}
BLOCK_INPUT;
{
XFontStruct *xfont = ((struct xfont_info *) font)->xfont;
int width = 0;
- int i, x;
+ int i, first, x;
if (metrics)
bzero (metrics, sizeof (struct font_metrics));
- for (i = 0, x = 0; i < nglyphs; i++)
+ for (i = 0, x = 0, first = 1; i < nglyphs; i++)
{
XChar2b char2b;
static XCharStruct *pcm;
pcm = xfont_get_pcm (xfont, &char2b);
if (! pcm)
continue;
- if (metrics->lbearing > width + pcm->lbearing)
- metrics->lbearing = width + pcm->lbearing;
- if (metrics->rbearing < width + pcm->rbearing)
- metrics->rbearing = width + pcm->rbearing;
- if (metrics->ascent < pcm->ascent)
- metrics->ascent = pcm->ascent;
- if (metrics->descent < pcm->descent)
- metrics->descent = pcm->descent;
+ if (first)
+ {
+ if (metrics)
+ {
+ metrics->lbearing = pcm->lbearing;
+ metrics->rbearing = pcm->rbearing;
+ metrics->ascent = pcm->ascent;
+ metrics->descent = pcm->descent;
+ }
+ first = 0;
+ }
+ else
+ {
+ if (metrics)
+ {
+ if (metrics->lbearing > width + pcm->lbearing)
+ metrics->lbearing = width + pcm->lbearing;
+ if (metrics->rbearing < width + pcm->rbearing)
+ metrics->rbearing = width + pcm->rbearing;
+ if (metrics->ascent < pcm->ascent)
+ metrics->ascent = pcm->ascent;
+ if (metrics->descent < pcm->descent)
+ metrics->descent = pcm->descent;
+ }
+ }
width += pcm->width;
}
if (metrics)