[latex3-commits] [git/LaTeX3-latex3-latex3] master: Better color support for drawings in dvisvgm (eab0d868d)

Joseph Wright joseph.wright at morningstar2.co.uk
Tue Jun 23 09:13:40 CEST 2020


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

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

commit eab0d868d74b17c9655443eb631aa97eedd10a45
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Jun 23 08:13:40 2020 +0100

    Better color support for drawings in dvisvgm


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

eab0d868d74b17c9655443eb631aa97eedd10a45
 l3backend/CHANGELOG.md       |  3 ++
 l3backend/l3backend-draw.dtx | 77 +++++++++++++++++++++++---------------------
 2 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/l3backend/CHANGELOG.md b/l3backend/CHANGELOG.md
index 2f5ec3936..12f718414 100644
--- a/l3backend/CHANGELOG.md
+++ b/l3backend/CHANGELOG.md
@@ -6,6 +6,9 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Changed
+- Improved color support for drawings with `dvisvgm`
+
 ### Fixed
 - Loading with `dvisvgm`
 
diff --git a/l3backend/l3backend-draw.dtx b/l3backend/l3backend-draw.dtx
index 4a56cb9f3..34ba9e2d0 100644
--- a/l3backend/l3backend-draw.dtx
+++ b/l3backend/l3backend-draw.dtx
@@ -1163,83 +1163,86 @@
 %     \@@_backend_color_fill_cmyk:n   ,
 %     \@@_backend_color_stroke_cmyk:n
 %   }
-% \begin{macro}{\@@_backend_color_fill_cmyk:w}
+% \begin{macro}{\@@_backend_color_cmyk:nw}
 % \begin{macro}
 %   {
 %     \@@_backend_color_fill_gray:n   ,
 %     \@@_backend_color_stroke_gray:n
 %   }
-% \begin{macro}{\@@_backend_color_gray_aux:n}
+% \begin{macro}{\@@_backend_color_gray:nn, \@@_backend_color_gray_aux:n}
 % \begin{macro}
 %   {
 %     \@@_backend_color_fill_rgb:n   ,
 %     \@@_backend_color_stroke_rgb:n
 %   }
-% \begin{macro}{\@@_backend_color_fill_rgb:w}
-% \begin{macro}{\@@_backend_color_fill:nnn}
-%  SVG fill color has to be covered outside of the stack, as for
-%  \texttt{dvips}. Here, we are only allowed RGB colors so there is some
-%  conversion to do.
+% \begin{macro}{\@@_backend_color_rgb:nw}
+% \begin{macro}{\@@_backend_color:nnnn}
+%   For drawings in SVG, we use scopes for all colors. That
+%   requires using \texttt{RGB} values, which luckily are easy to
+%   convert here (|cmyk| to |RGB| is a fixed function).
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_backend_color_fill_cmyk:n #1
-  { \@@_backend_color_fill_cmyk:w #1 \s_@@_stop }
-\cs_new_protected:Npn \@@_backend_color_fill_cmyk:w
-  #1 ~ #2 ~ #3 ~ #4 \s_@@_stop
+  { \@@_backend_color_cmyk:nw { fill } #1 \s_@@_stop }
+\cs_new_protected:Npn \@@_backend_color_stroke_cmyk:n #1
+  { \@@_backend_color_cmyk:nw { stroke } #1 \s_@@_stop }
+\cs_new_protected:Npn \@@_backend_color_cmyk:nw
+  #1#2 ~ #3 ~ #4 ~ #5 \s_@@_stop
   {
     \use:x
       {
-        \@@_backend_color_fill:nnn
-          { \fp_eval:n { -100 * ( 1 - min ( 1 , #1 + #4 ) ) } }
-          { \fp_eval:n { -100 * ( 1 - min ( 1 , #2 + #4 ) ) } }
-          { \fp_eval:n { -100 * ( 1 - min ( 1 , #3 + #4 ) ) } }
+        \@@_backend_color:nnnn
+          {#1}
+          { \fp_eval:n { -100 * ( 1 - min ( 1 , #2 + #5 ) ) } }
+          { \fp_eval:n { -100 * ( 1 - min ( 1 , #3 + #5 ) ) } }
+          { \fp_eval:n { -100 * ( 1 - min ( 1 , #4 + #5 ) ) } }
       }
   }
-\cs_new_protected:Npn \@@_backend_color_stroke_cmyk:n #1
-  { \@@_backend_select:n { cmyk ~ #1 } }
 \cs_new_protected:Npn \@@_backend_color_fill_gray:n #1
+  { \@@_backend_color_grab:nn { fill } {#1} }
+\cs_new_protected:Npn \@@_backend_color_stroke_gray:n #1
+  { \@@_backend_color_grab:nn { stroke } {#1} }
+\cs_new_protected:Npn \@@_backend_color_gray:nn #1#2
   {
     \use:x
       {
-        \@@_backend_color_gray_aux:n
-          { \fp_eval:n { 100 * (#1) } }
+        \@@_backend_color_gray_aux:nn
+          {#1}
+          { \fp_eval:n { 100 * (#2) } }
       }
   }
-\cs_new_protected:Npn \@@_backend_color_gray_aux:n #1
-  { \@@_backend_color_fill:nnn {#1} {#1} {#1} }
-\cs_new_protected:Npn \@@_backend_color_stroke_gray:n #1
-  { \@@_backend_select:x { gray~ \fp_eval:n {#1} } }
-\cs_new_protected:Npn \@@_backend_color_fill_rgb:n #1
-  { \@@_backend_color_fill_rgb:w #1 \s_@@_stop }
-\cs_new_protected:Npn \@@_backend_color_stroke_rgb:n #1
-  { \@@_backend_select:n { rgb ~ #1 } }
-\cs_new_protected:Npn \@@_backend_color_fill_rgb:w
-  #1 ~ #2 ~ #3 \s_@@_stop
+\cs_new_protected:Npn \@@_backend_color_gray_aux:nn #1#2
+  { \@@_backend_color:nnn {#1} {#2} {#2} {#2} }
+\cs_new_protected:Npn \@@_backend_color_rgb_cmyk:n #1
+  { \@@_backend_color_rgb:nw { fill } #1 \s_@@_stop }
+\cs_new_protected:Npn \@@_backend_color_rgb_cmyk:n #1
+  { \@@_backend_color_rgb:nw { stroke } #1 \s_@@_stop }
+\cs_new_protected:Npn \@@_backend_color_rgb:nw
+  #1#2 ~ #3 ~ #4\s_@@_stop
   {
     \use:x
       {
-        \@@_backend_color_fill:nnn
-          { \fp_eval:n { 100 * (#1) } }
+        \@@_backend_color:nnnn
+          { fill }
           { \fp_eval:n { 100 * (#2) } }
           { \fp_eval:n { 100 * (#3) } }
+          { \fp_eval:n { 100 * (#4) } }
       }
   }
-\cs_new_protected:Npn \@@_backend_color_fill:nnn #1#2#3
+\cs_new_protected:Npx \@@_backend_color:nnnn #1#2#3#4
   {
-    \@@_backend_scope:x
+    \@@_backend_scope:n
       {
-        fill =
+        #1 =
          "
            rgb
              (
-               #1 \c_percent_str ,
                #2 \c_percent_str ,
-               #3 \c_percent_str
+               #3 \c_percent_str ,
+               #4 \c_percent_str
              )
          "
       }
   }
-\cs_new_protected:Npn \@@_backend_color_stroke_rgb:n #1
-  { \@@_backend_select:n { rgb ~ #1 } }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}





More information about the latex3-commits mailing list.