summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luaotfload-auxiliary.lua126
-rw-r--r--src/luaotfload-init.lua134
2 files changed, 131 insertions, 129 deletions
diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua
index 2c2624e..6ba21e0 100644
--- a/src/luaotfload-auxiliary.lua
+++ b/src/luaotfload-auxiliary.lua
@@ -298,132 +298,6 @@ 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 (>4.4 MB as of 2016) and only a stripped
- down version is part of the isolated font loader. Nevertheless, we
- include an excerpt generated by the mkcharacters script that contains
- a subset of the fields of each character defined and some extra
- metadata.
-
- Currently, these are (compare the mkcharacters script!)
-
- · "direction"
- · "mirror"
- · "category"
- · "textclass"
-
- The directional information is required for packages like Simurgh [0]
- to work correctly. In an early stage [1] it was necessary to load
- further files from Context directly, including the full blown version
- of char-def. Since we have no use for most of the so imported
- functionality, the required parts have been isolated and are now
- instated along with luaotfload-characters.lua. We can extend the set
- of imported features easily should it not be enough.
-
- [0] https://github.com/persian-tex/simurgh
- [1] http://tex.stackexchange.com/a/132301/14066
-
---doc]]--
-
-characters = characters or { } --- should be created in basics-gen
-characters.data = nil
-local chardef = "luaotfload-characters"
-
-do
- local setmetatableindex = function (t, f)
- local mt = getmetatable (t)
- if mt then
- mt.__index = f
- else
- setmetatable (t, { __index = f })
- end
- end
-
- --- there are some special tables for each field that provide access
- --- to fields of the character table by means of a metatable
-
- local mkcharspecial = function (characters, tablename, field)
-
- local chardata = characters.data
-
- if chardata then
- local newspecial = { }
- characters [tablename] = newspecial --> e.g. “characters.data.mirrors”
-
- local idx = function (t, char)
- local c = chardata [char]
- if c then
- local m = c [field] --> e.g. “mirror”
- if m then
- t [char] = m
- return m
- end
- end
- newspecial [char] = false
- return char
- end
-
- setmetatableindex (newspecial, idx)
- end
-
- end
-
- local mkcategories = function (characters) -- different from the others
-
- local chardata = characters.data
-
- setmetatable (characters, { __index = function (t, char)
- if char then
- local c = chardata [char]
- c = c.category or char
- t [char] = c
- return c
- end
- end})
-
- end
-
- local load_failed = false
- local chardata --> characters.data; loaded on demand
-
- local load_chardef = function ()
-
- logreport ("both", 1, "aux", "Loading character metadata from %s.", chardef)
- chardata = dofile (kpse.find_file (chardef, "lua"))
-
- if chardata == nil then
- warning ("Could not load %s; continuing \z
- with empty character table.",
- chardef)
- chardata = { }
- load_failed = true
- end
-
- characters = { } --- nuke metatable
- characters.data = chardata
-
- --- institute some of the functionality from char-ini.lua
-
- mkcharspecial (characters, "mirrors", "mirror")
- mkcharspecial (characters, "directions", "direction")
- mkcharspecial (characters, "textclasses", "textclass")
- mkcategories (characters)
-
- end
-
- local charindex = function (t, k)
- if chardata == nil and load_failed ~= true then
- load_chardef ()
- end
-
- return characters [k]
- end
-
- setmetatableindex (characters, charindex)
-
-end
-----------------------------------------------------------------------
--- features / scripts / languages
diff --git a/src/luaotfload-init.lua b/src/luaotfload-init.lua
index 096d778..5fafceb 100644
--- a/src/luaotfload-init.lua
+++ b/src/luaotfload-init.lua
@@ -319,6 +319,137 @@ local init_adapt = function ()
end --- [init_adapt]
+--[[doc--
+
+ In Context, characters.data is where the data from char-def.lua
+ resides. The file is huge (>4.4 MB as of 2016) and only a stripped
+ down version is part of the isolated font loader. Nevertheless, we
+ include an excerpt generated by the mkcharacters script that contains
+ a subset of the fields of each character defined and some extra
+ metadata.
+
+ Currently, these are (compare the mkcharacters script!)
+
+ · "direction"
+ · "mirror"
+ · "category"
+ · "textclass"
+
+ The directional information is required for packages like Simurgh [0]
+ to work correctly. In an early stage [1] it was necessary to load
+ further files from Context directly, including the full blown version
+ of char-def. Since we have no use for most of the so imported
+ functionality, the required parts have been isolated and are now
+ instated along with luaotfload-characters.lua. We can extend the set
+ of imported features easily should it not be enough.
+
+ [0] https://github.com/persian-tex/simurgh
+ [1] http://tex.stackexchange.com/a/132301/14066
+
+--doc]]--
+
+characters = characters or { } --- should be created in basics-gen
+characters.data = nil
+local chardef = "luaotfload-characters"
+
+do
+ local setmetatableindex = function (t, f)
+ local mt = getmetatable (t)
+ if mt then
+ mt.__index = f
+ else
+ setmetatable (t, { __index = f })
+ end
+ end
+
+ --- there are some special tables for each field that provide access
+ --- to fields of the character table by means of a metatable
+
+ local mkcharspecial = function (characters, tablename, field)
+
+ local chardata = characters.data
+
+ if chardata then
+ local newspecial = { }
+ characters [tablename] = newspecial --> e.g. “characters.data.mirrors”
+
+ local idx = function (t, char)
+ local c = chardata [char]
+ if c then
+ local m = c [field] --> e.g. “mirror”
+ if m then
+ t [char] = m
+ return m
+ end
+ end
+ newspecial [char] = false
+ return char
+ end
+
+ setmetatableindex (newspecial, idx)
+ end
+
+ end
+
+ local mkcategories = function (characters) -- different from the others
+
+ local chardata = characters.data
+ local categories = characters.categories or { }
+ characters.categories = categories
+
+ setmetatable (categories, { __index = function (t, char)
+ if char then
+ local c = chardata [char]
+ c = c.category or char
+ t [char] = c
+ return c
+ end
+ end})
+
+ end
+
+ local load_failed = false
+ local chardata --> characters.data; loaded on demand
+
+ local load_chardef = function ()
+
+ logreport ("both", 1, "aux", "Loading character metadata from %s.", chardef)
+ chardata = dofile (kpse.find_file (chardef, "lua"))
+
+ if chardata == nil then
+ logreport ("both", 0, "aux",
+ "Could not load %s; continuing with empty character table.",
+ chardef)
+ chardata = { }
+ load_failed = true
+ end
+
+ characters = { } --- nuke metatable
+ characters.data = chardata
+ characters.classifiers = chardata.classifiers
+ chardata.classifiers = nil
+
+ --- institute some of the functionality from char-ini.lua
+
+ mkcharspecial (characters, "mirrors", "mirror")
+ mkcharspecial (characters, "directions", "direction")
+ mkcharspecial (characters, "textclasses", "textclass")
+ mkcategories (characters)
+
+ end
+
+ local charindex = function (t, k)
+ if chardata == nil and load_failed ~= true then
+ load_chardef ()
+ end
+
+ return characters [k]
+ end
+
+ setmetatableindex (characters, charindex)
+
+end
+
local init_main = function ()
local load_fontloader_module = luaotfload.loaders.fontloader
@@ -338,9 +469,6 @@ local init_main = function ()
or "reference"
fontloader = tostring (fontloader)
- --- Preload the characters table. This may vanish later.
- characters = luaotfload.loaders.luaotfload "characters"
-
if fontloader == "reference" then
logreport ("log", 0, "init", "Using reference fontloader.")
load_fontloader_module (luaotfload.fontloader_package)