[pstricks] Real transparency hack (was: Venn Diagram example?)

Jan Steffan me at jansteffan.de
Tue Jul 12 14:50:38 CEST 2005


On Saturday 09 July 2005 12:44, Herbert Voss wrote:
> Jan Steffan wrote:
> > On Friday 08 July 2005 09:12, Herbert Voss wrote:
> >>http://PSTricks.tug.org/main.cgi?file=beamer/beamer
> >>as an example for "transparency" colors.
> >
> > In this example the hatch lines are aligned exactly on top
> > of each other, so there is no transparency effect (at least with some
> > viewers and printers).
> [...]
> > Isn't there a way to slightly offset each fill so that the hatchlines
> > interleave? I could imagine that this would produce better results.
>
> feel free, it is easy to understand, how it works and then to create
> some more options

Well, I tried to understand how to do this, but I didn't get to far.

However, I found another hack, that allows the use of REAL transparency.
Although postscript does not support transparency, newer versions of 
ghostscript do:
http://www.cs.wisc.edu/~ghost/doc/AFPL/8.50/Language.htm#Transparency

When a file using these features is run through ps2pdf14 (not ps2pdf) it 
produces a nice PDF with real transparency effects.(In order to view or print 
it a PDF viewer is required that supports PDF version 1.4. Acrobat 5.0 and 
above and newer versions of ghostscript will do.

I hacked together a proof of concept based on pstricks that defines a new
fillstyle "transp" as this was the easiest the solution I could quickly find.
A real solution should provide transparency independently of filling.

I probably also did not consider all sideeffects and problems this hack may 
cause and I surely didn't fully comprehend the PDF transparency mode, which 
is quite complicated. 

Thsi little example works fine, though (see the attached PDF):



\documentclass{minimal}
\usepackage{pstricks-add}

% run through latex -> dvips -> ps2pdf14(!) and view 
% with Acrobat >= 5.0

\makeatletter
% use transpalpha=<mumber> to the the opacity level
\def\psset at transpalpha#1{\pst at checknum{#1}\pstranspalpha}
\psset at transpalpha{1}

% I defined a new fillstyle ``transp'' because this was the lowest
% hanging fruit... It should be possible to combine transparency with
% any other fillstyle.
\def\psfs at transp{%
  \addto at pscode{/Normal .setblendmode \pstranspalpha .setshapealpha}
  \psfs at solid
  }
\makeatother

\begin{document}
  \begin{pspicture}(-5,-5)(5,5)
    \pscircle[linestyle=none,fillcolor=green,fillstyle=transp,transpalpha=.5]
(2;135){2cm}
    \pscircle[linestyle=none,fillcolor=red,fillstyle=transp,transpalpha=.5]
(2;45){2cm}
    \pscircle[linestyle=none,fillcolor=blue,fillstyle=transp,transpalpha=.5]
(1;-90){2cm}
  \end{pspicture}
\end{document}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transparency.pdf
Type: application/pdf
Size: 1219 bytes
Desc: not available
Url : http://tug.org/pipermail/pstricks/attachments/20050712/accef1ad/attachment.pdf 


More information about the PSTricks mailing list