Function: font-spec

font-spec is a function defined in font.c.

Signature

(font-spec ARGS...)

Documentation

Return a newly created font-spec with arguments as properties.

ARGS must come in pairs KEY VALUE of font properties. KEY must be a valid font property name listed below:

:family, :weight, :slant, :width

They are the same as face attributes of the same name (see set-face-attribute), except that :family could also be a symbol, and the value of the other three properties can also be a number, the numerical value of the style.

:foundry

VALUE must be a string or a symbol specifying the font foundry, e.g. misc.

:adstyle

VALUE must be a string or a symbol specifying the additional typographic style information of a font, e.g. sans.

:registry

VALUE must be a string or a symbol specifying the charset registry and encoding of a font, e.g. iso8859-1.

:size

VALUE must be a non-negative integer or a floating point number specifying the font size. It specifies the font size in pixels (if VALUE is an integer), or in points (if VALUE is a float).

:dpi

VALUE must be a non-negative number that specifies the resolution
(dot per inch) for which the font is designed.

:spacing

VALUE specifies the spacing of the font: mono, proportional, charcell, or dual. It can be either a number (0 for proportional, 90 for dual,
100 for mono, 110 for charcell) or a 1-letter symbol: P, D, M,
or C (lower-case variants are also accepted).

:avgwidth

VALUE must be a non-negative integer specifying the average width of the font in 1/10 pixel units.

:name

VALUE must be a string of XLFD-style or fontconfig-style font name.

:script

VALUE must be a symbol representing a script that the font must support. It may be a symbol representing a subgroup of a script listed in the variable script-representative-chars.

:lang

VALUE must be a symbol whose name is a two-letter ISO-639 language name, e.g. ja. The value is matched against the "Additional Style" field of the XLFD spec of a font, if it's non-empty, on X, and against the codepages supported by the font on w32.

:otf

VALUE must be a list (SCRIPT-TAG LANGSYS-TAG GSUB [ GPOS ]) to specify required OpenType features.

  SCRIPT-TAG: OpenType script tag symbol (e.g. deva).
  LANGSYS-TAG: OpenType language system tag symbol,
     or nil for the default language system.
  GSUB: List of OpenType GSUB feature tag symbols, or nil if none required.
  GPOS: List of OpenType GPOS feature tag symbols, or nil if none required.

GSUB and GPOS may contain nil elements. In such a case, the font must not have any of the remaining elements.

For instance, if the VALUE is (thai nil nil (mark)), the font must be an OpenType font whose GPOS table of thai script's default language system must contain mark feature.

View in manual

Probably introduced at or before Emacs version 23.1.

Source Code

// Defined in /usr/src/emacs/src/font.c
{
  Lisp_Object spec = font_make_spec ();
  ptrdiff_t i;

  for (i = 0; i < nargs; i += 2)
    {
      Lisp_Object key = args[i], val;

      CHECK_SYMBOL (key);
      if (i + 1 >= nargs)
	error ("No value for key `%s'", SDATA (SYMBOL_NAME (key)));
      val = args[i + 1];

      if (EQ (key, QCname))
	{
	  CHECK_STRING (val);
	  if (font_parse_name (SSDATA (val), SBYTES (val), spec) < 0)
	    error ("Invalid font name: %s", SSDATA (val));
	  font_put_extra (spec, key, val);
	}
      else
	{
	  int idx = get_font_prop_index (key);

	  if (idx >= 0)
	    {
	      val = font_prop_validate (idx, Qnil, val);
	      if (idx < FONT_EXTRA_INDEX)
		ASET (spec, idx, val);
	      else
		font_put_extra (spec, key, val);
	    }
	  else
	    font_put_extra (spec, key, font_prop_validate (0, key, val));
	}
    }
  return spec;
}