[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Add more customization options for Color (7597723)
Marcel Fabian Krüger
tex at 2krueger.de
Sat Jun 4 12:41:53 CEST 2022
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/759772341d1aadc35e50bc0f1e5edfa52111a55e
>---------------------------------------------------------------
commit 759772341d1aadc35e50bc0f1e5edfa52111a55e
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sat Jun 4 12:41:53 2022 +0200
Add more customization options for Color
>---------------------------------------------------------------
759772341d1aadc35e50bc0f1e5edfa52111a55e
src/luaotfload-colors.lua | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index f53f205..2a59dff 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -53,6 +53,8 @@ local identifiers = fonts.hashes.identifiers
local add_color_callback --[[ this used to be a global‽ ]]
+local custom_setcolor, custom_settransparent, custom_parsecolor
+
--[[doc--
Color string parser.
--doc]]--
@@ -72,8 +74,8 @@ local extract_color = spaces * octet * octet * octet / function(r,g,b)
return stringformat("%.3g %.3g %.3g rg", r, g, b)
end * (opaque + octet)^-1 * spaces * -1
---- something is carried around in ``res``
---- for later use by color_handler() --- but what?
+-- Keep the currently collected page resources needed for the current
+-- colors in `res`.
local res = nil
@@ -89,14 +91,22 @@ end
--- string -> (string | nil)
local function sanitize_color_expression (digits)
digits = tostring(digits)
- local rgb, a = lpegmatch(extract_color, digits)
- if not rgb then
- logreport("both", 0, "color",
- "%q is not a valid rgb[a] color expression",
- digits)
- return
+ local rgb, a
+ if custom_parsecolor then
+ rgb, a = custom_parsecolor (digits)
+ else
+ rgb, a = lpegmatch(extract_color, digits)
+ if not rgb then
+ logreport("both", 0, "color",
+ "%q is not a valid rgb[a] color expression",
+ digits)
+ return
+ end
+ end
+ if a and not custom_settransparent then
+ a = pageresources(a)
end
- return rgb, (a and pageresources(a))
+ return rgb, a
end
local color_stack = 0
@@ -125,8 +135,6 @@ local colorstack_t = node.subtype("pdf_colorstack")
local color_callback
local color_attr = luatexbase.new_attribute("luaotfload_color_attribute")
-local custom_setcolor
-
-- Pass nil for new_color or old_color to indicate no color
-- If color is nil, pass tail to decide where to add whatsit
local function color_whatsit (head, curr, stack, old_color, new_color, tail)
@@ -391,6 +399,12 @@ end
function luaotfload.set_colorhandler(cb)
custom_setcolor = cb
end
+function luaotfload.set_transparenthandler(cb)
+ custom_setcolor = cb
+end
+function luaotfload.set_colorparser(cb)
+ custom_parsecolor = cb
+end
return function ()
logreport = luaotfload.log.report
More information about the latex3-commits
mailing list.