diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-09-14 12:47:15 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-09-14 12:47:15 +0200 |
commit | f1fefb2184a372ef7418807d1eeb4d9d159591a2 (patch) | |
tree | 78609d37f58a625867b5e3ab4bded0a1c809e063 | |
parent | 6494aafd35565dcc1b0689aa47f3ac5c4a103735 (diff) | |
download | luaotfload-f1fefb2184a372ef7418807d1eeb4d9d159591a2.tar.gz |
[aux,characters] import further Context code
this allows loading Context bidi code without importing the whole lot of
``char-def.lua`` and ``char-ini.lua``.
Addresses https://github.com/lualatex/luaotfload/issues/132
-rw-r--r-- | luaotfload-auxiliary.lua | 125 | ||||
-rwxr-xr-x | mkcharacters | 33 |
2 files changed, 138 insertions, 20 deletions
diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua index da3f5f2..311fae9 100644 --- a/luaotfload-auxiliary.lua +++ b/luaotfload-auxiliary.lua @@ -368,35 +368,124 @@ aux.name_of_slot = name_of_slot 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. + a subset of the fields of each character defined. + + 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 = { } -local chardef = "luaotfload-characters" +characters = characters or { } --- should be created in basics-gen +characters.data = nil +local chardef = "luaotfload-characters" do - local chardata - local index = function (t, k) + 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 () + + log ("Loading character metadata from %s.", chardef) + chardata = dofile (kpse.find_file (chardef, "lua")) + if chardata == nil then - log("Loading character metadata from %s.", chardef) - chardata = dofile(kpse.find_file(chardef, "lua")) - if chardata == nil then - warning("Could not load %s; continuing with empty character table.", + warning ("Could not load %s; continuing \z + with empty character table.", chardef) - chardata = { } - end + chardata = { } + load_failed = true end - return chardata[k] + + 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 mt = getmetatable(characters.data) - if mt then - mt.__index = index - else - setmetatable(characters.data, { __index = index }) + local charindex = function (t, k) + if chardata == nil and load_failed ~= true then + load_chardef () + end + + return characters [k] end + + setmetatableindex (characters, charindex) + end ----------------------------------------------------------------------- diff --git a/mkcharacters b/mkcharacters index a1c4204..63c78ed 100755 --- a/mkcharacters +++ b/mkcharacters @@ -15,10 +15,39 @@ -- config ----------------------------------------------------------------------- local charfile = "./luaotfload-characters.lua" -local chardef = "~phg/base/char-def.lua" -local import = { +local chardef = "/home/phg/base/char-def.lua" + +--- for every code point char-def.lua provides a set of fields. they +--- are: +--- +--- * adobename +--- * category +--- * cjkwd +--- * comment +--- * contextname +--- * description +--- * direction +--- * lccode +--- * linebreak +--- * mathclass +--- * mathextensible +--- * mathfiller +--- * mathname +--- * mathspec +--- * mathstretch +--- * mathsymbol +--- * mirror +--- * shcode +--- * specials +--- * textclass +--- * uccode +--- * unicodeslot +--- * variants + +local import = { "direction", "mirror", --> πολυγλωσσία/uax9 "category", --> https://gist.github.com/phi-gamma/5812290 + "textclass", --> https://gist.github.com/phi-gamma/6488187 } ----------------------------------------------------------------------- |