diff options
-rw-r--r-- | otfl-font-clr.lua | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/otfl-font-clr.lua b/otfl-font-clr.lua index 0594191..d9b543a 100644 --- a/otfl-font-clr.lua +++ b/otfl-font-clr.lua @@ -17,7 +17,7 @@ table.insert(fonts.triggers,"color") function initializers.common.color(tfmdata,value) if value then tfmdata.color = value - luaotfload.add_color_callback() + add_color_callback() end end @@ -98,11 +98,11 @@ local function lookup_next_color(head) return nil end -function luaotfload.node_colorize(head, current_color, next_color) +local function 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 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) + n.list, current_color = 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 @@ -129,14 +129,14 @@ function luaotfload.node_colorize(head, current_color, next_color) return head, current_color end -function luaotfload.colorize(head) +local function font_colorize(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 = tex.pdfpageresources:gsub(r, "") end - local h = luaotfload.node_colorize(head, nil, nil) + local h = 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..">>" @@ -145,24 +145,17 @@ function luaotfload.colorize(head) return h end -luaotfload.color_callback_activated = 0 +local color_callback_activated = 0 local message_displayed = 0 -function luaotfload.add_color_callback() +function add_color_callback() if tex.luatexversion < 44 then if message_displayed == 0 then luatextra.module_warning("luaotfload","You must have a LuaTeX with version >= 0.44 in order to get colors working, colors won't work.") message_displayed = 1 end - elseif luaotfload.color_callback_activated == 0 then - callback.add("pre_output_filter", luaotfload.colorize, "loaotfload.colorize") - luaotfload.color_callback_activated = 1 - end -end - -function luaotfload.remove_color_callback() - if luaotfload.color_callback_activated == 1 then - callback.remove("pre_output_filter", "loaotfload.colorize") - luaotfload.color_callback_activated = 0 + elseif color_callback_activated == 0 then + callback.add("pre_output_filter", font_colorize, "loaotfload.colorize") + color_callback_activated = 1 end end |