Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
[fontloader] sync with Context as of 2016-06-16
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-gamma committed Jun 16, 2016
1 parent fdd5fb7 commit 45d384f
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 405 deletions.
125 changes: 70 additions & 55 deletions src/fontloader/misc/fontloader-font-dsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ end
-- We generalize the chained lookups so that we can do with only one handler
-- when processing them.

local function readlookuparray(f,noflookups)
local lookups = { }
if noflookups > 0 then
local length = 0
for i=1,noflookups do
local index = readushort(f) + 1
if index > length then
length = index
end
lookups[index] = readushort(f) + 1
end
for index=1,length do
if not lookups[index] then
lookups[index] = false
end
end
end
return lookups
end

local function unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,what)
local tableoffset = lookupoffset + offset
setposition(f,tableoffset)
Expand All @@ -389,10 +409,7 @@ local function unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,n
for i=2,nofcurrent do
current[i] = { readushort(f) }
end
local lookups = { }
for i=1,noflookups do
lookups[readushort(f)+1] = readushort(f) + 1
end
local lookups = readlookuparray(f,noflookups)
rules[#rules+1] = {
current = current,
lookups = lookups
Expand Down Expand Up @@ -435,10 +452,7 @@ local function unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,n
for i=2,nofcurrent do
current[i] = currentclasses[readushort(f) + 1]
end
local lookups = { }
for i=1,noflookups do
lookups[readushort(f)+1] = readushort(f) + 1
end
local lookups = readlookuparray(f,noflookups)
rules[#rules+1] = {
current = current,
lookups = lookups
Expand All @@ -462,10 +476,7 @@ local function unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,n
elseif subtype == 3 then
local current = readarray(f)
local noflookups = readushort(f)
local lookups = { }
for i=1,noflookups do
lookups[readushort(f)+1] = readushort(f) + 1
end
local lookups = readlookuparray(f,noflookups)
current = readcoveragearray(f,tableoffset,current,true)
return {
format = "coverage",
Expand Down Expand Up @@ -525,10 +536,7 @@ local function chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nof
end
end
local noflookups = readushort(f)
local lookups = { }
for i=1,noflookups do
lookups[readushort(f)+1] = readushort(f) + 1
end
local lookups = readlookuparray(f,noflookups)
rules[#rules+1] = {
before = before,
current = current,
Expand Down Expand Up @@ -596,10 +604,7 @@ local function chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nof
end
-- no sequence index here (so why in context as it saves nothing)
local noflookups = readushort(f)
local lookups = { }
for i=1,noflookups do
lookups[readushort(f)+1] = readushort(f) + 1
end
local lookups = readlookuparray(f,noflookups)
rules[#rules+1] = {
before = before,
current = current,
Expand Down Expand Up @@ -627,10 +632,7 @@ local function chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nof
local current = readarray(f)
local after = readarray(f)
local noflookups = readushort(f)
local lookups = { }
for i=1,noflookups do
lookups[readushort(f)+1] = readushort(f) + 1
end
local lookups = readlookuparray(f,noflookups)
before = readcoveragearray(f,tableoffset,before,true)
current = readcoveragearray(f,tableoffset,current,true)
after = readcoveragearray(f,tableoffset,after,true)
Expand Down Expand Up @@ -1626,45 +1628,58 @@ do
report_issue(i,what,sequence,"empty")
rule.lookups = nil
else
for index, lookupid in sortedhash(rlookups) do -- nicer
local h = sublookuphash[lookupid]
if not h then
-- here we have a lookup that is used independent as well
-- as in another one
local lookup = lookups[lookupid]
if lookup then
local d = lookup.done
if d then
nofsublookups = nofsublookups + 1
-- report("registering %i as sublookup %i",lookupid,nofsublookups)
h = {
index = nofsublookups, -- handy for tracing
name = f_lookupname(lookupprefix,"d",lookupid+lookupidoffset),
derived = true, -- handy for tracing
steps = d.steps,
nofsteps = d.nofsteps,
type = d.lookuptype,
markclass = d.markclass or nil,
flags = d.flags,
-- chain = d.chain,
}
sublookuplist[nofsublookups] = h
sublookuphash[lookupid] = nofsublookups
sublookupcheck[lookupid] = 1
-- we can have holes in rlookups
-- for index, lookupid in sortedhash(rlookups) do
local length = #rlookups
-- for index in next, rlookups do
-- if index > length then
-- length = index
-- end
-- end
for index=1,length do
local lookupid = rlookups[index]
if lookupid then
local h = sublookuphash[lookupid]
if not h then
-- here we have a lookup that is used independent as well
-- as in another one
local lookup = lookups[lookupid]
if lookup then
local d = lookup.done
if d then
nofsublookups = nofsublookups + 1
-- report("registering %i as sublookup %i",lookupid,nofsublookups)
h = {
index = nofsublookups, -- handy for tracing
name = f_lookupname(lookupprefix,"d",lookupid+lookupidoffset),
derived = true, -- handy for tracing
steps = d.steps,
nofsteps = d.nofsteps,
type = d.lookuptype,
markclass = d.markclass or nil,
flags = d.flags,
-- chain = d.chain,
}
sublookuplist[nofsublookups] = h
sublookuphash[lookupid] = nofsublookups
sublookupcheck[lookupid] = 1
else
report_issue(i,what,sequence,"missing")
rule.lookups = nil
break
end
else
report_issue(i,what,sequence,"missing")
report_issue(i,what,sequence,"bad")
rule.lookups = nil
break
end
else
report_issue(i,what,sequence,"bad")
rule.lookups = nil
break
sublookupcheck[lookupid] = sublookupcheck[lookupid] + 1
end
rlookups[index] = h or false
else
sublookupcheck[lookupid] = sublookupcheck[lookupid] + 1
rlookups[index] = false
end
rlookups[index] = h
end
end
end
Expand Down
84 changes: 68 additions & 16 deletions src/fontloader/misc/fontloader-font-ocl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if not modules then modules = { } end modules ['font-ocl'] = {

-- todo : user list of colors

local tostring, next = tostring, next

local formatters = string.formatters

local otf = fonts.handlers.otf
Expand Down Expand Up @@ -168,31 +170,81 @@ if context and xml.convert then

local report_svg = logs.reporter("fonts","svg conversion")

local xmlconvert = xml.convert
local xmlfirst = xml.first
local loaddata = io.loaddata
local savedata = io.savedata
local remove = os.remove

-- function otfsvg.topdf(svgshapes)
-- local svgfile = "temp-otf-svg-shape.svg"
-- local pdffile = "temp-otf-svg-shape.pdf"
-- local command = "inkscape " .. svgfile .. " --export-pdf=" .. pdffile
-- local testrun = false
-- local pdfshapes = { }
-- local nofshapes = #svgshapes
-- report_svg("processing %i svg containers",nofshapes)
-- statistics.starttiming()
-- for i=1,nofshapes do
-- local entry = svgshapes[i]
-- for j=entry.first,entry.last do
-- local svg = xmlconvert(entry.data)
-- local data = xmlfirst(svg,"/svg[@id='glyph"..j.."']")
-- savedata(svgfile,tostring(data))
-- report_svg("processing svg shape of glyph %i in container %i",j,i)
-- os.execute(command)
-- pdfshapes[j] = loaddata(pdffile)
-- end
-- if testrun and i > testrun then
-- report_svg("quiting test run")
-- break
-- end
-- end
-- remove(svgfile)
-- statistics.stoptiming()
-- report_svg("conversion time: %0.3f",statistics.elapsedtime())
-- return pdfshapes
-- end

function otfsvg.topdf(svgshapes)
local svgfile = "temp-otf-svg-shape.svg"
local pdffile = "temp-otf-svg-shape.pdf"
local command = "inkscape " .. svgfile .. " --export-pdf=" .. pdffile
-- local command = [[python "c:\Users\Hans Hagen\AppData\Roaming\Python\Scripts\cairosvg" -f pdf ]] .. svgfile .. " -o " .. pdffile
local testrun = false
local inkscape = io.popen("inkscape --shell 2>&1","w")
local pdfshapes = { }
local nofshapes = #svgshapes
local f_svgfile = formatters["temp-otf-svg-shape-%i.svg"]
local f_pdffile = formatters["temp-otf-svg-shape-%i.pdf"]
local f_convert = formatters["%s --export-pdf=%s\n"]
report_svg("processing %i svg containers",nofshapes)
statistics.starttiming()
for i=1,nofshapes do
local entry = svgshapes[i]
for j=entry.first,entry.last do
local svg = xml.convert(entry.data)
local data = xml.first(svg,"/svg[@id='glyph"..j.."']")
io.savedata(svgfile,tostring(data))
report_svg("processing svg shape of glyph %i in container %i",j,i)
os.execute(command)
pdfshapes[j] = io.loaddata(pdffile)
end
if testrun and i > testrun then
report_svg("quiting test run")
break
local svg = xmlconvert(entry.data)
local root = svg and xmlfirst(svg,"/svg[@id='glyph"..j.."']")
local data = root and tostring(root)
if data and data ~= "" then
local svgfile = f_svgfile(j)
local pdffile = f_pdffile(j)
savedata(svgfile,data)
inkscape:write(f_convert(svgfile,pdffile))
pdfshapes[j] = true
end
end
end
os.remove(svgfile)
inkscape:write("quit\n")
-- while inkscape:read("*a") do
-- os.sleep(0.1)
-- end
inkscape:close()
report_svg("processing %i pdf results",nofshapes)
for i in next, pdfshapes do
local svgfile = f_svgfile(i)
local pdffile = f_pdffile(i)
pdfshapes[i] = loaddata(pdffile)
remove(svgfile)
remove(pdffile)
end
statistics.stoptiming()
report_svg("conversion time: %0.3f",statistics.elapsedtime())
return pdfshapes
end

Expand Down
4 changes: 2 additions & 2 deletions src/fontloader/misc/fontloader-font-otl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local report_otf = logs.reporter("fonts","otf loading")
local fonts = fonts
local otf = fonts.handlers.otf

otf.version = 3.022 -- beware: also sync font-mis.lua and in mtx-fonts
otf.version = 3.023 -- beware: also sync font-mis.lua and in mtx-fonts
otf.cache = containers.define("fonts", "otl", otf.version, true)
otf.svgcache = containers.define("fonts", "svg", otf.version, true)
otf.pdfcache = containers.define("fonts", "pdf", otf.version, true)
Expand Down Expand Up @@ -747,7 +747,7 @@ end
otf.getgsub = getgsub -- returns value, gsub_kind

function otf.getsubstitution(tfmdata,k,kind,value)
local found, kind = getgsub(tfmdata,k,kind)
local found, kind = getgsub(tfmdata,k,kind,value)
if not found then
--
elseif kind == "gsub_single" then
Expand Down
Loading

0 comments on commit 45d384f

Please sign in to comment.