I am having some confusions about the current transformation matrix (CTM) in PDFs. For page 5 in this PDF, I have examined the Token Stream (http://pastebin.com/k6g4BGih) and that shows the last cm
operation before the curve (c)
commands sets the transfomration matrix to COSInt{10},COSInt{0},COSInt{0},COSInt{10},COSInt{0},COSInt{0}
. The full output is at http://pastebin.com/9XaPQQm9 .
Next I used the following set of codes to extract the line and curve commands from the same page following a code @mkl provided in a related SO question
- Main class: http://pastebin.com/htiULanR
Helper classes:
a. Class that extends
PDFGraphicsStreamEngine
: http://pastebin.com/zL2p75hab.
Path
: http://pastebin.com/d3vXCgnCc.
Subpath
: http://pastebin.com/CxunHPiZd.
Segment
: http://pastebin.com/XP1Dby6Ue.
Rectangle
: http://pastebin.com/fNtHNtwsf.
Line
: http://pastebin.com/042cgZBpg.
Curve
: http://pastebin.com/wXbXZdqE
In that code, I printed the CTM using getGraphicsState().getCurrentTransformationMatrix()
inside the curveTo()
method that is overridden from PDFGraphicsStreamEngine
class. That shows the CTM as [0.1,0.0,0.0,0.1,0.0,0.0]
. So my questions are:
Shouldn't these two CTMs be the same?
Both these CTMs have scaling operations: the first one scales with a factor of 10 and the second one scales with a factor of 0.1. If I ignore the scaling, I can create an SVG which looks fairly close to the original PDF. But I am confused why that should happen. Do I need to consider
all transformation matrices before the path
instead of the last one?