From 467bddf27f4c158e04cfefa3d68d64b58a290a72 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 4 Jun 2014 22:15:12 +0200 Subject: aux: add helpers for accessing the index table/index file --- src/luaotfload-auxiliary.lua | 41 +++++++++++++++++++++++++++++++++++++++-- src/luaotfload-database.lua | 14 ++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua index 14c2ab5..89bf51b 100644 --- a/src/luaotfload-auxiliary.lua +++ b/src/luaotfload-auxiliary.lua @@ -20,6 +20,7 @@ local log = luaotfload.log local report = log.report local fonthashes = fonts.hashes local identifiers = fonthashes.identifiers +local fontnames = fonts.names local fontid = font.id local texsprint = tex.sprint @@ -590,8 +591,8 @@ aux.sprint_math_dimension = sprint_math_dimension --- extra database functions ----------------------------------------------------------------------- -local namesresolve = fonts.names.resolve -local namesscan_dir = fonts.names.scan_dir +local namesresolve = fontnames.resolve +local namesscan_dir = fontnames.scan_dir --[====[-- TODO -> port this to new db model @@ -663,6 +664,42 @@ end aux.resolve_fontlist = resolve_fontlist +--- index access ------------------------------------------------------ + +--- Based on a discussion on the Luatex mailing list: +--- http://tug.org/pipermail/luatex/2014-June/004881.html + +--[[doc-- + + aux.read_font_index -- Read the names index from the canonical + location and return its contents. This does not affect the behavior + of Luaotfload: The returned table is independent of what the font + resolvers use internally. Access is raw: each call to the function + will result in the entire table being re-read from disk. + +--doc]]-- + +local load_names = fontnames.load +local access_font_index = fontnames.access_font_index + +local read_font_index = function () + return load_names (true) or { } +end + +--[[doc-- + + aux.font_index -- Access Luaotfload’s internal database. If the + database hasn’t been loaded yet this will cause it to be loaded, with + all the possible side-effects like for instance creating the index + file if it doesn’t exist, reading all font files, &c. + +--doc]]-- + +local font_index = function () return access_font_index () end + +aux.read_font_index = read_font_index +aux.font_index = font_index + --- loaded fonts ------------------------------------------------------ --- just a proof of concept diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index f216f79..e171c52 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -452,6 +452,7 @@ local load_lua_file = function (path) end --- define locals in scope +local access_font_index local collect_families local crude_file_lookup local crude_file_lookup_verbose @@ -532,6 +533,18 @@ load_names = function (dry_run) return data end +--[[doc-- + + access_font_index -- Provide a reference of the index table. Will + cause the index to be loaded if not present. + +--doc]]-- + +access_font_index = function () + if not name_index then name_index = load_names () end + return name_index +end + getmetadata = function () if not name_index then name_index = load_names() end return tablefastcopy (name_index.meta) @@ -3457,6 +3470,7 @@ names.set_font_filter = set_font_filter names.flush_lookup_cache = flush_lookup_cache names.save_lookups = save_lookups names.load = load_names +names.access_font_index = access_font_index names.data = function () return name_index end names.save = save_names names.update = update_names -- cgit v1.2.3