diff options
Diffstat (limited to 'support/findfont/scripts/findfont.lua')
-rwxr-xr-x | support/findfont/scripts/findfont.lua | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/support/findfont/scripts/findfont.lua b/support/findfont/scripts/findfont.lua index 976e3405dc..4446e87590 100755 --- a/support/findfont/scripts/findfont.lua +++ b/support/findfont/scripts/findfont.lua @@ -1,12 +1,14 @@ #!/usr/bin/env texlua +-- % $Id: findfont.lua 330 2021-11-28 13:47:56Z herbert $ + ----------------------------------------------------------------------- -- FILE: findfont.lua -- DESCRIPTION: search for fonts in the database -- REQUIREMENTS: luatex v.0.80 or later; packages lualibs, xindex-lapp --- AUTHOR: Herbert Voß (C) 2021-11-24 +-- AUTHOR: Herbert Voß (C) 2021-11-27 ----------------------------------------------------------------------- findfont = findfont or { } - local version = 0.02 + local version = 0.03 findfont.version = version --[[ @@ -33,12 +35,17 @@ kpse.set_program_name("luatex") local f = kpse.find_file("lualibs.lua") require("lualibs") -- all part of LuaTeX ---require("lpeg") +--require("findfont-utflib") local args = require ('xindex-lapp') [[ + Version: 0.02 + Syntax: fintFont [options] <font> + By default the Lua program 'findfont' creates a list of the + fonts which have in its names the given string. parameter handling -q,--quiet -h,--help + -n,--nosymbolicnames -o,--otfinfo (default 0) -i,--info (default 0) -v... Verbosity level; can be -v, -vv, -vvv @@ -57,23 +64,22 @@ local vlevel = not args.v[1] and 0 or #args.v local not_quiet = not args["quiet"] local otfinfo = args["otfinfo"] local info = args["info"] +local noSymbolicNames = args["nosymbolicnames"] local maxStrLength = args["max_string"] local luaVersion = _VERSION print("We are using "..luaVersion) ---[[ -if args.h then -print( -Syntax: fintFont [options] <font> -By default the Lua program "findfont" creates a list of the -fonts which have in its names the given string.) -end -]] - local font_str = args.font if vlevel > 0 then print('Looking for font \"'..font_str..'\"') end +function getFileParts(fullpath,part) + local path, file, ext = string.match(fullpath, "(.-)([^/]-([^%.]+))$") + if part == "path" then return path + elseif part == "ext" then return ext + else return file end +end + function getFileLocation() local cachepaths = kpse.expand_var('$TEXMFCACHE') or "" if cachepaths == "" or cachepaths == "$TEXMFCACHE" then @@ -112,7 +118,7 @@ function getFileLocation() return file end -function readCompiledOrZippedFile(file) +function readBinaryOrZippedFile(file) print("Check for file "..file) local f,err = io.open (file..".luc", "rb") if not f then @@ -173,7 +179,7 @@ if fontListFile == "" then end fontListFile = fontListFile.."/luaotfload-names" -fontData = readCompiledOrZippedFile(fontListFile) +fontData = readBinaryOrZippedFile(fontListFile) if not fontData then print("umghhh ....") @@ -224,12 +230,15 @@ local fontList = {} local l_max = {1, 1, 1} for i, v in ipairs(fontDataMap) do if v["familyname"] then - if string.find (v["familyname"], font_str, 1, true) then + if string.find (v["familyname"], font_str, 1, true) or (font_str == "*") then -- print(string.format("%2d. %30s %20s %50s",j,v["basename"],v["familyname"],v["fullpath"])) fontList[#fontList+1] = v - if string.len(v["basename"]) > l_max[1] then l_max[1] = string.len(v["basename"]) end + local fullpath = getFileParts(v["fullpath"],"path") -- strip file name + local basename = v["basename"] +-- local basename = string.fromutf8(v["basename"]) + if string.len(basename) > l_max[1] then l_max[1] = string.len(basename) end if string.len(v["familyname"]) > l_max[2] then l_max[2] = string.len(v["familyname"]) end - if string.len(v["fullpath"]) > l_max[3] then l_max[3] = string.len(v["fullpath"]) end + if string.len(fullpath) > l_max[3] then l_max[3] = string.len(fullpath) end j = j + 1 end end @@ -239,12 +248,26 @@ end if l_max[3] > maxStrLength then l_max[3] = maxStrLength end local minChars = 26 +local Fontname = "Fontname" +local Path = "Path" +local SymbolicName = "Symbolic Name" +local lfdNr = "Nr." +if (font_str ~= "*") and not noSymbolicNames then + print(string.format("%4s %"..l_max[1].."s %"..l_max[2].."s %"..l_max[3].."s",lfdNr,Fontname,SymbolicName,Path)) + else + print(string.format("%4s %"..l_max[1].."s %"..l_max[3].."s",lfdNr,Fontname,Path)) +end + for i, v in ipairs(fontList) do - local path = v["fullpath"] + local path = getFileParts(v["fullpath"],"path") if string.len(path) > l_max[3] then path = string.sub (path, 1, minChars).."..."..string.sub (path, string.len(path)-maxStrLength+minChars+4) end - print(string.format("%2d. %"..l_max[1].."s %"..l_max[2].."s %"..l_max[3].."s",i,v["basename"],v["familyname"],path)) + if (font_str ~= "*") and not noSymbolicNames then + print(string.format("%4d. %"..l_max[1].."s %"..l_max[2].."s %"..l_max[3].."s",i,v["basename"],v["familyname"],path)) + else + print(string.format("%4d. %"..l_max[1].."s %"..l_max[3].."s",i,v["basename"],path)) + end end if otfinfo > 0 then |