[latex3-commits] [git/LaTeX3-latex3-latex3] luacolor: First attempt to cover XForms (3a8bd0147)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Feb 15 23:13:03 CET 2023
Repository : https://github.com/latex3/latex3
On branch : luacolor
Link : https://github.com/latex3/latex3/commit/3a8bd0147231669b8baf5225a29c0e3c94822dee
>---------------------------------------------------------------
commit 3a8bd0147231669b8baf5225a29c0e3c94822dee
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Fri Jun 4 14:23:27 2021 +0100
First attempt to 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.
I'm not sure how to 'cleanly' set \tex_pdfxform:D without
first using \cs_undefine:N
Notice that the keywords for \saveboxresources seem
to be more complex than for \pdfxform, and are
not all documented.
>---------------------------------------------------------------
3a8bd0147231669b8baf5225a29c0e3c94822dee
l3backend/l3backend-color.dtx | 79 ++++++++++++++++++++++---
l3kernel/testfiles-backend/d3pdfmode.luatex.tlg | 1 +
l3kernel/testfiles-backend/d3xetex.luatex.tlg | 1 +
l3kernel/testfiles/m3expl001.luatex.tlg | 1 +
l3kernel/testfiles/m3expl002.luatex.tlg | 1 +
l3kernel/testfiles/m3expl003.luatex.tlg | 1 +
l3kernel/testfiles/m3expl004.luatex.tlg | 1 +
l3kernel/testfiles/m3expl006.luatex.tlg | 1 +
l3kernel/testfiles/m3expl007.luatex.tlg | 1 +
l3kernel/testfiles/m3names001.luatex.tlg | 2 +-
10 files changed, 79 insertions(+), 10 deletions(-)
diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index cb54da763..c55a6d0fb 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -1415,15 +1415,17 @@ local texio = texio
%
% 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}
@@ -1639,6 +1641,63 @@ 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}
+%
+% \begin{macro}{\tex_pdfxform:D}
+% We redefine the \pkg{expl3} version of the primitive to do the replacement
+% implicitly. The keywords \texttt{margin} and \texttt{type} are not
+% documented at the \TeX{} level.
+% \begin{macrocode}
+luacmd('tex_pdfxform:D', function()
+ 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,false,xtype,margin)
+end,'global','protected')
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macrocode}
%</lua>
% \end{macrocode}
@@ -1654,7 +1713,9 @@ end
%<*luatex>
% \end{macrocode}
%
+% This needs some work: undefine from Lua?
% \begin{macrocode}
+\cs_undefine:N \tex_pdfxform:D
\lua_now:n { require("l3backend-luatex") }
% \end{macrocode}
%
diff --git a/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg b/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg
index 7f6a2580f..8fdff2ffa 100644
--- a/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg
+++ b/l3kernel/testfiles-backend/d3pdfmode.luatex.tlg
@@ -10,6 +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 tex_pdfxform:D = ...
\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 c48be6c85..c63aeb087 100644
--- a/l3kernel/testfiles-backend/d3xetex.luatex.tlg
+++ b/l3kernel/testfiles-backend/d3xetex.luatex.tlg
@@ -18,6 +18,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 tex_pdfxform:D = ...
\l__pdf_internal_box=\box...
))
Author: Joseph Wright
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 8aee52593..423e6d2a5 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -74,6 +74,7 @@ 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 tex_pdfxform:D = ...
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..9fa8361c9 100644
--- a/l3kernel/testfiles/m3expl002.luatex.tlg
+++ b/l3kernel/testfiles/m3expl002.luatex.tlg
@@ -10,5 +10,6 @@ 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 tex_pdfxform:D = ...
\l__pdf_internal_box=\box...
))
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 8aee52593..423e6d2a5 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -74,6 +74,7 @@ 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 tex_pdfxform:D = ...
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..ec438d958 100644
--- a/l3kernel/testfiles/m3expl004.luatex.tlg
+++ b/l3kernel/testfiles/m3expl004.luatex.tlg
@@ -8,5 +8,6 @@ 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 tex_pdfxform:D = ...
\l__pdf_internal_box=\box...
))
diff --git a/l3kernel/testfiles/m3expl006.luatex.tlg b/l3kernel/testfiles/m3expl006.luatex.tlg
index c98862f85..2062ed15c 100644
--- a/l3kernel/testfiles/m3expl006.luatex.tlg
+++ b/l3kernel/testfiles/m3expl006.luatex.tlg
@@ -9,5 +9,6 @@ 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 tex_pdfxform:D = ...
\l__pdf_internal_box=\box...
))
diff --git a/l3kernel/testfiles/m3expl007.luatex.tlg b/l3kernel/testfiles/m3expl007.luatex.tlg
index b5ccf8ba3..5892ad73b 100644
--- a/l3kernel/testfiles/m3expl007.luatex.tlg
+++ b/l3kernel/testfiles/m3expl007.luatex.tlg
@@ -9,6 +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 tex_pdfxform:D = ...
\l__pdf_internal_box=\box...
)) (expl3.sty
Package: expl3 ....-..-.. L3 programming layer (loader)
diff --git a/l3kernel/testfiles/m3names001.luatex.tlg b/l3kernel/testfiles/m3names001.luatex.tlg
index afa948f71..b61b2ad27 100644
--- a/l3kernel/testfiles/m3names001.luatex.tlg
+++ b/l3kernel/testfiles/m3names001.luatex.tlg
@@ -17,5 +17,5 @@ Don't change this file in any respect.
\tex_pdfoutput:D=\outputmode
\tex_pdfrefxform:D=\useboxresource
\tex_pdfrefximage:D=\useimageresource
-\tex_pdfxform:D=\saveboxresource
+\tex_pdfxform:D=luacall 13
\tex_pdfximage:D=\saveimageresource
More information about the latex3-commits
mailing list.