summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-ocl.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-11-29 20:53:37 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2018-11-29 20:53:37 +0100
commit9bd28a3039a458b054459fe1ef80161b107b798f (patch)
treec15bf6aedc4313de999a97bf92dc63b16ca60794 /tex/context/base/mkiv/font-ocl.lua
parent744095aa4676553437db0d71c281a74557a3222f (diff)
downloadcontext-9bd28a3039a458b054459fe1ef80161b107b798f.tar.gz
2018-11-29 19:54:00
Diffstat (limited to 'tex/context/base/mkiv/font-ocl.lua')
-rw-r--r--tex/context/base/mkiv/font-ocl.lua154
1 files changed, 92 insertions, 62 deletions
diff --git a/tex/context/base/mkiv/font-ocl.lua b/tex/context/base/mkiv/font-ocl.lua
index 866d6dd36..8cb5a12fb 100644
--- a/tex/context/base/mkiv/font-ocl.lua
+++ b/tex/context/base/mkiv/font-ocl.lua
@@ -63,31 +63,41 @@ end)
if context then
+ -- \definefontcolorpalette [emoji-r] [emoji-red,emoji-gray,textcolor] -- looks bad
+ -- \definefontcolorpalette [emoji-r] [emoji-red,emoji-gray] -- looks okay
+
local colors = attributes.list[attributes.private('color')] or { }
local transparencies = attributes.list[attributes.private('transparency')] or { }
function otf.registerpalette(name,values)
sharedpalettes[name] = values
+ local color = lpdf.color
+ local transparency = lpdf.transparency
+ local register = colors.register
for i=1,#values do
local v = values[i]
- local c = nil
- local t = nil
- if type(v) == "table" then
- c = colors.register(name,"rgb",
- max(round((v.r or 0)*255),255)/255,
- max(round((v.g or 0)*255),255)/255,
- max(round((v.b or 0)*255),255)/255
- )
+ if v == "textcolor" then
+ values[i] = false
else
- c = colors[v]
- t = transparencies[v]
- end
- if c and t then
- values[i] = hash[lpdf.color(1,c) .. " " .. lpdf.transparency(t)]
- elseif c then
- values[i] = hash[lpdf.color(1,c)]
- elseif t then
- values[i] = hash[lpdf.color(1,t)]
+ local c = nil
+ local t = nil
+ if type(v) == "table" then
+ c = register(name,"rgb",
+ max(round((v.r or 0)*255),255)/255,
+ max(round((v.g or 0)*255),255)/255,
+ max(round((v.b or 0)*255),255)/255
+ )
+ else
+ c = colors[v]
+ t = transparencies[v]
+ end
+ if c and t then
+ values[i] = hash[color(1,c) .. " " .. transparency(t)]
+ elseif c then
+ values[i] = hash[color(1,c)]
+ elseif t then
+ values[i] = hash[color(1,t)]
+ end
end
end
end
@@ -98,11 +108,13 @@ else -- for generic
sharedpalettes[name] = values
for i=1,#values do
local v = values[i]
- values[i] = hash[f_color(
- max(round((v.r or 0)*255),255)/255,
- max(round((v.g or 0)*255),255)/255,
- max(round((v.b or 0)*255),255)/255
- )]
+ if v then
+ values[i] = hash[f_color(
+ max(round((v.r or 0)*255),255)/255,
+ max(round((v.g or 0)*255),255)/255,
+ max(round((v.b or 0)*255),255)/255
+ )]
+ end
end
end
@@ -217,7 +229,7 @@ end
-- -- Here we have no color change in BT .. ET and more q Q pairs but even then acrobat
-- -- fails displaying the overlays correctly. Other renderers do it right.
-local function initialize(tfmdata,kind,value) -- hm, always value
+local function initialize(tfmdata,kind,value)
if value then
local resources = tfmdata.resources
local palettes = resources.colorpalettes
@@ -228,8 +240,14 @@ local function initialize(tfmdata,kind,value) -- hm, always value
converted = setmetatableindex(convert)
resources.converted = converted
end
- local colorvalues = sharedpalettes[value] or converted[palettes[tonumber(value) or 1] or palettes[1]] or { }
- local classes = #colorvalues
+ local colorvalues = sharedpalettes[value]
+ local default = false -- so the text color (bad for icon overloads)
+ if colorvalues then
+ default = colorvalues[#colorvalues]
+ else
+ colorvalues = converted[palettes[tonumber(value) or 1] or palettes[1]] or { }
+ end
+ local classes = #colorvalues
if classes == 0 then
return
end
@@ -244,7 +262,6 @@ local function initialize(tfmdata,kind,value) -- hm, always value
}
--
local getactualtext = otf.getactualtext
- local default = colorvalues[#colorvalues]
local b, e = getactualtext(tounicode(0xFFFD))
local actualb = { "pdf", "page", b } -- saves tables
local actuale = { "pdf", "page", e } -- saves tables
@@ -276,6 +293,12 @@ local function initialize(tfmdata,kind,value) -- hm, always value
f = true
n = n + 1 t[n] = v
l = v
+ else
+ if f then
+ n = n + 1 t[n] = pop
+ end
+ f = false
+ l = nil
end
n = n + 1 t[n] = charcommand[entry.slot]
if s > 1 and i < s and goback then
@@ -352,7 +375,7 @@ end
-- I'll probably make a variant for context as we can do it more efficient there than in
-- generic.
-local function pdftovirtual(tfmdata,pdfshapes,kind) -- kind = sbix|svg
+local function pdftovirtual(tfmdata,pdfshapes,kind) -- kind = png|svg
if not tfmdata or not pdfshapes or not kind then
return
end
@@ -553,27 +576,27 @@ fonts.handlers.otf.features.register {
-- This can be done differently e.g. with ffi and gm and we can share code anway. Using
-- batchmode in gm is not faster and as it accumulates we would need to flush all
--- individual shapes.
+-- individual shapes. But ... in context lmtx (and maybe the backport) we will use
+-- a different and more efficient method anyway. I'm still wondering if I should
+-- keep color code in generic. Maybe it should be optional.
-local otfsbix = otf.sbix or { }
-otf.sbix = otfsbix
-otf.sbixenabled = true
+local otfpng = otf.png or { }
+otf.png = otfpng
+otf.pngenabled = true
do
- -- for now png but also other bitmap formats
-
- local report_sbix = logs.reporter("fonts","sbix conversion")
+ local report_png = logs.reporter("fonts","png conversion")
local loaddata = io.loaddata
local savedata = io.savedata
local remove = os.remove
local runner = sandbox and sandbox.registerrunner {
- name = "otfsbix",
+ name = "otfpng",
program = "gm",
- template = "convert -quality 100 temp-otf-sbix-shape.sbix temp-otf-sbix-shape.pdf > temp-otf-svg-shape.log",
- -- reporter = report_sbix,
+ template = "convert -quality 100 temp-otf-png-shape.png temp-otf-png-shape.pdf > temp-otf-svg-shape.log",
+ -- reporter = report_png,
}
if not runner then
@@ -581,29 +604,29 @@ do
-- poor mans variant for generic:
--
runner = function()
- return os.execute("gm convert -quality 100 temp-otf-sbix-shape.sbix temp-otf-sbix-shape.pdf > temp-otf-svg-shape.log")
+ return os.execute("gm convert -quality 100 temp-otf-png-shape.png temp-otf-png-shape.pdf > temp-otf-svg-shape.log")
end
end
-- Alternatively we can create a single pdf file with -adjoin and then pick up pages from
-- that file but creating thousands of small files is no fun either.
- function otfsbix.topdf(sbixshapes)
+ function otfpng.topdf(pngshapes)
local pdfshapes = { }
- local sbixfile = "temp-otf-sbix-shape.sbix"
- local pdffile = "temp-otf-sbix-shape.pdf"
+ local pngfile = "temp-otf-png-shape.png"
+ local pdffile = "temp-otf-png-shape.pdf"
local nofdone = 0
- local indices = sortedkeys(sbixshapes) -- can be sparse
+ local indices = sortedkeys(pngshapes) -- can be sparse
local nofindices = #indices
- report_sbix("processing %i sbix containers",nofindices)
+ report_png("processing %i png containers",nofindices)
statistics.starttiming()
for i=1,nofindices do
local index = indices[i]
- local entry = sbixshapes[index]
- local data = entry.data
+ local entry = pngshapes[index]
+ local data = entry.data -- or placeholder
local x = entry.x
local y = entry.y
- savedata(sbixfile,data)
+ savedata(pngfile,data)
runner()
pdfshapes[index] = {
x = x ~= 0 and x or nil,
@@ -612,45 +635,44 @@ do
}
nofdone = nofdone + 1
if nofdone % 100 == 0 then
- report_sbix("%i shapes processed",nofdone)
+ report_png("%i shapes processed",nofdone)
end
end
- report_sbix("processing %i pdf results",nofindices)
- remove(sbixfile)
+ report_png("processing %i pdf results",nofindices)
+ remove(pngfile)
remove(pdffile)
statistics.stoptiming()
if statistics.elapsedseconds then
- report_sbix("sbix conversion time %s",statistics.elapsedseconds() or "-")
+ report_png("png conversion time %s",statistics.elapsedseconds() or "-")
end
return pdfshapes
- -- end
end
end
-- This will change in a future version of context. More direct.
-local function initializesbix(tfmdata,kind,value) -- hm, always value
- if value and otf.sbixenabled then
- local sbix = tfmdata.properties.sbix
- local hash = sbix and sbix.hash
- local timestamp = sbix and sbix.timestamp
+local function initializepng(tfmdata,kind,value) -- hm, always value
+ if value and otf.pngenabled then
+ local png = tfmdata.properties.png
+ local hash = png and png.hash
+ local timestamp = png and png.timestamp
if not hash then
return
end
local pdffile = containers.read(otf.pdfcache,hash)
local pdfshapes = pdffile and pdffile.pdfshapes
if not pdfshapes or pdffile.timestamp ~= timestamp then
- local sbixfile = containers.read(otf.sbixcache,hash)
- local sbixshapes = sbixfile and sbixfile.sbixshapes
- pdfshapes = sbixshapes and otfsbix.topdf(sbixshapes) or { }
+ local pngfile = containers.read(otf.pngcache,hash)
+ local pngshapes = pngfile and pngfile.pngshapes
+ pdfshapes = pngshapes and otfpng.topdf(pngshapes) or { }
containers.write(otf.pdfcache, hash, {
pdfshapes = pdfshapes,
timestamp = timestamp,
})
end
--
- pdftovirtual(tfmdata,pdfshapes,"sbix")
+ pdftovirtual(tfmdata,pdfshapes,"png")
end
end
@@ -658,8 +680,16 @@ fonts.handlers.otf.features.register {
name = "sbix",
description = "sbix glyphs",
manipulators = {
- base = initializesbix,
- node = initializesbix,
+ base = initializepng,
+ node = initializepng,
}
}
+fonts.handlers.otf.features.register {
+ name = "cblc",
+ description = "cblc glyphs",
+ manipulators = {
+ base = initializepng,
+ node = initializepng,
+ }
+}