pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.08k stars 104 forks source link

support of CMYK colors in the dvisvgm backend #1319

Open mgieseki opened 2 months ago

mgieseki commented 2 months ago

Brief outline of the proposed feature

As of dvisvgm 3.3 the conversion of CMYK colors to RGB has been modified so that they are now more similar to those shown by Ghostscript and several PDF viewers. When using the dvips backend, the colors can be processed accordingly because the DVI file contains color specials. The dvisvgm backend, on the other hand, sometimes creates literal SVG fragments with the color hard-coded as RGB hex values. In this case, the CMYK to RGB conversion takes place in a LaTeX (or TikZ) package and dvisvgm can't apply its color interpolation.

Here's an example:

\documentclass[dvisvgm]{standalone}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\definecolor{mycolor}{cmyk}{1, 0, 1, 0} 
\begin{document}
\begin{tikzpicture}
  \fill[mycolor] circle(2);
\end{tikzpicture}
\end{document}

The resulting SVG graphics created with dvips (left) and dvisvgm backend:

cmyktest-ps cmyktest

Here are the corresponding DVI snippets:

xxx: 'color push cmyk 1 0 1 0'
xxx: 'ps:: 56.69362 0.0 moveto '
xxx: 'ps:: 56.69362 31.31142 31.31142 56.69362 0.0 56.69362 curveto '
xxx: 'ps:: -31.31142 56.69362 -56.69362 31.31142 -56.69362 0.0 curveto '
xxx: 'ps:: -56.69362 -31.31142 -31.31142 -56.69362 0.0 -56.69362 curveto '
xxx: 'ps:: 31.31142 -56.69362 56.69362 -31.31142 56.69362 0.0 curveto '
xxx: 'ps:: closepath '
xxx: 'dvisvgm:raw <g stroke="#0f0" fill="#0f0">{?nl} '
xxx: 'dvisvgm:raw <path d=" '
xxx: 'dvisvgm:raw M 56.90549 0.0 C 56.90549 31.42844 31.42844 56.90549 0.0 56.90549 ... '
xxx: 'dvisvgm:raw " stroke="none"/>{?nl} '
xxx: 'dvisvgm:raw </g>{?nl} '

It would be great if the dvisvgm backend could create color specials too, e.g. something like this:

xxx: 'color push cmyk 1 0 1 0'
xxx: 'dvisvgm:raw <g stroke="{?color}" fill="{?color}">{?nl} '

To apply different stroke and fill colors, the SVG elements could also be split into several specials:

xxx: 'color push cmyk 1 0 1 0'
xxx: 'dvisvgm:raw <g stroke="{?color}"'
xxx: 'color pop'
xxx: 'color push cmyk 1 0 1 0'
xxx: 'dvisvgm:raw fill="{?color}">{?nl} '

Usage example

No response