summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/font-shp.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-03-05 00:48:46 +0000
committerKarl Berry <karl@freefriends.org>2020-03-05 00:48:46 +0000
commitf210bce174e1f2f05305ab03e88e120a1cbfc4da (patch)
tree5c4e2ad096b5c745e859516ac3196fa0864292d5 /Master/texmf-dist/tex/context/base/mkiv/font-shp.lua
parent35fd641a3546acc0c62e0aa7f134888e36da30d4 (diff)
context (from cont-tmf.zip of Feb 17 16:00, size 116339406)
git-svn-id: svn://tug.org/texlive/trunk@54086 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/font-shp.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/font-shp.lua150
1 files changed, 82 insertions, 68 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/font-shp.lua b/Master/texmf-dist/tex/context/base/mkiv/font-shp.lua
index d5c194c858e..3d2e5b7c902 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/font-shp.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/font-shp.lua
@@ -17,12 +17,16 @@ local pfb = fonts.handlers.pfb
local hashes = fonts.hashes
local identifiers = hashes.identifiers
-local version = 0.007
+local version = 0.009
local shapescache = containers.define("fonts", "shapes", version, true)
local streamscache = containers.define("fonts", "streams", version, true)
-- shapes (can be come a separate file at some point)
+local compact_streams = false
+
+directives.register("fonts.streams.compact", function(v) compact_streams = v end)
+
local function packoutlines(data,makesequence)
local subfonts = data.subfonts
if subfonts then
@@ -40,26 +44,27 @@ local function packoutlines(data,makesequence)
return
end
if makesequence then
--- for index=1,#glyphs do
- for index=0,#glyphs-1 do
+ for index=0,#glyphs do
local glyph = glyphs[index]
- local segments = glyph.segments
- if segments then
- local sequence = { }
- local nofsequence = 0
- for i=1,#segments do
- local segment = segments[i]
- local nofsegment = #segment
- -- why last first ... needs documenting
- nofsequence = nofsequence + 1
- sequence[nofsequence] = segment[nofsegment]
- for i=1,nofsegment-1 do
+ if glyph then
+ local segments = glyph.segments
+ if segments then
+ local sequence = { }
+ local nofsequence = 0
+ for i=1,#segments do
+ local segment = segments[i]
+ local nofsegment = #segment
+ -- why last first ... needs documenting
nofsequence = nofsequence + 1
- sequence[nofsequence] = segment[i]
+ sequence[nofsequence] = segment[nofsegment]
+ for i=1,nofsegment-1 do
+ nofsequence = nofsequence + 1
+ sequence[nofsequence] = segment[i]
+ end
end
+ glyph.sequence = sequence
+ glyph.segments = nil
end
- glyph.sequence = sequence
- glyph.segments = nil
end
end
else
@@ -67,32 +72,36 @@ local function packoutlines(data,makesequence)
local common = { }
local reverse = { }
local last = 0
--- for index=1,#glyphs do
- for index=0,#glyphs-1 do
- local segments = glyphs[index].segments
- if segments then
- for i=1,#segments do
- local h = concat(segments[i]," ")
- hash[h] = (hash[h] or 0) + 1
+ for index=0,#glyphs do
+ local glyph = glyphs[index]
+ if glyph then
+ local segments = glyph.segments
+ if segments then
+ for i=1,#segments do
+ local h = concat(segments[i]," ")
+ hash[h] = (hash[h] or 0) + 1
+ end
end
end
end
--- for index=1,#glyphs do
- for index=0,#glyphs-1 do
- local segments = glyphs[index].segments
- if segments then
- for i=1,#segments do
- local segment = segments[i]
- local h = concat(segment," ")
- if hash[h] > 1 then -- minimal one shared in order to hash
- local idx = reverse[h]
- if not idx then
- last = last + 1
- reverse[h] = last
- common[last] = segment
- idx = last
+ for index=0,#glyphs do
+ local glyph = glyphs[index]
+ if glyph then
+ local segments = glyph.segments
+ if segments then
+ for i=1,#segments do
+ local segment = segments[i]
+ local h = concat(segment," ")
+ if hash[h] > 1 then -- minimal one shared in order to hash
+ local idx = reverse[h]
+ if not idx then
+ last = last + 1
+ reverse[h] = last
+ common[last] = segment
+ idx = last
+ end
+ segments[i] = idx
end
- segments[i] = idx
end
end
end
@@ -119,14 +128,16 @@ local function unpackoutlines(data)
if not glyphs then
return
end
--- for index=1,#glyphs do
- for index=0,#glyphs-1 do
- local segments = glyphs[index].segments
- if segments then
- for i=1,#segments do
- local c = common[segments[i]]
- if c then
- segments[i] = c
+ for index=0,#glyphs do
+ local glyph = glyphs[index]
+ if glyph then
+ local segments = glyph.segments
+ if segments then
+ for i=1,#segments do
+ local c = common[segments[i]]
+ if c then
+ segments[i] = c
+ end
end
end
end
@@ -202,6 +213,11 @@ local function loadoutlines(cache,filename,sub,instance)
return data
end
+local function cachethem(cache,hash,data)
+ containers.write(cache,hash,data,compact_streams) -- arg 4 aka fast
+ return containers.read(cache,hash) -- frees old mem
+end
+
local function loadstreams(cache,filename,sub,instance)
local base = file.basename(filename)
local name = file.removesuffix(base)
@@ -210,7 +226,7 @@ local function loadstreams(cache,filename,sub,instance)
local size = attr and attr.size or 0
local time = attr and attr.modification or 0
local sub = tonumber(sub)
- if size > 0 and (kind == "otf" or kind == "ttf" or kind == "tcc") then
+ if size > 0 and (kind == "otf" or kind == "ttf" or kind == "ttc") then
local hash = makehash(filename,sub,instance)
data = containers.read(cache,hash)
if not data or data.time ~= time or data.size ~= size then
@@ -219,8 +235,13 @@ local function loadstreams(cache,filename,sub,instance)
local glyphs = data.glyphs
local streams = { }
if glyphs then
- for i=0,#glyphs-1 do
- streams[i] = glyphs[i].stream or ""
+ for i=0,#glyphs do
+ local glyph = glyphs[i]
+ if glyph then
+ streams[i] = glyph.stream or ""
+ else
+ streams[i] = ""
+ end
end
end
data.streams = streams
@@ -228,8 +249,7 @@ local function loadstreams(cache,filename,sub,instance)
data.size = size
data.format = data.format or (kind == "otf" and "opentype") or "truetype"
data.time = time
- containers.write(cache,hash,data)
- data = containers.read(cache,hash) -- frees old mem
+ data = cachethem(cache,hash,data)
end
end
elseif size > 0 and (kind == "pfb") then
@@ -283,8 +303,7 @@ local function loadstreams(cache,filename,sub,instance)
weight = metadata.weight,
},
}
- containers.write(cache,hash,data)
- data = containers.read(cache,hash) -- frees old mem
+ data = cachethem(cache,hash,data)
end
end
else
@@ -333,8 +352,11 @@ end
local function loadstreamdata(fontdata)
local properties = fontdata.properties
+ local shared = fontdata.shared
+ local rawdata = shared and shared.rawdata
+ local metadata = rawdata and rawdata.metadata
local filename = properties.filename
- local subindex = fontdata.subindex
+ local subindex = metadata and metadata.subfontindex
local instance = properties.instance
local hash = makehash(filename,subindex,instance)
local loaded = loadedstreams[hash]
@@ -348,26 +370,18 @@ end
hashes.streams = table.setmetatableindex(function(t,k)
local f = identifiers[k]
if f then
- return loadstreamdata(f,true)
+ return loadstreamdata(f)
end
end)
otf.loadoutlinedata = loadoutlinedata -- not public
otf.loadstreamdata = loadstreamdata -- not public
otf.loadshapes = loadshapes
-otf.getstreamhash = getstreamhash -- not public, might move to other namespace
+otf.getstreamhash = getstreamhash -- not public, might move to other namespace
--- experimental code, for me only ... unsupported (todo: use %N)
-
-local f_c = formatters["%F %F %F %F %F %F c"]
-local f_l = formatters["%F %F l"]
-local f_m = formatters["%F %F m"]
-
-directives.register("pdf.stripzeros",function()
- f_c = formatters["%N %N %N %N %N %N c"]
- f_l = formatters["%N %N l"]
- f_m = formatters["%N %N m"]
-end)
+local f_c = formatters["%.6N %.6N %.6N %.6N %.6N %.6N c"]
+local f_l = formatters["%.6N %.6N l"]
+local f_m = formatters["%.6N %.6N m"]
local function segmentstopdf(segments,factor,bt,et)
local t = { }