[latex3-commits] [git/LaTeX3-latex3-latex3] main: Support for "tHsb" color (4c347f982)

Joseph Wright joseph.wright at morningstar2.co.uk
Tue Aug 23 08:14:56 CEST 2022


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/4c347f982f9fa6926cc4753c04590c7a9262385e

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

commit 4c347f982f9fa6926cc4753c04590c7a9262385e
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Aug 23 07:14:56 2022 +0100

    Support for "tHsb" color


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

4c347f982f9fa6926cc4753c04590c7a9262385e
 l3kernel/CHANGELOG.md             |  2 +-
 l3kernel/l3color.dtx              | 48 +++++++++++++++++++++++++++++++++++++++
 l3kernel/testfiles/m3color002.lvt | 12 ++++++++++
 l3kernel/testfiles/m3color002.tlg | 40 ++++++++++++++++++++++++++------
 4 files changed, 94 insertions(+), 8 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 4434d84f1..442b5b879 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -12,7 +12,7 @@ this project uses date-based 'snapshot' version identifiers.
   strings with `\str_(g)set_convert:Nnnn`. 
 - `\color_if_exist:n(TF)`
 - Support for case changing Vietnamese characters with 8-bit engines
-- Parsing of `cmy` and `&spot` color models to support data exchange with
+- Parsing of `cmy`, `tHsb` and `&spot` color models to support data exchange with
   `xcolor`
 
 ### Changed
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index 5fb0c6c6f..a1d118ee5 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -125,6 +125,10 @@
 % \begin{itemize}
 %   \item \texttt{cmy} Cyan-magenta-yellow color with three axes, one for
 %     each of the components; converted to |cmyk|
+%   \item \texttt{tHsb} \enquote{Tuned} hue-saturation-brightness color with three
+%     axes, integer in the range $[0,360]$ for hue, real values in the range
+%     $[0,1]$ for saturation and brightness; converted to |rgb| using the
+%     standard tuning map defined by \pkg{xcolor}
 %   \item \texttt{\&spot} Spot color tint with one value; treated as a gray
 %     tint as spot color data is not available for extraction
 % \end{itemize}
@@ -1294,6 +1298,50 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_parse_model_tHsb:w}
+% \begin{macro}{\@@_parse_model_tHsb:n}
+% \begin{macro}{\@@_parse_model_tHsb:nw}
+%   There are three stages to the process here: bring the |tH| argument into
+%   the normal range, divide through to get to |hsb| and finally convert that
+%   to |rgb|. The final stage can be delegated to the parsing function for
+%   |hsb|, and the conversion from |Hsb| to |hsb| is trivial, so the main focus
+%   here is the first stage. We use a simple expandable loop to do the work,
+%   and we implement the equation given in the \pkg{xcolor} manual
+%   (number~85 there) as a simple expression.
+%    \begin{macrocode}
+\cs_new:Npn \@@_parse_model_tHsb:w #1 , #2 , #3 , #4 \s_@@_stop
+  {
+    \exp_args:Ne \@@_parse_model_hsb:nnn
+      { \@@_parse_model_tHsb:n {#1} } {#2} {#3}
+  }
+\cs_new:Npn \@@_parse_model_tHsb:n #1
+  {
+    \@@_parse_model_tHsb:nw {#1}
+        0 ,   0 ; 
+       60 ,  30 ;
+      120 ,  60 ;
+      180 , 120 ;
+      210 , 180 ;
+      240 , 240 ;
+      360 , 360 ;
+      \q_recursion_tail , ;
+      \q_recursion_stop
+  }
+\cs_new:Npn \@@_parse_model_tHsb:nw #1 #2 , #3 ; #4 , #5 ;
+  {
+    \quark_if_recursion_tail_stop_do:nn {#4} { 0 }
+    \fp_compare:nNnTF {#1} > {#4}
+      { \@@_parse_model_tHsb:nw {#1} #4 , #5 ; }
+      {
+        \use_i_delimit_by_q_recursion_stop:nw
+          { \fp_eval:n { ((#1 - #2) / (#4 - #2) * (#5 - #3) + #3) / 360 } }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}{\@@_parse_model_&spot:w}
 %   We cannot extract data here from that passed by \pkg{xcolor}, so
 %   we fall back on a black tint. 
diff --git a/l3kernel/testfiles/m3color002.lvt b/l3kernel/testfiles/m3color002.lvt
index 6e125a365..b4cdad349 100644
--- a/l3kernel/testfiles/m3color002.lvt
+++ b/l3kernel/testfiles/m3color002.lvt
@@ -86,6 +86,18 @@
     \color_show:n { foo1 }
   }
 
+\TEST { tHsb~model }
+  {
+    \color_set:nnn { foo1 } { tHsb } { 90 , 1 , 1 }
+    \color_show:n { foo1 }
+    \color_set:nnn { foo2 } { tHsb } { 187.5 , 1 , 1 }
+    \color_show:n { foo2 }
+    \color_set:nnn { foo3 } { tHsb } { 270 , 1 , 1 }
+    \color_show:n { foo3 }
+    \color_set:nnn { foo4 } { tHsb } { 360 , 1 , 1 }
+    \color_show:n { foo4 }
+  }
+
 \TEST { &spot~model }
   {
     \color_set:nnn { foo1 } { &spot } {  0.54 }
diff --git a/l3kernel/testfiles/m3color002.tlg b/l3kernel/testfiles/m3color002.tlg
index c75d1324b..d4fcdd9e2 100644
--- a/l3kernel/testfiles/m3color002.tlg
+++ b/l3kernel/testfiles/m3color002.tlg
@@ -196,7 +196,35 @@ The color foo1 has the properties:
 l. ...  }
 ============================================================
 ============================================================
-TEST 7: &spot model
+TEST 7: tHsb model
+============================================================
+The color foo1 has the properties:
+>  model  =>  rgb
+>  rgb  =>  1.0 0.75 0.
+<recently read> }
+l. ...  }
+The color foo2 has the properties:
+>  model  =>  rgb
+>  rgb  =>  0 1.0 0.25.
+<recently read> }
+l. ...  }
+Defining \l__color_named_foo3_tl on line ...
+Defining \l__color_named_foo3_prop on line ...
+The color foo3 has the properties:
+>  model  =>  rgb
+>  rgb  =>  0.5 0 1.0.
+<recently read> }
+l. ...  }
+Defining \l__color_named_foo4_tl on line ...
+Defining \l__color_named_foo4_prop on line ...
+The color foo4 has the properties:
+>  model  =>  rgb
+>  rgb  =>  1.0 0 0.
+<recently read> }
+l. ...  }
+============================================================
+============================================================
+TEST 8: &spot model
 ============================================================
 The color foo1 has the properties:
 >  model  =>  gray
@@ -205,7 +233,7 @@ The color foo1 has the properties:
 l. ...  }
 ============================================================
 ============================================================
-TEST 8: Exporting colors
+TEST 9: Exporting colors
 ============================================================
 > \l_tmpa_tl={rgb}{0.0 0.0 1.0}.
 <recently read> }
@@ -257,7 +285,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 9: Exporting color: errors
+TEST 10: Exporting color: errors
 ============================================================
 ! LaTeX Error: Unknown export format 'mumble'.
 For immediate help type H <return>.
@@ -267,7 +295,7 @@ LaTeX has been asked to export a color in format 'mumble', but this has never
 been defined.
 ============================================================
 ============================================================
-TEST 10: Exporting complex models
+TEST 11: Exporting complex models
 ============================================================
 > \l_tmpa_tl={BarToneCMYK}{0.6}.
 <recently read> }
@@ -307,10 +335,8 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 11: Multiple models
+TEST 12: Multiple models
 ============================================================
-Defining \l__color_named_foo3_tl on line ...
-Defining \l__color_named_foo3_prop on line ...
 The color foo3 has the properties:
 >  model  =>  rgb
 >  rgb  =>  0.231 0.231 0.70.





More information about the latex3-commits mailing list.