# [pdftex] Some problems with form Xobjects and \pdfliteral

Thomas Lavergne thomas.lavergne at reveurs.org
Thu May 21 13:08:36 CEST 2009

Hi,

I'm working on a drawing application wich can output the graphics using
pdf drawing operations. I have a TeX output filter who take theses and
put them in a \pdfliteral with a little magic around so the graphics can
be easily used with pdftex.
So I will get something like this :
\pdfliteral{0 0 m 50 50 l 50 0 l S}
The magic around are boxing stuff for easier manipulation in TeX and
isn't interesting here.

All works fine for simples graphics with just lines, curves... My
problems start when I want to include some textual contents.

An easy solution would be to build a complete PDF file and juste include
it in TeX using \pdfximage primitive. The PDF will include is own font
and do is own text rendering.
But the result will look ugly. Text and figure will use different fonts
at different sizes with different way to render text.

What I want is to render the text with TeX himself and use the result in
the graphics.
Solution I have found is to render the text in a box using TeX and put
the resulting box in a form XObject. Next I can use this form XObject in
my \pdfliteral to place the text on my graphics.
This first step is easy :
\setbox0=\hbox{My text here}\immediate\pdfxform0

This is where the problem arise. In order to draw the form XObject, it
must be named as of section 8.10.1 of the pdf reference. This name must
be defined in the XObject subdictionary of the current resource
dictionary.
And I cannot find a way to add something to this dictionary. If I do
something like :
\pdfpageattr{/Resources << /XObject << ... >>
This new Resources and XObject dictionary are not merged with the ones
produced by pdftex, so my entries are ignored by viewers. So I cannot
create myself a name for my form XObjects.

A solution to solve this is to let pdftex create himself the names, for
this I have to use \pdfrefxobject. But this led to two problems :
- First I have to find the name given to my XObjects by pdftex. I have
only found a ugly solution for this : pdftex seems to name XObjects
by cating "/Fm" with the object reference number, so I can construct
the name with \pdflastxobject.
This works but I'm not sure this is really a good way to do
things...
- Second, in order for pdftex to really produce the name, the XObject
have to be used, so the form XObject is drawn on my graphics (this
is ok :-) but also somewhere else on the page by the \pdfrefxobject
call, and this is obviously not ok...

Just to explain perhaps more cleanly my problems, this is a very simple
example :
\setbox0=\hbow{My text here}\pdfxform0
\edef\oname{\the\pdflastxform}
\pdfrefxobject\oname
\pdfliteral{/Fm\oname\space Do}

In this example, the \pdfliteral will draw my text as I want, but this
text will also be drawn somewhere else by the \pdfrefxobject which is
needed in order to get a name associated to the XObject.

So, is there a solution to this problem ?
Thanks

Tom

PS: I'm very sory for my poor english.

--
Thomas Lavergne                    "Entia non sunt multiplicanda praeter
necessitatem." (Guillaume d'Ockham)
thomas.lavergne at reveurs.org                            http://oniros.org