[latex3-commits] [git/LaTeX3-latex3-latex3] master: Move SVG scope operations to backend-basics (7db968be9)

Joseph Wright joseph.wright at morningstar2.co.uk
Tue Aug 4 11:10:49 CEST 2020


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/7db968be9238e20164329698f7da24d95b26b525

>---------------------------------------------------------------

commit 7db968be9238e20164329698f7da24d95b26b525
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Aug 4 10:10:49 2020 +0100

    Move SVG scope operations to backend-basics
    
    They are needed by both color and drawing.


>---------------------------------------------------------------

7db968be9238e20164329698f7da24d95b26b525
 l3backend/l3backend-basics.dtx          | 61 +++++++++++++++++++++++++--------
 l3backend/l3backend-box.dtx             |  7 ++--
 l3backend/l3backend-color.dtx           |  2 +-
 l3backend/l3backend-draw.dtx            | 49 ++------------------------
 l3experimental/l3color/l3color.dtx      |  3 +-
 l3kernel/testfiles/d3dvisvgm.luatex.tlg |  4 +--
 l3kernel/testfiles/d3dvisvgm.tlg        |  4 +--
 l3kernel/testfiles/d3dvisvgm.xetex.tlg  |  4 +--
 8 files changed, 61 insertions(+), 73 deletions(-)

diff --git a/l3backend/l3backend-basics.dtx b/l3backend/l3backend-basics.dtx
index 00367dea5..c33404e4a 100644
--- a/l3backend/l3backend-basics.dtx
+++ b/l3backend/l3backend-basics.dtx
@@ -358,27 +358,60 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\__kernel_backend_scope_begin:, \__kernel_backend_scope_end:}
-%   A scope in SVG terms is slightly different to the other backends as
-%   operations have to be \enquote{tied} to these not simply inside them.
+% \begin{variable}{\g__kernel_backend_scope_int, \l__kernel_backend_scope_int}
+%   In SVG, we need to track scope nesting as properties attach to scopes; that
+%   requires a pair of \texttt{int} registers.
 %    \begin{macrocode}
-\cs_new_protected:Npn \__kernel_backend_scope_begin:
-  { \__kernel_backend_literal_svg:n { <g> } }
-\cs_new_protected:Npn \__kernel_backend_scope_end:
-  { \__kernel_backend_literal_svg:n { </g> } }
+\int_new:N \g__kernel_backend_scope_int
+\int_new:N \l__kernel_backend_scope_int
 %    \end{macrocode}
-% \end{macro}
+% \end{variable}
 %
+% \begin{macro}{\__kernel_backend_scope_begin:, \__kernel_backend_scope_end:}
 % \begin{macro}{\__kernel_backend_scope_begin:n, \__kernel_backend_scope_begin:x}
-%   In SVG transformations, clips and so on are attached directly to scopes so
-%   we need a way or allowing for that. This is rather more useful than
-%   \cs{__kernel_backend_scope_begin:} as a result.
-%   No assumptions are made about the nature
-%   of the scoped operation(s).
+% \begin{macro}{\__kernel_backend_scope:n, \__kernel_backend_scope:x}
+%   In SVG, the need to attach concepts to a scope means we need to be sure we
+%   will close all of the open scopes. That is easiest done if we only need
+%   an outer \enquote{wrapper} \texttt{begin}/\texttt{end} pair, and within
+%   that we apply operations as a simple scoped statements. To keep down the
+%   non-productive groups, we also have a \texttt{begin} version that does take
+%   an argument.
 %    \begin{macrocode}
+\cs_new_protected:Npn \__kernel_backend_scope_begin:
+  {
+    \__kernel_backend_literal_svg:n { <g> }
+    \int_set_eq:NN
+      \l__kernel_backend_scope_int
+      \g__kernel_backend_scope_int
+    \group_begin:
+      \int_gset:Nn \g__kernel_backend_scope_int { 1 }
+  }
+\cs_new_protected:Npn \__kernel_backend_scope_end:
+  {
+      \prg_replicate:nn
+        { \g__kernel_backend_scope_int }
+        { \__kernel_backend_literal_svg:n { </g> } }
+    \group_end:
+    \int_gset_eq:NN
+      \g__kernel_backend_scope_int
+      \l__kernel_backend_scope_int
+  }
 \cs_new_protected:Npn \__kernel_backend_scope_begin:n #1
-  { \__kernel_backend_literal_svg:n { <g~ #1 > } }
+  {
+    \__kernel_backend_literal_svg:n { <g ~ #1 > }
+    \int_set_eq:NN
+      \l__kernel_backend_scope_int
+      \g__kernel_backend_scope_int
+    \group_begin:
+      \int_gset:Nn \g__kernel_backend_scope_int { 1 }
+  }
 \cs_generate_variant:Nn \__kernel_backend_scope_begin:n { x }
+\cs_new_protected:Npn \__kernel_backend_scope:n #1
+  {
+    \__kernel_backend_literal_svg:n { <g ~ #1 > }
+    \int_gincr:N \g__kernel_backend_scope_int
+  }
+\cs_generate_variant:Nn \__kernel_backend_scope:n { x }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3backend/l3backend-box.dtx b/l3backend/l3backend-box.dtx
index 8a63b8db1..fa1427655 100644
--- a/l3backend/l3backend-box.dtx
+++ b/l3backend/l3backend-box.dtx
@@ -387,12 +387,12 @@
             scale ( 1 , -1 )
           "
       }
-    \__kernel_backend_scope_begin:x
+    \__kernel_backend_scope:x
       {
         clip-path =
           "url ( \c_hash_str l3cp \int_use:N \g_@@_clip_path_int ) "
       }
-    \__kernel_backend_scope_begin:n
+    \__kernel_backend_scope:n
       {
         transform =
           "
@@ -403,9 +403,6 @@
       }
     \box_use:N #1
     \__kernel_backend_scope_end:
-    \__kernel_backend_scope_end:
-    \__kernel_backend_scope_end:
-%    \skip_horizontal:n { \box_wd:N #1 }
   }
 \int_new:N \g_@@_clip_path_int
 %    \end{macrocode}
diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index fe448e5f2..9a2c6e7ff 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -406,7 +406,7 @@
   }
 \cs_new_protected:Npx \@@_backend:nnnn #1#2#3#4
   {
-    \@@_backend_scope:n
+    \__kernel_backend_scope:n
       {
         #1 =
          "
diff --git a/l3backend/l3backend-draw.dtx b/l3backend/l3backend-draw.dtx
index c3a75b014..b81e13ac8 100644
--- a/l3backend/l3backend-draw.dtx
+++ b/l3backend/l3backend-draw.dtx
@@ -778,54 +778,11 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_backend_begin:
   {
-    \@@_backend_scope_begin:
-    \@@_backend_scope:n { transform="translate({?x},{?y})~scale(1,-1)" }
-  }
-\cs_new_protected:Npn \@@_backend_end:
-  { \@@_backend_scope_end: }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\@@_backend_scope_begin:, \@@_backend_scope_end:}
-% \begin{macro}{\@@_backend_scope:n, \@@_backend_scope:x}
-% \begin{variable}{\g_@@_draw_scope_int, \l_@@_draw_scope_int}
-%   Several settings that with other backends are \enquote{stand alone} have
-%   to be given as part of a scope in SVG. As a result, there is a need to
-%   provide a mechanism to automatically close these extra scopes. That is
-%   done using a dedicated function and a pair of tracking variables. Within
-%   each graphics scope we use a global variable to do the work, with a group
-%   used to save the value between scopes. The result is that no direct action
-%   is needed when creating a scope.
-%    \begin{macrocode}
-\cs_new_protected:Npn \@@_backend_scope_begin:
-  {
-    \int_set_eq:NN
-      \l_@@_draw_scope_int
-      \g_@@_draw_scope_int
-    \group_begin:
-      \int_gzero:N \g_@@_draw_scope_int
-  }
-\cs_new_protected:Npn \@@_backend_scope_end:
-  {
-      \prg_replicate:nn
-        { \g_@@_draw_scope_int }
-        { \@@_backend_literal:n { </g> } }
-    \group_end:
-    \int_gset_eq:NN
-      \g_@@_draw_scope_int
-      \l_@@_draw_scope_int
-  }
-\cs_new_protected:Npn \@@_backend_scope:n #1
-  {
-    \@@_backend_literal:n { <g~ #1 > }
-    \int_gincr:N \g_@@_draw_scope_int
+    \__kernel_backend_scope_begin:
+    \__kernel_backend_scope:n { transform="translate({?x},{?y})~scale(1,-1)" }
   }
-\cs_generate_variant:Nn \@@_backend_scope:n { x }
-\int_new:N \g_@@_draw_scope_int
-\int_new:N \l_@@_draw_scope_int
+\cs_new_eq:NN \@@_backend_end: \__kernel_backend_scope_end:
 %    \end{macrocode}
-% \end{variable}
-% \end{macro}
 % \end{macro}
 %
 % \begin{macro}{\@@_backend_moveto:nn, \@@_backend_lineto:nn}
diff --git a/l3experimental/l3color/l3color.dtx b/l3experimental/l3color/l3color.dtx
index 3af2498dc..2b83cc681 100644
--- a/l3experimental/l3color/l3color.dtx
+++ b/l3experimental/l3color/l3color.dtx
@@ -247,7 +247,8 @@
 % \emph{may} apply to text, but this is backend-depended and the general
 % \cs{color_select:n(n)} should be used for typeset text. In contrast to
 % general color, these operations are \emph{not} stacked and thus must
-% \emph{not} split across pages.
+% \emph{not} split across pages. Also, an appropriate scope must be applied
+% to the color change, for example \cs{draw_begin:}/\cs{draw_end:}.
 %
 % \begin{function}{\color_fill:n, \color_stroke:n}
 %   \begin{syntax}
diff --git a/l3kernel/testfiles/d3dvisvgm.luatex.tlg b/l3kernel/testfiles/d3dvisvgm.luatex.tlg
index b27992d1d..44544864f 100644
--- a/l3kernel/testfiles/d3dvisvgm.luatex.tlg
+++ b/l3kernel/testfiles/d3dvisvgm.luatex.tlg
@@ -6,9 +6,9 @@ Package: expl3 ....-..-.. L3 programming layer (loader)
 File: l3debug.def ....-..-.. L3 Debugging support
 ) (l3backend-dvisvgm.def
 File: l3backend-dvisvgm.def ....-..-.. L3 backend support: dvisvgm
+\g__kernel_backend_scope_int=\count...
+\l__kernel_backend_scope_int=\count...
 \g__box_clip_path_int=\count...
-\g__draw_draw_scope_int=\count...
-\l__draw_draw_scope_int=\count...
 \g__draw_path_int=\count...
 \l__pdf_internal_box=\box...
 ))
diff --git a/l3kernel/testfiles/d3dvisvgm.tlg b/l3kernel/testfiles/d3dvisvgm.tlg
index 2e0c06024..63d2014e4 100644
--- a/l3kernel/testfiles/d3dvisvgm.tlg
+++ b/l3kernel/testfiles/d3dvisvgm.tlg
@@ -6,9 +6,9 @@ Package: expl3 ....-..-.. L3 programming layer (loader)
 File: l3debug.def ....-..-.. L3 Debugging support
 ) (l3backend-dvisvgm.def
 File: l3backend-dvisvgm.def ....-..-.. L3 backend support: dvisvgm
+\g__kernel_backend_scope_int=\count...
+\l__kernel_backend_scope_int=\count...
 \g__box_clip_path_int=\count...
-\g__draw_draw_scope_int=\count...
-\l__draw_draw_scope_int=\count...
 \g__draw_path_int=\count...
 \l__pdf_internal_box=\box...
 ))
diff --git a/l3kernel/testfiles/d3dvisvgm.xetex.tlg b/l3kernel/testfiles/d3dvisvgm.xetex.tlg
index 2e0c06024..63d2014e4 100644
--- a/l3kernel/testfiles/d3dvisvgm.xetex.tlg
+++ b/l3kernel/testfiles/d3dvisvgm.xetex.tlg
@@ -6,9 +6,9 @@ Package: expl3 ....-..-.. L3 programming layer (loader)
 File: l3debug.def ....-..-.. L3 Debugging support
 ) (l3backend-dvisvgm.def
 File: l3backend-dvisvgm.def ....-..-.. L3 backend support: dvisvgm
+\g__kernel_backend_scope_int=\count...
+\l__kernel_backend_scope_int=\count...
 \g__box_clip_path_int=\count...
-\g__draw_draw_scope_int=\count...
-\l__draw_draw_scope_int=\count...
 \g__draw_path_int=\count...
 \l__pdf_internal_box=\box...
 ))





More information about the latex3-commits mailing list.