summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2016-04-26 00:36:52 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2016-04-26 00:36:56 +0200
commit2a60462172f9e077e6df0887654a5e54fe4ce204 (patch)
treee49454a09277fb6d21bc375580e600c7aa1cb123
parent5efcb3555bd11f7caf6bc28d5eae8b0d4ae83026 (diff)
downloadluaotfload-2a60462172f9e077e6df0887654a5e54fe4ce204.tar.gz
[aux] probe multiple characters when guessing the capital height
Provide fallbacks in case no ‘X’ character is available for capheight measurement.
-rw-r--r--src/luaotfload-auxiliary.lua26
1 files changed, 22 insertions, 4 deletions
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