[latex3-commits] [git/LaTeX3-latex3-latex3] master: Extend dvips backend to cover arbitrary Separations (64bfbde3b)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Sep 11 15:20:40 CEST 2020


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/64bfbde3b11dfe3d15e854c4ca6ff601894aa450

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

commit 64bfbde3b11dfe3d15e854c4ca6ff601894aa450
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Sep 11 14:20:21 2020 +0100

    Extend dvips backend to cover arbitrary Separations
    
    This will be needed for CIELAB support.


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

64bfbde3b11dfe3d15e854c4ca6ff601894aa450
 l3backend/l3backend-color.dtx          | 106 ++++++++++++++++++++++++++++++++-
 l3kernel/testfiles/m3expl001.ptex.tlg  |   7 +++
 l3kernel/testfiles/m3expl001.uptex.tlg |   7 +++
 l3kernel/testfiles/m3expl003.ptex.tlg  |   7 +++
 l3kernel/testfiles/m3expl003.uptex.tlg |   7 +++
 5 files changed, 132 insertions(+), 2 deletions(-)

diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index 3e48edb14..eb54b518c 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -327,6 +327,13 @@
 %     \@@_backend_separation_init_/DeviceRGB:nnn
 %   }
 % \begin{macro}[EXP]{\@@_backend_separation_init_Device:Nn}
+% \begin{macro}[EXP]{\@@_backend_separation_init:nnn}
+% \begin{macro}[EXP]{\@@_backend_separation_init_count:n}
+% \begin{macro}[EXP]{\@@_backend_separation_init_count:w}
+% \begin{macro}[EXP]{\@@_backend_separation_init:nnnn}
+% \begin{macro}[EXP]{\@@_backend_separation_init:w}
+% \begin{macro}[EXP]{\@@_backend_separation_init:n}
+% \begin{macro}[EXP]{\@@_backend_separation_init:nw}
 % \begin{macro}{\@@_backend_separation_init_CIELAB:nnn}
 %   Initialising here means creating a small header set up plus massaging
 %   some data. This comes about as we have to deal with PDF-focussed data,
@@ -359,8 +366,9 @@
               /Separation ~ ( \str_convert_pdfname:n {#1} ) ~
               #2 ~
                 {
-                  \use:c { @@_backend_separation_init_ #2 :nnn }
-                    {#3} {#4} {#5}
+                  \cs_if_exist_use:cF { @@_backend_separation_init_ #2 :nnn }
+                    { \@@_backend_separation_init:nnn }
+                      {#3} {#4} {#5}
                 }
             ] ~ setcolorspace
           } ~ def ~
@@ -381,6 +389,93 @@
     \int_eval:n { #1 + 1 } ~ -1 ~ roll ~ pop
   }
 %    \end{macrocode}
+%   For the generic case, we cannot use |/FunctionType 2| unfortunately, so
+%   we have to code that idea up in PostScript. Here, we will therefore assume
+%   that a range is \emph{always} given. First, we count values in each argument:
+%   at the backend level, we can assume there are always well-behaved with
+%   spaces present.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_separation_init:nnn #1#2#3
+  {
+   \exp_args:Ne \@@_backend_separation_init:nnnn
+     { \@@_backend_separation_init_count:n {#2} }
+     {#1} {#2} {#3}
+  }
+\cs_new:Npn \@@_backend_separation_init_count:n #1
+  { \int_eval:n { 0 \@@_backend_separation_init_count:w #1 ~ \s_@@_stop } }
+\cs_new:Npn \@@_backend_separation_init_count:w #1 ~ #2 \s_@@_stop
+  {
+    +1
+    \tl_if_blank:nF {#2}
+      { \@@_backend_separation_init_count:w #2 \s_@@_stop }
+  }
+%    \end{macrocode}
+%   Now we implement the algorithm. In the terms in the PostScript manual,
+%   we have $\mathbf{N} = 1$ and $\mathbf{Domain} = [0~1]$, with
+%   $\mathbf{Range}$ as |#2|, $\mathbf{C0}$ as |#3| and $\mathbf{C1}$
+%   as |#4|, with the number of output components in |#1|. So all we have
+%   to do is implement $y_{i} = \mathbf{C0}_{i} + x(\mathbf{C1}_{i} -
+%   \mathbf{C0}_{i})$ with lots of stack manipulation, then check the
+%   ranges. That's done by adding everything to the stack first, then using
+%   the fact we know all of the offsets. As manipulating the stack is tricky,
+%   we start by re-formatting the $\mathbf{C0}$ and $\mathbf{C1}$ arrays to
+%   be interleaved, and add a \texttt{0} to each pair: this is used
+%   to keep the stack of constant length while we are doing the first pass of
+%   mathematics. We then working through that list, calculating from the
+%   last to the first value before tidying up by removing all of the input
+%   values. We do that by first copying all of the final $y$ values to the
+%   end of the stack, then rolling everything so we can pop the now-unneeded
+%   material.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_separation_init:nnnn #1#2#3#4
+  {
+    \@@_backend_separation_init:w #3 ~ \s_@@_stop #4 ~ \s_@@_stop
+    \prg_replicate:nn {#1}
+      {
+        pop ~ 1 ~ index ~ neg ~ 1 ~ index ~ add ~
+        \int_eval:n { 3 * #1 } ~ index ~ mul ~
+        2 ~ index ~ add ~
+        \int_eval:n { 3 * #1 } ~ #1 ~ roll ~
+      }
+    \int_step_function:nnnN {#1} { -1 } { 1 }
+      \@@_backend_separation_init:n
+    \int_eval:n { 4 * #1 + 1 } ~ #1 ~ roll ~
+    \prg_replicate:nn { 3 * #1 + 1 } { pop ~ }
+    \tl_if_blank:nF {#2}
+      { \@@_backend_separation_init:nw {#1} #2 ~ \s_@@_stop }
+  }
+\cs_new:Npn \@@_backend_separation_init:w
+  #1 ~ #2 \s_@@_stop #3 ~ #4 \s_@@_stop
+  {
+    #1 ~ #3 ~ 0 ~
+    \tl_if_blank:nF {#2}
+      { \@@_backend_separation_init:w #2 \s_@@_stop #4 \s_@@_stop }
+  }
+\cs_new:Npn \@@_backend_separation_init:n #1
+  { \int_eval:n { #1 * 2 } ~ index ~ }
+%    \end{macrocode}
+%   Finally, we deal with the range limit if required. This is handled
+%   by splitting the range into pairs. It's then just a question of doing
+%   the comparisons, this time dropping everything except the desired
+%   result.
+%    \begin{macrocode}
+\cs_new:Npn \@@_backend_separation_init:nw #1#2 ~ #3 ~ #4 \s_@@_stop
+  {
+     #2 ~ #3 ~
+     2 ~ index ~ 2 ~ index ~ lt ~
+       { ~ pop ~ exch ~ pop ~ } ~
+       { ~
+         2 ~ index ~ 1 ~ index ~ gt ~
+           { ~ exch ~ pop ~ exch ~ pop ~ } ~
+           { ~ pop ~ pop ~ } ~
+         ifelse ~
+       }
+    ifelse ~
+    #1 ~ 1 ~ roll ~
+    \tl_if_blank:nF {#4}
+      { \@@_backend_separation_init:nw {#1} #4 \s_@@_stop }
+  }
+%    \end{macrocode}
 %  Currently no CIELAB support.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_backend_separation_init_CIELAB:nnn #1#2#3 { }
@@ -389,6 +484,13 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
 %
 %    \begin{macrocode}
 %</dvips>
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index e4182a138..28e8aac1f 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -41,6 +41,13 @@ Defining \__color_backend_separation_init_/DeviceCMYK:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceGray:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceRGB:nnn on line ...
 Defining \__color_backend_separation_init_Device:Nn on line ...
+Defining \__color_backend_separation_init:nnn on line ...
+Defining \__color_backend_separation_init_count:n on line ...
+Defining \__color_backend_separation_init_count:w on line ...
+Defining \__color_backend_separation_init:nnnn on line ...
+Defining \__color_backend_separation_init:w on line ...
+Defining \__color_backend_separation_init:n on line ...
+Defining \__color_backend_separation_init:nw on line ...
 Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index e4182a138..28e8aac1f 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -41,6 +41,13 @@ Defining \__color_backend_separation_init_/DeviceCMYK:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceGray:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceRGB:nnn on line ...
 Defining \__color_backend_separation_init_Device:Nn on line ...
+Defining \__color_backend_separation_init:nnn on line ...
+Defining \__color_backend_separation_init_count:n on line ...
+Defining \__color_backend_separation_init_count:w on line ...
+Defining \__color_backend_separation_init:nnnn on line ...
+Defining \__color_backend_separation_init:w on line ...
+Defining \__color_backend_separation_init:n on line ...
+Defining \__color_backend_separation_init:nw on line ...
 Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index e4182a138..28e8aac1f 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -41,6 +41,13 @@ Defining \__color_backend_separation_init_/DeviceCMYK:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceGray:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceRGB:nnn on line ...
 Defining \__color_backend_separation_init_Device:Nn on line ...
+Defining \__color_backend_separation_init:nnn on line ...
+Defining \__color_backend_separation_init_count:n on line ...
+Defining \__color_backend_separation_init_count:w on line ...
+Defining \__color_backend_separation_init:nnnn on line ...
+Defining \__color_backend_separation_init:w on line ...
+Defining \__color_backend_separation_init:n on line ...
+Defining \__color_backend_separation_init:nw on line ...
 Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index e4182a138..28e8aac1f 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -41,6 +41,13 @@ Defining \__color_backend_separation_init_/DeviceCMYK:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceGray:nnn on line ...
 Defining \__color_backend_separation_init_/DeviceRGB:nnn on line ...
 Defining \__color_backend_separation_init_Device:Nn on line ...
+Defining \__color_backend_separation_init:nnn on line ...
+Defining \__color_backend_separation_init_count:n on line ...
+Defining \__color_backend_separation_init_count:w on line ...
+Defining \__color_backend_separation_init:nnnn on line ...
+Defining \__color_backend_separation_init:w on line ...
+Defining \__color_backend_separation_init:n on line ...
+Defining \__color_backend_separation_init:nw on line ...
 Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...





More information about the latex3-commits mailing list.