summaryrefslogtreecommitdiff
path: root/src/fontloader/misc
diff options
context:
space:
mode:
Diffstat (limited to 'src/fontloader/misc')
-rw-r--r--src/fontloader/misc/fontloader-font-afm.lua11
-rw-r--r--src/fontloader/misc/fontloader-font-ini.lua2
-rw-r--r--src/fontloader/misc/fontloader-font-otf.lua24
-rw-r--r--src/fontloader/misc/fontloader-l-file.lua131
-rw-r--r--src/fontloader/misc/fontloader-l-io.lua5
-rw-r--r--src/fontloader/misc/fontloader-l-lua.lua11
-rw-r--r--src/fontloader/misc/fontloader-l-table.lua32
-rw-r--r--src/fontloader/misc/fontloader-util-str.lua4
8 files changed, 127 insertions, 93 deletions
diff --git a/src/fontloader/misc/fontloader-font-afm.lua b/src/fontloader/misc/fontloader-font-afm.lua
index ca5616a..a96c668 100644
--- a/src/fontloader/misc/fontloader-font-afm.lua
+++ b/src/fontloader/misc/fontloader-font-afm.lua
@@ -48,6 +48,11 @@ local definers = fonts.definers
local readers = fonts.readers
local constructors = fonts.constructors
+local fontloader = fontloader
+local font_to_table = fontloader.to_table
+local open_font = fontloader.open
+local close_font = fontloader.close
+
local afm = constructors.newhandler("afm")
local pfb = constructors.newhandler("pfb")
@@ -222,10 +227,10 @@ end
local function get_indexes(data,pfbname)
data.resources.filename = resolvers.unresolve(pfbname) -- no shortcut
- local pfbblob = fontloader.open(pfbname)
+ local pfbblob = open_font(pfbname)
if pfbblob then
local characters = data.characters
- local pfbdata = fontloader.to_table(pfbblob)
+ local pfbdata = font_to_table(pfbblob)
if pfbdata then
local glyphs = pfbdata.glyphs
if glyphs then
@@ -251,7 +256,7 @@ local function get_indexes(data,pfbname)
elseif trace_loading then
report_afm("no data in pfb file %a",pfbname)
end
- fontloader.close(pfbblob)
+ close_font(pfbblob)
elseif trace_loading then
report_afm("invalid pfb file %a",pfbname)
end
diff --git a/src/fontloader/misc/fontloader-font-ini.lua b/src/fontloader/misc/fontloader-font-ini.lua
index 884b224..c547f89 100644
--- a/src/fontloader/misc/fontloader-font-ini.lua
+++ b/src/fontloader/misc/fontloader-font-ini.lua
@@ -29,4 +29,4 @@ fonts.readers = { }
fonts.definers = { methods = { } }
fonts.loggers = { register = function() end }
-fontloader.totable = fontloader.to_table
+fontloader.totable = fontloader.to_table -- not used
diff --git a/src/fontloader/misc/fontloader-font-otf.lua b/src/fontloader/misc/fontloader-font-otf.lua
index 1bb608f..44ad893 100644
--- a/src/fontloader/misc/fontloader-font-otf.lua
+++ b/src/fontloader/misc/fontloader-font-otf.lua
@@ -56,13 +56,14 @@ otf.glists = { "gsub", "gpos" }
otf.version = 2.802 -- beware: also sync font-mis.lua
otf.cache = containers.define("fonts", "otf", otf.version, true)
-local fontdata = fonts.hashes.identifiers
-local chardata = characters and characters.data -- not used
-
+local hashes = fonts.hashes
local definers = fonts.definers
local readers = fonts.readers
local constructors = fonts.constructors
+local fontdata = hashes and hashes.identifiers
+local chardata = characters and characters.data -- not used
+
local otffeatures = constructors.newfeatures("otf")
local registerotffeature = otffeatures.register
@@ -84,7 +85,12 @@ local applyruntimefixes = fonts.treatments and fonts.treatments.applyfixes
local wildcard = "*"
local default = "dflt"
-local fontloaderfields = fontloader.fields
+local fontloader = fontloader
+local open_font = fontloader.open
+local close_font = fontloader.close
+local font_fields = fontloader.fields
+local apply_featurefile = fontloader.apply_featurefile
+
local mainfields = nil
local glyphfields = nil -- not used yet
@@ -137,7 +143,7 @@ local function load_featurefile(raw,featurefile)
if trace_loading then
report_otf("using featurefile %a", featurefile)
end
- fontloader.apply_featurefile(raw, featurefile)
+ apply_featurefile(raw, featurefile)
end
end
@@ -437,12 +443,12 @@ function otf.load(filename,sub,featurefile) -- second argument (format) is gone
report_otf("loading %a, hash %a",filename,hash)
local fontdata, messages
if sub then
- fontdata, messages = fontloader.open(filename,sub)
+ fontdata, messages = open_font(filename,sub)
else
- fontdata, messages = fontloader.open(filename)
+ fontdata, messages = open_font(filename)
end
if fontdata then
- mainfields = mainfields or (fontloaderfields and fontloaderfields(fontdata))
+ mainfields = mainfields or (font_fields and font_fields(fontdata))
end
if trace_loading and messages and #messages > 0 then
if type(messages) == "string" then
@@ -526,7 +532,7 @@ function otf.load(filename,sub,featurefile) -- second argument (format) is gone
report_otf("preprocessing and caching time %s, packtime %s",
elapsedtime(data),packdata and elapsedtime(packtime) or 0)
end
- fontloader.close(fontdata) -- free memory
+ close_font(fontdata) -- free memory
if cleanup > 3 then
collectgarbage("collect")
end
diff --git a/src/fontloader/misc/fontloader-l-file.lua b/src/fontloader/misc/fontloader-l-file.lua
index 2742e99..2c471d7 100644
--- a/src/fontloader/misc/fontloader-l-file.lua
+++ b/src/fontloader/misc/fontloader-l-file.lua
@@ -15,51 +15,53 @@ if not lfs then
lfs = optionalrequire("lfs")
end
-if not lfs then
-
- lfs = {
- getcurrentdir = function()
- return "."
- end,
- attributes = function()
- return nil
- end,
- isfile = function(name)
- local f = io.open(name,'rb')
- if f then
- f:close()
- return true
- end
- end,
- isdir = function(name)
- print("you need to load lfs")
- return false
- end
- }
-
-elseif not lfs.isfile then
-
- local attributes = lfs.attributes
-
- function lfs.isdir(name)
- return attributes(name,"mode") == "directory"
- end
-
- function lfs.isfile(name)
- return attributes(name,"mode") == "file"
- end
-
- -- function lfs.isdir(name)
- -- local a = attributes(name)
- -- return a and a.mode == "directory"
- -- end
-
- -- function lfs.isfile(name)
- -- local a = attributes(name)
- -- return a and a.mode == "file"
- -- end
-
-end
+-- -- see later
+--
+-- if not lfs then
+--
+-- lfs = {
+-- getcurrentdir = function()
+-- return "."
+-- end,
+-- attributes = function()
+-- return nil
+-- end,
+-- isfile = function(name)
+-- local f = io.open(name,'rb')
+-- if f then
+-- f:close()
+-- return true
+-- end
+-- end,
+-- isdir = function(name)
+-- print("you need to load lfs")
+-- return false
+-- end
+-- }
+--
+-- elseif not lfs.isfile then
+--
+-- local attributes = lfs.attributes
+--
+-- function lfs.isdir(name)
+-- return attributes(name,"mode") == "directory"
+-- end
+--
+-- function lfs.isfile(name)
+-- return attributes(name,"mode") == "file"
+-- end
+--
+-- -- function lfs.isdir(name)
+-- -- local a = attributes(name)
+-- -- return a and a.mode == "directory"
+-- -- end
+--
+-- -- function lfs.isfile(name)
+-- -- local a = attributes(name)
+-- -- return a and a.mode == "file"
+-- -- end
+--
+-- end
local insert, concat = table.insert, table.concat
local match, find, gmatch = string.match, string.find, string.gmatch
@@ -72,6 +74,28 @@ local checkedsplit = string.checkedsplit
local P, R, S, C, Cs, Cp, Cc, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpeg.Cp, lpeg.Cc, lpeg.Ct
+-- better this way:
+
+local tricky = S("/\\") * P(-1)
+local attributes = lfs.attributes
+
+if sandbox then
+ sandbox.redefine(lfs.isfile,"lfs.isfile")
+ sandbox.redefine(lfs.isdir, "lfs.isdir")
+end
+
+function lfs.isdir(name)
+ if lpegmatch(tricky,name) then
+ return attributes(name,"mode") == "directory"
+ else
+ return attributes(name.."/.","mode") == "directory"
+ end
+end
+
+function lfs.isfile(name)
+ return attributes(name,"mode") == "file"
+end
+
local colon = P(":")
local period = P(".")
local periods = P("..")
@@ -554,23 +578,6 @@ function file.collapsepath(str,anchor) -- anchor: false|nil, true, "."
end
end
--- better this way:
-
-local tricky = S("/\\") * P(-1)
-local attributes = lfs.attributes
-
-function lfs.isdir(name)
- if lpegmatch(tricky,name) then
- return attributes(name,"mode") == "directory"
- else
- return attributes(name.."/.","mode") == "directory"
- end
-end
-
-function lfs.isfile(name)
- return attributes(name,"mode") == "file"
-end
-
-- local function test(str,...)
-- print(string.format("%-20s %-15s %-30s %-20s",str,file.collapsepath(str),file.collapsepath(str,true),file.collapsepath(str,".")))
-- end
diff --git a/src/fontloader/misc/fontloader-l-io.lua b/src/fontloader/misc/fontloader-l-io.lua
index 020e811..a91d44d 100644
--- a/src/fontloader/misc/fontloader-l-io.lua
+++ b/src/fontloader/misc/fontloader-l-io.lua
@@ -339,11 +339,6 @@ function io.readstring(f,n,m)
return str
end
---
-
-if not io.i_limiter then function io.i_limiter() end end -- dummy so we can test safely
-if not io.o_limiter then function io.o_limiter() end end -- dummy so we can test safely
-
-- This works quite ok:
--
-- function io.piped(command,writer)
diff --git a/src/fontloader/misc/fontloader-l-lua.lua b/src/fontloader/misc/fontloader-l-lua.lua
index 9565f48..1a2a987 100644
--- a/src/fontloader/misc/fontloader-l-lua.lua
+++ b/src/fontloader/misc/fontloader-l-lua.lua
@@ -165,3 +165,14 @@ end
if lua then
lua.mask = load([[τεχ = 1]]) and "utf" or "ascii"
end
+
+local flush = io.flush
+
+if flush then
+
+ local execute = os.execute if execute then function os.execute(...) flush() return execute(...) end end
+ local exec = os.exec if exec then function os.exec (...) flush() return exec (...) end end
+ local spawn = os.spawn if spawn then function os.spawn (...) flush() return spawn (...) end end
+ local popen = io.popen if popen then function io.popen (...) flush() return popen (...) end end
+
+end
diff --git a/src/fontloader/misc/fontloader-l-table.lua b/src/fontloader/misc/fontloader-l-table.lua
index 3eb8b85..97e0441 100644
--- a/src/fontloader/misc/fontloader-l-table.lua
+++ b/src/fontloader/misc/fontloader-l-table.lua
@@ -49,9 +49,19 @@ function table.keys(t)
end
end
+-- local function compare(a,b)
+-- local ta, tb = type(a), type(b) -- needed, else 11 < 2
+-- if ta == tb then
+-- return a < b
+-- else
+-- return tostring(a) < tostring(b) -- not that efficient
+-- end
+-- end
+
local function compare(a,b)
- local ta, tb = type(a), type(b) -- needed, else 11 < 2
- if ta == tb then
+ local ta = type(a) -- needed, else 11 < 2
+ local tb = type(b) -- needed, else 11 < 2
+ if ta == tb and ta == "number" then
return a < b
else
return tostring(a) < tostring(b) -- not that efficient
@@ -469,7 +479,7 @@ local function do_serialize(root,name,depth,level,indexed)
end
end
-- we could check for k (index) being number (cardinal)
- if root and next(root) then
+ if root and next(root) ~= nil then
-- local first, last = nil, 0 -- #root cannot be trusted here (will be ok in 5.2 when ipairs is gone)
-- if compact then
-- -- NOT: for k=1,#root do (we need to quit at nil)
@@ -513,7 +523,7 @@ local function do_serialize(root,name,depth,level,indexed)
handle(format("%s %q,",depth,v))
end
elseif tv == "table" then
- if not next(v) then
+ if next(v) == nil then
handle(format("%s {},",depth))
elseif inline then -- and #t > 0
local st = simple_table(v)
@@ -597,7 +607,7 @@ local function do_serialize(root,name,depth,level,indexed)
end
end
elseif tv == "table" then
- if not next(v) then
+ if next(v) == nil then
if tk == "number" then
if hexify then
handle(format("%s [0x%X]={},",depth,k))
@@ -683,7 +693,7 @@ local function do_serialize(root,name,depth,level,indexed)
--~ end
end
end
- if level > 0 then
+ if level > 0 then
handle(format("%s},",depth))
end
end
@@ -748,7 +758,7 @@ local function serialize(_handle,root,name,specification) -- handle wins
root._w_h_a_t_e_v_e_r_ = nil
end
-- Let's forget about empty tables.
- if next(root) then
+ if next(root) ~= nil then
do_serialize(root,name,"",0)
end
end
@@ -928,7 +938,7 @@ local function sparse(old,nest,keeptables)
if not (v == "" or v == false) then
if nest and type(v) == "table" then
v = sparse(v,nest)
- if keeptables or next(v) then
+ if keeptables or next(v) ~= nil then
new[k] = v
end
else
@@ -1066,11 +1076,11 @@ end
-- slower than #t on indexed tables (#t only returns the size of the numerically indexed slice)
function table.is_empty(t)
- return not t or not next(t)
+ return not t or next(t) == nil
end
function table.has_one_entry(t)
- return t and not next(t,next(t))
+ return t and next(t,next(t)) == nil
end
-- new
@@ -1157,7 +1167,7 @@ function table.filtered(t,pattern,sort,cmp)
else
local n = next(t)
local function iterator()
- while n do
+ while n ~= nil do
local k = n
n = next(t,k)
if find(k,pattern) then
diff --git a/src/fontloader/misc/fontloader-util-str.lua b/src/fontloader/misc/fontloader-util-str.lua
index a040b01..a677a82 100644
--- a/src/fontloader/misc/fontloader-util-str.lua
+++ b/src/fontloader/misc/fontloader-util-str.lua
@@ -361,10 +361,10 @@ strings.tracers = tracedchars
function string.tracedchar(b)
-- todo: table
if type(b) == "number" then
- return tracedchars[b] or (utfchar(b) .. " (U+" .. format('%05X',b) .. ")")
+ return tracedchars[b] or (utfchar(b) .. " (U+" .. format("%05X",b) .. ")")
else
local c = utfbyte(b)
- return tracedchars[c] or (b .. " (U+" .. format('%05X',c) .. ")")
+ return tracedchars[c] or (b .. " (U+" .. (c and format("%05X",c) or "?????") .. ")")
end
end