[latex3-commits] [git/LaTeX3-latex3-latex3] luacolor: Cover XForms (e2fb85357)
Joseph Wright
joseph.wright at morningstar2.co.uk
Thu Feb 16 14:07:14 CET 2023
Repository : https://github.com/latex3/latex3
On branch : luacolor
Link : https://github.com/latex3/latex3/commit/e2fb853571617a8a45464c405b3f7f5c5291ca72
>---------------------------------------------------------------
commit e2fb853571617a8a45464c405b3f7f5c5291ca72
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Tue Jun 8 12:58:18 2021 +0100
Cover XForms
I've tried to keep as much of the code in Lua as
possible: I'm assuming we are targeting only
newer engines.
Notice that the keywords for \saveboxresources seem
to be more complex than for \pdfxform, and are
not all documented.
>---------------------------------------------------------------
e2fb853571617a8a45464c405b3f7f5c5291ca72
l3backend/l3backend-color.dtx | 89 ++++++++++++++++++++++---
l3kernel/testfiles-backend/d3pdfmode.luatex.tlg | 2 +
l3kernel/testfiles-backend/d3xetex.luatex.tlg | 2 +
l3kernel/testfiles/m3expl001.luatex.tlg | 2 +
l3kernel/testfiles/m3expl002.luatex.tlg | 2 +
l3kernel/testfiles/m3expl003.luatex.tlg | 2 +
l3kernel/testfiles/m3expl004.luatex.tlg | 2 +
l3kernel/testfiles/m3expl006.luatex.tlg | 2 +
l3kernel/testfiles/m3expl007.luatex.tlg | 2 +
9 files changed, 96 insertions(+), 9 deletions(-)
diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index df1e2f83b..d1b77b4eb 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -1414,15 +1414,17 @@ local tex = tex
%
% Local copies of standard functions.
% \begin{macrocode}
-local module_error = luatexbase.module_error
-local has_attribute = node.has_attribute
-local id = node.id
-local insert_before = node.insert_before
-local node_new = node.new
-local node_traverse = node.traverse
-local set_attribute = tex.setattribute
-local type = node.type
-local subtype = node.subtype
+local getbox = tex.getbox
+local has_attribute = node.has_attribute
+local id = node.id
+local insert_before = node.insert_before
+local module_error = luatexbase.module_error
+local node_new = node.new
+local node_traverse = node.traverse
+local saveboxresources = tex.saveboxresources
+local set_attribute = tex.setattribute
+local type = node.type
+local subtype = node.subtype
% \end{macrocode}
%
% \begin{macro}{ltx.color.select}
@@ -1603,6 +1605,73 @@ if luaotfload and luaotfload.set_colorhandler then
end
% \end{macrocode}
%
+% \begin{macro}{luacmd}
+% Copied from \pkg{l3luatex}: we need to think about how to make this available
+% (perhaps in |ltx.utils|?).
+% \begin{macrocode}
+local luacmd do
+ local token_create = token.create
+ local set_lua = token.set_lua
+ local undefined_cs = token.command_id'undefined_cs'
+
+ if not context and not luatexbase then require'ltluatex' end
+ if luatexbase then
+ local new_luafunction = luatexbase.new_luafunction
+ local functions = lua.get_functions_table()
+ function luacmd(name, func, ...)
+ local id
+ local tok = token_create(name)
+ if tok.command == undefined_cs then
+ id = new_luafunction(name)
+ set_lua(name, id, ...)
+ else
+ id = tok.index or tok.mode
+ end
+ functions[id] = func
+ end
+ elseif context then
+ local register = context.functions.register
+ local functions = context.functions.known
+ function luacmd(name, func, ...)
+ local tok = token.create(name)
+ if tok.command == undefined_cs then
+ token.set_lua(name, register(func), ...)
+ else
+ functions[tok.index or tok.mode] = func
+ end
+ end
+ end
+end
+% \end{macrocode}
+% \end{macro}
+%
+%<@@=pdfxform>
+%
+% \begin{macro}{pdfxform}
+% \begin{macro}{\@@_backend_now:w, \@@_backend_delayed:w}
+% Here we define an internal for the |pdfxform| module: the
+% same ideas work in \pdfTeX{} as macros, and other engines don't
+% use quite the same abstraction.
+% \begin{macrocode}
+local function pdfxform(immediate)
+ local attr = scan_keyword'attr' and scan_string() or nil
+ local resources = scan_keyword'length' and scan_string() or nil
+ local xtype = scan_keyword'type' and scan_string() or nil
+ local margin = scan_keyword'margin' and scan_string() or nil
+ local n = scan_int() or nil
+ traverse(getbox(n),"")
+ saveboxresources(n,attr,resources,immediate,xtype,margin)
+end
+luacmd('@@_backend_now:w', function()
+ pdfxform(true)
+end,'global','protected')
+luacmd('@@_backend_delayed:w', function()
+ pdfxform(false)
+end,'global','protected')
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \begin{macrocode}
%</lua>
% \end{macrocode}
@@ -1611,6 +1680,8 @@ end
%<*package>
% \end{macrocode}
%
+%<@@=color>
+%
% At present we only set up for \LuaTeX{} in PDF mode: later we will expand
% on that!
%
diff --git a/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg b/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg
index 481762133..29ee6a45d 100644
--- a/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg
+++ b/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg
@@ -10,6 +10,8 @@ File: l3backend-luatex.def ....-..-.. L3 backend support: PDF output (LuaTeX)
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
\l__pdf_internal_box=\box...
))
Author: Joseph Wright
diff --git a/l3kernel/testfiles-backend/d3xetex.luatex.tlg b/l3kernel/testfiles-backend/d3xetex.luatex.tlg
index 8f3043e6d..561294cad 100644
--- a/l3kernel/testfiles-backend/d3xetex.luatex.tlg
+++ b/l3kernel/testfiles-backend/d3xetex.luatex.tlg
@@ -18,6 +18,8 @@ File: l3backend-luatex.def ....-..-.. L3 backend support: PDF output (LuaTeX)
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
\l__pdf_internal_box=\box...
))
Author: Joseph Wright
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 8aee52593..8933aa17e 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -74,6 +74,8 @@ Defining \__color_backend_stroke_reset: on line ...
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
Defining \__box_backend_clip:N on line ...
Defining \__box_backend_rotate:Nn on line ...
Defining \__box_backend_rotate_aux:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl002.luatex.tlg b/l3kernel/testfiles/m3expl002.luatex.tlg
index 520443cc5..9c556923e 100644
--- a/l3kernel/testfiles/m3expl002.luatex.tlg
+++ b/l3kernel/testfiles/m3expl002.luatex.tlg
@@ -10,5 +10,7 @@ File: l3backend-luatex.def ....-..-.. L3 backend support: PDF output (LuaTeX)
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
\l__pdf_internal_box=\box...
))
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 8aee52593..8933aa17e 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -74,6 +74,8 @@ Defining \__color_backend_stroke_reset: on line ...
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
Defining \__box_backend_clip:N on line ...
Defining \__box_backend_rotate:Nn on line ...
Defining \__box_backend_rotate_aux:Nn on line ...
diff --git a/l3kernel/testfiles/m3expl004.luatex.tlg b/l3kernel/testfiles/m3expl004.luatex.tlg
index 0d80bb024..10b9751e7 100644
--- a/l3kernel/testfiles/m3expl004.luatex.tlg
+++ b/l3kernel/testfiles/m3expl004.luatex.tlg
@@ -8,5 +8,7 @@ File: l3backend-luatex.def ....-..-.. L3 backend support: PDF output (LuaTeX)
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
\l__pdf_internal_box=\box...
))
diff --git a/l3kernel/testfiles/m3expl006.luatex.tlg b/l3kernel/testfiles/m3expl006.luatex.tlg
index c98862f85..f04377859 100644
--- a/l3kernel/testfiles/m3expl006.luatex.tlg
+++ b/l3kernel/testfiles/m3expl006.luatex.tlg
@@ -9,5 +9,7 @@ File: l3backend-luatex.def ....-..-.. L3 backend support: PDF output (LuaTeX)
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
\l__pdf_internal_box=\box...
))
diff --git a/l3kernel/testfiles/m3expl007.luatex.tlg b/l3kernel/testfiles/m3expl007.luatex.tlg
index b5ccf8ba3..90896b98b 100644
--- a/l3kernel/testfiles/m3expl007.luatex.tlg
+++ b/l3kernel/testfiles/m3expl007.luatex.tlg
@@ -9,6 +9,8 @@ File: l3backend-luatex.def ....-..-.. L3 backend support: PDF output (LuaTeX)
Lua module: l3backend-luatex ....-..-..
Lua-only attribute color = 1
Inserting `color' at position 1 in `pre_shipout_filter'.
+Lua function __pdfxform_backend_now:w = ...
+Lua function __pdfxform_backend_delayed:w = ...
\l__pdf_internal_box=\box...
)) (expl3.sty
Package: expl3 ....-..-.. L3 programming layer (loader)
More information about the latex3-commits
mailing list.