Function: create-fontset-from-fontset-spec

create-fontset-from-fontset-spec is a byte-compiled function defined in fontset.el.gz.

Signature

(create-fontset-from-fontset-spec FONTSET-SPEC &optional STYLE-VARIANT NOERROR)

Documentation

Create a fontset from fontset specification string FONTSET-SPEC.

FONTSET-SPEC is a string of the format:
FONTSET-NAME[,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1] ...
Any number of SPACE, TAB, and NEWLINE can be put before and after commas.

When a frame uses the fontset as the font parameter, the frame's default font name is derived from FONTSET-NAME by substituting
"iso8859-1" for the tail part "fontset-XXX". But, if SCRIPT-NAMEn
is "ascii", use the corresponding FONT-NAMEn as the default font name.

Optional 2nd and 3rd arguments exist just for backward compatibility, and are ignored.

It returns a name of the created fontset.

For backward compatibility, SCRIPT-NAME may be a charset name, in which case, the corresponding script is decided by the variable charset-script-alist (which see).

View in manual

Probably introduced at or before Emacs version 20.1.

Source Code

;; Defined in /usr/src/emacs/lisp/international/fontset.el.gz
(defun create-fontset-from-fontset-spec (fontset-spec
					 &optional _style-variant _noerror)
  "Create a fontset from fontset specification string FONTSET-SPEC.
FONTSET-SPEC is a string of the format:
	FONTSET-NAME[,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1] ...
Any number of SPACE, TAB, and NEWLINE can be put before and after commas.

When a frame uses the fontset as the `font' parameter, the frame's
default font name is derived from FONTSET-NAME by substituting
\"iso8859-1\" for the tail part \"fontset-XXX\".  But, if SCRIPT-NAMEn
is \"ascii\", use the corresponding FONT-NAMEn as the default font
name.

Optional 2nd and 3rd arguments exist just for backward compatibility,
and are ignored.

It returns a name of the created fontset.

For backward compatibility, SCRIPT-NAME may be a charset name, in
which case, the corresponding script is decided by the variable
`charset-script-alist' (which see)."
  (or (string-match "^[^,]+" fontset-spec)
      (error "Invalid fontset spec: %s" fontset-spec))
  (let ((idx (match-end 0))
	(name (match-string 0 fontset-spec))
	default-spec target script fontlist)
    (or (string-match xlfd-tight-regexp name)
	(error "Fontset name \"%s\" not conforming to XLFD" name))
    (setq default-spec (font-spec :name name))
    ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
    (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
			 fontset-spec idx)
      (setq idx (match-end 0))
      (setq target (intern (match-string 1 fontset-spec)))
      (cond ((or (eq target 'ascii)
		 (memq target (char-table-extra-slot char-script-table 0)))
	     (push (list target (match-string 2 fontset-spec)) fontlist))
	    ((setq script (cdr (assq target charset-script-alist)))
	     (push (list script (match-string 2 fontset-spec)) fontlist))
	    ((charsetp target)
	     (push (list target (match-string 2 fontset-spec)) fontlist))))

    ;; Complement FONTLIST.
    (setq fontlist (x-complement-fontset-spec default-spec fontlist))

    ;; Create a fontset.
    (new-fontset name (nreverse fontlist))))