Skip to content

Instantly share code, notes, and snippets.

@phst
Created April 25, 2011 15:31
Show Gist options
  • Save phst/940677 to your computer and use it in GitHub Desktop.
Save phst/940677 to your computer and use it in GitHub Desktop.
Integration of lltxplatform into luaotfload
diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua
index 2ad6898..ce074b6 100644
--- a/otfl-font-nms.lua
+++ b/otfl-font-nms.lua
@@ -19,9 +19,21 @@ names.path = {
systemdir = file.join(kpse.expand_var("$TEXMFSYSVAR"), names_dir),
}
+local success = pcall(require, "luatexbase.modutils")
+if success then
+ success = pcall(luatexbase.require_module, "lualatex-platform", "2011/03/30")
+end
+local get_installed_fonts
+if success then
+ get_installed_fonts = lualatex.platform.get_installed_fonts
+else
+ function get_installed_fonts()
+ end
+end
local splitpath, expandpath = file.split_path, kpse.expand_path
local glob, basename = dir.glob, file.basename
+local extname = file.extname
local upper, lower, format = string.upper, string.lower, string.format
local gsub, match, rpadd = string.gsub, string.match, string.rpadd
local gmatch, sub, find = string.gmatch, string.sub, string.find
@@ -445,6 +457,36 @@ end
local font_extensions = { "otf", "ttf", "ttc", "dfont" }
+local function scan_installed_fonts(fontnames, newfontnames)
+ -- Try to query and add font list from operating system.
+ -- This uses the lualatex-platform module.
+ logs.info("Scanning fonts known to operating system...")
+ local extensions = {}
+ for key, value in ipairs(font_extensions) do
+ extensions[value] = true
+ end
+ local fonts = get_installed_fonts()
+ if fonts then
+ if trace_search then
+ logs.report("%d operating system fonts found", #fonts)
+ end
+ for key, value in ipairs(fonts) do
+ local file = value.path
+ if file and extensions[extname(file)] then
+ file = path_normalize(file)
+ if trace_loading then
+ logs.report("loading font: %s", file)
+ end
+ load_font(file, fontnames, newfontnames, false)
+ end
+ end
+ else
+ if trace_search then
+ logs.report("Could not retrieve list of installed fonts")
+ end
+ end
+end
+
local function scan_dir(dirname, fontnames, newfontnames, texmf)
--[[
This function scans a directory and populates the list of fonts
@@ -647,6 +689,7 @@ local function update_names(fontnames, force)
end
local newfontnames = fontnames_init()
read_blacklist()
+ scan_installed_fonts(fontnames, newfontnames)
scan_texmf_fonts(fontnames, newfontnames)
if expandpath("$OSFONTDIR"):is_empty() then
scan_os_fonts(fontnames, newfontnames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment