【发布时间】:2020-08-05 22:39:50
【问题描述】:
font-info 返回字体的一些指标,例如上升和下降。如何获得 x 高度?
为确保问题正文符合 Stack Overflow 的质量标准,这里有一个随机生成的俳句。我认为它实际上并没有增加任何东西,但我有什么资格与启发式争论呢?
Oh stack overflow
before common sense ruins
at the perfect ai
【问题讨论】:
font-info 返回字体的一些指标,例如上升和下降。如何获得 x 高度?
为确保问题正文符合 Stack Overflow 的质量标准,这里有一个随机生成的俳句。我认为它实际上并没有增加任何东西,但我有什么资格与启发式争论呢?
Oh stack overflow
before common sense ruins
at the perfect ai
【问题讨论】:
以下有效,但 1. 它需要 ttfdump(包含在 Texlive 中)和 2. 可能不适用于所有字体。
(defun my-xheight (font)
"Return the x-height of FONT."
(let* ((info (font-info font))
(file (elt info 12))
(ascent (elt info 8)))
(round (* ascent (my-xheight-frac file)))))
(defun my-xheight-frac (file)
"Return the x-height of a font as a fraction of its ascent height."
(with-temp-buffer
(let ((exitcode
(call-process "ttfdump" nil t nil "-t" "OS/2" file)))
(unless (= exitcode 0)
(error (buffer-string))))
(goto-char (point-min))
(save-match-data
(let ((sxheight (save-excursion
(search-forward-regexp (rx bol (0+ blank) "sxHeight:" (0+ blank)
(group (1+ digit))))
(string-to-number (match-string 1))))
(ascent (save-excursion
(search-forward-regexp (rx bol (0+ blank) "usWinAscent:" (0+ blank)
(group (1+ digit))))
(string-to-number (match-string 1)))))
(/ sxheight (float ascent))))))
【讨论】: