summaryrefslogtreecommitdiff
path: root/luaotfload-colors.lua
diff options
context:
space:
mode:
authorDohyun Kim <nomosnomos@gmail.com>2013-12-29 12:04:14 +0900
committerDohyun Kim <nomosnomos@gmail.com>2013-12-29 12:04:14 +0900
commite1946776a33eeea9ac9c2a4460a1a221fccd0817 (patch)
tree4d0c7586c35cf2891ec1ea96daf931ed54a7d97c /luaotfload-colors.lua
parent30be6cbba415038b5263120d8701d3dcfd148af9 (diff)
downloadluaotfload-e1946776a33eeea9ac9c2a4460a1a221fccd0817.tar.gz
use table instead of string for transparency
Diffstat (limited to 'luaotfload-colors.lua')
-rw-r--r--luaotfload-colors.lua38
1 files changed, 18 insertions, 20 deletions
diff --git a/luaotfload-colors.lua b/luaotfload-colors.lua
index d8fb77a..3b430f3 100644
--- a/luaotfload-colors.lua
+++ b/luaotfload-colors.lua
@@ -126,18 +126,12 @@ registerotffeature {
--- something is carried around in ``res``
--- for later use by color_handler() --- but what?
-local res --- <- state of what?
+local res = {}
--- float -> unit
local function pageresources(alpha)
- local tpr = tex.pdfpageresources
- local newtrans = stringformat("/TransGs%s<</ca %s/CA %s>>",
- alpha, alpha, alpha)
- res = res or ""
- if stringfind(tpr,newtrans) or stringfind(res,newtrans) then
- else
- res = res..newtrans
- end
+ res[#res+1] = stringformat("/TransGs%s<</ca %s/CA %s>>",
+ alpha, alpha, alpha)
end
--- we store results of below color handler as tuples of
@@ -281,19 +275,23 @@ end
local color_handler = function (head)
local new_head = node_colorize(head, nil, nil)
-- now append our page resources
- if res and stringfind(res, "%S") then -- test for non-empty string
- local tpr = tex.pdfpageresources
- local endtrans = "/TransGs1<</ca 1/CA 1>>"
- if stringfind(tpr,endtrans) or stringfind(res,endtrans) then
- else
- res = res..endtrans
+ if res and #res > 0 then
+ local tpr, t = tex.pdfpageresources, ""
+ res[#res+1] = "/TransGs1<</ca 1/CA 1>>"
+ for i = 1,#res do
+ if stringfind(tpr,res[i]) or stringfind(t,res[i]) then
+ else
+ t = t .. res[i]
+ end
end
- if not stringfind(tpr,"/ExtGState<<.*>>") then
- tpr = tpr.."/ExtGState<<>>"
+ if t ~= "" then
+ if not stringfind(tpr,"/ExtGState<<.*>>") then
+ tpr = tpr.."/ExtGState<<>>"
+ end
+ tpr = stringgsub(tpr,"/ExtGState<<","%1"..t)
+ tex.pdfpageresources = tpr
end
- tpr = stringgsub(tpr,"/ExtGState<<","%1"..res)
- tex.pdfpageresources = tpr
- res = nil -- reset res
+ res = {} -- reset res
end
return new_head
end