summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-ocl.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-03-15 16:04:31 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-03-15 16:04:31 +0100
commita4e07f30e880ab27c2918f81f136e257475b7729 (patch)
tree02db002d3001a49777a049f9a98fdc872a5e1ad1 /tex/context/base/mkiv/font-ocl.lua
parentcbc37c39432e0ebe38e0922fc6d14c2955ab3ba2 (diff)
downloadcontext-a4e07f30e880ab27c2918f81f136e257475b7729.tar.gz
2018-03-15 15:36:00
Diffstat (limited to 'tex/context/base/mkiv/font-ocl.lua')
-rw-r--r--tex/context/base/mkiv/font-ocl.lua159
1 files changed, 133 insertions, 26 deletions
diff --git a/tex/context/base/mkiv/font-ocl.lua b/tex/context/base/mkiv/font-ocl.lua
index 2ecf1ba42..b17cf991d 100644
--- a/tex/context/base/mkiv/font-ocl.lua
+++ b/tex/context/base/mkiv/font-ocl.lua
@@ -1,6 +1,6 @@
if not modules then modules = { } end modules ['font-ocl'] = {
version = 1.001,
- comment = "companion to font-otf.lua (context)",
+ comment = "companion to font-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
@@ -8,7 +8,7 @@ if not modules then modules = { } end modules ['font-ocl'] = {
-- todo : user list of colors
-local tostring, next, format = tostring, next, string.format
+local tostring, tonumber, next = tostring, tonumber, next
local round, max = math.round, math.round
local sortedkeys, sortedhash = table.sortedkeys, table.sortedhash
local setmetatableindex = table.setmetatableindex
@@ -18,8 +18,8 @@ local tounicode = fonts.mappings.tounicode
local otf = fonts.handlers.otf
-local f_color = formatters["pdf:direct:%f %f %f rg"]
-local f_gray = formatters["pdf:direct:%f g"]
+local f_color = formatters["%.3f %.3f %.3f rg"]
+local f_gray = formatters["%.3f g"]
if context then
@@ -49,7 +49,7 @@ end
local sharedpalettes = { }
local hash = setmetatableindex(function(t,k)
- local v = { "special", k }
+ local v = { "pdf", "direct", k }
t[k] = v
return v
end)
@@ -76,11 +76,11 @@ if context then
t = transparencies[v]
end
if c and t then
- values[i] = hash["pdf:direct:" .. lpdf.color(1,c) .. " " .. lpdf.transparency(t)]
+ values[i] = hash[lpdf.color(1,c) .. " " .. lpdf.transparency(t)]
elseif c then
- values[i] = hash["pdf:direct:" .. lpdf.color(1,c)]
+ values[i] = hash[lpdf.color(1,c)]
elseif t then
- values[i] = hash["pdf:direct:" .. lpdf.color(1,t)]
+ values[i] = hash[lpdf.color(1,t)]
end
end
end
@@ -101,12 +101,11 @@ else -- for generic
end
--- We need to force page first because otherwise the q's get outside
--- the font switch and as a consequence the next character has no font
--- set (well, it has: the preceding one). As a consequence these fonts
--- are somewhat inefficient as each glyph gets the font set. It's a
--- side effect of the fact that a font is handled when a character gets
--- flushed.
+-- We need to force page first because otherwise the q's get outside the font switch and
+-- as a consequence the next character has no font set (well, it has: the preceding one). As
+-- a consequence these fonts are somewhat inefficient as each glyph gets the font set. It's
+-- a side effect of the fact that a font is handled when a character gets flushed. Okay, from
+-- now on we can use text as literal mode.
local function convert(t,k)
local v = { }
@@ -123,6 +122,105 @@ local function convert(t,k)
return v
end
+local start = { "pdf", "mode", "font" } -- force text mode (so get q Q right)
+----- stop = { "pdf", "mode", "page" } -- force page mode (else overlap)
+local push = { "pdf", "page", "q" }
+local pop = { "pdf", "page", "Q" }
+
+if not LUATEXFUNCTIONALITY or LUATEXFUNCTIONALITY < 6472 then
+ start = { "nop" }
+ ----- = stop
+end
+
+-- -- This one results in color directives inside BT ET but has less q Q pairs. It
+-- -- only shows the first glyph in acrobat and nothing more. No problem with other
+-- -- renderers.
+--
+-- local function initializecolr(tfmdata,kind,value) -- hm, always value
+-- if value then
+-- local resources = tfmdata.resources
+-- local palettes = resources.colorpalettes
+-- if palettes then
+-- --
+-- local converted = resources.converted
+-- if not converted then
+-- 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
+-- if classes == 0 then
+-- return
+-- end
+-- --
+-- local characters = tfmdata.characters
+-- local descriptions = tfmdata.descriptions
+-- local properties = tfmdata.properties
+-- --
+-- properties.virtualized = true
+-- tfmdata.fonts = {
+-- { id = 0 }
+-- }
+-- local widths = setmetatableindex(function(t,k)
+-- local v = { "right", -k }
+-- t[k] = v
+-- return v
+-- end)
+-- --
+-- 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
+-- --
+-- local cache = setmetatableindex(function(t,k)
+-- local v = { "char", k } -- could he a weak shared hash
+-- t[k] = v
+-- return v
+-- end)
+-- --
+-- for unicode, character in next, characters do
+-- local description = descriptions[unicode]
+-- if description then
+-- local colorlist = description.colors
+-- if colorlist then
+-- local u = description.unicode or characters[unicode].unicode
+-- local w = character.width or 0
+-- local s = #colorlist
+-- local goback = w ~= 0 and widths[w] or nil -- needs checking: are widths the same
+-- local t = {
+-- start,
+-- not u and actualb or { "pdf", "page", (getactualtext(tounicode(u))) }
+-- }
+-- local n = 2
+-- local l = nil
+-- n = n + 1 t[n] = push
+-- for i=1,s do
+-- local entry = colorlist[i]
+-- local v = colorvalues[entry.class] or default
+-- if v and l ~= v then
+-- n = n + 1 t[n] = v
+-- l = v
+-- end
+-- n = n + 1 t[n] = cache[entry.slot]
+-- if s > 1 and i < s and goback then
+-- n = n + 1 t[n] = goback
+-- end
+-- end
+-- n = n + 1 t[n] = pop
+-- n = n + 1 t[n] = actuale
+-- n = n + 1 t[n] = stop
+-- character.commands = t
+-- end
+-- end
+-- end
+-- end
+-- end
+-- 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 initializecolr(tfmdata,kind,value) -- hm, always value
if value then
local resources = tfmdata.resources
@@ -157,13 +255,11 @@ local function initializecolr(tfmdata,kind,value) -- hm, always value
local getactualtext = otf.getactualtext
local default = colorvalues[#colorvalues]
local b, e = getactualtext(tounicode(0xFFFD))
- local start = { "special", "pdf:page:q" }
- local stop = { "special", "pdf:raw:Q" }
- local actualb = { "special", "pdf:page:" .. b } -- saves tables
- local actuale = { "special", "pdf:page:" .. e } -- saves tables
+ local actualb = { "pdf", "page", b } -- saves tables
+ local actuale = { "pdf", "page", e } -- saves tables
--
local cache = setmetatableindex(function(t,k)
- local v = { "char", k }
+ local v = { "char", k } -- could he a weak shared hash
t[k] = v
return v
end)
@@ -178,15 +274,21 @@ local function initializecolr(tfmdata,kind,value) -- hm, always value
local s = #colorlist
local goback = w ~= 0 and widths[w] or nil -- needs checking: are widths the same
local t = {
- start,
- not u and actualb or { "special", "pdf:raw:" .. getactualtext(tounicode(u)) }
+ start, -- really needed
+ not u and actualb or { "pdf", "page", (getactualtext(tounicode(u))) }
}
local n = 2
local l = nil
+ local f = false
for i=1,s do
local entry = colorlist[i]
local v = colorvalues[entry.class] or default
if v and l ~= v then
+ if f then
+ n = n + 1 t[n] = pop
+ end
+ n = n + 1 t[n] = push
+ f = true
n = n + 1 t[n] = v
l = v
end
@@ -195,8 +297,11 @@ local function initializecolr(tfmdata,kind,value) -- hm, always value
n = n + 1 t[n] = goback
end
end
+ if f then
+ n = n + 1 t[n] = pop
+ end
n = n + 1 t[n] = actuale
- n = n + 1 t[n] = stop
+ -- n = n + 1 t[n] = stop -- not needed
character.commands = t
end
end
@@ -301,7 +406,9 @@ local function pdftovirtual(tfmdata,pdfshapes,kind) -- kind = sbix|svg
local getactualtext = otf.getactualtext
local storepdfdata = otf.storepdfdata
--
- -- local nop = { "nop" }
+ local b, e = getactualtext(tounicode(0xFFFD))
+ local actualb = { "pdf", "page", b } -- saves tables
+ local actuale = { "pdf", "page", e } -- saves tables
--
for unicode, character in sortedhash(characters) do -- sort is nicer for svg
local index = character.index
@@ -323,18 +430,18 @@ local function pdftovirtual(tfmdata,pdfshapes,kind) -- kind = sbix|svg
if data then
local setcode, name, nilcode = storepdfdata(data)
if name then
- local bt, et = getactualtext(unicode)
+ local bt = unicode and getactualtext(unicode)
local wd = character.width or 0
local ht = character.height or 0
local dp = character.depth or 0
character.commands = {
- { "special", "pdf:direct:" .. bt },
+ not unicode and actualb or { "pdf", "page", (getactualtext(unicode)) },
{ "down", dp + dy * hfactor },
{ "right", dx * hfactor },
-- setcode and { "lua", setcode } or nop,
{ "image", { filename = name, width = wd, height = ht, depth = dp } },
-- nilcode and { "lua", nilcode } or nop,
- { "special", "pdf:direct:" .. et },
+ actuale,
}
character[kind] = true
end