summaryrefslogtreecommitdiff
path: root/luaotfload-auxiliary.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-05-01 21:08:07 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-05-01 21:08:07 +0200
commitc0f5ff48cd1685b69bc7570ff4fb98bea7142993 (patch)
treee5cbd0e6abaaecd8b1677322eb99735a35212e41 /luaotfload-auxiliary.lua
parentb5e475547fbd9cc6f9f9fe883f6ccd05d277b081 (diff)
downloadluaotfload-c0f5ff48cd1685b69bc7570ff4fb98bea7142993.tar.gz
add glyph name <-> codepoint resolver
Diffstat (limited to 'luaotfload-auxiliary.lua')
-rw-r--r--luaotfload-auxiliary.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua
index a5f22dd..f7886be 100644
--- a/luaotfload-auxiliary.lua
+++ b/luaotfload-auxiliary.lua
@@ -174,6 +174,44 @@ end
aux.do_if_glyph_else = do_if_glyph_else
+--- this one is approximately “name_to_slot” from the microtype
+--- package
+
+--- string -> (int | false)
+local codepoint_of_name = function (glyphname)
+ local fontdata = identifiers[font.current()]
+ if fontdata then
+ local unicode = fontdata.resources.unicodes[glyphname]
+ if unicode and type(unicode) == "number" then
+ return unicode
+ else
+ return unicode[1] --- again, does that even happen?
+ end
+ end
+ return false
+end
+
+aux.codepoint_of_name = codepoint_of_name
+
+--- inverse of above
+
+local indices
+
+--- int -> (string | false)
+local name_of_codepoint = function (codepoint)
+ if not indices then --- this will load the glyph list
+ local unicodes = fonts.encodings.agl.unicodes
+ indices = table.swapped(unicodes)
+ end
+ local glyphname = indices[codepoint]
+ if glyphname then
+ return glyphname
+ end
+ return false
+end
+
+aux.name_of_codepoint = name_of_codepoint
+
-----------------------------------------------------------------------
--- features / scripts / languages
-----------------------------------------------------------------------