diff options
author | Karl Berry <karl@freefriends.org> | 2015-06-16 21:22:12 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-06-16 21:22:12 +0000 |
commit | 5ab17f932f63c1c6cded36de80cf157042a05d5d (patch) | |
tree | 95245ad0e9e3c7113caa84ecb9544a1016829d2a /Master/texmf-dist | |
parent | 1533fd06f8be031b9db6baf261cd9931923ae063 (diff) |
colorspace (1jun15)
git-svn-id: svn://tug.org/texlive/trunk@37573 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/colorspace/README | 22 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/colorspace/colorspace.pdf | bin | 96854 -> 104967 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/colorspace/colorspace.tex | 122 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/colorspace/colorspace.sty | 379 |
4 files changed, 440 insertions, 83 deletions
diff --git a/Master/texmf-dist/doc/latex/colorspace/README b/Master/texmf-dist/doc/latex/colorspace/README index f5c998bc9f0..8f6fbab7dce 100644 --- a/Master/texmf-dist/doc/latex/colorspace/README +++ b/Master/texmf-dist/doc/latex/colorspace/README @@ -1,25 +1,23 @@ colorspace ----------- -PDF color spaces. Currently, only spot colors and overprinting are -supported (requires xcolor; only pdftex and luatex). To define a spot -color, just say: +PDF color spaces. Currently, it supports: -\definespotcolor{foo}{BarTone 555 GN}{.3, .4, .5, .6} +* spot colors +* mixing inks (spot and process), up to 4 +* ICC based default CMYK, RGB and Gray spaces +* overprinting -That's all. You can use tints as usual in xcolor, like: +It requires xcolor and currently only pdftex and luatex. -\color{foo!60} -\colorlet{foo60}{foo!60} +For example, to define a spot color, just say: -and even set tints from other tints. It seems to work with tikz. +\definespotcolor{foo}{BarTone 555 GN}{.3, .4, .5, .6} -Mixing spot colors (with process colors or other spots colors) and -other functions related to the PDF color spaces (like indexed colors) -are not yet suported, but they are under study. +That's all. Those docs, like the package itself, are still somewhat tentative, but the basic behaviour described here will be preserved in future versions. -2015-05-11
\ No newline at end of file +2015-06-01
\ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/colorspace/colorspace.pdf b/Master/texmf-dist/doc/latex/colorspace/colorspace.pdf Binary files differindex 7ea9c65501a..52984c76f63 100644 --- a/Master/texmf-dist/doc/latex/colorspace/colorspace.pdf +++ b/Master/texmf-dist/doc/latex/colorspace/colorspace.pdf diff --git a/Master/texmf-dist/doc/latex/colorspace/colorspace.tex b/Master/texmf-dist/doc/latex/colorspace/colorspace.tex index 86cc87e25ce..eae643f99a8 100644 --- a/Master/texmf-dist/doc/latex/colorspace/colorspace.tex +++ b/Master/texmf-dist/doc/latex/colorspace/colorspace.tex @@ -21,34 +21,39 @@ %% This work consists of the files colorspace.tex and colorspace.sty. \documentclass{article} -\title{\textsf{colorspace}\\\large Version 1.0.0} +\title{\textsf{colorspace}\\\large Version 1.1.0} \author{Javier Bezos\\\texttt{http://www.tex-tipografia.com}} \raggedright \parskip=1ex -\date{2015-05-11} +\date{2015-06-01} \begin{document} \maketitle -This package is essentially a reworking of the previous attempts to -provide spot colors and other additional features by Jens Elstner, -Stephan Lehmke and Siep Kroonenberg (with some inspiration from -\textsf{ConTeXt}, too). It requires \textsf{xcolor}, which is loaded -if it has not been before. +This package is built on the previous attempts to provide spot colors +and other additional features by Jens Elstner, Stephan Lehmke and Siep +Kroonenberg (with some inspiration from \textsf{ConTeXt}, too). It +requires \textsf{xcolor}, which is loaded if it has not been before. -It provides a clean user interface, with a single command for -defining a spot color. It seems to work with \textsf{tikz}. Currently -only \textsf{pdftex} and \textsf{luatex} are supported. Mixing spot -colors (with process colors or other spots colors) and other functions -related to the PDF color spaces (like indexed colors) are not yet -suported, but they are\texttt{} under study. +It provides a clean user interface, with a single command for defining +a spot color. It seems to work with \textsf{tikz}. Currently only +\textsf{pdftex} and \textsf{luatex} are supported. -Those docs, like the package itself, are still somewhat tentative, but -the basic behaviour described here will be preserved in future versions. +Mixing spot colors (with process colors or other spots colors) is +supported to some extent (see below). You can also assign ICC profiles +to the default CMYK, RGB and Gray spaces. Other functions related to +the PDF color spaces (indexed, calibrated, Lab spaces) are not yet +suported, but they are\texttt{} under study. They apply to text and +line art only, not external images. Declarations are global. Using +\verb|\selectcolormodel| does not work yet. + +Those docs, like the package itself, are still somewhat tentative (as +you very likely have noticed), but the basic behaviour described here +will be preserved in future versions. For transparencies, see \textsf{transparent}, by Heiko Oberdiek. @@ -71,9 +76,7 @@ You can use tints as usual in \textsf{xcolor}, like: \color{foo!60} \colorlet{foo60}{foo!60} \end{verbatim} -and even set tints from other tints, but this is the only operation -currently supported. Something like \verb|spot!10!black| (mixing inks) -does not work. +and even set tints from other tints. To mix inks, see below. The special PDF names \verb|All| (for all plates) and \verb|None| work as expected: @@ -94,6 +97,89 @@ set something like: \end{verbatim} (It can be empty.) To return to the default color space, which contains all the defined spot colors, use \verb|\resetpagecolorspace|. +Use this macro with care, because of the asynchronous nature of \TeX{} +-- remember it affects the whole current page. + +\section{Mixing spot colors} + +To mix spot colors you must first declare a color space (or model) +including them. This is done with something like: +\begin{verbatim} +\definecolorspace{name}{mixed}{color1,color2,color3} +\end{verbatim} +(The second argument is the type of color space.) For example, if we +have two spot colors named \verb|spot1| and \verb|spot2|, and we want +in addition yellow: +\begin{verbatim} +\definecolorspace{spot12y}{mixed}{spot1,spot2,yellow} +\end{verbatim} +A typical usage, for shades, would be: +\begin{verbatim} +\definecolorspace{shaded1}{mixed}{spot1,black} +\end{verbatim} + +Due to internal limitations of \textsf{xcolor}, no more than four +colors are allowed. The alternate color space in the PDF file is that +of the spot colors (which means currently it is CMYK). + +Then, you can define a color with: +\begin{verbatim} +\definecolor{mix12y}{spot12y}{.5,.4,.6} +\definecolor{sh1}{shaded1}{.6,.3} +\end{verbatim} +or set it with +\begin{verbatim} +\color[spot12y]{.5,.4,.3} +\color[shaded1]{.6,.3} +\end{verbatim} +As in spot colors, the only operation allowed is \verb|!| for tints +(ie, \verb|color!num|). But there is an easy trick to mix colors with +\verb|!| and \verb|color,num| -- just define an ortogonal set of +colors based on the new color model: +\begin{verbatim} +\definecolor{xspot1}{spot12y}{1,0,0} +\definecolor{xspot2}{spot12y}{0,1,0} +\definecolor{xyellow}{spot12y}{0,0,1} +\end{verbatim} +and then you can say: +\begin{verbatim} +\color{xspot1!30!xspot2!40!xyellow} +\color{spot12y:xspot1,3;xspot2,2;xyellow,1} +\end{verbatim} +Of course, it is just a trick and a better and direct interface is +under study. + +Color series are also partially supported. For example: +\begin{verbatim} +\definecolorseries{test}{spot12y}{grad}[spot12y]{.95,.85,.55}{3,11,17} +\definecolorseries{test}{spot12y}{last}{xyellow!50}{xspotA} +\end{verbatim} + +(The key is not to mix the new model with other color models.) + +\section{ICC Based spaces} + +The starred version \verb|\definecolorspace*| does not define a new +color model, but sets the behaviour of the three basic color spaces +(\verb|cmyk|, \verb|rgb| and \verb|gray|). When belonging to the same +space, the last one for that space takes precedence. It cannot be used +to define new colors or set them. Currently, only a type is supported -- +\verb|iccbased|. For example, +\begin{verbatim} +\definecolorspace*{sRGB}{iccbased}{sRGB Profile.icc} +\end{verbatim} + +The space it applies to is read from the ICC profile. The name can be +used in \verb|\pagecolorspace| (and must, if you want it to be +active). Alternatively, there are 3 reserved names: \verb|*rgb|, +\verb|*gray|, \verb|*cmyk|, which stand for the current default +spaces. The former are not set by \verb|\resetpagecolorspace|, but the +starred named are. + +Note those ICC spaces does not go to the output intent dictionary (see +the \textsf{pdfx} package). The latter, as the PDF reference explains, +supplements rather than replaces the ICC profiles in a default color +space. \section{Overprinting} diff --git a/Master/texmf-dist/tex/latex/colorspace/colorspace.sty b/Master/texmf-dist/tex/latex/colorspace/colorspace.sty index c8180fc89bc..97d7b64c5be 100644 --- a/Master/texmf-dist/tex/latex/colorspace/colorspace.sty +++ b/Master/texmf-dist/tex/latex/colorspace/colorspace.sty @@ -21,7 +21,7 @@ %% This work consists of the files colorspace.tex and colorspace.sty. \ProvidesPackage{colorspace} - [2015/05/11 v1.0.0 PDF color spaces (spot colors...) for pdfTeX] + [2015/06/01 v1.1.0 PDF color spaces (spot colors...) for pdfTeX] \edef\spc@savedcatcodes{% \catcode`\noexpand\/=\the\catcode`\/ @@ -31,7 +31,7 @@ \catcode`\/=12 \catcode`\>=12 \catcode`\<=12 -\catcode`\&=12 +\catcode`\&=11 % we use it in macro names \def\spc@unknown#1#2{% \@ifundefined{#1}% @@ -42,34 +42,43 @@ \@ifundefined{XC@sdef}{\RequirePackage{xcolor}}{} \long\def\spc@afterfi#1\fi{\fi#1} - -% Define the color model spot. We need define the following 3 macros: - -\XC@sdef\XC@mod@spot{spot} -\def\color@spot#1#2{% +% Trim spaces in strings and normalize to single spaces +\def\spc@spaces#1 #2{% + #1\ifx\@empty#2\else\spc@afterfi\spc@spaces@i{#1}#2\fi} +\def\spc@spaces@i#1{% + \ifx\\#1\\\else\space\fi\spc@spaces} +\def\spc@dospaces#1{% + \edef#1{#1\space}% + \edef#1{\expandafter\spc@spaces#1\@empty}} + +% Define a pseudo-model for spot colors. We need define the following +% 3 macros: + +\XC@sdef\XC@mod@&spot{&spot} +\def\color@&spot#1#2{% \c@lor@arg{#2}% \edef#1{\spc@ir\space cs \spc@ir\space CS #2 sc #2 SC}} -\def\XC@clr@spot@white{0} +\def\XC@clr@&spot@white{0} % A somewhat dirty hack for converting cmyk to spot. The internal -% format is {}{/&Color cs /&Color CS n sc n SC}{spot}{n}, where n=1 -% is a tint of 100%. +% format is {}{/&Color cs /&Color CS n sc n SC}{spot}{n}, where n=1 is +% a tint of 100%. The original CMYK values are stored in +% \spc@ascmyk@<name>. \def\spc@cmyktospot#1#2{% \begingroup \def\spc@tempc##1 ##2 ##3 ##4 k##5\@@{##1 ##2 ##3 ##4}% \def\xcolor@##1##2##3##4{% - \protected@xdef#1{% - \noexpand\xcolor@{##1}{/ cs / CS 1 sc 1 SC}{spot}{1}}% - \xdef\spc@tempa{\spc@tempc##2\@@}}% - #1% + \expandafter\protected@xdef\csname\string\color@#1\endcsname{% + \noexpand\xcolor@{##1}{/ cs / CS 1 sc 1 SC}{&spot}{1}}% + \xdef\spc@tempa{\spc@tempc##2\@@}% + \expandafter\xdef\csname spc@ascmyk@#1\endcsname{##4}}% + \csname\string\color@#1\endcsname \endgroup} % The internal PDF name (which is like the public one with a & % prepended) is available in the first argument of \xcolor@. The -% following macros extract it. The original CMYK values are -% discarded once written to the PDF, but perhaps they should be -% stored, just in case. +% following macros extract it. \def\spc@getir#1{% \begingroup @@ -81,24 +90,26 @@ % We need to redefine an xcolor macro for the tint operator ! to be % recognized. It's done in a more modular way than xcolor: -\def\spc@infl@cmyk#1{#1} % 4 values = 4 - 4 commas -\def\spc@infl@spot#1{,,,#1,,,} % 1 value = 4 - 1 commas -\def\spc@infl@gray#1{,,,#1,,,} % 1 value +\def\spc@infl@cmyk{\let\spc@inflcommas\@empty}% 4 values=4-4 commas +\def\spc@infl@gray{\def\spc@inflcommas{,,,}}% 1 value=4-1 commas +\def\spc@infl@&spot{% + \spc@getir{\string\color@\@@nam}% + \def\spc@inflcommas{,,,}}% \def\XC@inflate#1#2#3#4{% - \spc@getir{\expandafter\string\csname color@\@@nam\endcsname}% - \edef#4{#2,% - \@ifundefined{spc@infl@\@@mod}% - {,#3,}% Assume 3 values = 4 - 3 commas - {\@nameuse{spc@infl@\@@mod}{#3}}}} + \def\spc@inflcommas{,}% Assume 3 values=4-3 commas + \@nameuse{spc@infl@\@@mod}% + \edef#4{#2,\spc@inflcommas#3\spc@inflcommas}} -% The following macro stores all spot colors, with the LaTeX name +% The following macro stores all spot colors, with the LaTeX name. It +% also stores other color spaces. Internally is an \spc@elt list. \let\spc@csall\@empty -% Now the main command for defining colors: +% Now the main command for defining spot colors. \spc@ir@<latex-name> +% contains {/&Spot X 0 R} -\newcommand\definespotcolor[2]{\def\spc@tempa{{#1}{#2}}\spc@defsc} +\newcommand\definespotcolor[2]{\protected@edef\spc@tempa{{#1}{#2}}\spc@defsc} \newcommand\spc@defsc[2][cmyk]{\expandafter\spc@defsc@i\spc@tempa{#1}{#2}} \def\spc@defsc@i#1#2#3#4{% \def\spc@tempc##1 ##2{% Converts spaces to #20 @@ -108,26 +119,26 @@ \spc@afterfi\spc@tempc##2% \fi}% \edef\spc@tempb{\spc@tempc#2 \@empty}% Apply to convert - \@for\spc@tempa:=\spc@csall\do{% - \@expandtwoargs\in@{/&\spc@tempb\space}{\@nameuse{spc@ir@\spc@tempa}}% + \def\spc@elt##1##2{% + \@expandtwoargs\in@{/&\spc@tempb\space}{\@nameuse{spc@ir@##2}}% \ifin@ \PackageError{colorspace}{Duplicated spot name `#2'}% - {This spot name was taken by `\spc@tempa'.}% - \fi}% + {This spot name was taken by `##2'.}% + \fi} + \spc@csall \definecolor{#1}{cmyk:#3}{#4}% internally always cmyk - \expandafter\spc@cmyktospot % Convert from cmyk to spot - \csname\string\color@#1\endcsname - \spc@tempb + \expandafter\spc@cmyktospot{#1}\spc@tempb % Convert from cmyk to spot \immediate\pdfobj{[ /Separation /\spc@tempb\space /DeviceCMYK << /FunctionType 2 /Domain [0 1] /C0 [0 0 0 0] /C1 [\spc@tempa] /N 1 >> ]}% pdf separation \expandafter\xdef\csname spc@ir@#1\endcsname{% /&\spc@tempb\space\the\pdflastobj\space 0 R}% save ref to obj - \xdef\spc@csall{\ifx\spc@csall\@empty\else\spc@csall,\fi#1}} + \let\spc@elt\relax + \xdef\spc@csall{\spc@csall\spc@elt2{#1}}} \AtBeginDocument{% - \ifx\spc@csall\@empty\else % ie, if spot colors - \pagecolorspace{\spc@csall}% + \ifx\spc@csall\@empty\else % ie, if spot/iccbased colors + \resetpagecolorspace \fi} % Page color spaces. The arrays mapping the spot colors to the obj @@ -144,26 +155,34 @@ \let\spc@cs@\@empty \newcommand\pagecolorspace[1]{% + \protected@edef\spc@tempa{{#1}}% + \expandafter\spc@pagecs\spc@tempa} + +\def\spc@pagecs#1{% \ifx\spc@currcs\@empty\else \edef\tempa{% \noexpand\spc@remcs\the\pdfpageresources \noexpand\spc@remcs{\spc@currcs}}% \tempa \fi - \let\spc@tempd\@empty + \let\spc@tempd\@empty % list with known spaces \@for\spc@tempa:=#1\do{% - \spc@unknown{spc@ir@\spc@tempa}{spot color `\spc@tempa'}% - \edef\spc@tempd{,\spc@tempd,\spc@tempa,}}% - \let\spc@tempb\@empty - \let\spc@tempc\@empty - \@for\spc@tempa:=\spc@csall\do{% - \@expandtwoargs\in@{,\spc@tempa,}{\spc@tempd}% + \ifx\spc@tempa\@empty\else + \spc@dospaces\spc@tempa + \spc@unknown{spc@ir@\spc@tempa}{color (space) `\spc@tempa'}% + \edef\spc@tempd{,\spc@tempd,\spc@tempa,}% + \fi}% + \let\spc@tempb\@empty % elements in /ColorSpace + \let\spc@tempc\@empty % name for macro (\..&..&) with pdf ref + \def\spc@elt##1##2{% + \@expandtwoargs\in@{,##2,}{\spc@tempd}% \ifin@ \protected@edef\spc@tempb{% - \spc@tempb\@nameuse{spc@ir@\spc@tempa}\space}% + \spc@tempb\@nameuse{spc@ir@##2}\space}% \protected@edef\spc@tempc{% - \spc@tempc\@nameuse{spc@ir@\spc@tempa}&}% + \spc@tempc\@nameuse{spc@ir@##2}&}% \fi}% + \spc@csall % Uses \spc@elt \@ifundefined{spc@cs@\spc@tempc}% {\immediate\pdfobj{<< \spc@tempb>>}% \expandafter\xdef\csname spc@cs@\spc@tempc\endcsname{\the\pdflastobj}}% @@ -175,7 +194,10 @@ \spc@tempa \fi} -\newcommand\resetpagecolorspace{\pagecolorspace{\spc@csall}} +\newcommand\resetpagecolorspace{% + \def\spc@elt##1##2{\ifnum##1>1 ##2,\fi}% + \edef\spc@tempa{{\spc@csall}}% + \expandafter\pagecolorspace\spc@tempa} \def\spc@remcs#1\spc@remcs#2{% \def\spc@tempc##1 /ColorSpace #2 ##2 R##3\spc@tempc{% @@ -184,17 +206,268 @@ % Support for pgf (I hope--) -\def\pgfsys@color@spot@stroke#1{% +\def\pgfsys@color@&spot@stroke#1{% \spc@getir{\string\color@pgfstrokecolor}% \pgfsysprotocol@literal{\spc@ir\space CS}% \pgfsysprotocol@literal{#1 SC}} -\def\pgfsys@color@spot@fill#1{% +\def\pgfsys@color@&spot@fill#1{% \spc@getir{\string\color@pgffillcolor}% \pgfsysprotocol@literal{\spc@ir\space cs}% \pgfsysprotocol@literal{#1 sc}} -\def\pgfsys@color@spot#1{% - \pgfsys@color@spot@stroke{#1}% - \pgfsys@color@spot@fill{#1}} +\def\pgfsys@color@&spot#1{% + \pgfsys@color@&spot@stroke{#1}% + \pgfsys@color@&spot@fill{#1}} + +% ==== Mixed colors ==== + +% xspace assumes color models have 1, 3 or 4 components. We need +% modify a couple of macros, but we'll do it only if a 2-component +% space is defined: + +\def\spc@twocomps{% + \let\spc@twocomps\relax + \gdef\XC@vec##1,##2,##3,##4,##5,##6,##7,##8,##9{% + \def\@@tmp{}% + \XC@vec@{##1}{##5}% + \ifx,##2,\else\XC@vec@{##2}{##6}% + \ifx,##3,\else\XC@vec@{##3}{##7}% + \ifx,##4,\else\XC@vec@{##4}{##8}% + \fi\fi\fi + \aftergroupdef##9\@@tmp}% + \gdef\XC@calc@##1,##2,##3,##4,##5:##6{% + \XC@let@Nc\@@cmd{XC@calc##6}% + \@@cmd{##1}\@@tmp + \ifx,##2,% + \else\@@cmd{##2}\@tempa + \ifx,##3,\edef\@@tmp{\@@tmp,\@tempa}% + \else\@@cmd{##3}\@tempb + \ifx,##4,\edef\@@tmp{\@@tmp,\@tempa,\@tempb}% + \else\@@cmd{##4}\@tempc\edef\@@tmp{\@@tmp,\@tempa,\@tempb,\@tempc}% + \fi\fi\fi}} + +% The following macros define models with 1 to 4 components. It's +% written with the "copypaste" pattern, so it should be +% improved. Here, the limitations of xcolor become aparent, because +% 5 components would require "-1" commas. + +\def\spc@mix@i#1#2{% + \expandafter\XC@sdef\csname XC@mod@#1\endcsname{#1}% + \@namedef{color@#1}##1##2{\@nameuse{c@lor@@#1}##2\@@##1}% + \@namedef{c@lor@@#1}##1\@@##2{% + \c@lor@arg{##1}% + \edef##2{#2 cs #2 CS ##1 scn ##1 SCN}}% + \@namedef{XC@clr@#1@white}{0}% + \@namedef{spc@infl@#1}{\def\spc@inflcommas{,,,}}} % 1 value = 4 - 1 commas + +\def\spc@mix@ii#1#2{% + \expandafter\XC@sdef\csname XC@mod@#1\endcsname{#1}% + \@namedef{color@#1}##1##2{\@nameuse{c@lor@@#1}##2\@@##1}% + \@namedef{c@lor@@#1}##1,##2\@@##3{% + \c@lor@arg{##1}% + \c@lor@arg{##2}% + \edef##3{#2 cs #2 CS ##1 ##2 scn ##1 ##2 SCN}}% + \@namedef{XC@clr@#1@white}{0,0}% + \@namedef{spc@infl@#1}{\def\spc@inflcommas{,,}}} % 2 values = 4 - 2 commas + +\def\spc@mix@iii#1#2{% + \expandafter\XC@sdef\csname XC@mod@#1\endcsname{#1}% + \@namedef{color@#1}##1##2{\@nameuse{c@lor@@#1}##2\@@##1}% + \@namedef{c@lor@@#1}##1,##2,##3\@@##4{% + \c@lor@arg{##1}% + \c@lor@arg{##2}% + \c@lor@arg{##3}% + \edef##4{#2 cs #2 CS ##1 ##2 ##3 scn ##1 ##2 ##3 SCN}}% + \@namedef{XC@clr@#1@white}{0,0,0}% + \@namedef{spc@infl@#1}{\def\spc@inflcommas{,}}} % 3 values = 4 - 1 commas + +\def\spc@mix@iv#1#2{% + \expandafter\XC@sdef\csname XC@mod@#1\endcsname{#1}% + \@namedef{color@#1}##1##2{\@nameuse{c@lor@@#1}##2\@@##1}% + \@namedef{c@lor@@#1}##1,##2,##3,##4\@@##5{% + \c@lor@arg{##1}% + \c@lor@arg{##2}% + \c@lor@arg{##3}% + \c@lor@arg{##4}% + \edef##5{#2 cs #2 CS ##1 ##2 ##3 ##4 scn ##1 ##2 ##3 ##4 SCN}}% + \@namedef{XC@clr@#1@white}{0,0,0,0}% + \@namedef{spc@infl@#1}{\let\spc@inflcommas\@empty}} % 4 value = 4 - + % 0 commas + +% A few auxliary macros: + +\def\spc@nl{^^J} + +\def\spc@getirbase/ #2\@@{#1} +\def\spc@getirbaseC/ #2\@@{#1 #2} + +\def\spc@writecomp#1#2{% + \advance\@tempcntb\@ne + \edef#1{#1 + \the\numexpr\@tempcntb-\@tempcnta\relax\space + index -#2\space mul 1.0 add mul\spc@nl}} + +\def\spc@writecmykcomps#1,#2,#3,#4\@@{% + \spc@writecomp\spc@@cyan{#1}% + \spc@writecomp\spc@@magenta{#2}% + \spc@writecomp\spc@@yellow{#3}% + \spc@writecomp\spc@@black{#4}} + +% And the main macro: + +\newif\ifspc@dflt + +\newcommand\definecolorspace{% + \@ifstar + {\spc@dflttrue\spc@defcs}% + {\spc@dfltfalse\spc@defcs}} + +\def\spc@defcs#1#2#3{% + \@ifundefined{spc@defcs@#2}% + {\spc@unknown{spc@defcs@#2}{color space type `#2'}}% + {\protected@edef\spc@tempa{% + \expandafter\noexpand\csname spc@defcs@#2\endcsname + {#1}{#3}}% + \spc@tempa}} + +\def\spc@defcs@mixed#1#2{% + \ifspc@dflt + \PackageError{colorspace}{Unsupported}% + {`mixed' only works with the unstarred command}% + \fi + \begingroup + % the process part of the tint transform: + \def\spc@@Pcyan{1.0\spc@nl}\def\spc@@Pmagenta{1.0\spc@nl}% + \def\spc@@Pyellow{1.0\spc@nl}\def\spc@@Pblack{1.0\spc@nl}% + % the spot part: + \let\spc@@cyan\@empty\let\spc@@magenta\@empty + \let\spc@@yellow\@empty\let\spc@@black\@empty + % position on stack + \edef\spc@@poscyan{0}\edef\spc@@posmagenta{1}% + \edef\spc@@posyellow{2}\edef\spc@@posblack{3}% + \@tempcntb\z@ % Number of colors + \let\spc@pdfdoms\@empty % stores /Domain + \let\spc@@pops\@empty + \@for\spc@tempa:=#2\do{% + \advance\@tempcntb\@ne % Count colors + \edef\spc@@pops{\spc@@pops\space pop}% + \edef\spc@pdfdoms{\spc@pdfdoms0 1 }}% + \ifcase\@tempcntb\or1\or\spc@twocomps\or\or\else + \PackageError{colorspace}{Too many inks}% + {Currently, only up to 4 components are supported}% + \fi + \@tempcnta\z@ % position on stack + \let\spc@pdfdevn\@empty % stores names for /DeviceN + \let\spc@pdfclrnts\@empty % stores /Colorants + \let\spc@name\@empty % stores name for page /ColorSpace + \def\spc@ir@cyan{Cyan}\def\spc@ir@magenta{Magenta}% + \def\spc@ir@yellow{Yellow}\def\spc@ir@black{Black}% + \@for\spc@tempa:=#2\do{% + \spc@dospaces\spc@tempa + \advance\@tempcnta\@ne + \edef\spc@ir{\csname spc@ir@\spc@tempa\endcsname}% + \@expandtwoargs\in@{,\spc@tempa,}{,cyan,magenta,yellow,black,}% + \ifin@ + \edef\spc@pdfdevn{\spc@pdfdevn\space/\spc@ir}% + \edef\spc@name{\spc@name &\spc@ir}% + \expandafter + \edef\csname spc@@P\spc@tempa\endcsname{% + \the\numexpr\@tempcntb+\@nameuse{spc@@pos\spc@tempa}% + -\@tempcnta\relax\space + index neg 1.0 add\spc@nl}% ========== + \else + \@ifundefined{spc@ascmyk@\spc@tempa}% + {\spc@unknown{spc@ascmyk@\spc@tempa}{spot color + `\spc@tempa'}}% + {}% + \edef\spc@pdfdevn{\spc@pdfdevn\space + /\expandafter\spc@getirbase\spc@ir\@@}% + \edef\spc@pdfclrnts{\spc@pdfclrnts\space + /\expandafter\spc@getirbaseC\spc@ir\@@}% + \edef\spc@name{\spc@name + &\expandafter\spc@getirbase\spc@ir\@@}% + \expandafter\expandafter\expandafter\spc@writecmykcomps + \csname spc@ascmyk@\spc@tempa\endcsname\@@ + \advance\@tempcntb-4\relax + \fi}% + \immediate\pdfobj stream attr + {/FunctionType 4 + /Domain [ \spc@pdfdoms] + /Range [ 0 1 0 1 0 1 0 1 ]}% + {\string{\space + \spc@@Pcyan\spc@@cyan neg 1.0 add\spc@nl + \spc@@Pmagenta\spc@@magenta neg 1.0 add\spc@nl + \spc@@Pyellow\spc@@yellow neg 1.0 add\spc@nl + \spc@@Pblack\spc@@black neg 1.0 add\spc@nl + \the\numexpr4+\@tempcntb\relax\space 4 roll\spc@@pops + \space\string}}% + \immediate\pdfobj{[ /DeviceN [\spc@pdfdevn\space] /DeviceCMYK + \the\pdflastobj\space0 R + << /Colorants <<\spc@pdfclrnts\space >> >> ]}% + \expandafter\xdef\csname spc@ir@#1\endcsname{% + /\spc@name\space\the\pdflastobj\space 0 R}% save ref to obj + \let\spc@elt\relax + \xdef\spc@csall{\spc@csall\spc@elt2{#1}}% + \xdef\spc@tempa{% + \expandafter\noexpand + \csname spc@mix@\romannumeral\@tempcntb\endcsname + {#1}{/\spc@name}}% + \endgroup + \spc@tempa} + +% === ICC based dafault spaces === + +% luatex removed pdffiledump, so we use lua code. + +\def\spc@defcs@iccbased#1#2{% + \ifspc@dflt\else + \PackageError{colorspace}{Unsupported}% + {`iccbased' only works with the starred command}% + \fi + \begingroup + % hex equivalents (which is the filedump format) and literal + % (which is the lua format) + \@namedef{spc@@47524159}{0}\@namedef{spc@@GRAY}{0}% + \@namedef{spc@@52474220}{1}\@namedef{spc@@RGB }{1}% + \@namedef{spc@@434D594B}{2}\@namedef{spc@@CMYK}{2}% + \def\spc@@space{\ifcase\spc@tempa Gray\or RGB\or CMYK\fi}% + \def\spc@@spacelc{\ifcase\spc@tempa gray\or rgb\or cmyk\fi}% + % read the icc file and extract the space it applies to + \ifx\pdffiledump\@undefined + \directlua{ + local icc = io.open([[#2]], "r") + if icc then + icc:seek("set", 16) + tex.print([[\noexpand\csname @namedef\endcsname{spc@tempa}{]] + .. icc:read(4) .. [[}]]) + end}% + \else + \edef\spc@tempa{\pdffiledump offset 16 length 4 {#2}}% + \fi + \@ifundefined{spc@@\spc@tempa}% + {\PackageError{colorspace}{Unsupported ICC space}% + {Currently, only Gray, RGB and CMYK are supported}}% + {\edef\spc@tempa{\@nameuse{spc@@\spc@tempa}}}% + \immediate\pdfobj + stream attr {\ifcase\spc@tempa + /N 1 /Alternate /DeviceGray\or + /N 3 /Alternate /DeviceRGB\or + /N 4 /Alternate /DeviceCMYK\fi}% + file {#2}% + \immediate\pdfobj{[ /ICCBased \the\pdflastobj\space 0 R ]}% + % to the default color list, add an intermediate name *<model> + % (only once) containing the last setting (add also the + % actual name with flag 1 instead of 2) + \let\spc@elt\relax + \@ifundefined{spc@ir@*\spc@@spacelc}% + {\xdef\spc@csall{\spc@csall\spc@elt2{*\spc@@spacelc}}}% + {} % -- do nothing + \expandafter\xdef\csname spc@ir@*\spc@@spacelc\endcsname{% + /Default\spc@@space\space\the\pdflastobj\space 0 R}% + \xdef\spc@csall{\spc@csall\spc@elt1{#1}}% + \expandafter\xdef\csname spc@ir@#1\endcsname{% + /Default\spc@@space\space\the\pdflastobj\space 0 R}% + \endgroup} + % ==== Overprint/Knokout ==== |