summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-onr.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/font-onr.lua')
-rw-r--r--tex/context/base/mkiv/font-onr.lua79
1 files changed, 59 insertions, 20 deletions
diff --git a/tex/context/base/mkiv/font-onr.lua b/tex/context/base/mkiv/font-onr.lua
index 26a782649..8523d8729 100644
--- a/tex/context/base/mkiv/font-onr.lua
+++ b/tex/context/base/mkiv/font-onr.lua
@@ -26,7 +26,7 @@ local match, lower, gsub, strip, find = string.match, string.lower, string.gsub,
local char, byte, sub = string.char, string.byte, string.sub
local abs = math.abs
local bxor, rshift = bit32.bxor, bit32.rshift
-local P, S, R, Cmt, C, Ct, Cs, Carg, Cf, Cg = lpeg.P, lpeg.S, lpeg.R, lpeg.Cmt, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cf, lpeg.Cg
+local P, S, R, V, Cmt, C, Ct, Cs, Carg, Cf, Cg, Cc = lpeg.P, lpeg.S, lpeg.R, lpeg.V, lpeg.Cmt, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cf, lpeg.Cg, lpeg.Cc
local lpegmatch, patterns = lpeg.match, lpeg.patterns
local trace_indexing = false trackers.register("afm.indexing", function(v) trace_indexing = v end)
@@ -83,31 +83,40 @@ do
end
- local charstrings = P("/CharStrings")
- local subroutines = P("/Subrs")
- local encoding = P("/Encoding")
- local dup = P("dup")
- local put = P("put")
- local array = P("array")
- local name = P("/") * C((R("az","AZ","09")+S("-_."))^1)
- local digits = R("09")^1
- local cardinal = digits / tonumber
- local spaces = P(" ")^1
- local spacing = patterns.whitespace^0
+ local charstrings = P("/CharStrings")
+ local subroutines = P("/Subrs")
+ local encoding = P("/Encoding")
+ local dup = P("dup")
+ local put = P("put")
+ local array = P("array")
+ local name = P("/") * C((R("az","AZ","09")+S("-_."))^1)
+ local digits = R("09")^1
+ local cardinal = digits / tonumber
+ local spaces = P(" ")^1
+ local spacing = patterns.whitespace^0
local routines, vector, chars, n, m
local initialize = function(str,position,size)
n = 0
- m = size -- % tonumber(size)
+ m = size
return position + 1
end
local setroutine = function(str,position,index,size,filename)
- local forward = position + tonumber(size)
+ if routines[index] then
+ -- we have passed the end
+ return false
+ end
+ local forward = position + size
local stream = decrypt(sub(str,position+1,forward),4330,4)
routines[index] = { byte(stream,1,#stream) }
- return forward
+ n = n + 1
+ if n >= m then
+ -- m should be index now but can we assume ordering?
+ return #str
+ end
+ return forward + 1
end
local setvector = function(str,position,name,size,filename)
@@ -152,7 +161,7 @@ do
local p_filterroutines = -- dup <i> <n> RD or -| <n encrypted bytes> NP or |
(1-subroutines)^0 * subroutines * spaces * Cmt(cardinal,initialize)
- * (Cmt(cardinal * spaces * cardinal * p_rd * Carg(1), setroutine) * p_np + P(1))^1
+ * (Cmt(cardinal * spaces * cardinal * p_rd * Carg(1), setroutine) * p_np + (1-p_nd))^1
local p_filtershapes = -- /foo <n> RD <n encrypted bytes> ND
(1-charstrings)^0 * charstrings * spaces * Cmt(cardinal,initialize)
@@ -175,7 +184,33 @@ do
-- if one of first 4 not 0-9A-F then binary else hex
- local function loadpfbvector(filename,shapestoo)
+ local key = spacing * P("/") * R("az","AZ")
+ local str = spacing * Cs { (P("(")/"") * ((1 - P("\\(") - P("\\)") - S("()")) + V(1))^0 * (P(")")/"") }
+ local num = spacing * (R("09") + S("+-."))^1 / tonumber
+ local arr = spacing * Ct (S("[{") * (num)^0 * spacing * S("]}"))
+ local boo = spacing * (P("true") * Cc(true) + P("false") * Cc(false))
+ local nam = spacing * P("/") * Cs(R("az","AZ")^1)
+
+ local p_filtermetadata = (
+ P("/") * Carg(1) * ( (
+ C("version") * str
+ + C("Copyright") * str
+ + C("Notice") * str
+ + C("FullName") * str
+ + C("FamilyName") * str
+ + C("Weight") * str
+ + C("ItalicAngle") * num
+ + C("isFixedPitch") * boo
+ + C("UnderlinePosition") * num
+ + C("UnderlineThickness") * num
+ + C("FontName") * nam
+ + C("FontMatrix") * arr
+ + C("FontBBox") * arr
+ ) ) / function(t,k,v) t[lower(k)] = v end
+ + P(1)
+ )^0 * Carg(1)
+
+ local function loadpfbvector(filename,shapestoo,streams)
-- for the moment limited to encoding only
local data = io.loaddata(resolvers.findfile(filename))
@@ -200,11 +235,14 @@ do
binary = decrypt(binary,55665,4)
local names = { }
+
local encoding = lpegmatch(p_filterencoding,ascii)
+ local metadata = lpegmatch(p_filtermetadata,ascii,1,{})
local glyphs = { }
routines, vector, chars = { }, { }, { }
- if shapestoo then
+ if shapestoo or streams then
+ -- io.savedata("foo.txt",binary)
lpegmatch(p_filterroutines,binary,1,filename)
lpegmatch(p_filtershapes,binary,1,filename)
local data = {
@@ -216,7 +254,8 @@ do
}
},
}
- fonts.handlers.otf.readers.parsecharstrings(false,data,glyphs,true,true)
+ -- only cff 1 in type 1 fonts
+ fonts.handlers.otf.readers.parsecharstrings(false,data,glyphs,true,"cff",streams)
else
lpegmatch(p_filternames,binary,1,filename)
end
@@ -225,7 +264,7 @@ do
routines, vector, chars = nil, nil, nil
- return names, encoding, glyphs
+ return names, encoding, glyphs, metadata
end