Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XObjects and (TikZ) transparency

50 views
Skip to first unread message

Martin Scharrer

unread,
Dec 17, 2011, 2:24:32 PM12/17/11
to
Hi,

Since I discovered that the pdftex driver of graphics uses PDF XForms
(\pdfxform) to store images so that they are only included into the
output PDF once even when they are used several times, I liked to apply
this also to other arbitrary TeX material. I wrote the 'storebox'
package based on this. It works similar to \savebox but will only
include the content once in the PDF.

Unfortunately I discovered that transparency is not supported by this,
i.e. transparent material in a TikZ-picture is shown completely solid.
I'm not sure if this is a known limitation of XForms or maybe caused by
a limitation of the TikZ drivers for pdftex. In the second case it might
be overcome, I guess, by adding some driver code before and after the
material, similar as it is done for colors using \color@setgroup ..
\color@endgroup.

It would be nice if the experts for PDF/pdftex or TikZ could give me
some advice about this. I also discovered this limitation when I tried
to insert some transparent TikZ code to the page during the output
routine. I guess some driver code must be added to every PDF page
holding some transparent material, but I was unable to locate it in the
TikZ code yet.

Thanks a lot,
Martin Scharrer

Martin Scharrer

unread,
Dec 17, 2011, 2:31:01 PM12/17/11
to
I forget to state something important. The transparency work if there is
some other tikzpicture which also holds some transparent material, but
not if the storebox is the only transparent material on the page.
This lead me to the idea that some driver code is added to every PDF page.

Best Regards,
Martin Scharrer

zappathustra

unread,
Dec 18, 2011, 3:00:38 AM12/18/11
to
[What follows is hypothetical; I haven't played with PDF graphics for
some time.]
Form XObjects require a Resources dictionary, or they can inherit the
page's dictionary. When TikZ creates transparency (which must be
registered in a Resources dictionary), I suppose it creates the proper
dictionary and adds it to the page where the painting occurs. With an
XObject, though, as far as TikZ is concerned, nothing is ever painted,
so the dictionary isn't added to the page unless, as you remarked,
another painting occurs.

The solution is: add the dictionary to the XObject, which is easier said
than done... But I'd be surprised if TikZ didn't handled XObjects by itself.

Best,
Paul

Alexander Grahn

unread,
Dec 19, 2011, 3:20:13 AM12/19/11
to
You need to add/declare the resources used by the graphic to the
resources dictionary of the Form XObject. They are automatically put
to the resources dict of the page, which was active when the (TikZ)
graphics was drawn, but have to be repeated in the resources dict of
the XObject as said before. I had the same problem with my animate
package and I could solve it by:

\immediate\pdfxform resources {\the\pdfpageresources} \mybox

where \mybox is the box register containing the graphical/textual
material.

Alexander



Martin Scharrer

unread,
Dec 19, 2011, 4:29:05 AM12/19/11
to
Thanks a lot,
this sounds very promising!
However I'm unable to make it work. I still don't get transparencies.

I tried it as follows:

\documentclass{article}
\usepackage{tikz}
\newsavebox\mybox
\begin{document}

\sbox\mybox{%
\begin{tikzpicture}
\shade [left color=blue, right color=red]
(0,0) rectangle (1,1);
\fill [semitransparent,green]
(1,0) rectangle (2,1);
\end{tikzpicture}%
}
\usebox\mybox

\immediate\pdfxform resources {\the\pdfpageresources} \mybox
\mathchardef\myform=\pdflastxform
\mbox{\pdfrefxform\myform}%
\clearpage
\mbox{\pdfrefxform\myform}%
\clearpage
\mbox{\pdfrefxform\myform}%

\end{document}


The first box has a semitransparent green, but the others done with an
XForm still are only solid.

Best Regards,
Martin Scharrer

Alexander Grahn

unread,
Dec 19, 2011, 6:46:00 AM12/19/11
to
This seems to be a bug in pdftex or in TikZ. If you remove the code
for the shaded rectangle, transparency works (I put a cross-hair
beneath the transparent rectangle.):

\documentclass{article}
\usepackage{tikz}
\newsavebox\mybox
\begin{document}

\sbox\mybox{%
\begin{tikzpicture}
% \shade [left color=blue, right color=red]
% (0,0) rectangle (1,1);
\draw (1,0)--(2,1);
\draw (1,1)--(2,0);

Martin Scharrer

unread,
Dec 19, 2011, 10:16:19 AM12/19/11
to
Thanks for pointing this out! I should have kept the example really
minimal, instead having a second test in it (here for shading which can
cause issues as well, like with XeLaTeX).

I wonder why this is, maybe the attributes required for shading block
the ones required for transparencies. I guess it's an issue of the
TikZ/PGF driver. I will report it, but I don't think they will assign it
a high priority.

Best Regards,
Martin Scharrer

Martin Scharrer

unread,
Dec 19, 2011, 5:16:24 PM12/19/11
to
Thanks again, I just uploaded 'storebox' v1.2 to CTAN which contains
this changes.


> I wonder why this is, maybe the attributes required for shading block
> the ones required for transparencies. I guess it's an issue of the
> TikZ/PGF driver. I will report it, but I don't think they will assign it
> a high priority.
I reported this now to the TikZ/PGF bug tracker:
https://sourceforge.net/tracker/?func=detail&aid=3462542&group_id=142562&atid=752792


Best Regards,
Martin Scharrer

Alexander Grahn

unread,
Dec 20, 2011, 4:25:18 AM12/20/11
to
> I reported this now to the TikZ/PGF bug tracker:https://sourceforge.net/tracker/?func=detail&aid=3462542&group_id=142...
>
> Best Regards,
> Martin Scharrer

Martin, I experimented a little with the pgfsys-pdftex.def file
(pgfsys-pdftex.def,v 1.26 2009/05/22).

I could get your original code with shaded and transparent boxes
working! I simply placed \immediate in front of \pdfxform on lines 84,
100 and 124 in
pgfsys-pdftex.def.

Alexander

Alexander Grahn

unread,
Dec 20, 2011, 6:34:48 AM12/20/11
to
> I reported this now to the TikZ/PGF bug tracker:https://sourceforge.net/tracker/?func=detail&aid=3462542&group_id=142...
>
> Best Regards,
> Martin Scharrer

The following trick avoids patching pgfsys-pdftex.def:

\def\pdfxformorig{\pdfprimitive\pdfxform}
\def\pdfxform{\immediate\pdfxformorig}

Does this have undesirable side effects?

Alexander

Martin Scharrer

unread,
Dec 20, 2011, 9:08:58 AM12/20/11
to
One side effect in my 'storebox' package is that if I use \immediate
there, any \storebox content is always written to the PDF, even if it is
never actual used. However, this should be the minority of cases, but
was a nice little extra feature.
I think I make this optional for the \pdfxform used by \storebox.

For the \pdfxform's used in the PGF driver I don't think there will be
side effects caused by always added \immediate, but I can't be 100% sure.

I uploaded a new version of 'storebox' already which patches the PGF
driver code. I also had the idea to redefine \pdfxform, but I normally
try to avoid such things. You never know which other packages you affect
with it.

Thanks a lot for you help. I hope the PGF drivers are updated with this.
Best Regards,
Martin Scharrer


0 new messages