changeset 22672:9cfa1a788a5a

(create-fontset-from-fontset-spec): Returns a created fontset. (create-fontset-from-ascii-font): New function.
author Kenichi Handa <handa@m17n.org>
date Fri, 03 Jul 1998 04:39:22 +0000
parents 5dee1f64801f
children e61968818555
files lisp/international/fontset.el
diffstat 1 files changed, 62 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/international/fontset.el	Fri Jul 03 04:39:22 1998 +0000
+++ b/lisp/international/fontset.el	Fri Jul 03 04:39:22 1998 +0000
@@ -456,7 +456,9 @@
 fontset uses the font for ASCII character set.
 
 If this function attempts to create already existing fontset, error is
-signaled unless the optional 3rd argument NOERROR is non-nil."
+signaled unless the optional 3rd argument NOERROR is non-nil.
+
+It returns a name of the created fontset."
   (if (not (string-match "^[^,]+" fontset-spec))
       (error "Invalid fontset spec: %s" fontset-spec))
   (let ((idx (match-end 0))
@@ -540,7 +542,65 @@
 		  (setq fontset-alias-alist
 			(cons (cons new-name new-ascii-font)
 			      fontset-alias-alist)))
-		(setq style-variant (cdr style-variant)))))))))
+		(setq style-variant (cdr style-variant)))))))
+    name))
+
+(defun create-fontset-from-ascii-font (font &optional resolved-font
+					    fontset-name)
+  "Create a fontset from an ASCII font FONT.
+
+Optional 1st arg RESOLVED-FONT is a resolved name of FONT.  If
+omitted, x-resolve-font-name is called to get the resolved name.  At
+this time, if FONT is not avairable, error is signaled.
+
+Optional 2nd arg FONTSET-NAME is a string to be used in
+`<CHARSET_ENCODING>' fields of a new fontset name.  If it is omitted,
+an appropriate name is generated automatically.
+
+Style variants of the fontset is created too.  Font names in the
+variants are generated automatially from FONT unless X resources
+XXX.attribyteFont explicitly specify them.
+
+It returns a name of the created fontset."
+  (or resolved-font
+      (setq resolved-font (x-resolve-font-name font)))
+  (let* ((faces (copy-sequence fontset-default-styles))
+	 (styles faces)
+	 (xlfd (x-decompose-font-name font))
+	 (resolved-xlfd  (x-decompose-font-name resolved-font))
+	 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
+	  (setcar faces (cons face face-font)))
+      (setq faces (cdr faces)))
+    (aset xlfd xlfd-regexp-foundry-subnum nil)
+    (aset xlfd xlfd-regexp-family-subnum nil)
+    (aset xlfd xlfd-regexp-registry-subnum "fontset")
+    (or fontset-name
+	(setq fontset-name
+	      (format "%s_%s_%s"
+		      (aref resolved-xlfd xlfd-regexp-registry-subnum)
+		      (aref resolved-xlfd xlfd-regexp-encoding-subnum)
+		      (aref resolved-xlfd xlfd-regexp-pixelsize-subnum))))
+    (aset xlfd xlfd-regexp-encoding-subnum fontset-name)
+    ;; The fontset name should have concrete values in weight and
+    ;; slant field.
+    (let ((weight (aref xlfd xlfd-regexp-weight-subnum))
+	  (slant (aref xlfd xlfd-regexp-slant-subnum)))
+      (if (or (not weight) (string-match "[*?]*" weight))
+	  (aset xlfd xlfd-regexp-weight-subnum
+		(aref resolved-xlfd xlfd-regexp-weight-subnum)))
+      (if (or (not slant) (string-match "[*?]*" slant))
+	  (aset xlfd xlfd-regexp-slant-subnum
+		(aref resolved-xlfd xlfd-regexp-slant-subnum))))
+    (setq fontset (x-compose-font-name xlfd))
+    (or (query-fontset fontset)
+	(create-fontset-from-fontset-spec (concat fontset ", ascii:" font)
+					  styles))))
 
 (defun instantiate-fontset (fontset)
   "Make FONTSET be readly to use.