[luatex] LuaTeX warning: Misplaced \pdfrestore by (983040sp, 0sp)
Heiko Oberdiek
heiko.oberdiek at googlemail.com
Thu Apr 25 23:30:20 CEST 2013
On 25.04.2013 22:08, Patrick Gundlach wrote:
> Hello Heiko,
>
>>> when running the following code, I have a problem that subsequent
>>> boxes are misplaced. A warning is issued:
>>>
>>> LuaTeX warning: Misplaced \pdfrestore by (983040sp, 0sp)
>>>
>>> What am I doing wrong?
>
>
>> There are two different coordinate
>> systems: PDF and TeX, \pdfrestore restores the graphics state including
>> the current transfer matrix to the state of \pdfsave in the PDF
>> coordinate system. But if the TeX position has moved away, the
>> two coordinate systems are out of sync. Therefore you get a warning
>> that you might shoot yourself in the foot.
>
> I my case, I did get garbled output, so the warning was very good.
>
> Thanks for your comment. This is what I have now:
>
> local function scalebox(scalefactor,box)
> local pdf_save, pdf_restore, pdf_setmatrix
> pdf_save = node.new("whatsit","pdf_save")
> pdf_restore = node.new("whatsit","pdf_restore")
> pdf_setmatrix = node.new("whatsit","pdf_setmatrix")
> pdf_setmatrix.data=string.format("%.4g 0 0
> %.4g",scalefactor,scalefactor)
"%.4g" allows the "e style", you get invalid PDF, if scalefactor
is equal smaller than 0.000099995 (e.g. 0,00009 => 9e-05) or
equal/greater than 9999.5 (e.g. 10000 => 1e+04).
PDF numbers must not be given in exponential notation.
> local hbox = node.hpack(box)
> hbox = node.insert_before(hbox,hbox,pdf_setmatrix)
> hbox = node.insert_before(hbox,pdf_setmatrix,pdf_save)
>
> hbox = node.hpack(hbox)
> hbox.height = box.height * scalefactor
> hbox.width = box.width * scalefactor
> hbox.depth = 0
> node.insert_after(hbox,node.tail(hbox),pdf_restore)
>
> local newbox = node.vpack(hbox)
> return newbox
> end
>
> which seems to work because the box doesn't have any depth.
The original box might have a depth. The other parameters (width and
height) are recalculated, but the depth is set to zero?
The graphics package uses something like:
\setbox0=\hbox{<user box content>}
\setbox2=\hbox{%
\pdfsave
\pdfsetmatrix...
\hbox to 0pt{%
\copy0
\hss
}%
\pdfrestore
}
\wd2=<scale factor>\wd0
\box2
Yours sincerely
Heiko Oberdiek
More information about the luatex
mailing list