+;; W32 systems have different fonts than commonly found on X, so
+;; we define our own standard fontset here.
+(defvar w32-standard-fontset-spec
+ "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard,
+ latin-iso8859-2:-*-Courier New CE-normal-r-*-*-13-*-*-*-c-*-iso8859-2,
+ latin-iso8859-3:-*-Courier New Tur-normal-r-*-*-13-*-*-*-c-*-iso8859-3,
+ latin-iso8859-4:-*-Courier New Baltic-normal-r-*-*-13-*-*-*-c-*-iso8859-4,
+ cyrillic-iso8859-5:-*-Courier New Cyr-normal-r-*-*-13-*-*-*-c-*-iso8859-5,
+ greek-iso8859-7:-*-Courier New Greek-normal-r-*-*-13-*-*-*-c-*-iso8859-7"
+ "String of fontset spec of the standard fontset. This defines a
+fontset consisting of the Courier New variations for European
+languages which are distributed with Windows as \"Multilanguage Support\".
+
+See the documentation of `create-fontset-from-fontset-spec for the format.")
+
+(if (fboundp 'new-fontset)
+ (progn
+ (defun w32-create-initial-fontsets ()
+ "Create fontset-startup, fontset-standard and any fontsets
+specified in X resources."
+ ;; Create the standard fontset.
+ (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
+
+ ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
+ (create-fontset-from-x-resource)
+
+ ;; Try to create a fontset from a font specification which comes
+ ;; from initial-frame-alist, default-frame-alist, or X resource.
+ ;; A font specification in command line argument (i.e. -fn XXXX)
+ ;; should be already in default-frame-alist as a `font'
+ ;; parameter. However, any font specifications in site-start
+ ;; library, user's init file (.emacs), and default.el are not
+ ;; yet handled here.
+
+ (let ((font (or (cdr (assq 'font initial-frame-alist))
+ (cdr (assq 'font default-frame-alist))
+ (x-get-resource "font" "Font")))
+ xlfd-fields resolved-name)
+ (if (and font
+ (not (query-fontset font))
+ (setq resolved-name (x-resolve-font-name font))
+ (setq xlfd-fields (x-decompose-font-name font)))
+ (if (string= "fontset"
+ (aref xlfd-fields xlfd-regexp-registry-subnum))
+ (new-fontset font
+ (x-complement-fontset-spec xlfd-fields nil))
+ ;; Create a fontset from FONT. The fontset name is
+ ;; generated from FONT. Create style variants of the
+ ;; fontset too. Font names in the variants are
+ ;; generated automatially unless X resources
+ ;; XXX.attribyteFont explicitly specify them.
+ (let ((styles (mapcar 'car x-style-funcs-alist))
+ (faces '(bold italic bold-italic))
+ face face-font fontset fontset-spec)
+ (while faces
+ (setq face (car faces))
+ (setq face-font (x-get-resource (concat (symbol-name face)
+ ".attributeFont")
+ "Face.AttributeFont"))
+ (if face-font
+ (setq styles (cons (cons face face-font)
+ (delq face styles))))
+ (setq faces (cdr faces)))
+ (aset xlfd-fields xlfd-regexp-foundry-subnum nil)
+ (aset xlfd-fields xlfd-regexp-family-subnum nil)
+ (aset xlfd-fields xlfd-regexp-registry-subnum "fontset")
+ (aset xlfd-fields xlfd-regexp-encoding-subnum "startup")
+ ;; The fontset name should have concrete values in
+ ;; weight and slant field.
+ (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
+ (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
+ xlfd-temp)
+ (if (or (not weight) (string-match "[*?]*" weight))
+ (progn
+ (setq xlfd-temp
+ (x-decompose-font-name resolved-name))
+ (aset xlfd-fields xlfd-regexp-weight-subnum
+ (aref xlfd-temp xlfd-regexp-weight-subnum))))
+ (if (or (not slant) (string-match "[*?]*" slant))
+ (progn
+ (or xlfd-temp
+ (setq xlfd-temp
+ (x-decompose-font-name resolved-name)))
+ (aset xlfd-fields xlfd-regexp-slant-subnum
+ (aref xlfd-temp xlfd-regexp-slant-subnum)))))
+ (setq fontset (x-compose-font-name xlfd-fields))
+ (create-fontset-from-fontset-spec
+ (concat fontset ", ascii:" font) styles)
+ )))))
+ ;; This cannot be run yet, as creating fontsets requires a
+ ;; Window to be initialised so the fonts can be listed.
+ ;; Add it to a hook so it gets run later.
+ (add-hook 'before-init-hook 'w32-create-initial-fontsets)
+ ))
+