[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Allow more kinds of normalization (d42e309)
Marcel Krüger
zauguin at gmail.com
Tue Sep 14 19:44:00 CEST 2021
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/d42e30901db310c1d1f0c8ca8d3815c8d896086b
>---------------------------------------------------------------
commit d42e30901db310c1d1f0c8ca8d3815c8d896086b
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Tue Jul 6 18:13:36 2021 +0200
Allow more kinds of normalization
>---------------------------------------------------------------
d42e30901db310c1d1f0c8ca8d3815c8d896086b
src/luaotfload-features.lua | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index 3630ba0..183ff79 100644
--- a/src/luaotfload-features.lua
+++ b/src/luaotfload-features.lua
@@ -831,14 +831,43 @@ do
}
end
-local uni_normalize = require'lua-uni-normalize'.direct.NFC
+local uni_normalize = require'lua-uni-normalize'.direct
+local normalize_lookup = setmetatable({}, {__index = function(t, f)
+ local fontdir = assert(font.getfont(f))
+ local normalize_func = t[fontdir]
+ local characters = fontdir.characters
+ local function result(head)
+ return normalize_func(head, f, characters, true)
+ end
+ t[fontdir] = result
+ return result
+end})
+local normalize_funcs = {
+ nfc = uni_normalize.NFC,
+ nfd = uni_normalize.NFD,
+ nfkd = uni_normalize.NFKD,
+}
fonts.constructors.features.otf.register {
- name = 'nfc',
- default = true,
+ name = 'normalize',
+ default = 'nfc',
description = 'Normalize text to NFC before shaping',
+ manipulators = {
+ node = function(fonttable, _, value)
+ if value == true then
+ value = 'nfc'
+ end
+ local func = normalize_funcs[value]
+ if not func then
+ report ("report", 0, "features",
+ "Unsupported normalization method replaced by NFC")
+ func = normalize_funcs.nfc
+ end
+ normalize_lookup[fonttable] = func
+ end,
+ },
processors = {
node = function(head, f, _, _, _)
- return uni_normalize(head, f, font.getfont(f).characters, true)
+ return normalize_lookup[f](head)
end,
},
}
More information about the latex3-commits
mailing list.