Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

l3color named color support and spotcolors in LuaLaTeX #494

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Change history
* Support variable fonts under LuaLaTeX.
* Skip scanning for filenames when loading fonts by name on LuaLaTeX.
* Allow restricting filename lookup to kpathsea lookups using `KpseOnly`.
* added support for named colors from l3color
* support with lualatex spotcolors and cmyk colors in the pdf.


## v2.8a (2022/01/15)
Expand Down
3 changes: 2 additions & 1 deletion fontspec-code-internal.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@

\str_if_eq:eeF { \l_@@_hexcol_tl \l_@@_opacity_tl }
{ \c_@@_hexcol_tl \c_@@_opacity_tl }
{ \@@_update_featstr:n { color = \l_@@_hexcol_tl\l_@@_opacity_tl } }
%<XE> { \@@_update_featstr:n { color = \l_@@_hexcol_tl\l_@@_opacity_tl } }
%<LU> { \@@_update_featstr:n { color = {\l_@@_hexcol_tl\l_@@_opacity_tl} } }
}
% \end{macrocode}
% \end{macro}
Expand Down
54 changes: 45 additions & 9 deletions fontspec-code-keyval.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -697,26 +697,61 @@
% \end{macrocode}
%
% \paragraph{Color}
% Hooks into pkg{xcolor}, which names its colours \texttt{\char`\\color@<name>}.
% Test first if the color is a named l3color, then if it is a color from
% \pkg{xcolor}, which names its colours \texttt{\char`\\color@<name>}.
% If this fails the argument is assumed to be a hex color.
%
% \begin{macrocode}
\@@_keys_define_code:nnn {fontspec} {Color}
{
\cs_if_exist:cTF { \token_to_str:N \color@ #1 }
%<*XE>
\color_if_exist:nTF {#1}
{
\convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl
\color_export:nnN {#1} {HTML}\l_@@_hexcol_tl
}
{
\int_compare:nTF { \tl_count:n {#1} == 6 }
{ \tl_set:Nn \l_@@_hexcol_tl {#1} }
\cs_if_exist:cTF { \token_to_str:N \color@ #1 }
{
\convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl
}
{
\int_compare:nTF { \tl_count:n {#1} == 8 }
{ \fontspec_parse_colour:viii #1 }
\int_compare:nTF { \tl_count:n {#1} == 6 }
{ \tl_set:Nn \l_@@_hexcol_tl {#1} }
{
\bool_if:NF \l_@@_firsttime_bool
{ \@@_warning:nx {bad-colour} {#1} }
\int_compare:nTF { \tl_count:n {#1} == 8 }
{ \fontspec_parse_colour:viii #1 }
{
\bool_if:NF \l_@@_firsttime_bool
{ \@@_warning:nx {bad-colour} {#1} }
}
}
}
}
%</XE>
%<*LU>
\color_if_exist:nTF {#1}
{
\tl_set:Nn \l_@@_hexcol_tl {#1}
}
{
\cs_if_exist:cTF { \token_to_str:N \color@ #1 }
{
\convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl
}
{
\int_compare:nTF { \tl_count:n {#1} == 6 }
{ \tl_set:Nn \l_@@_hexcol_tl {#1} }
{
\int_compare:nTF { \tl_count:n {#1} == 8 }
{ \fontspec_parse_colour:viii #1 }
{
\bool_if:NF \l_@@_firsttime_bool
{ \@@_warning:nx {bad-colour} {#1} }
}
}
}
}
%</LU>
}
% \end{macrocode}
%
Expand Down Expand Up @@ -745,6 +780,7 @@
}
\tl_set:Nx \l_@@_opacity_tl
{
%<LU> ,
\int_compare:nT { \l_@@_tmp_int <= "F } {0} % zero pad
\int_to_hex:n { \l_@@_tmp_int }
}
Expand Down
3 changes: 2 additions & 1 deletion fontspec-code-vars.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@
%
% \begin{macrocode}
\tl_const:Nn \c_@@_hexcol_tl {000000}
\tl_const:Nn \c_@@_opacity_tl {FF~}
%<XE> \tl_const:Nn \c_@@_opacity_tl {FF~}
%<LU> \tl_const:Nn \c_@@_opacity_tl {}
\tl_const:Nn \c_@@_postadjust_tl { \l_@@_wordspace_adjust_tl \l_@@_punctspace_adjust_tl }
% \end{macrocode}
%
Expand Down
56 changes: 49 additions & 7 deletions fontspec-doc-featset.tex
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ \subsection{Colour}
(For example, if you set the colour in a \verb|\setmainfont| command, \verb|\color{...}| and related commands, including hyperlink colouring, will no longer have any effect on text in this font.)
Therefore, \pkg{fontspec}'s colour commands are best used to set explicit colours in specific situations, and the \pkg{xcolor} package is recommended for more general colour functionality.

The colour is defined as a triplet of two-digit Hex RGB
The colour can be defined as a triplet of two-digit Hex RGB
values, with optionally another value for the transparency (where
|00| is completely transparent and |FF| is opaque.)
\begin{Lexample}{color}{Selecting colour with transparency.}
Expand All @@ -341,8 +341,6 @@ \subsection{Colour}
{\addfontfeature{Color=DDBB2299}P}\kern-0.5ex
{\addfontfeature{Color=00BB3399}R}
\end{Lexample}
Transparency is supported by \LuaLaTeX; \XeLaTeX\ with the \texttt{xdvipdfmx} driver
does not support this feature.

If you load the \pkg{xcolor} package, you may use any named colour instead
of writing the colours in hexadecimal.
Expand All @@ -353,17 +351,61 @@ \subsection{Colour}
\definecolor{Foo}{rgb}{0.3,0.4,0.5}
\fontspec[Color=Foo]{Verdana} ...
\end{Verbatim}
The \pkg{color} package is \emph{not} supported; use \pkg{xcolor} instead.

You may specify the transparency with a named colour using the \feat{Opacity}
feature which takes an decimal from zero to one corresponding to
transparent to opaque respectively:
You may also use named colours defined with the color commands of the L3
programming layer:
\begin{Verbatim}
\ExplSyntaxOn
\color_set:nnn{Foo}{rgb}{0.3,0.4,0.5}
\ExplSyntaxOff
...
\fontspec[Color=Foo]{Verdana} ...
\end{Verbatim}

Color expressions (\verb+red!50!blue+) are not supported. The \pkg{color}
package is \emph{not} supported neither.

The code will at first test for color names of the L3 layer, then for xcolor
names and at last try to use the argument as a hexadecimal value.

You may specify the transparency with a named colour using the \feat{Opacity}
feature which takes an decimal from zero to one corresponding to transparent
to opaque respectively:
\begin{Verbatim}
\fontspec[Color=red,Opacity=0.7]{Verdana} ...
\end{Verbatim}
It is still possible to specify a colour in six-char hexadecimal form
while defining opacity in this way, if you like.

\subsubsection{Color models}

With \XeTeX\ color are always written in the rgb color model into the PDF.
When using \LuaTeX, colors with the commands of the L3 layer can be written
as rgb or cmyk or as spot color depending on their definition and of the
value of the variable \verb+\l_color_fixed_model_tl+.

\subsubsection{Spot colors}
With \LuaTeX\ it is possible to use spot colors. This requires the use of the
PDF management:
\begin{Verbatim}
\DocumentMetadata{}
\documentclass{article}
\usepackage{fontspec}
\ExplSyntaxOn
\color_model_new:nnn { sepblue } { Separation }
{
name = PANTONE~3005~U ,
alternative-model = cmyk ,
alternative-values = {1, 0.56, 0,0},
}
\color_set:nnn{spotblue}{sepblue}{1}
\ExplSyntaxOff
...
\fontspec[Color=spotblue]{texgyreheros}
\end{Verbatim}



\subsection{Scale}

\cmdbox{
Expand Down
10 changes: 5 additions & 5 deletions testfiles/aff-group.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ TU/texgyretermes-regular.otf(0)/m/n:
[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;
Adding a colour:
TU/texgyretermes-regular.otf(1)/m/n:
"[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color=AA00AAFF ;"
[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color={AA00AA};
Back to normalfont:
TU/texgyretermes-regular.otf(0)/m/n:
[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;
Open group and add a different colour:
TU/texgyretermes-regular.otf(2)/m/n:
"[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color=00AAAAFF ;"
[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color={00AAAA};
End the group:
TU/texgyretermes-regular.otf(0)/m/n:
[texgyretermes-regular.otf]:mode=node;script=latn;language=dflt;+tlig;
Expand All @@ -21,17 +21,17 @@ The following demonstrates strange behaviour to be wary of.
TU/texgyrepagella-regular.otf(0)/m/n:
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;
TU/texgyrepagella-regular.otf(0)/m/n:
"[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color=AA00AAFF ;"
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color={AA00AA};
TU/texgyrepagella-regular.otf(0)/m/n:
"[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color=AA00AAFF ;"
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color={AA00AA};
============================================================
And check NFSSFamily use inside a group.
Reload another font:
TU/texgyreheros-regular.otf(0)/m/n:
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;+tlig;
Open group and add a different colour, without changing family:
TU/texgyreheros-regular.otf(0)/m/n:
"[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color=00AAAAFF ;"
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;+tlig;color={00AAAA};
End the group:
TU/texgyreheros-regular.otf(0)/m/n:
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;+tlig;
Expand Down
12 changes: 6 additions & 6 deletions testfiles/aff-italic-only.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ TU/texgyrepagella(0)/m/n:
TU/texgyrepagella(0)/m/sc:
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;
TU/texgyrepagella(0)/m/it:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;color={AA0000};
TU/texgyrepagella(0)/m/scit:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;color={AA0000};
TU/texgyrepagella(0)/b/n:
[texgyrepagella-bold.otf]:mode=node;script=latn;language=dflt;+tlig;
TU/texgyrepagella(0)/b/sc:
Expand All @@ -23,9 +23,9 @@ TU/texgyrepagella(1)/m/n:
TU/texgyrepagella(1)/m/sc:
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;+smcp;
TU/texgyrepagella(1)/m/it:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;color={AA0000};
TU/texgyrepagella(1)/m/scit:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;+smcp;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;+smcp;color={AA0000};
TU/texgyrepagella(1)/b/n:
[texgyrepagella-bold.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;
TU/texgyrepagella(1)/b/sc:
Expand All @@ -40,9 +40,9 @@ TU/texgyrepagella(2)/m/n:
TU/texgyrepagella(2)/m/sc:
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;
TU/texgyrepagella(2)/m/it:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;color={AA0000};
TU/texgyrepagella(2)/m/scit:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;+smcp;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+onum;+smcp;color={AA0000};
TU/texgyrepagella(2)/b/n:
[texgyrepagella-bold.otf]:mode=node;script=latn;language=dflt;+tlig;
TU/texgyrepagella(2)/b/sc:
Expand Down
8 changes: 4 additions & 4 deletions testfiles/aff-sc-repeated.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ TU/texgyrepagella(0)/m/n:
TU/texgyrepagella(0)/m/sc:
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;
TU/texgyrepagella(0)/m/it:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;color={AA0000};
TU/texgyrepagella(0)/m/scit:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;color={AA0000};
TU/texgyrepagella(0)/b/n:
[texgyrepagella-bold.otf]:mode=node;script=latn;language=dflt;+tlig;
TU/texgyrepagella(0)/b/sc:
Expand All @@ -23,9 +23,9 @@ TU/texgyrepagella(1)/m/n:
TU/texgyrepagella(1)/m/sc:
[texgyrepagella-regular.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;+onum;
TU/texgyrepagella(1)/m/it:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;color={AA0000};
TU/texgyrepagella(1)/m/scit:
"[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;+pnum;color=AA0000FF ;"
[texgyrepagella-italic.otf]:mode=node;script=latn;language=dflt;+tlig;+smcp;+pnum;color={AA0000};
TU/texgyrepagella(1)/b/n:
[texgyrepagella-bold.otf]:mode=node;script=latn;language=dflt;+tlig;
TU/texgyrepagella(1)/b/sc:
Expand Down
11 changes: 7 additions & 4 deletions testfiles/colour-basic.luatex.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ Loading xcolor...
...done
Loading a font with hex colour:
TU/texgyreheros-regular.otf(0)/m/n:
"[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color=5500FFFF ;"
Loading a font by name (xcolor):
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color={5500FF};
Loading a font by name (l3color+xcolor):
TU/texgyreheros-regular.otf(1)/m/n:
"[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color=FF0000FF ;"
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color={red};
Defining a new xcolor colour and using it:
TU/texgyreheros-regular.otf(2)/m/n:
"[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color=4D6680FF ;"
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color={4D6680};
Defining a new l3color colour and using it:
TU/texgyreheros-regular.otf(3)/m/n:
[texgyreheros-regular.otf]:mode=node;script=latn;language=dflt;color={Bar};
***************
Compilation 1 of test file completed with exit status 0
10 changes: 8 additions & 2 deletions testfiles/colour-basic.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
\MSG{Loading a font with hex colour:}
{\fontspec[Color=5500FF]{texgyreheros-regular.otf}\CURRNFSS}

\MSG{Loading a font by name (xcolor):}
\MSG{Loading a font by name (l3color+xcolor):}
{\fontspec[Color=red]{texgyreheros-regular.otf}\CURRNFSS}

\MSG{Defining a new xcolor colour and using it:}
\definecolor{Foo}{rgb}{0.3,0.4,0.5}
{\fontspec[Color=Foo]{texgyreheros-regular.otf}\CURRNFSS}

\end{document}
\MSG{Defining a new l3color colour and using it:}
\ExplSyntaxOn
\color_set:nnn{Bar}{rgb}{0.5,0.4,0.3}
\ExplSyntaxOff
{\fontspec[Color=Bar]{texgyreheros-regular.otf}\CURRNFSS}

\end{document}
5 changes: 4 additions & 1 deletion testfiles/colour-basic.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ Loading xcolor...
Loading a font with hex colour:
TU/texgyreheros-regular.otf(0)/m/n:
"[texgyreheros-regular.otf]/OT:script=latn;language=dflt;color=5500FFFF ;" at 10.0pt
Loading a font by name (xcolor):
Loading a font by name (l3color+xcolor):
TU/texgyreheros-regular.otf(1)/m/n:
"[texgyreheros-regular.otf]/OT:script=latn;language=dflt;color=FF0000FF ;" at 10.0pt
Defining a new xcolor colour and using it:
TU/texgyreheros-regular.otf(2)/m/n:
"[texgyreheros-regular.otf]/OT:script=latn;language=dflt;color=4D6680FF ;" at 10.0pt
Defining a new l3color colour and using it:
TU/texgyreheros-regular.otf(3)/m/n:
"[texgyreheros-regular.otf]/OT:script=latn;language=dflt;color=80664CFF ;" at 10.0pt
***************
Compilation 1 of test file completed with exit status 0
Loading