[latex3-commits] [git/LaTeX3-latex3-latex3] main: Add support for ICC-based color profiles (4a25838a6)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Oct 18 14:00:02 CEST 2021


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

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

commit 4a25838a6a66c789a9f454a86e28405ac0fdadb9
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Feb 21 17:18:57 2021 +0000

    Add support for ICC-based color profiles


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

4a25838a6a66c789a9f454a86e28405ac0fdadb9
 l3backend/l3backend-color.dtx | 52 +++++++++++++++++++++--
 l3kernel/CHANGELOG.md         |  3 ++
 l3kernel/l3color.dtx          | 95 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+), 3 deletions(-)

diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index 3bd3fbc42..92fe5a1c9 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -546,6 +546,13 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_backend_select_iccbased:nn}
+%   No support.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_select_iccbased:nn #1#2 { }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}
 %   {
 %     \@@_backend_separation_init:nnnnn,
@@ -815,11 +822,17 @@
 %<*dvisvgm>
 %    \end{macrocode}
 %
-% \begin{macro}{\@@_backend_select_separation:nn, \@@_backend_select_devicen:nn}
+% \begin{macro}
+%   {
+%     \@@_backend_select_separation:nn,
+%     \@@_backend_select_devicen:nn   ,
+%     \@@_backend_select_iccbased:nn
+%   }
 %   No support at present.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_backend_select_separation:nn #1#2 { }
-\cs_new_protected:Npn \@@_backend_select_devicen:nn #1#2 { }
+\cs_new_eq:NN \@@_backend_select_devicen:nn \@@_backend_select_separation:nn
+\cs_new_eq:NN \@@_backend_select_iccbased:nn \@@_backend_select_separation:nn
 %    \end{macrocode}
 % \end{macro}
 %
@@ -840,7 +853,12 @@
 %<*dvipdfmx|luatex|pdftex|xetex>
 %    \end{macrocode}
 %
-% \begin{macro}{\@@_backend_select_separation:nn, \@@_backend_select_devicen:nn}
+% \begin{macro}
+%   {
+%     \@@_backend_select_separation:nn,
+%     \@@_backend_select_devicen:nn   ,
+%     \@@_backend_select_iccbased:nn
+%   }
 %   Although \texttt{(x)dvipdfmx} has a built-in approach to color spaces, that
 %   can't be used with the generic color stacks. So we take an approach in which
 %   we share the same code as for \pdfTeX{}.
@@ -848,6 +866,7 @@
 \cs_new_protected:Npn \@@_backend_select_separation:nn #1#2
   { \@@_backend_select:nn { /#1 ~ cs ~ #2 ~ scn  } { /#1 ~ CS ~ #2 ~ SCN } }
 \cs_new_eq:NN \@@_backend_select_devicen:nn \@@_backend_select_separation:nn
+\cs_new_eq:NN \@@_backend_select_iccbased:nn \@@_backend_select_separation:nn
 %    \end{macrocode}
 % \end{macro}
 %
@@ -981,6 +1000,33 @@
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+%
+% \begin{macro}{\@@_backend_iccbased_init:nnn}
+%  Lots of data to save here: we only want to do that once per file,
+%  so track it by name.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_iccbased_init:nnn #1#2#3
+  {
+    \pdf_object_if_exist:nF { @@_icc_ #1 }
+      {
+        \pdf_object_new:nn { @@_icc_ #1 } { fstream }
+        \pdf_object_write:nn { @@_icc_ #1 }
+          {
+            { /N ~ #2 }
+            {#1}
+          }
+      }
+    \pdf_object_unnamed_write:nx { array }
+      { /ICCBased~ \pdf_object_ref:n { @@_icc_ #1 } }
+    \cs_if_exist:NT \pdfmanagement_add:nnn
+      {
+        \pdfmanagement_add:nnx { Page / Resources / ColorSpace }
+          {#3} { ~ \pdf_object_ref_last: }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+
 %
 %    \begin{macrocode}
 %</dvipdfmx|luatex|pdftex|xetex>
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index c1daa97b1..57c31221d 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Added
+- Support for ICC-based color profiles
+
 ## [2021-10-17]
 
 ### Changed
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index 176594a3f..d52f18518 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -393,6 +393,7 @@
 %   The latter should be one of
 %   \begin{itemize}
 %     \item \texttt{DeviceN}
+%     \item \texttt{ICCBased}
 %     \item \texttt{Separation}
 %   \end{itemize}
 %   (The \meta{family} may be given in mixed case as-in the PDF reference:
@@ -436,6 +437,13 @@
 %   a process color name (\texttt{cyan}, etc.) or the special name \texttt{none}.
 % \end{itemize}
 %
+% For a \texttt{ICCBased} space, there are two \emph{compulsory} key.
+% \begin{itemize}
+%   \item \texttt{file} The name of the file containing the profile.
+%   \item \texttt{components} The number of components the profile requires:
+%     must be one of $1$, $3$ or $4$.
+% \end{itemize}
+%
 % \end{documentation}
 %
 % \begin{implementation}
@@ -2513,6 +2521,69 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\@@_model_iccbased:n}
+% \begin{macro}{\@@_model_iccbased:nn}
+% \begin{macro}{\@@_model_iccbased:nnn, \@@_model_iccbased_aux:nnn}
+%   For an ICC profile, we need a file name and a number of components. The
+%   file name is processed here so the backend can treat it as a string.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_model_iccbased:n #1
+  {
+    \prop_get:NnNTF \l_@@_internal_prop { file }
+      \l_@@_internal_tl
+      {
+        \exp_args:NV \@@_model_iccbased:nn
+          \l_@@_internal_tl {#1}
+      }
+      {
+        \msg_error:nnn { color }
+          { ICCBased-requires-file } {#1}
+      }
+  }
+\cs_new_protected:Npn \@@_model_iccbased:nn #1#2
+  {
+    \prop_get:NnNTF \l_@@_internal_prop { components }
+      \l_@@_internal_tl
+      {
+        \exp_args:NV \@@_model_iccbased:nnn
+          \l_@@_internal_tl {#2} {#1}
+      }
+      {
+        \msg_error:nnn { color }
+          { ICCBased-requires-components } {#2}
+      }
+  }
+\cs_new_protected:Npn \@@_model_iccbased:nnn #1#2#3
+  {
+    \bool_lazy_any:nTF
+      {
+        { \int_compare_p:nNn {#1} = 1 }
+        { \int_compare_p:nNn {#1} = 3 }
+        { \int_compare_p:nNn {#1} = 4 }
+      }
+      { \@@_model_iccbased_aux:nnn {#1} {#2} {#3} }
+      {
+        \msg_error:nnn { color }
+          { ICCBased-component-number } {#2}
+      }
+  }
+%    \end{macrocode}
+%   Here, we can use the same internals as for DeviceN approach as we know the
+%   number of components. No conversion is possible, so there is no need
+%   to worry about that at all.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_model_iccbased_aux:nnn #1#2#3
+  {
+    \@@_model_init:nnn {#2} {#1} { iccbased }
+    \use:c { @@_model_devicen_parse_ #1 :nn } {#2} {#1}
+    \exp_args:Nx \@@_backend_devicen_init:nnn
+      { \file_full_name:n {#3} } {#1} {#2}
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Diagnostics}
 %
 % \begin{macro}{\color_show:n, \color_log:n, \@@_show:Nn}
@@ -2589,6 +2660,30 @@
     \\ \\
     key~was~given~with~the~correct~information.
   }
+\msg_new:nnnn { color } { ICCBased-component-number }
+  { Too~many~components~for~ICCBased~color~space~'#1'. }
+  {
+    LaTeX~has~been~asked~to~create~an~ICCBased~color~space~with~#1~components,~
+    but~only~1,~3~or~4~components~are~allowed.
+  }
+\msg_new:nnnn { color } { ICCBased-requires-components }
+  { ICCBased~color~space~'#1'~require~a~number~of~components. }
+  {
+    LaTeX~has~been~asked~to~create~an~ICCBased~color~space,~but~no~\\ \\
+    \iow_indent:n { compontents~=~<number> }
+    \\ \\
+    key~was~given~with~the~correct~information.~LaTeX~will~use~ignore~this~
+    request.
+  }
+\msg_new:nnnn { color } { ICCBased-requires-file }
+  { ICCBased~color~space~'#1'~require~an~file. }
+  {
+    LaTeX~has~been~asked~to~create~an~ICCBased~color~space,~but~no~\\ \\
+    \iow_indent:n { file~=~<name> }
+    \\ \\
+    key~was~given~with~the~correct~information.~LaTeX~will~use~ignore~this~
+    request.
+  }
 \msg_new:nnnn { color } { model-already-defined }
   { Color~model~'#1'~already~defined. }
   {





More information about the latex3-commits mailing list.