diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2016-04-17 12:45:14 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2016-04-17 12:45:14 +0200 |
commit | c8734018b81eb2120372493a3767617eeaf0299c (patch) | |
tree | 987d7791ae6f39bcf371c72f87d6e8cf759f0c75 /src/luaotfload-init.lua | |
parent | fc973a6dde1a78a59e50bc3850dfd0d06e7b2a03 (diff) | |
parent | 97ec9e582e5be33001c136a9c69b5eebee4fdb2a (diff) | |
download | luaotfload-c8734018b81eb2120372493a3767617eeaf0299c.tar.gz |
Merge pull request #330 from phi-gamma/master
fontloader update
Diffstat (limited to 'src/luaotfload-init.lua')
-rw-r--r-- | src/luaotfload-init.lua | 188 |
1 files changed, 166 insertions, 22 deletions
diff --git a/src/luaotfload-init.lua b/src/luaotfload-init.lua index 7ed9c96..8b13fe6 100644 --- a/src/luaotfload-init.lua +++ b/src/luaotfload-init.lua @@ -238,6 +238,7 @@ local context_modules = { { false, "l-boolean" }, { false, "l-math" }, { false, "util-str" }, + { false, "util-fil" }, --- These constitute the fontloader proper. { ltx, "luatex-basics-gen" }, @@ -247,21 +248,27 @@ local context_modules = { { ctx, "font-con" }, { ltx, "luatex-fonts-enc" }, { ctx, "font-cid" }, + { ctx, "font-map" }, { ltx, "luatex-fonts-syn" }, - { ltx, "luatex-fonts-tfm" }, + { ctx, "font-tfm" }, + { ctx, "font-afm" }, + { ctx, "font-afk" }, { ctx, "font-oti" }, - { ctx, "font-otf" }, - { ctx, "font-otb" }, - { ctx, "font-inj" }, - { ltx, "luatex-fonts-ota" }, - { ctx, "font-otn" }, - { ctx, "font-otp" }, - { ltx, "luatex-fonts-lua" }, + { ctx, "font-otr" }, + { ctx, "font-cff" }, + { ctx, "font-ttf" }, + { ctx, "font-dsp" }, + { ctx, "font-oup" }, + { ctx, "font-otl" }, + { ctx, "font-oto" }, + { ctx, "font-otj" }, + { ctx, "font-ota" }, + { ctx, "font-ots" }, + { ctx, "font-osd" }, + { ctx, "font-lua" }, { ctx, "font-def" }, - { ltx, "luatex-fonts-def" }, { ltx, "luatex-fonts-ext" }, - { ltx, "luatex-fonts-cbk" }, - { ctx, "font-map" }, + { ctx, "font-gbn" }, } --[[context_modules]] @@ -312,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 rawget (characters, k) + end + + setmetatableindex (characters, charindex) + +end + local init_main = function () local load_fontloader_module = luaotfload.loaders.fontloader @@ -362,9 +500,9 @@ local init_main = function () ignore_module "l-boolean" ignore_module "l-math" ignore_module "util-str" + ignore_module "util-fil" ignore_module "luatex-basics-gen" - --- These constitute the fontloader proper. load_fontloader_module "data-con" load_fontloader_module "basics-nod" load_fontloader_module "font-ini" @@ -373,19 +511,25 @@ local init_main = function () load_fontloader_module "font-cid" load_fontloader_module "font-map" load_fontloader_module "fonts-syn" - load_fontloader_module "fonts-tfm" + load_fontloader_module "font-tfm" + load_fontloader_module "font-afm" + load_fontloader_module "font-afk" load_fontloader_module "font-oti" - load_fontloader_module "font-otf" - load_fontloader_module "font-otb" - load_fontloader_module "font-inj" - load_fontloader_module "fonts-ota" - load_fontloader_module "font-otn" - load_fontloader_module "font-otp" --> since 2013-04-23 - load_fontloader_module "fonts-lua" + load_fontloader_module "font-otr" + load_fontloader_module "font-cff" + load_fontloader_module "font-ttf" + load_fontloader_module "font-dsp" + load_fontloader_module "font-oup" + load_fontloader_module "font-otl" + load_fontloader_module "font-oto" + load_fontloader_module "font-otj" + load_fontloader_module "font-ota" + load_fontloader_module "font-ots" + load_fontloader_module "font-osd" + load_fontloader_module "font-lua" load_fontloader_module "font-def" - load_fontloader_module "fonts-def" load_fontloader_module "fonts-ext" - load_fontloader_module "fonts-cbk" + load_fontloader_module "font-gbn" elseif fontloader == "context" then logreport ("log", 0, "init", |