diff options
-rwxr-xr-x | fontdbutil.lua | 3 | ||||
-rw-r--r-- | luaotfload-database.lua | 144 | ||||
-rw-r--r-- | luaotfload-features.lua | 44 | ||||
-rw-r--r-- | luaotfload.dtx | 4 |
4 files changed, 135 insertions, 60 deletions
diff --git a/fontdbutil.lua b/fontdbutil.lua index fd01abb..fed1840 100755 --- a/fontdbutil.lua +++ b/fontdbutil.lua @@ -85,6 +85,7 @@ We intercept them with dummies. local dummy_function = function ( ) end local backup_write, backup_write_nl = texio.write, texio.write_nl + texio.write, texio.write_nl = dummy_function, dummy_function require"luaotfload-basics-gen.lua" texio.write, texio.write_nl = backup_write, backup_write_nl @@ -239,7 +240,7 @@ actions.generate = function (job) local fontnames, savedname fontnames = names.update(fontnames, job.force_reload) logs.names_report("log", 0, "db", - "fonts in the database", "%i", #fontnames.mappings) + "Fonts in the database: %i", #fontnames.mappings) savedname = names.save(fontnames) if savedname then --- FIXME have names.save return bool return true, true diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 50f3e08..b8a993a 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -46,6 +46,7 @@ local utf8lower = unicode.utf8.lower local dirglob = dir.glob local dirmkdirs = dir.mkdirs local filebasename = file.basename +local filenameonly = file.nameonly local filedirname = file.dirname local filecollapsepath = file.collapsepath or file.collapse_path local fileextname = file.extname @@ -83,32 +84,6 @@ end names.path.dir = writable_path names.path.path = filejoin(writable_path, names.path.basename) - ----- <FIXME> ---- ---- these lines load some binary module called “lualatex-platform” ---- that doesn’t appear to build with Lua 5.2. I’m going ahead and ---- disable it for the time being until someone clarifies what it ---- is supposed to do and whether we should care to fix it. ---- ---local success = pcall(require, "luatexbase.modutils") ---if success then --- success = pcall(luatexbase.require_module, --- "lualatex-platform", "2011/03/30") --- print(success) ---end - ---local get_installed_fonts ---if success then --- get_installed_fonts = lualatex.platform.get_installed_fonts ---else --- function get_installed_fonts() --- end ---end ----- </FIXME> - -local get_installed_fonts = nil - --[[doc-- Auxiliary functions --doc]]-- @@ -157,7 +132,12 @@ local fontnames_init = function ( ) return { mappings = { }, status = { }, - filenames = { }, --- (basename, fullname) hash; maybe overkill + --- adding filename mapping increases the + --- size of the serialized db on my system + --- (5840 font files) by a factor of ... + barenames = { },--- incr. by 1.11 + basenames = { },--- incr. by 1.22 +-- fullnames = { },--- incr. by 1.48 version = names.version, } end @@ -259,6 +239,55 @@ end local fonts_loaded = false local fonts_reloaded = false +local crude_file_lookup_verbose = function (data, filename) + local found = data.barenames[filename] + if found then + report("info", 0, "db", + "crude file lookup: req=%s; hit=bare; ret=%s", + filename, found[1]) + return found + end +-- found = data.fullnames[filename] +-- if found then +-- report("info", 0, "db", +-- "crude file lookup: req=%s; hit=bare; ret=%s", +-- filename, found[1]) +-- return found +-- end + found = data.basenames[filename] + if found then + report("info", 0, "db", + "crude file lookup: req=%s; hit=bare; ret=%s", + filename, found[1]) + return found + end + found = resolvers.findfile(filename, "tfm") + if found then + report("info", 0, "db", + "crude file lookup: req=tfm; hit=bare; ret=%s", found) + return { found, false } + end + found = resolvers.findfile(filename, "ofm") + if found then + report("info", 0, "db", + "crude file lookup: req=ofm; hit=bare; ret=%s", found) + return { found, false } + end + return false +end + +local crude_file_lookup = function (data, filename) + local found = data.barenames[filename] +-- or data.fullnames[filename] + or data.basenames[filename] + if found then return found end + found = resolvers.findfile(filename, "tfm") + if found then return { found, false } end + found = resolvers.findfile(filename, "ofm") + if found then return { found, false } end + return false +end + --[[doc-- Luatex-fonts, the font-loader package luaotfload imports, comes with @@ -285,8 +314,10 @@ font database created by the mkluatexfontdb script. --- · specification: string (== <lookup> ":" <name>) --- · sub: string --- ---- the return value of “resolve” is the file name of the requested ---- font +--- the first return value of “resolve” is the file name of the +--- requested font (string) +--- the second is of type bool or string and indicates the subfont of a +--- ttc --- --- 'a -> 'a -> table -> (string * string | bool * bool) --- @@ -296,6 +327,18 @@ font database created by the mkluatexfontdb script. --- --- resolve = function (_,_,specification) -- the 1st two parameters are used by ConTeXt + if not fonts_loaded then + names.data = load_names() + fonts_loaded = true + end + local data = names.data + + if specification.lookup == "file" then + local found = crude_file_lookup(data, specification.name) + --local found = crude_file_lookup_verbose(data, specification.name) + if found then return found[1], found[2], true end + end + local name = sanitize_string(specification.name) local style = sanitize_string(specification.style) or "regular" @@ -306,12 +349,6 @@ resolve = function (_,_,specification) -- the 1st two parameters are used by Con size = specification.size / 65536 end - if not fonts_loaded then - names.data = load_names() - fonts_loaded = true - end - - local data = names.data if type(data) == "table" then local db_version, nms_version = data.version, names.version if data.version ~= names.version then @@ -632,10 +669,20 @@ end local load_font = function (fullname, fontnames, newfontnames, texmf) local newmappings = newfontnames.mappings local newstatus = newfontnames.status + +-- local newfullnames = newfontnames.fullnames + local newbasenames = newfontnames.basenames + local newbarenames = newfontnames.barenames + local mappings = fontnames.mappings local status = fontnames.status - local filenames = fontnames.filenames +-- local fullnames = fontnames.fullnames + local basenames = fontnames.basenames + local barenames = fontnames.barenames + local basename = filebasename(fullname) + local barename = filenameonly(fullname) + --- entryname is apparently the identifier a font is --- loaded by; it is different for files in the texmf --- (due to kpse? idk.) @@ -669,19 +716,24 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) newstatus[entryname].timestamp = timestamp newstatus[entryname].index = newstatus[entryname].index or { } - if db_timestamp == timestamp and not newstatus[entryname].index[1] then + if db_timestamp == timestamp + and not newstatus[entryname].index[1] then for _,v in next, status[entryname].index do - local index = #newstatus[entryname].index - newmappings[#newmappings+1] = mappings[v] + local index = #newstatus[entryname].index + local fullinfo = mappings[v] + newmappings[#newmappings+1] = fullinfo --- keep newstatus[entryname].index[index+1] = #newmappings +-- newfullnames[fullname] = fullinfo.filename + newbasenames[basename] = fullinfo.filename + newbarenames[barename] = fullinfo.filename end report("log", 2, "db", "font “%s” already indexed", entryname) return false end - local info = fontloaderinfo(fullname) + local info = fontloaderinfo(fullname) if info then - if type(info) == "table" and #info > 1 then + if type(info) == "table" and #info > 1 then --- ttc for i in next, info do local fullinfo = font_fullinfo(fullname, i-1, texmf) if not fullinfo then @@ -693,7 +745,10 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) else index = #newmappings+1 end - newmappings[index] = fullinfo + newmappings[index] = fullinfo +-- newfullnames[fullname] = fullinfo.filename + newbasenames[basename] = fullinfo.filename + newbarenames[barename] = fullinfo.filename newstatus[entryname].index[i] = index end else @@ -707,7 +762,10 @@ local load_font = function (fullname, fontnames, newfontnames, texmf) else index = #newmappings+1 end - newmappings[index] = fullinfo + newmappings[index] = fullinfo +-- newfullnames[fullname] = { fullinfo.filename[1], fullinfo.filename[2] } + newbasenames[basename] = { fullinfo.filename[1], fullinfo.filename[2] } + newbarenames[barename] = { fullinfo.filename[1], fullinfo.filename[2] } newstatus[entryname].index[1] = index end diff --git a/luaotfload-features.lua b/luaotfload-features.lua index 0121ede..3c5aa8c 100644 --- a/luaotfload-features.lua +++ b/luaotfload-features.lua @@ -37,6 +37,12 @@ local stringfind = string.find local stringexplode = string.explode local stringis_empty = string.is_empty +--[[doc-- +Apparently, these “modifiers” are another measure of emulating \XETEX, +cf. “About \XETEX”, by Jonathan Kew, 2005; and + “The \XETEX Reference Guide”, by Will Robertson, 2011. +--doc]]-- + local supported = { b = "bold", i = "italic", @@ -123,7 +129,7 @@ defaults.tibt = defaults.khmr defaults.lao = defaults.thai -local function set_default_features(script) +local set_default_features = function (script) local features local script = script or "dflt" report("log", 0, "load font", @@ -171,9 +177,13 @@ local options = P(":") * spaces * (P(";")^0 * option)^0 local pattern = (filename + fontname) * subvalue^0 * stylespec^0 * options^0 local function colonized(specification) -- xetex mode + --print"~~~~~~~~~~~~~~~~~~~~~~~~" + --print(specification.specification) feature_list = { } lpeg.match(pattern,specification.specification) set_default_features(feature_list.script) + --inspect(feature_list) + --os.exit() if feature_list.style then specification.style = feature_list.style feature_list.style = nil @@ -206,27 +216,31 @@ local function colonized(specification) -- xetex mode -- if no mode is set, use our default feature_list.mode = fonts.mode end + --inspect(feature_list) specification.features.normal = fonts.handlers.otf.features.normalize(feature_list) + --inspect(specification.features.normal) return specification end fonts.definers.registersplit(":",colonized,"cryptic") fonts.definers.registersplit("", colonized,"more cryptic") -- catches \font\text=[names] -function fonts.definers.applypostprocessors(tfmdata) - local postprocessors = tfmdata.postprocessors - if postprocessors then - for i=1,#postprocessors do - local extrahash = postprocessors[i](tfmdata) -- after scaling etc - if type(extrahash) == "string" and extrahash ~= "" then - -- e.g. a reencoding needs this - extrahash = string.gsub(lower(extrahash),"[^a-z]","-") - tfmdata.properties.fullname = format("%s-%s",tfmdata.properties.fullname,extrahash) - end - end - end - return tfmdata -end +--- TODO below section is literally the same in luatex-fonts-def +--- why is it here? +--function fonts.definers.applypostprocessors(tfmdata) +-- local postprocessors = tfmdata.postprocessors +-- if postprocessors then +-- for i=1,#postprocessors do +-- local extrahash = postprocessors[i](tfmdata) -- after scaling etc +-- if type(extrahash) == "string" and extrahash ~= "" then +-- -- e.g. a reencoding needs this +-- extrahash = string.gsub(lower(extrahash),"[^a-z]","-") +-- tfmdata.properties.fullname = format("%s-%s",tfmdata.properties.fullname,extrahash) +-- end +-- end +-- end +-- return tfmdata +--end ---[[ end included font-ltx.lua ]] --[[doc-- diff --git a/luaotfload.dtx b/luaotfload.dtx index e265389..81f1873 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -1328,6 +1328,8 @@ add_to_callback("find_vf_file", loadmodule"lib-dir.lua" --- required by luaofload-database.lua loadmodule"override.lua" --- “luat-ovr” +logs.set_loglevel(2) + % \end{macrocode} % \CONTEXT does not support ofm, these lines were added in order to make it % work. However they do not seem necessary so they are commented for now. @@ -1399,7 +1401,7 @@ local define_font_wrapper = function (...) --- definers.read if stringfind(k, "Percent") then -- keep percent values as is - print(k,v) + --print(k,v) mathconstants[k] = v else mathconstants[k] = v / units_per_em * size |