Function: list-fonts

list-fonts is a function defined in font.c.

Signature

(list-fonts FONT-SPEC &optional FRAME NUM PREFER)

Documentation

List available fonts matching FONT-SPEC on the current frame.

Optional 2nd argument FRAME specifies the target frame. Optional 3rd argument NUM, if non-nil, limits the number of returned fonts. Optional 4th argument PREFER, if non-nil, is a font-spec to control the order of the returned list. Fonts are sorted by how close they are to PREFER.

View in manual

Probably introduced at or before Emacs version 23.1.

Source Code

// Defined in /usr/src/emacs/src/font.c
{
  struct frame *f = decode_live_frame (frame);
  Lisp_Object vec, list;
  EMACS_INT n = 0;

  CHECK_FONT_SPEC (font_spec);
  if (! NILP (num))
    {
      CHECK_FIXNUM (num);
      n = XFIXNUM (num);
      if (n <= 0)
	return Qnil;
    }
  if (! NILP (prefer))
    CHECK_FONT_SPEC (prefer);

  list = font_list_entities (f, font_spec);
  if (NILP (list))
    return Qnil;
  if (NILP (XCDR (list))
      && ASIZE (XCAR (list)) == 1)
    return list1 (AREF (XCAR (list), 0));

  if (! NILP (prefer))
    vec = font_sort_entities (list, prefer, f, 0);
  else
    vec = font_vconcat_entity_vectors (list);
  if (n == 0 || n >= ASIZE (vec))
    list = CALLN (Fappend, vec, Qnil);
  else
    {
      for (list = Qnil, n--; n >= 0; n--)
	list = Fcons (AREF (vec, n), list);
    }
  return list;
}