From 046a43ae585eb409f8026c3bcfd525010b58efd7 Mon Sep 17 00:00:00 2001 From: Dohyun Kim Date: Sun, 29 Dec 2013 02:35:15 +0900 Subject: trancyparency conflicts with other packages --- luaotfload-colors.lua | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/luaotfload-colors.lua b/luaotfload-colors.lua index b5c1fb9..d8fb77a 100644 --- a/luaotfload-colors.lua +++ b/luaotfload-colors.lua @@ -130,15 +130,14 @@ local res --- <- state of what? --- float -> unit local function pageresources(alpha) - local res2 - if not res then - res = "/TransGs1<>" + local tpr = tex.pdfpageresources + local newtrans = stringformat("/TransGs%s<>", + alpha, alpha, alpha) + res = res or "" + if stringfind(tpr,newtrans) or stringfind(res,newtrans) then + else + res = res..newtrans end - res2 = stringformat("/TransGs%s<>", - alpha, alpha, alpha) - res = stringformat("%s%s", - res, - stringfind(res, res2) and "" or res2) end --- we store results of below color handler as tuples of @@ -280,17 +279,21 @@ end --- node -> node local color_handler = function (head) - -- check if our page resources existed in the previous run - -- and remove it to avoid duplicating it later - if res then - local r = "/ExtGState<<" .. res .. ">>" - tex.pdfpageresources = stringgsub(tex.pdfpageresources, r, "") - end 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 r = "/ExtGState<<" .. res .. ">>" - tex.pdfpageresources = tex.pdfpageresources..r + local tpr = tex.pdfpageresources + local endtrans = "/TransGs1<>" + if stringfind(tpr,endtrans) or stringfind(res,endtrans) then + else + res = res..endtrans + end + if not stringfind(tpr,"/ExtGState<<.*>>") then + tpr = tpr.."/ExtGState<<>>" + end + tpr = stringgsub(tpr,"/ExtGState<<","%1"..res) + tex.pdfpageresources = tpr + res = nil -- reset res end return new_head end -- cgit v1.2.3 From 651147e15c030f4a5ac92f2e504f71f3df928ebb Mon Sep 17 00:00:00 2001 From: Dohyun Kim Date: Sun, 29 Dec 2013 02:35:15 +0900 Subject: transparency conflicts with other packages --- luaotfload-colors.lua | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/luaotfload-colors.lua b/luaotfload-colors.lua index b5c1fb9..d8fb77a 100644 --- a/luaotfload-colors.lua +++ b/luaotfload-colors.lua @@ -130,15 +130,14 @@ local res --- <- state of what? --- float -> unit local function pageresources(alpha) - local res2 - if not res then - res = "/TransGs1<>" + local tpr = tex.pdfpageresources + local newtrans = stringformat("/TransGs%s<>", + alpha, alpha, alpha) + res = res or "" + if stringfind(tpr,newtrans) or stringfind(res,newtrans) then + else + res = res..newtrans end - res2 = stringformat("/TransGs%s<>", - alpha, alpha, alpha) - res = stringformat("%s%s", - res, - stringfind(res, res2) and "" or res2) end --- we store results of below color handler as tuples of @@ -280,17 +279,21 @@ end --- node -> node local color_handler = function (head) - -- check if our page resources existed in the previous run - -- and remove it to avoid duplicating it later - if res then - local r = "/ExtGState<<" .. res .. ">>" - tex.pdfpageresources = stringgsub(tex.pdfpageresources, r, "") - end 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 r = "/ExtGState<<" .. res .. ">>" - tex.pdfpageresources = tex.pdfpageresources..r + local tpr = tex.pdfpageresources + local endtrans = "/TransGs1<>" + if stringfind(tpr,endtrans) or stringfind(res,endtrans) then + else + res = res..endtrans + end + if not stringfind(tpr,"/ExtGState<<.*>>") then + tpr = tpr.."/ExtGState<<>>" + end + tpr = stringgsub(tpr,"/ExtGState<<","%1"..res) + tex.pdfpageresources = tpr + res = nil -- reset res end return new_head end -- cgit v1.2.3 From e1946776a33eeea9ac9c2a4460a1a221fccd0817 Mon Sep 17 00:00:00 2001 From: Dohyun Kim Date: Sun, 29 Dec 2013 12:04:14 +0900 Subject: use table instead of string for transparency --- luaotfload-colors.lua | 38 ++++++++++++++++++-------------------- 1 file 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<>", - 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<>", + 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<>" - 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<>" + 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 -- cgit v1.2.3 From 1de7c5bdfda40e81aa7786ce4856233c1c9a3a52 Mon Sep 17 00:00:00 2001 From: Dohyun Kim Date: Sun, 29 Dec 2013 14:46:00 +0900 Subject: reduce the size of res table --- luaotfload-colors.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/luaotfload-colors.lua b/luaotfload-colors.lua index 3b430f3..b8ecb87 100644 --- a/luaotfload-colors.lua +++ b/luaotfload-colors.lua @@ -126,12 +126,12 @@ registerotffeature { --- something is carried around in ``res`` --- for later use by color_handler() --- but what? -local res = {} +local res = nil --- float -> unit local function pageresources(alpha) - res[#res+1] = stringformat("/TransGs%s<>", - alpha, alpha, alpha) + res = res or {} + res[alpha] = true end --- we store results of below color handler as tuples of @@ -275,13 +275,13 @@ end local color_handler = function (head) local new_head = node_colorize(head, nil, nil) -- now append our page resources - if res and #res > 0 then + if res then + res["1"] = true local tpr, t = tex.pdfpageresources, "" - res[#res+1] = "/TransGs1<>" - for i = 1,#res do - if stringfind(tpr,res[i]) or stringfind(t,res[i]) then - else - t = t .. res[i] + for k in pairs(res) do + local str = stringformat("/TransGs%s<>", k, k, k) + if not stringfind(tpr,str) then + t = t .. str end end if t ~= "" then @@ -291,7 +291,7 @@ local color_handler = function (head) tpr = stringgsub(tpr,"/ExtGState<<","%1"..t) tex.pdfpageresources = tpr end - res = {} -- reset res + res = nil -- reset res end return new_head end -- cgit v1.2.3