summaryrefslogtreecommitdiff
path: root/tex/context/modules/mkiv/s-fonts-system.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/modules/mkiv/s-fonts-system.lua')
-rw-r--r--tex/context/modules/mkiv/s-fonts-system.lua144
1 files changed, 122 insertions, 22 deletions
diff --git a/tex/context/modules/mkiv/s-fonts-system.lua b/tex/context/modules/mkiv/s-fonts-system.lua
index b91b3e75d..e05eef0fa 100644
--- a/tex/context/modules/mkiv/s-fonts-system.lua
+++ b/tex/context/modules/mkiv/s-fonts-system.lua
@@ -30,11 +30,15 @@ if not modules then modules = { } end modules ['s-fonts-system'] = {
moduledata.fonts = moduledata.fonts or { }
moduledata.fonts.system = moduledata.fonts.system or { }
-local lower = string.lower
-
local context = context
local NC, NR, HL = context.NC, context.NR, context.HL
-local bold = context.bold
+local ctx_bold = context.bold
+local ctx_verbatim = context.verbatim
+local lpegmatch = lpeg.match
+local sortedhash = table.sortedhash
+local formatters = string.formatters
+local concat = table.concat
+local lower = string.lower
local function allfiles(specification)
local pattern = lower(specification.pattern or "")
@@ -54,12 +58,12 @@ function moduledata.fonts.system.showinstalled(specification)
if files then
context.starttabulate { "|Tl|Tl|Tl|Tl|Tl|Tl|" }
HL()
- NC() bold("filename")
- NC() bold("fontname")
- NC() bold("subfamily")
- NC() bold("variant")
- NC() bold("weight")
- NC() bold("width")
+ NC() ctx_bold("filename")
+ NC() ctx_bold("fontname")
+ NC() ctx_bold("subfamily")
+ NC() ctx_bold("variant")
+ NC() ctx_bold("weight")
+ NC() ctx_bold("width")
NC() NR()
HL()
for filename, data in table.sortedpairs(files) do
@@ -80,25 +84,121 @@ function moduledata.fonts.system.cacheinstalled(specification)
local files = allfiles(specification)
if files then
local threshold = tonumber(specification.threshold)
+ local suffixes = specification.suffixes
+ if suffixes then
+ suffixes = utilities.parsers.settings_to_set(suffixes)
+ else
+ suffixes = { otf = true, ttf = true }
+ end
for filename, data in table.sortedpairs(files) do
if string.find(filename," ") then
-- skip this one
- else
- local s = file.suffix(filename)
- if s == "otf" or s == "ttf" then
- local fullname = resolvers.findfile(filename)
- context.start()
- context.type(fullname)
- context.par()
- if threshold and file.size(fullname) > threshold then
- logs.report("fonts","ignoring : %s",fullname)
- else
- logs.report("fonts","caching : %s",fullname)
- context.definedfont { filename }
+ elseif suffixes[file.suffix(filename)] then
+ local fullname = resolvers.findfile(filename)
+ context.start()
+ context.type(fullname)
+ context.par()
+ if threshold and file.size(fullname) > threshold then
+ logs.report("fonts","ignoring : %s",fullname)
+ else
+ logs.report("fonts","caching : %s",fullname)
+ context.definedfont { filename }
+ end
+ context.stop()
+ end
+ end
+ end
+end
+
+local splitter = lpeg.splitat(lpeg.S("._"),true)
+
+local method = 3
+
+function moduledata.fonts.system.showinstalledglyphnames(specification)
+ specification = interfaces.checkedspecification(specification)
+ local paths = caches.getreadablepaths()
+ local files = { }
+ local names = table.setmetatableindex("table")
+ local f_u = formatters["%04X"]
+ for i=1,#paths do
+ local list = dir.glob(paths[i].."/fonts/o*/**.tmc")
+ for i=1,#list do
+ files[list[i]] = true
+ end
+ end
+ for filename in table.sortedhash(files) do
+ logs.report("system","fontfile: %s",file.nameonly(filename))
+ local data = table.load(filename)
+ if data then
+ if method == 1 then
+ local unicodes = data.resources.unicodes
+ if unicodes then
+ for n, u in sortedhash(unicodes) do
+ if u >= 0xF0000 or (u >= 0xE000 and u <= 0xF8FF) then
+ -- skip
+ else
+ local f = lpegmatch(splitter,n) or n
+ if #f > 0 then
+ local t = names[f]
+ t[u] = (t[u] or 0) + 1
+ end
+ end
+ end
+ end
+ elseif method == 2 then
+ local unicodes = data.resources.unicodes
+ if unicodes then
+ for n, u in sortedhash(unicodes) do
+ if u >= 0xF0000 or (u >= 0xE000 and u <= 0xF8FF) then
+ -- skip
+ else
+ local t = names[n]
+ t[u] = (t[u] or 0) + 1
+ end
end
- context.stop()
end
+ elseif method == 3 then
+ local descriptions = data.descriptions
+ if descriptions then
+ for u, d in sortedhash(descriptions) do
+ local n = d.name
+ local u = d.unicode
+ if n and u then
+ if type(u) == "table" then
+ local t = { }
+ for i=1,#u do
+ t[i] = f_u(u[i])
+ end
+ u = concat(t," ")
+ end
+ local t = names[n]
+ t[u] = (t[u] or 0) + 1
+ end
+ end
+ end
+ else
+ -- nothing
end
end
end
+ if next(names) then
+ context.starttabulate { "|l|pl|" }
+ local f_u = formatters["%04X~(%i)"]
+ local f_s = formatters["%s~(%i)"]
+ for k, v in sortedhash(names) do
+ local t = { }
+ for k, v in sortedhash(v) do
+ if type(k) == "string" then
+ t[#t+1] = f_s(k,v)
+ else
+ t[#t+1] = f_u(k,v)
+ end
+ end
+ NC() ctx_verbatim(k)
+ NC() context("% t",t)
+ NC() NR()
+ end
+ context.stoptabulate()
+ end
+ table.save("s-fonts-system-glyph-names.lua",names)
end