changeset 4362:f5693b5f7f2d

Compute size for Xft fonts. 2007-12-23 Mike Sperber <mike@xemacs.org> * font.el (xft-font-create-object): Use `fc-pattern-get-or-compute-size' instead of `fc-pattern-get-size'. * fontconfig.el (fc-pattern-get-or-compute-size): Add.
author Mike Sperber <sperber@deinprogramm.de>
date Thu, 27 Dec 2007 08:16:15 +0100
parents 146742e30f05
children c9ab656691c0
files lisp/ChangeLog lisp/font.el lisp/fontconfig.el
diffstat 3 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Dec 26 22:38:40 2007 -0800
+++ b/lisp/ChangeLog	Thu Dec 27 08:16:15 2007 +0100
@@ -1,3 +1,11 @@
+2007-12-23  Mike Sperber  <mike@xemacs.org>
+
+	* font.el (xft-font-create-object): Use
+	`fc-pattern-get-or-compute-size' instead of
+	`fc-pattern-get-size'.
+
+	* fontconfig.el (fc-pattern-get-or-compute-size): Add.
+
 2007-12-22  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	Factor out lists of operators specially treated by `make-autoload'.
--- a/lisp/font.el	Wed Dec 26 22:38:40 2007 -0800
+++ b/lisp/font.el	Thu Dec 27 08:16:15 2007 +0100
@@ -813,7 +813,7 @@
 	 (pattern (fc-font-match device (fc-name-parse name)))
 	 (font-obj (make-font))
 	 (family (fc-pattern-get-family pattern 0))
-	 (size (fc-pattern-get-size pattern 0))
+	 (size (fc-pattern-get-or-compute-size pattern 0))
 	 (weight (fc-pattern-get-weight pattern 0)))
     (set-font-family font-obj 
 		     (and (not (equal family 'fc-result-no-match)) 
--- a/lisp/fontconfig.el	Wed Dec 26 22:38:40 2007 -0800
+++ b/lisp/fontconfig.el	Thu Dec 27 08:16:15 2007 +0100
@@ -350,6 +350,21 @@
   (let ((pair (assoc str fc-font-name-weight-mapping-string-reverse)))
     (if pair (cdr pair))))
 
+(defun fc-pattern-get-or-compute-size (pattern id)
+  "Get the size from `pattern' associated with `id' or try to compute it.
+Returns 'fc-result-no-match if unsucessful."
+  ;;  Many font patterns don't have a "size" property, but do have a
+  ;;  "dpi" and a "pixelsize" property".
+  (let ((maybe (fc-pattern-get-size pattern id)))
+    (if (not (eq maybe 'fc-result-no-match))
+	maybe
+      (let ((dpi (fc-pattern-get-dpi pattern id))
+	    (pixelsize (fc-pattern-get-pixelsize pattern id)))
+	(if (and (numberp dpi)
+		 (numberp pixelsize))
+	    (* pixelsize (/ 72 dpi))
+	  'fc-result-no-match)))))
+
 (defun fc-copy-pattern-partial (pattern attribute-list)
   "Return a copy of PATTERN restricted to ATTRIBUTE-LIST.