Skip to content

Commit

Permalink
TeX : fontscrpts : don't require +/- thing for map files in check & k…
Browse files Browse the repository at this point in the history
…ludge to keep line nos same in log
  • Loading branch information
Clea F. Rees committed Feb 19, 2025
1 parent 46bd966 commit 32c00c0
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 71 deletions.
80 changes: 20 additions & 60 deletions fontscripts/fntbuild-build.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,8 @@
-- $Id: fntbuild-build.lua 10803 2025-02-14 02:10:09Z cfrees $
-- $Id: fntbuild-build.lua 10818 2025-02-19 05:44:13Z cfrees $
-------------------------------------------------
-- fntbuild-build
-------------------------------------------------
-------------------------------------------------
-- map_cat (frags,dir,mapfile) {{{
---@param frags table
---@param dir string
---@param mapfile string
---@return 0 on success, number of errors otherwise
---@see
---@usage private
local function map_cat (frags,dir,mapfile)
mapfile = mapfile or "pdftex.map"
local n = 0
if #frags == 0 then
frags = { "cm.map", "cm-super-t1.map", "cm-super-ts1.map", "lm.map" }
end
if #fnt.mapfiles_add ~= 0 then
for _,i in ipairs(fnt.mapfiles_add) do
table.insert(frags,i)
end
end
if fileexists(dir .. "/" .. mapfile) then
local errorlevel = rm(dir,mapfile)
fnt.gwall("Removal of ",dir .. "/" .. mapfile,errorlevel)
end
if #frags ~= 0 then
local m = assert(io.open(dir .. "/" .. mapfile,"a"))
for _,i in ipairs(frags) do
-- kpse.find_file assumes filetype tex i.e. ignores file ext.
local ff = kpse.find_file(i,"map")
if ff ~= "" then
local f = assert(io.open(ff),"rb")
local l = f:read("*all")
f:close()
m:write(l)
else
fnt.gwall("Search for map fragment ",i,1)
n = n + 1
end
end
m:close()
end
return n
end
-- }}}
-------------------------------------------------
-- buildinit_hook
---@return 0
---@usage public
Expand Down Expand Up @@ -110,12 +67,12 @@ local function buildinit ()
end
print("Copied fontinst files to " .. fnt.fntdir)
end
if not fnt.buildsearch then
-- we aren't typesetting, so we really don't need a map file
-- not sure this is really needed - do any tools use this anyway?
-- https://rosettacode.org/wiki/Create_a_file
io.open(fnt.fntdir .. "/pdftex.map", "w"):close()
end
-- if not fnt.buildsearch then
-- -- we aren't typesetting, so we really don't need a map file
-- -- not sure this is really needed - do any tools use this anyway?
-- -- https://rosettacode.org/wiki/Create_a_file
-- io.open(fnt.fntdir .. "/pdftex.map", "w"):close()
-- end
print("Initialised build.")
return fnt.buildinit_hook()
end
Expand Down Expand Up @@ -199,6 +156,10 @@ end
---@usage public
local function fntkeeper (dir)
dir = dir or fnt.fntdir
if fileexists(dir .. "/pdftex.map") then
local errorlevel = rm(dir,"pdftex.map")
fnt.gwall("Removing ","pdftex.map",errorlevel)
end
local rtn = direxists(fnt.keepdir)
if not rtn then
local errorlevel = mkdir(fnt.keepdir)
Expand Down Expand Up @@ -328,11 +289,11 @@ local function uniquify (tag)
else
dir = fnt.fntdir
end
if fileexists(dir .. "/pdftex.map") then
print("\nRemoving temporary pdftex.map from ", dir, "...\n")
local errorlevel = rm(dir,"pdftex.map")
fnt.gwall("Removing ","pdftex.map",errorlevel)
end
-- if fileexists(dir .. "/pdftex.map") then
-- print("\nRemoving temporary pdftex.map from ", dir, "...\n")
-- local errorlevel = rm(dir,"pdftex.map")
-- fnt.gwall("Removing ","pdftex.map",errorlevel)
-- end
if pkgbase == "" then
print("pkgbase unspecified. Trying to guess ... ")
if not fnt.standalone then
Expand Down Expand Up @@ -677,10 +638,10 @@ local function afm2tfm (dir)
-- need to do this as uniquify() isn't used
-- otherwise the file ends up in localdir (and probably the package)
-- catching this is the only benefit I can see in my inability to clean localdir
if fileexists(dir .. "/pdftex.map") then
local errorlevel = rm(dir,"pdftex.map")
fnt.gwall("Removing ","pdftex.map",errorlevel)
end
-- if fileexists(dir .. "/pdftex.map") then
-- local errorlevel = rm(dir,"pdftex.map")
-- fnt.gwall("Removing ","pdftex.map",errorlevel)
-- end
local f
f = assert(io.open(dir .. "/" .. map, "w"))
f:write((string.gsub(content,"\n",fnt.os_newline_cp)))
Expand All @@ -706,7 +667,6 @@ fnt.fntkeeper = fntkeeper
fnt.fntsubsetter = fntsubsetter
fnt.afm2tfm = afm2tfm
fnt.fontinst = fontinst
fnt.map_cat = map_cat
fnt.uniquify = uniquify
-- }}}
-------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions fontscripts/fntbuild-check.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- $Id: fntbuild-check.lua 10802 2025-02-12 20:11:33Z cfrees $
-- $Id: fntbuild-check.lua 10818 2025-02-19 05:44:13Z cfrees $
-------------------------------------------------
-- fntbuild-check
-------------------------------------------------
Expand Down Expand Up @@ -81,25 +81,24 @@ local function test (fntpkgname,fds,content,maps,fdsdir)
end
end
end
coll = maps .. "\n\\usepackage[enc=t1]{" .. fntpkgname
-- the two skipped lines keep the line numbers the same in the log even though I've removed the lines subtracting/adding map lines
coll = "\n\n%% map file lines in local pdftex.map\n\\usepackage[enc=t1]{" .. fntpkgname
.. "}\n\\begin{document}\n\\START\n"
.. coll .. "\n\\END\n\\end{document}\n"
collly = maps .. "\n\\usepackage[enc=ly1]{" .. fntpkgname
collly = "\n\n%% map file lines in local pdftex.map\n\\usepackage[enc=ly1]{" .. fntpkgname
.. "}\n\\begin{document}\n\\START\n" .. collly
.. "\n\\END\n\\end{document}\n"
else
-- assume package doesn't have an encoding option and is t1/ts1 only
coll = maps .. "\n\\usepackage{" .. fntpkgname
coll = "\n\n%% map file lines in local pdftex.map\n\\usepackage{" .. fntpkgname
.. "}\n\\begin{document}\n\\START\n" .. coll
.. "\n\\END\n\\end{document}\n"
end
-- coll = maps .. "\n\\begin{document}\n\\START\n" .. coll .. "\n\\END\n\\end{document}\n"
local new_content =
"%% Do not edit this file as changes will be overwritten.\n%% It was generated by l3build on "
.. os.date("%Y-%M-%d %H:%m:%S") .. ".\n"
.. string.gsub(content, "\nSAMP *\n", coll)
local f = assert(io.open(targfile,"w"))
-- this somehow removes the second value returned by string.gsub??
f:write((string.gsub(new_content,"\n",fnt.os_newline_cp)))
f:close()
if yy == 1 then
Expand Down Expand Up @@ -144,7 +143,7 @@ local function check_init ()
local fdsdir = ""
-- local adds = checksuppfiles_addlst or maindir .. "/checksuppfiles-add.lst"
if not checksearch then
fnt.map_cat(fnt.mapfiles_sys,testdir)
fnt.map_cat_sys(fnt.mapfiles_sys,testdir)
end
-- how did this ever work?
for _,i in ipairs(filelist(fnt.keepdir)) do
Expand Down Expand Up @@ -239,6 +238,7 @@ local function check_init ()
mapsdir = fnt.keepdir
print("\nUsing maps from", fnt.keepdir)
end
assert(fnt.map_cat_pkg(mapfiles,mapsdir,testdir),"Could not concatenate new maps!")
local fntpkgnames = fntpkgnames or filelist(unpackdir,"*.sty")
for i, j in ipairs(fntpkgnames) do
fntpkgnames[i] = string.gsub(j,"%.sty","")
Expand Down Expand Up @@ -307,9 +307,9 @@ local function check_init ()
end
end
-------
for i, j in ipairs(mapfiles) do
maps = maps .. "\n\\pdfmapfile{-" .. j .. "}\n\\pdfmapfile{+" .. j .. "}"
end
-- for i, j in ipairs(mapfiles) do
-- maps = maps .. "\n\\pdfmapfile{-" .. j .. "}\n\\pdfmapfile{+" .. j .. "}"
-- end
-- maps = maps .. "\n\\pdfmapfile{+pdftex.map}"
if next(fnt.fnttestfds) == nil then
print("Skipping test creation.\n")
Expand Down
104 changes: 103 additions & 1 deletion fontscripts/fntbuild-utils.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- $Id: fntbuild-utils.lua 10803 2025-02-14 02:10:09Z cfrees $
-- $Id: fntbuild-utils.lua 10818 2025-02-19 05:44:13Z cfrees $
-------------------------------------------------
-- fntbuild-utils
-------------------------------------------------
Expand Down Expand Up @@ -224,6 +224,106 @@ local function build_config()
end
-- }}}
-------------------------------------------------
-- map_cat_aux (frags,dir,mapfile,append) {{{
---@param frags table
---@param dir string
---@param mapfile string
---@param append boolean
---@return 0 on success, number of errors otherwise
---@see
---@usage private
local function map_cat_aux (frags,dir,mapfile,append)
mapfile = mapfile or "pdftex.map"
append = append or false
if #frags == 0 then return 0 end
if fileexists(dir .. "/" .. mapfile) and not append then
local errorlevel = rm(dir,mapfile)
fnt.gwall("Removal of ",dir .. "/" .. mapfile,errorlevel)
end
local m = assert(io.open(dir .. "/" .. mapfile,"a"))
for _,i in ipairs(frags) do
local f = assert(io.open(i,"rb"))
local l = f:read("*all")
f:close()
m:write(l)
end
m:close()
return 0
end
-- }}}
-------------------------------------------------
-- map_cat_sys (frags,dir,mapfile,append) {{{
---@param frags table
---@param dir string
---@param mapfile string
---@param append boolean
---@return 0 on success, number of errors otherwise
---@see
---@usage private
local function map_cat_sys (frags,dir,mapfile,append)
mapfile = mapfile or "pdftex.map"
append = append or false
local n = 0
if #frags == 0 then
frags = { "cm.map", "cm-super-t1.map", "cm-super-ts1.map", "lm.map" }
end
if #fnt.mapfiles_add ~= 0 then
for _,i in ipairs(fnt.mapfiles_add) do
table.insert(frags,i)
end
end
local ffrags = {}
if #frags ~= 0 then
for _,i in ipairs(frags) do
-- kpse.find_file assumes filetype tex i.e. ignores file ext.
local ff = kpse.find_file(i,"map")
if ff ~= "" then
table.insert(ffrags,ff)
else
fnt.gwall("Search for map fragment ",i,1)
n = n + 1
end
end
frags = ffrags
end
n = n + map_cat_aux(frags,dir,mapfile,append)
return n
end
-- }}}
-------------------------------------------------
-- map_cat_pkg (frags,dir,mapfile,append) {{{
---@param frags table
---@param fragdir string
---@param dir string
---@param mapfile string
---@param append boolean
---@return 0 on success, number of errors otherwise
---@see
---@usage private
local function map_cat_pkg (frags,fragdir,dir,mapfile,append)
mapfile = mapfile or "pdftex.map"
append = append or true
local n = 0
if #frags == 0 then return 0 end
-- abspath() only works for directories
for i,j in ipairs(frags) do
if fileexists(j) then
frags[i] = abspath(dirname(j) .. "/" .. basename(j))
elseif fileexists(fragdir .. "/" .. j) then
frags[i] = abspath(fragdir) .. "/" .. j
elseif fileexists(dir .. "/" .. j) then
frags[i] = abspath(dir) .. "/" .. j
else
fnt.gwall("Finding mapfile fragment ",j,1)
frags[i] = nil
n = n + 1
end
end
if #frags == 0 then return n end
return map_cat_aux(frags,dir,mapfile,append)
end
-- }}}
-------------------------------------------------
-------------------------------------------------
-- exports {{{
fnt.build_config = build_config
Expand All @@ -232,6 +332,8 @@ fnt.dep_install = dep_install
fnt.localtexmf = localtexmf
fnt.lsrdir = lsrdir
fnt.os_newline_cp = os_newline_cp
fnt.map_cat_pkg = map_cat_pkg
fnt.map_cat_sys = map_cat_sys
-------------------------------------------------
-------------------------------------------------
-- vim: ts=2:sw=2:et:foldmethod=marker:

0 comments on commit 32c00c0

Please sign in to comment.