[latex3-commits] [git/LaTeX3-latex3-latex3] master: Basic color support in l3draw (a0193f6)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Feb 21 08:54:09 CET 2018


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

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

commit a0193f6323ffb5466bb192da5f06990fdb5b880b
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Feb 20 23:02:58 2018 +0000

    Basic color support in l3draw


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

a0193f6323ffb5466bb192da5f06990fdb5b880b
 l3experimental/l3color/l3color.dtx     |   40 ++++++++++++++++---
 l3experimental/l3draw/l3draw-state.dtx |   67 ++++++++++++++++++++++++++++++++
 l3experimental/l3draw/l3draw.dtx       |   14 +++++++
 l3kernel/l3color-base.dtx              |    2 +-
 4 files changed, 116 insertions(+), 7 deletions(-)

diff --git a/l3experimental/l3color/l3color.dtx b/l3experimental/l3color/l3color.dtx
index ae3f7c6..6e4952e 100644
--- a/l3experimental/l3color/l3color.dtx
+++ b/l3experimental/l3color/l3color.dtx
@@ -216,6 +216,34 @@
 %   and similar are not influenced by this setting.
 % \end{variable}
 %
+% \section{Core color representation}
+%
+% To allow data to be handled internally, \pkg{l3color} uses a simple
+% representation of color, based on that used by the \pkg{dvips} program.
+% This is a token list made up of the model name followed by one or more
+% data entries, each separated by a \emph{space}. The valid forms are thus
+% \begin{itemize}
+%   \item \texttt{gray \meta{gray}} Grayscale color with the \meta{gray}
+%     value running from $0$ (fully black) to $1$ (fully white)
+%   \item \texttt{cmyk \meta{cyan} \meta{magenta} \meta{yellow} \meta{black}},
+%     each of which falls in the range $[0,1]$
+%   \item \texttt{rgb \meta{red} \meta{green} \meta{blue}},
+%     each of which falls in the range $[0,1]$
+%   \item \texttt{spot \meta{name} \meta{tint}} A pre-defined spot color,
+%     where the \meta{name} should be a pre-defined string color name and the
+%     \meta{tint} should be in the range $[0,1]$.
+% \end{itemize}
+%
+% This core representation is produced when parsing color expressions.
+% 
+% \begin{function}{\color_parse:nN}
+%   \begin{syntax}
+%     \cs{color_parse:nN} \Arg{color expression} \Arg{tl}
+%   \end{syntax}
+%   Parses the \meta{color expression} as described above, and sets the
+%   \meta{tl} the the equivalent \meta{core color representation}.
+% \end{function}
+%
 % \section{Spot colors}
 % \label{l3color:sec:spot}
 %
@@ -395,8 +423,8 @@
 %    \end{macrocode}
 % \end{variable}
 %
+% \begin{macro}{\color_parse:nN}
 % \begin{macro}{\@@_parse:nN}
-% \begin{macro}{\@@_parse_aux:nN}
 % \begin{macro}{\@@_parse:Nw}
 % \begin{macro}{\@@_parse_loop_init:Nnn}
 % \begin{macro}{\@@_parse_loop:w}
@@ -415,7 +443,7 @@
 %   otherwise expands, then starts working through the expression itself.
 %   At the end, we apply the payload.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_parse:nN #1#2
+\cs_new_protected:Npn \color_parse:nN #1#2
   {
     \group_begin:
       \seq_map_inline:Nn \l_char_active_seq
@@ -425,14 +453,14 @@
         }
       \tl_set:Nx \l_@@_tmp_tl {#1}
     \exp_args:NNV \group_end:
-    \@@_parse_aux:nN \l_@@_tmp_tl #2
+    \@@_parse:nN \l_@@_tmp_tl #2
   }
 %    \end{macrocode}
 %   Before going to all of the effort of parsing an expression, these two
 %   precursor functions look for a pre-defined name, either on its own or
 %   with a trailing |!| (which is the same thing).
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_parse_aux:nN #1#2
+\cs_new_protected:Npn \@@_parse:nN #1#2
   {
     \tl_if_exist:cTF { l_@@_named_ #1 _tl }
       { \tl_set_eq:Nc #2 { l_@@_named_ #1 _tl } }
@@ -667,7 +695,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \color_select:n #1
   {
-    \@@_parse:nN {#1} \l_@@_current_tl
+    \color_parse:nN {#1} \l_@@_current_tl
     \@@_select:
   }
 \cs_new_protected:Npn \color_select:nn #1#2
@@ -729,7 +757,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \color_set:nn #1#2
   {
-    \@@_parse:nN {#2} \l_@@_named_tl
+    \color_parse:nN {#2} \l_@@_named_tl
     \@@_store:Nn \l_@@_named_tl {#1}
   }
 \cs_new_protected:Npn \color_set:nnn #1#2#3
diff --git a/l3experimental/l3draw/l3draw-state.dtx b/l3experimental/l3draw/l3draw-state.dtx
index 33e04ed..2c39973 100644
--- a/l3experimental/l3draw/l3draw-state.dtx
+++ b/l3experimental/l3draw/l3draw-state.dtx
@@ -117,6 +117,73 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{variable}{\l_@@_color_tmp_tl}
+%   Scratch space.
+%    \begin{macrocode}
+\tl_new:N \l_@@_color_tmp_tl
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_fill_color_tl, \g_@@_stroke_color_tl}
+%   For tracking.
+%    \begin{macrocode}
+\tl_new:N \g_@@_fill_color_tl
+\tl_new:N \g_@@_stroke_color_tl
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\draw_color:n, \draw_color_fill:n, \draw_color_stroke:n}
+% \begin{macro}{\@@_color:nn}
+% \begin{macro}{\@@_color_aux:nn, \@@_color_aux:Vn}
+% \begin{macro}{\@@_color:nw}
+% \begin{macro}
+%   {
+%     \@@_select_cmyk:nw, \@@_select_gray:nw,
+%     \@@_select_rgb:nw, \@@_split_select:nw
+%   }
+%   Much the same as for core color support but calling the relevant
+%   driver-level function.
+%    \begin{macrocode}
+\cs_new_protected:Npn \draw_color:n #1
+  { \@@_color:nn { } {#1} }
+\cs_new_protected:Npn \draw_color_fill:n #1
+  { \@@_color:nn { fill } {#1} }
+\cs_new_protected:Npn \draw_color_stroke:n #1
+  { \@@_color:nn { stroke } {#1} }
+\cs_new_protected:Npn \@@_color:nn #1#2
+  {
+    \color_parse:nN {#2} \l_@@_color_tmp_tl
+    \tl_if_blank:nTF {#1}
+      {
+        \tl_gset_eq:NN \g_@@_fill_color_tl \l_@@_color_tmp_tl
+        \tl_gset_eq:NN \g_@@_stroke_color_tl \l_@@_color_tmp_tl
+        \@@_color_aux:Vn \l_@@_color_tmp_tl { color }
+      }
+      {
+        \tl_gset_eq:cN { g_@@_ #1 _color_tl } \l_@@_color_tmp_tl
+        \@@_color_aux:Vn \l_@@_color_tmp_tl { #1 }
+      }
+  }
+\cs_new_protected:Npn \@@_color_aux:nn #1#2
+  { \@@_color:nw {#2} #1 \q_stop }
+\cs_generate_variant:Nn \@@_color_aux:nn { V }
+\cs_new_protected:Npn \@@_color:nw #1#2 ~ #3 \q_stop
+  { \use:c { @@_color_ #2 :nw } {#1} #3 \q_stop }
+\cs_new_protected:Npn \@@_color_cmyk:nw #1#2 ~ #3 ~ #4 ~ #5 \q_stop
+  { \use:c { driver_draw_ #1 _cmyk:nnnn } {#2} {#3} {#4} {#5} }
+\cs_new_protected:Npn \@@_color_gray:nw #1#2 \q_stop
+  { \use:c { driver_draw_ #1 _gray:n } {#2} }
+\cs_new_protected:Npn \@@_color_rgb:nw #1#2 ~ #3 ~ #4 \q_stop
+  { \use:c { driver_draw_ #1 _rgb:nnn } {#2} {#3} {#4} }
+\cs_new_protected:Npn \@@_color_spot:nw #1#2 ~ #3 \q_stop
+  { \use:c { driver_draw_ #1 _spot:nn } {#2} {#3} }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 %    \begin{macrocode}
 %</initex|package>
 %    \end{macrocode}
diff --git a/l3experimental/l3draw/l3draw.dtx b/l3experimental/l3draw/l3draw.dtx
index 8235a54..f4271cf 100644
--- a/l3experimental/l3draw/l3draw.dtx
+++ b/l3experimental/l3draw/l3draw.dtx
@@ -478,6 +478,16 @@
 %   \end{itemize}
 % \end{function}
 %
+% \subsection{Color}
+%
+% \begin{function}{\draw_color:n, \draw_fill:n, \draw_stroke:n}
+%   \begin{syntax}
+%     \cs{draw_color:n} \Arg{color expression}
+%   \end{syntax}
+%   Evaluates the \meta{color expression} as described for \pkg{l3color},
+%   
+% \endq{function}
+%
 % \subsection{Transformations}
 %
 % Points are normally used unchanged relative to the canvas axes. This can
@@ -551,6 +561,10 @@
 %</package>
 %    \end{macrocode}
 %
+%    \begin{macrocode}
+\RequirePackage { l3color }
+%    \end{macrocode}
+%
 % Everything else is in the sub-files!
 %
 %    \begin{macrocode}
diff --git a/l3kernel/l3color-base.dtx b/l3kernel/l3color-base.dtx
index 3ef7080..037354d 100644
--- a/l3kernel/l3color-base.dtx
+++ b/l3kernel/l3color-base.dtx
@@ -155,7 +155,7 @@
 % \begin{macro}{\@@_select:n, \@@_select:V}
 % \begin{macro}{\@@_select:w}
 % \begin{macro}
-%   {\@@_split_cmyk:w, \@@_split_gray:w, \@@_split_rgb:w, \@@_split_spot:w}
+%   {\@@_select_cmyk:w, \@@_select_gray:w, \@@_select_rgb:w, \@@_select_spot:w}
 %    Take an internal color specification and pass it to the driver. This code
 %    is needed to ensure the current color but will also be used by the
 %    higher-level experimental material.





More information about the latex3-commits mailing list