From 06a2e9118d9f6d98d800a394f4234508c7c23336 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Tue, 19 Jan 2010 10:23:51 +0100 Subject: More optimizations Now the boxes are "transparent" to the algorithm. This saves 5% space on a uncompressed PDF, about 0.5% in a compressed one, but may be a lot more for documents with a lot of boxes. --- otfl-font-msc.lua | 58 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/otfl-font-msc.lua b/otfl-font-msc.lua index 0ebe1a4..491229b 100644 --- a/otfl-font-msc.lua +++ b/otfl-font-msc.lua @@ -136,35 +136,35 @@ local function lookup_next_color(head) return nil end -function luaotfload.node_colorize(head, current_color) +function luaotfload.node_colorize(head, current_color, next_color) for n in node.traverse(head) do - if n.id == hlist or n.id == vlist or n.id == sbox then - n.list = luaotfload.node_colorize(n.list, current_color) - current_color = nil -- to optimize, but needs deeper changes - elseif n.id == glyph then - local tfmdata = fonts.ids[n.font] - if tfmdata and tfmdata.color then - if tfmdata.color ~= current_color then - local pushcolor = hex_to_rgba(tfmdata.color) - local push = node.new(whatsit, 8) - push.mode = 1 - push.data = pushcolor - head = node.insert_before(head, n, push) - current_color = tfmdata.color - end - local next_color = lookup_next_color (n.next) - if next_color ~= tfmdata.color then - local _, popcolor = hex_to_rgba(tfmdata.color) - local pop = node.new(whatsit, 8) - pop.mode = 1 - pop.data = popcolor - head = node.insert_after(head, n, pop) - current_color = nil - end - end - end - end - return head + if n.id == hlist or n.id == vlist or n.id == sbox then + local next_color_in = lookup_next_color(n.next) or next_color + n.list, current_color = luaotfload.node_colorize(n.list, current_color, next_color_in) + elseif n.id == glyph then + local tfmdata = fonts.ids[n.font] + if tfmdata and tfmdata.color then + if tfmdata.color ~= current_color then + local pushcolor = hex_to_rgba(tfmdata.color) + local push = node.new(whatsit, 8) + push.mode = 1 + push.data = pushcolor + head = node.insert_before(head, n, push) + current_color = tfmdata.color + end + local next_color_in = lookup_next_color (n.next) or next_color + if next_color_in ~= tfmdata.color then + local _, popcolor = hex_to_rgba(tfmdata.color) + local pop = node.new(whatsit, 8) + pop.mode = 1 + pop.data = popcolor + head = node.insert_after(head, n, pop) + current_color = nil + end + end + end + end + return head, current_color end function luaotfload.colorize(head) @@ -174,7 +174,7 @@ function luaotfload.colorize(head) local r = "/ExtGState<<"..res..">>" tex.pdfpageresources = tex.pdfpageresources:gsub(r, "") end - local h = luaotfload.node_colorize(head, nil) + local h = luaotfload.node_colorize(head, nil, nil) -- now append our page resources if res and res:find("%S") then -- test for non-empty string local r = "/ExtGState<<"..res..">>" -- cgit v1.2.3