summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-05-17 14:56:59 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-05-17 14:56:59 +0200
commitad95948e09bde3357faf57b6b13e63ae74fe60bb (patch)
tree708ee55608dd67b3388edb00e1c4627eaf90a8e8
parent1184d5032b4a812f8185d9d54a7a101c2c77bc35 (diff)
downloadluaotfload-ad95948e09bde3357faf57b6b13e63ae74fe60bb.tar.gz
load character data on demand
-rw-r--r--luaotfload-auxiliary.lua42
1 files changed, 41 insertions, 1 deletions
diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua
index 64fac90..1a48914 100644
--- a/luaotfload-auxiliary.lua
+++ b/luaotfload-auxiliary.lua
@@ -26,6 +26,9 @@ local identifiers = fonts.hashes.identifiers
local fontid = font.id
local texsprint = tex.sprint
+local dofile = dofile
+local getmetatable = getmetatable
+local setmetatable = setmetatable
local utf8 = unicode.utf8
local stringlower = string.lower
local stringformat = string.format
@@ -227,7 +230,7 @@ luatexbase.add_to_callback(
"luaotfload.aux.set_capheight")
-----------------------------------------------------------------------
---- glyphs
+--- glyphs and characters
-----------------------------------------------------------------------
local agl = fonts.encodings.agl
@@ -321,6 +324,43 @@ end
aux.name_of_slot = name_of_slot
+--[[doc--
+
+ In Context, characters.data is where the data from char-def.lua
+ resides. The file is huge (>3.7 MB as of 2013) and not part of the
+ isolated font loader. Nevertheless, we include a partial version
+ generated by the mkcharacters script that contains only the
+ “direction” and “mirror” fields of each character defined.
+
+--doc]]--
+
+characters = characters or { } --- should be created in basics-gen
+characters.data = { }
+local chardef = "luaotfload-characters"
+
+do
+ local chardata
+ local index = function (t, k)
+ if chardata == nil then
+ log("Loading character metadata from %s.", chardef)
+ chardata = dofile(kpse.find_file("luaotfload-characters.lua"))
+ if chardata == nil then
+ warning("Could not load %s; continuing with empty character table.",
+ chardef)
+ chardata = { }
+ end
+ end
+ return chardata[k]
+ end
+
+ local mt = getmetatable(characters.data)
+ if mt then
+ mt.__index = index
+ else
+ setmetatable(characters.data, { __index = index })
+ end
+end
+
-----------------------------------------------------------------------
--- features / scripts / languages
-----------------------------------------------------------------------