[pdftex] transparency in pdfTeX

Heiko Oberdiek oberdiek at uni-freiburg.de
Fri Nov 10 19:12:57 CET 2006

```On Fri, Nov 10, 2006 at 03:33:41PM +0100, Wouter Bergmann Tiest wrote:

> I posted some of this a little while ago on the pdftex-def-dev list, but
> got little reaction, so I'll try on this list. I have written an addition

Sorry, I haven't unsubscribed from this list, but I don't got your message,
just the short reply of Martin.

> to the pdftex.def file which introduces two new colour models, rgba and
> cmyka.

There are other drivers such as dvipdfm that also could benefit from
a new color model. Thus a better place for new color models is
the (x)color package.

> The `a' stands for alpha, which describes the opacity of the
> colour. It can be any number between 0 (invisible) and 1 (opaque), but
> there are actually only 11 levels of transparency supported, and the
> number is rounded off. It makes use of the transparency features that
> are new since PDF 1.4. It can be used with the color.sty package, for
> example like this:
>
> \definecolor{transparentblue}{rgba}{0,0,1,.7}
> \textcolor{transparentblue}{This is transparent}
>
> I use it for creating text-boxes with transparent backgrounds which
> overlay a background image---looks cool on posters. It is implemented by
> defining 11 Extended Graphics States and choosing one of those based on
> the value of the `a' parameter. Could this be included in the regular
> pdfTeX distribution? I think it will make a worthwhile addition to pdfTeX.
> Below is a patch for pdftex.def v0.03t. Here is a complete example of
> usage; it draws three partially overlapping coloured disks.

> +% Set up 11 Extended Graphics States for different levels of transparency

Why not 101 or 1001 or 1234 values?
Another strategy: use only the values, specified by the user.
I think most of the time this are far less than 11 values.

> +\immediate\pdfobj{<< /Type /ExtGState /ca 0 /CA 0 >>}
> +\edef\my at PDF{/ExtGState << /transGS0 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.1 /CA 0.1 >>}
> +\edef\my at PDF{\my at PDF\space/transGS1 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.2 /CA 0.2 >>}
> +\edef\my at PDF{\my at PDF\space/transGS2 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.3 /CA 0.3 >>}
> +\edef\my at PDF{\my at PDF\space/transGS3 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.4 /CA 0.4 >>}
> +\edef\my at PDF{\my at PDF\space/transGS4 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.5 /CA 0.5 >>}
> +\edef\my at PDF{\my at PDF\space/transGS5 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.6 /CA 0.6 >>}
> +\edef\my at PDF{\my at PDF\space/transGS6 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.7 /CA 0.7 >>}
> +\edef\my at PDF{\my at PDF\space/transGS7 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.8 /CA 0.8 >>}
> +\edef\my at PDF{\my at PDF\space/transGS8 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 0.9 /CA 0.9>>}
> +\edef\my at PDF{\my at PDF\space/transGS9 \the\pdflastobj\space 0 R}
> +\immediate\pdfobj{<< /Type /ExtGState /ca 1 /CA 1 >>}
> +\edef\my at PDF{\my at PDF\space/transGS10 \the\pdflastobj\space 0 R >>}

No need to increase the file size by obsolete white space:
...{<</Type/ExtGState/ca 1/CA 1>>}
...{\my at PDF/transGS10 \the\pdflastobj\space 0 R>>}

\immediate\pdfobj has the disadvantage to occupy objects even if
transparency is not used at all.

Without \immediate, the actually used objects can be marked by \pdfrefobj.
A small disadvantage remains: unused objects end as free objects in
the xref table.

This can be solved by using two passes:
The first pass writes the uses in an auxiliary file.
At the begin of the second pass, the auxiliary data are read
and decided which values are supported. During the pass
the values are used or rounded to a supported value.

Also pages get the resource that do not need them.

This is more tricky to solve, because \pdfpageresources
also has to be changed at page level. Macros that change at
page level will not help.

> +% Add ExtGStates to resource dictionary
> +\edef\my at Comm{\pdfpageresources{\my at PDF}}

And no one else can use \pdfpageresources :-(((
The next use of \pdfpageresources will overwrite the previous one.
At least you should add the previous contents:
\edef\my at Comm{%
\pdfpageresources\expandafter{\the\pdfpageresources\my at PDF}%
}%
And hope remains, others will also do so.

Next problem is a collision of /ExtGState, because
pgf also supports transparency and other packages may use /ExtGState
as well.

Unhappily pdfTeX doesn't provide a way to handle this kind
of global resources. It could be solved at macro level, if there
properties and all other packages would use it.

Furthermore I expect problems with page breaks, thus I would use
an additional colorstack for this purpose, see my latest patch.

Because of the severe unsolved problems, I cannot add this patch
to pdftex.def. It's better to make a package. Then the user
can decide using it, if he needs it, or not using it otherwise
or in case of conflicts.

Yours sincerely
Heiko <oberdiek at uni-freiburg.de>
--
```