[pdftex] transparency in pdfTeX
Wouter Bergmann Tiest
W.M.BergmannTiest at phys.uu.nl
Fri Nov 10 15:33:41 CET 2006
Hi all,
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
to the pdftex.def file which introduces two new colour models, rgba and
cmyka. 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.
\documentclass{article}
\usepackage{color}
\definecolor{transred}{rgba}{1,0,0,.5}
\definecolor{transblue}{rgba}{0,1,0,.5}
\definecolor{transgreen}{rgba}{0,0,1,.5}
\begin{document}
\setlength{\unitlength}{1.5mm}
\begin{picture}(10,10)
\color{transred}
\put(6,6){\circle*{4}}
\color{transblue}
\put(4,5){\circle*{4}}
\color{transgreen}
\put(6,4){\circle*{4}}
\end{picture}
\end{document}
Wouter Bergmann Tiest
--------->8------ cut here ---------->8--------
--- pdftex.def.orig Fri Nov 10 14:40:26 2006
+++ pdftex.def Fri Nov 10 15:01:28 2006
@@ -251,7 +251,9 @@
% Colour Support. The following models may be used.
% * cmyk supported directly.
+% * cmyka supported directly using extended graphics state.
% * rgb supported directly.
+% * rgba supported directly using extended graphics state.
% * RGB converted to rgb by this file.
% * gray supported directly.
% * named converted to cmyk by this file.
@@ -263,24 +265,80 @@
\PackageError{color}{Argument `#1' not in range [0,1]}\@ehd
\fi
}
+% Set up 11 Extended Graphics States for different levels of transparency
+\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 >>}
+% Add ExtGStates to resource dictionary
+\edef\my at Comm{\pdfpageresources{\my at PDF}}
+\my at Comm
+% Define function for translating alpha value [0..1] to integer between 0
and 10
+\newdimen\my at dim
+\newcount\my at count
+\def\r at und#1#2{\my at dim#1pt
+ \multiply\my at dim 10
+ \divide\my at dim 65535
+ \my at count\my at dim
+ \edef#2{\the\my at count}
+}
\def\color at cmyk#1#2{\c at lor@@cmyk#2\@@#1}
\def\c at lor@@cmyk#1,#2,#3,#4\@@#5{%
\c at lor@arg{#4}%
\c at lor@arg{#1}%
\c at lor@arg{#2}%
\c at lor@arg{#3}%
- \edef#5{#1 #2 #3 #4 k #1 #2 #3 #4 K}%
+ \edef#5{#1 #2 #3 #4 k #1 #2 #3 #4 K /transGS10 gs}%
+}
+% Define new colour model cmyka (cyan, magenta, yellow, black, alpha)
+\def\color at cmyka#1#2{\c at lor@@cmyka#2\@@#1}
+\def\c at lor@@cmyka#1,#2,#3,#4,#5\@@#6{%
+ \c at lor@arg{#4}%
+ \c at lor@arg{#1}%
+ \c at lor@arg{#2}%
+ \c at lor@arg{#3}%
+ \c at lor@arg{#5}%
+ \r at und{#5}\@lpha%
+ \edef#6{#1 #2 #3 #4 k #1 #2 #3 #4 K /transGS\@lpha\space gs}%
}
\def\color at gray#1#2{%
\c at lor@arg{#2}%
- \edef#1{#2 g #2 G}%
+ \edef#1{#2 g #2 G /transGS10 gs}%
}
\def\color at rgb#1#2{\c at lor@@rgb#2\@@#1}
\def\c at lor@@rgb#1,#2,#3\@@#4{%
\c at lor@arg{#1}%
\c at lor@arg{#2}%
\c at lor@arg{#3}%
- \edef#4{#1 #2 #3 rg #1 #2 #3 RG}%
+ \edef#4{#1 #2 #3 rg #1 #2 #3 RG /transGS10 gs}% Make sure normal rgb
colour is opaque
+}
+% Define new colour model rgba (red, green, blue, alpha)
+\def\color at rgba#1#2{\c at lor@@rgba#2\@@#1}
+\def\c at lor@@rgba#1,#2,#3,#4\@@#5{%
+ \c at lor@arg{#1}%
+ \c at lor@arg{#2}%
+ \c at lor@arg{#3}%
+ \c at lor@arg{#4}%
+ \r at und{#4}\@lpha%
+ \edef#5{#1 #2 #3 rg #1 #2 #3 RG /transGS\@lpha\space gs}%
}
\def\color at RGB#1#2{\c at lor@@RGB#2\@@#1}
\def\c at lor@@RGB#1,#2,#3\@@#4{%
@@ -312,7 +370,7 @@
\def\define at color@named#1#2{%
\expandafter\edef\csname col@#1\endcsname{#2}%
}
-\def\current at color{0 g 0 G}
+\def\current at color{0 g 0 G /transGS10 gs}
% v0.02t: support for \pagecolor
% fixed in v0.02p by using a box register, see
More information about the pdftex
mailing list