summaryrefslogtreecommitdiff
path: root/luaotfload-database.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-02-09 16:57:00 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2014-02-09 16:57:00 +0100
commitc148347cb5c2c6cd3b58ac9daaad751500e190fd (patch)
tree9a54c17e9a1730aeb65453f27f010c4f8d57171f /luaotfload-database.lua
parent72692325b88bda53a115e62c66b321253297533b (diff)
parent2c6feb979da6435bb9f6636a46be576f688f7f78 (diff)
downloadluaotfload-c148347cb5c2c6cd3b58ac9daaad751500e190fd.tar.gz
Merge pull request #192 from phi-gamma/texlive2014
overhaul of the logging subsystem
Diffstat (limited to 'luaotfload-database.lua')
-rw-r--r--luaotfload-database.lua142
1 files changed, 89 insertions, 53 deletions
diff --git a/luaotfload-database.lua b/luaotfload-database.lua
index 77a7162..c69fc03 100644
--- a/luaotfload-database.lua
+++ b/luaotfload-database.lua
@@ -44,6 +44,13 @@ local read_fonts_conf = parsers.read_fonts_conf
local stripslashes = parsers.stripslashes
local splitcomma = parsers.splitcomma
+local log = luaotfload.log
+local report = log.report
+local report_status = log.names_status
+local report_status_start = log.names_status_start
+local report_status_stop = log.names_status_stop
+
+
--- Luatex builtins
local load = load
local next = next
@@ -151,11 +158,6 @@ local make_luanames = function (path)
filereplacesuffix(path, "luc")
end
-local report = logs.names_report
-local report_status = logs.names_status
-local report_status_start = logs.names_status_start
-local report_status_stop = logs.names_status_stop
-
--- The “termwidth” value is only considered when printing
--- short status messages, e.g. when building the database
--- online.
@@ -231,7 +233,11 @@ if not runasscript then
index.lua, index.luc = make_luanames (index_file)
else --- running as script, inject some dummies
caches = { }
- logs = { report = function () end }
+ local dummy_function = function () end
+ log = { report = dummy_function,
+ report_status = dummy_function,
+ report_status_start = dummy_function,
+ report_status_stop = dummy_function, }
end
@@ -1373,23 +1379,7 @@ local get_size_info = function (metadata)
return false
end
-local get_english_names = function (metadata, basename)
- local validation_state = metadata.validation_state
- if validation_state
- and tablecontains (validation_state, "bad_ps_fontname")
- then
- report("both", 3, "db",
- "%s has invalid postscript font names, using dummies.",
- basename)
- --- Broken names table, e.g. avkv.ttf with UTF-16 strings;
- --- we put some dummies in place like the fontloader
- --- (font-otf.lua) does.
- return {
- fontname = "bad-fontname-" .. basename,
- fullname = "bad-fullname-" .. basename,
- }
- end
-
+local get_english_names = function (metadata)
local names = metadata.names
local english_names
@@ -1397,34 +1387,78 @@ local get_english_names = function (metadata, basename)
--inspect(names)
for _, raw_namedata in next, names do
if raw_namedata.lang == "English (US)" then
- english_names = raw_namedata.names
+ return raw_namedata.names
end
end
end
- if not english_names then
- -- no (English) names table, probably a broken font
+ -- no (English) names table, probably a broken font
+ report("both", 3, "db",
+ "%s: missing or broken English names table.", basename)
+ return { fontname = metadata.fontname,
+ fullname = metadata.fullname, }
+end
+
+--[[--
+ In case of broken PS names we set some dummies. However, we cannot
+ directly modify the font data as returned by fontloader.open() because
+ it is a userdata object.
+
+ For this reason we copy what is necessary whilst keeping the table
+ structure the same as in the tfmdata.
+--]]--
+local get_raw_info = function (metadata, basename)
+ local fullname
+ local fontname
+ local psname
+
+ local validation_state = metadata.validation_state
+ if validation_state
+ and tablecontains (validation_state, "bad_ps_fontname")
+ then
+ --- Broken names table, e.g. avkv.ttf with UTF-16 strings;
+ --- we put some dummies in place like the fontloader
+ --- (font-otf.lua) does.
report("both", 3, "db",
- "%s: missing or broken names table.", basename)
+ "%s has invalid postscript font names, using dummies.",
+ basename)
+ fontname = "bad-fontname-" .. basename
+ fullname = "bad-fullname-" .. basename
+ else
+ fontname = metadata.fontname
+ fullname = metadata.fullname
end
- return english_names or { }
+ return {
+ familyname = metadata.familyname,
+ fontname = fontname,
+ fontstyle_name = metadata.fontstyle_name,
+ fullname = fullname,
+ italicangle = metadata.italicangle,
+ names = metadata.names,
+ pfminfo = metadata.pfminfo,
+ units_per_em = metadata.units_per_em,
+ version = metadata.version,
+ design_size = metadata.design_size,
+ design_range_top = metadata.design_range_top,
+ design_range_bottom = metadata.design_range_bottom,
+ }
end
-local organize_namedata = function (metadata,
+local organize_namedata = function (rawinfo,
english_names,
basename,
info)
local default_name = english_names.compatfull
or english_names.fullname
or english_names.postscriptname
- or metadata.fullname
- or metadata.fontname
+ or rawinfo.fullname
+ or rawinfo.fontname
or info.fullname
or info.fontname
local default_family = english_names.preffamily
or english_names.family
- or metadata.familyname
+ or rawinfo.familyname
or info.familyname
-- local default_modifier = english_names.prefmodifiers
-- or english_names.subfamily
@@ -1458,9 +1492,9 @@ local organize_namedata = function (metadata,
},
metadata = {
- fullname = metadata.fullname,
- fontname = metadata.fontname,
- familyname = metadata.familyname,
+ fullname = rawinfo.fullname,
+ fontname = rawinfo.fontname,
+ familyname = rawinfo.familyname,
},
info = {
@@ -1471,14 +1505,14 @@ local organize_namedata = function (metadata,
}
-- see http://www.microsoft.com/typography/OTSPEC/features_pt.htm#size
- if metadata.fontstyle_name then
+ if rawinfo.fontstyle_name then
--- not present in all fonts, often differs from the preferred
--- subfamily as well as subfamily fields, e.g. with
--- LMSans10-BoldOblique:
--- subfamily: “Bold Italic”
--- prefmodifiers: “10 Bold Oblique”
--- fontstyle_name: “Bold Oblique”
- for _, name in next, metadata.fontstyle_name do
+ for _, name in next, rawinfo.fontstyle_name do
if name.lang == 1033 then --- I hate magic numbers
fontnames.fontstyle_name = name.name
end
@@ -1487,9 +1521,9 @@ local organize_namedata = function (metadata,
return {
sanitized = sanitize_fontnames (fontnames),
- fontname = metadata.fontname,
- fullname = metadata.fullname,
- familyname = metadata.familyname,
+ fontname = rawinfo.fontname,
+ fullname = rawinfo.fullname,
+ familyname = rawinfo.familyname,
}
end
@@ -1546,13 +1580,18 @@ ot_fullinfo = function (filename,
return nil
end
- local english_names = get_english_names (metadata, basename)
- local namedata = organize_namedata (metadata,
+ local rawinfo = get_raw_info (metadata, basename)
+ --- Closing the file manually is a tad faster and more memory
+ --- efficient than having it closed by the gc
+ fontloaderclose (metadata)
+
+ local english_names = get_english_names (rawinfo)
+ local namedata = organize_namedata (rawinfo,
english_names,
basename,
info)
local style = organize_styledata (namedata.fontname,
- metadata,
+ rawinfo,
english_names,
info)
@@ -1564,11 +1603,8 @@ ot_fullinfo = function (filename,
format = format,
names = namedata,
style = style,
- version = metadata.version,
+ version = rawinfo.version,
}
- --- Closing the file manually is a tad faster and more memory
- --- efficient than having it closed by the gc
- fontloaderclose (metadata)
return res
end
@@ -2254,7 +2290,7 @@ local scan_texmf_fonts = function (currentnames, targetnames, dry_run)
report ("info", 1, "db", "Scanning TEXMF fonts...")
else
report ("info", 1, "db", "Scanning TEXMF and OS fonts...")
- if logs.get_loglevel () > 3 then
+ if log.get_loglevel () > 3 then
local osdirs = filesplitpath (osfontdir)
report ("info", 0, "db",
"$OSFONTDIR has %d entries:", #osdirs)
@@ -2577,7 +2613,7 @@ local pull_values = function (entry)
--- pull name info ...
entry.psname = english.psname
- entry.fontname = info.fontname
+ entry.fontname = info.fontname or metadata.fontname
entry.fullname = english.fullname or info.fullname
entry.splainname = metadata.fullname
entry.prefmodifiers = english.prefmodifiers
@@ -2949,7 +2985,7 @@ local collect_statistics = function (mappings)
local n_fullname = setsize (fullname)
local n_family = setsize (family)
- if logs.get_loglevel () > 1 then
+ if log.get_loglevel () > 1 then
local pprint_top = function (hash, n, set)
local freqs = { }
@@ -3135,7 +3171,7 @@ update_names = function (currentnames, force, dry_run)
if success then
local success = save_lookups ()
if success then
- logs.names_report ("info", 2, "cache",
+ report ("info", 2, "cache",
"Lookup cache emptied.")
return targetnames
end
@@ -3324,7 +3360,7 @@ end
local purge_cache = function ( )
local writable_path = getwritablecachepath ()
local luanames, lucnames, rest = collect_cache(writable_path)
- if logs.get_loglevel() > 1 then
+ if log.get_loglevel() > 1 then
print_cache("writable path", writable_path, luanames, lucnames, rest)
end
local success = purge_from_cache("writable path", writable_path, luanames, false)
@@ -3335,7 +3371,7 @@ end
local erase_cache = function ( )
local writable_path = getwritablecachepath ()
local luanames, lucnames, rest, all = collect_cache(writable_path)
- if logs.get_loglevel() > 1 then
+ if log.get_loglevel() > 1 then
print_cache("writable path", writable_path, luanames, lucnames, rest)
end
local success = purge_from_cache("writable path", writable_path, all, true)