From 2a60462172f9e077e6df0887654a5e54fe4ce204 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 26 Apr 2016 00:36:52 +0200 Subject: [aux] probe multiple characters when guessing the capital height MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide fallbacks in case no ‘X’ character is available for capheight measurement. --- src/luaotfload-auxiliary.lua | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua index 22f8201..06821f6 100644 --- a/src/luaotfload-auxiliary.lua +++ b/src/luaotfload-auxiliary.lua @@ -177,14 +177,32 @@ Comment from fontspec: --doc]]-- -local capheight_reference_char = stringbyte "X" -- might be ‘M’, ‘Ж’, or ‘ξ’. +local capheight_reference_chars = { "X", "M", "Ж", "ξ", } +local capheight_reference_codepoints do + local utfbyte = unicode.utf8.byte + capheight_reference_codepoints = { } + for i = 1, #capheight_reference_chars do + local chr = capheight_reference_chars [i] + capheight_reference_codepoints [i] = utfbyte (chr) + end +end local determine_capheight = function (fontdata) local parameters = fontdata.parameters if not parameters then return false end local characters = fontdata.characters if not characters then return false end - local refchar = characters [capheight_reference_char] - if refchar then - return refchar.height + --- Pretty simplistic but it does return *some* value for most fonts; + --- we could also refine the approach to return some kind of average + --- of all capital letters or a user-provided subset. + for i = 1, #capheight_reference_codepoints do + local refcp = capheight_reference_codepoints [i] + local refchar = characters [refcp] + if refchar then + logreport ("both", 4, "aux", + "picked height of character ‘%s’ (U+%d) as \\fontdimen8 \z + candidate", + capheight_reference_chars [i], refcp) + return refchar.height + end end return false end -- cgit v1.2.3