diff options
Diffstat (limited to 'luaotfload-auxiliary.lua')
-rw-r--r-- | luaotfload-auxiliary.lua | 94 |
1 files changed, 92 insertions, 2 deletions
diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua index 64fac90..2bfcbf0 100644 --- a/luaotfload-auxiliary.lua +++ b/luaotfload-auxiliary.lua @@ -21,11 +21,15 @@ config.luaotfload = config.luaotfload or { } local aux = luaotfload.aux local log = luaotfload.log local warning = luaotfload.log -local identifiers = fonts.hashes.identifiers +local fonthashes = fonts.hashes +local identifiers = fonthashes.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 +231,7 @@ luatexbase.add_to_callback( "luaotfload.aux.set_capheight") ----------------------------------------------------------------------- ---- glyphs +--- glyphs and characters ----------------------------------------------------------------------- local agl = fonts.encodings.agl @@ -321,6 +325,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 ----------------------------------------------------------------------- @@ -640,4 +681,53 @@ end aux.get_raw_fonts = get_raw_fonts +----------------------------------------------------------------------- +--- font parameters +----------------------------------------------------------------------- +--- analogy of font-hsh + +fonthashes.parameters = fonthashes.parameters or { } +fonthashes.quads = fonthashes.quads or { } + +local parameters = fonthashes.parameters or { } +local quads = fonthashes.quads or { } + +setmetatable(parameters, { __index = function (t, font_id) + local tfmdata = identifiers[font_id] + if not tfmdata then --- unsafe; avoid + tfmdata = font.fonts[font_id] + end + if tfmdata and type(tfmdata) == "table" then + local fontparameters = tfmdata.parameters + t[font_id] = fontparameters + return fontparameters + end + return nil +end}) + +--[[doc-- + + Note that the reason as to why we prefer functions over table indices + is that functions are much safer against unintended manipulation. + This justifies the overhead they cost. + +--doc]]-- + +--- int -> (number | false) +local get_quad = function (font_id) + local quad = quads[font_id] + if quad then + return quad + end + local fontparameters = parameters[font_id] + if fontparameters then + local quad = fontparameters.quad or 0 + quads[font_id] = quad + return quad + end + return false +end + +aux.get_quad = get_quad + -- vim:tw=71:sw=2:ts=2:expandtab |