[latex3-commits] [git/LaTeX3-latex3-latex3] main: Support cmy color model (060cb9556)
Joseph Wright
joseph.wright at morningstar2.co.uk
Sun Aug 21 10:58:42 CEST 2022
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/060cb95564d47aef2f9a19918826070f7c90cff6
>---------------------------------------------------------------
commit 060cb95564d47aef2f9a19918826070f7c90cff6
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Sun Aug 21 09:58:42 2022 +0100
Support cmy color model
>---------------------------------------------------------------
060cb95564d47aef2f9a19918826070f7c90cff6
l3kernel/CHANGELOG.md | 1 +
l3kernel/l3color.dtx | 44 +++++++++++++++++++++++++++++++++------
l3kernel/testfiles/m3color002.lvt | 7 +++++++
l3kernel/testfiles/m3color002.tlg | 17 +++++++++++----
4 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 2b33b5270..289f78524 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -12,6 +12,7 @@ this project uses date-based 'snapshot' version identifiers.
strings with `\str_convert`.
- `\color_if_exist:n(TF)`
- Support for case changing Vietnamese characters with 8-bit engines
+- Support for `cmy` color model
## [2022-08-05]
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index e8f993778..ab76a35a6 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -95,6 +95,7 @@
% \item \texttt{cmyk} Cyan-magenta-yellow-black color, with four axes, one for
% each of the components
% \end{itemize}
+%
% There are also interface models: these are convenient for users but have
% to be manipulated before storing/passing to the backend. Interface models
% are primarily integer-based: see below for more detail. The supported
@@ -118,6 +119,14 @@
% \end{itemize}
% All interface models are internally stored as |rgb|.
%
+% Finally, there are a small number of models which are parsed to allow
+% data transfer from \pkg{xcolor} but which should not be used by end-users.
+% These are
+% \begin{itemize}
+% \item \texttt{cmy} Cyan-magenta-yellow color with three axes, one for
+% each of the components; converted to |cmyk|
+% \end{itemize}
+%
% To allow parsing of data from \pkg{xcolor}, any leading model up the first
% \texttt{:} will be discarded; the approach of selecting an internal form
% for data is \emph{not} used in \pkg{l3color}.
@@ -688,6 +697,7 @@
% \@@_convert_rgb_rgb:w
% \@@_convert_rgb_cmyk:w
% }
+% \begin{macro}[EXP]{\@@_convert_rgb_cmyk:nnn}
% \begin{macro}[EXP]{\@@_convert_rgb_cmyk:nnnn}
% Model conversion is carried out using standard formulae for base models,
% as described in the manual for \pkg{xcolor} (see also the \emph{PostScript
@@ -751,18 +761,28 @@
% removal} functions. The PostScript reference describes them as
% device-dependent, but following \pkg{xcolor} we assume they are linear.
% Moreover, as the likelihood of anyone using a non-unitary matrix here is
-% tiny, we simplify and treat those two concepts as no-ops.
+% tiny, we simplify and treat those two concepts as no-ops. To allow code
+% sharing with parsing of |cmy| values, we have an intermediate function
+% here (\cs{@@_convert_rgb_cmyk:nnn}) which actually takes |cmy| values
+% as input.
% \begin{macrocode}
\cs_new:Npn \@@_convert_rgb_cmyk:w #1 ~ #2 ~ #3 \s_@@_stop
{
- \exp_args:Nf \@@_convert_rgb_cmyk:nnnn
- { \fp_eval:n { min ( 1 - #1 , 1 - #2 , 1 - #3 ) } } {#1} {#2} {#3}
+ \exp_args:Neee \@@_convert_rgb_cmyk:nnn
+ { \fp_eval:n { 1 - #1 } }
+ { \fp_eval:n { 1 - #2 } }
+ { \fp_eval:n { 1 - #3 } }
+ }
+\cs_new:Npn \@@_convert_rgb_cmyk:nnn #1#2#3
+ {
+ \exp_args:Ne \@@_convert_rgb_cmyk:nnnn
+ { \fp_eval:n { min( #1, #2 , #3 ) } } {#1} {#2} {#3}
}
\cs_new:Npn \@@_convert_rgb_cmyk:nnnn #1#2#3#4
{
- \fp_eval:n { min ( 1 , max ( 0 , 1 - #2 - #1 ) ) } \c_space_tl
- \fp_eval:n { min ( 1 , max ( 0 , 1 - #3 - #1 ) ) } \c_space_tl
- \fp_eval:n { min ( 1 , max ( 0 , 1 - #4 - #1 ) ) } \c_space_tl
+ \fp_eval:n { min ( 1 , max ( 0 , #2 - #1 ) ) } \c_space_tl
+ \fp_eval:n { min ( 1 , max ( 0 , #3 - #1 ) ) } \c_space_tl
+ \fp_eval:n { min ( 1 , max ( 0 , #4 - #1 ) ) } \c_space_tl
#1
}
\cs_new:Npn \@@_convert_cmyk_gray:w #1 ~ #2 ~ #3 ~ #4 \s_@@_stop
@@ -780,6 +800,7 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \subsection{Color expressions}
%
@@ -1264,6 +1285,17 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}{\@@_parse_model_cmy:w}
+% Simply pass data to the conversion functions.
+% \begin{macrocode}
+\cs_new:Npn \@@_parse_model_cmy:w #1 , #2 , #3 , #4 \s_@@_stop
+ {
+ { cmyk }
+ { \@@_convert_rgb_cmyk:nnn {#1} {#2} {#3} }
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Selecting colors (and color models)}
%
% \begin{variable}{\l_color_fixed_model_tl}
diff --git a/l3kernel/testfiles/m3color002.lvt b/l3kernel/testfiles/m3color002.lvt
index 5056216a5..6a7a4d574 100644
--- a/l3kernel/testfiles/m3color002.lvt
+++ b/l3kernel/testfiles/m3color002.lvt
@@ -80,6 +80,13 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST { cmy~model }
+ {
+ \color_set:nnn { foo1 } { cmy } { 0.123 , 0.234 , 0.345 }
+ \color_show:n { foo1 }
+ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\TEST { Exporting~colors }
{
diff --git a/l3kernel/testfiles/m3color002.tlg b/l3kernel/testfiles/m3color002.tlg
index b154ecdd6..dec91131e 100644
--- a/l3kernel/testfiles/m3color002.tlg
+++ b/l3kernel/testfiles/m3color002.tlg
@@ -187,7 +187,16 @@ The color foo2 has the properties:
l. ... }
============================================================
============================================================
-TEST 6: Exporting colors
+TEST 6: cmy model
+============================================================
+The color foo1 has the properties:
+> model => cmyk
+> cmyk => 0 0.111 0.222 0.123.
+<recently read> }
+l. ... }
+============================================================
+============================================================
+TEST 7: Exporting colors
============================================================
> \l_tmpa_tl={rgb}{0.0 0.0 1.0}.
<recently read> }
@@ -239,7 +248,7 @@ l. ... }
l. ... }
============================================================
============================================================
-TEST 7: Exporting color: errors
+TEST 8: Exporting color: errors
============================================================
! LaTeX3 Error: Unknown export format 'mumble'.
For immediate help type H <return>.
@@ -249,7 +258,7 @@ LaTeX has been asked to export a color in format 'mumble', but this has never
been defined.
============================================================
============================================================
-TEST 8: Exporting complex models
+TEST 9: Exporting complex models
============================================================
> \l_tmpa_tl={BarToneCMYK}{0.6}.
<recently read> }
@@ -289,7 +298,7 @@ l. ... }
l. ... }
============================================================
============================================================
-TEST 9: Multiple models
+TEST 10: Multiple models
============================================================
Defining \l__color_named_foo3_tl on line ...
Defining \l__color_named_foo3_prop on line ...
More information about the latex3-commits
mailing list.