[latex3-commits] [git/LaTeX3-latex3-latex3] main: Support ICC profiles for device colour spaces (c1814d5b7)

GitHub noreply at github.com
Mon Oct 18 14:42:04 CEST 2021


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

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

commit c1814d5b7236277d0be0d3af2bfaf741ad52860b
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Mon Oct 18 13:42:04 2021 +0100

    Support ICC profiles for device colour spaces


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

c1814d5b7236277d0be0d3af2bfaf741ad52860b
 l3backend/l3backend-color.dtx           | 59 ++++++++++++++++++++++++++--
 l3kernel/CHANGELOG.md                   |  1 +
 l3kernel/l3color.dtx                    | 68 +++++++++++++++++++++++++++++++++
 l3kernel/testfiles/m3expl001.luatex.tlg |  1 +
 l3kernel/testfiles/m3expl001.tlg        |  1 +
 l3kernel/testfiles/m3expl001.xetex.tlg  |  1 +
 l3kernel/testfiles/m3expl003.luatex.tlg |  1 +
 l3kernel/testfiles/m3expl003.tlg        |  1 +
 l3kernel/testfiles/m3expl003.xetex.tlg  |  1 +
 9 files changed, 131 insertions(+), 3 deletions(-)

diff --git a/l3backend/l3backend-color.dtx b/l3backend/l3backend-color.dtx
index 12f43895d..433a2f849 100644
--- a/l3backend/l3backend-color.dtx
+++ b/l3backend/l3backend-color.dtx
@@ -832,14 +832,12 @@
 % \begin{macro}
 %   {
 %     \@@_backend_select_separation:nn,
-%     \@@_backend_select_devicen:nn   ,
-%     \@@_backend_select_iccbased:nn
+%     \@@_backend_select_devicen:nn
 %   }
 %   No support at present.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_backend_select_separation: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}
 %
@@ -852,6 +850,30 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_backend_select_iccbased:nn}
+%   As detailed in \url{https://www.w3.org/TR/css-color-4/#at-profile},
+%   we can apply a color profile using CSS. As we have a local file, we use
+%   a relative URL.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_select_iccbased:nn #1#2
+  {
+    \__kernel_backend_literal_svg:x
+      {
+        <style>
+          @color-profile ~
+            \str_if_eq:nnTF {#2} { cmyk }
+              { device-cmyk }
+              { --color \int_use:N \g_@@_model_int }
+                \c_space_tl
+            {
+              src:("#1")
+            }
+        </style>
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 %    \begin{macrocode}
 %</dvisvgm>
 %    \end{macrocode}
@@ -1041,6 +1063,37 @@
 %    \end{macrocode}
 % \end{macro}
 
+%
+% \begin{macro}{\@@_backend_iccbased_device:nnn}
+%   This is very similar to setting up a color space: the only part we
+%   skip is adding it to the page resources.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_backend_iccbased_device: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 ~ #3 }
+            {#1}
+          }
+      }
+    \pdf_object_unnamed_write:nx { array }
+      { /ICCBased ~ \pdf_object_ref:n { @@_icc_ #1 } }
+    \cs_if_exist:NT \pdfmanagement_add:nnn
+      {
+        \use:x
+          {
+            \pdfmanagement_add:nnn
+              { Page / Resources / ColorSpace }
+              { Default #2 }
+              { \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 57c31221d..c0eb56e45 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -9,6 +9,7 @@ this project uses date-based 'snapshot' version identifiers.
 
 ### Added
 - Support for ICC-based color profiles
+- `\color_iccprofile_apply:nn`
 
 ## [2021-10-17]
 
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index 92dc61eca..6c8f93197 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -442,6 +442,23 @@
 %   \item \texttt{file} The name of the file containing the profile.
 % \end{itemize}
 %
+% \subsection{Color profiles}
+%
+% Color profiles are used to ensure color accuracy by linking to collaboration.
+% Applying a profile can be used to standardise color which is otherwise
+% device-dependence.
+%
+% \begin{function}[added = 2021-02-23]{\color_profile_apply:nn}
+%   \begin{syntax}
+%     \cs{color_profile_apply:nn} \Arg{profile} \Arg{model}
+%   \end{syntax}
+%   This function applies a \meta{profile} to one of the device \meta{models}.
+%   The profile will then apply to all color of the selected \meta{model}. The
+%   \meta{profile} should specify an ICC profile file. The \meta{model} has to
+%   be one the standard device models: \texttt{cmyk}, \texttt{gray} or
+%   \texttt{rgb}.
+% \end{function}
+%
 % \end{documentation}
 %
 % \begin{implementation}
@@ -2596,6 +2613,51 @@
 % \end{macro}
 % \end{macro}
 %
+% \subsection{Applying profiles}
+%
+% \begin{macro}{\color_profile_apply:nn, \@@_profile_apply:nn}
+% \begin{macro}
+%   {
+%     \@@_profile_apply_gray:n ,
+%     \@@_profile_apply_rgb:n  ,
+%     \@@_profile_apply_cmyk:n
+%   }
+%   With a limited range of outcomes, this is largely about getting data to the
+%   backend.
+%    \begin{macrocode}
+\cs_new_protected:Npn \color_profile_apply:nn #1#2
+  {
+    \exp_args:Ne \@@_profile_apply:nn
+      { \file_full_name:n {#1} } {#2}
+  }
+\cs_new_protected:Npn \@@_profile_apply:nn #1#2
+  {
+    \cs_if_exist_use:cF { @@_profile_apply_ \tl_to_str:n {#2} :n }
+      {
+        \msg_error:nnn { color } { ICC-Device-unknown } {#2}
+        \use_none:n
+      }
+        {#1}
+  }
+\cs_new_protected:Npn \@@_profile_apply_gray:n #1
+  {
+    \int_gincr:N \g_@@_model_int
+    \@@_backend_iccbased_device:nnn {#1} { Gray } { 1 }
+  }
+\cs_new_protected:Npn \@@_profile_apply_rgb:n #1
+  {
+    \int_gincr:N \g_@@_model_int
+    \@@_backend_iccbased_device:nnn {#1} { RGB } { 3 }
+  }
+\cs_new_protected:Npn \@@_profile_apply_cmyk:n #1
+  {
+    \int_gincr:N \g_@@_model_int
+    \@@_backend_iccbased_device:nnn {#1} { CMYK } { 4 }
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Diagnostics}
 %
 % \begin{macro}{\color_show:n, \color_log:n, \@@_show:Nn}
@@ -2672,6 +2734,12 @@
     \\ \\
     key~was~given~with~the~correct~information.
   }
+\msg_new:nnnn { color } { ICC-Device-unknown }
+  { Unknown~device~color~space~'#1'. }
+  {
+    LaTeX~has~been~asked~to~apply~an~ICC~profile~but~the~device~color~space~
+    '#1'~is~unknown.
+  }
 \msg_new:nnnn { color } { ICCBased-unsupported-colorspace }
   { ICCBased~color~space~'#1'~uses~an~unsupported~data~color~space. }
   {
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 212f4c0cb..78e3ebcb1 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -54,6 +54,7 @@ Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_devicen_init:nnn on line ...
 Defining \__color_backend_devicen_init:w on line ...
 Defining \__color_backend_iccbased_init:nnn on line ...
+Defining \__color_backend_iccbased_device:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
 Defining \__color_backend_fill_rgb:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 1bb3202d0..630d88a33 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -54,6 +54,7 @@ Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_devicen_init:nnn on line ...
 Defining \__color_backend_devicen_init:w on line ...
 Defining \__color_backend_iccbased_init:nnn on line ...
+Defining \__color_backend_iccbased_device:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
 Defining \__color_backend_fill_rgb:n on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index b5219d427..4aafbe695 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -59,6 +59,7 @@ Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_devicen_init:nnn on line ...
 Defining \__color_backend_devicen_init:w on line ...
 Defining \__color_backend_iccbased_init:nnn on line ...
+Defining \__color_backend_iccbased_device:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
 Defining \__color_backend_fill_rgb:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 212f4c0cb..78e3ebcb1 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -54,6 +54,7 @@ Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_devicen_init:nnn on line ...
 Defining \__color_backend_devicen_init:w on line ...
 Defining \__color_backend_iccbased_init:nnn on line ...
+Defining \__color_backend_iccbased_device:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
 Defining \__color_backend_fill_rgb:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 1bb3202d0..630d88a33 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -54,6 +54,7 @@ Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_devicen_init:nnn on line ...
 Defining \__color_backend_devicen_init:w on line ...
 Defining \__color_backend_iccbased_init:nnn on line ...
+Defining \__color_backend_iccbased_device:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
 Defining \__color_backend_fill_rgb:n on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index b5219d427..4aafbe695 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -59,6 +59,7 @@ Defining \__color_backend_separation_init_CIELAB:nnn on line ...
 Defining \__color_backend_devicen_init:nnn on line ...
 Defining \__color_backend_devicen_init:w on line ...
 Defining \__color_backend_iccbased_init:nnn on line ...
+Defining \__color_backend_iccbased_device:nnn on line ...
 Defining \__color_backend_fill_cmyk:n on line ...
 Defining \__color_backend_fill_gray:n on line ...
 Defining \__color_backend_fill_rgb:n on line ...





More information about the latex3-commits mailing list.