# What is the difference between Element.GetCtm() and Element.GState.GetTransform()?

Q: What is the difference between Element.GetCtm() and
Element.GState.GetTransform()?
I see that there is Element.GetCTM() for the CTM and a
GState.GetTransform(). I have done some testing with several
documents, and have found that the matrix returned by Element.GetCtm()
is always equal to the matrix returned by GState.GetTransform(). Is
this by design?
-----
A: Element.GetCtm() is not always equal to the matrix returned by
Element.GState.GetTransform().

GetCtm() returns Current Transformation Matrix (CTM) that maps
coordinates to the initial user space, whereas
Element.GState.GetTransform() returns a transform that was explicitly
associated with a given element.

For example:

10 0 0 10 0 0 cm
1 1 10 10 re
f
20 20 10 10 re
f
20 0 0 20 0 0 cm
0 0 10 10 re
f

For the first rectangle, the CTM (i.e. Current Transformation Matrix)
will be [10 0 0 10 0 0].
GetTransform() will return the same matrix ([10 0 0 10 0 0]) since
this 'cm' immediately precedes this element.

For the second rectangle, the CTM will also be [10 0 0 10 0 0].
GetTransform() should in this case return identity matrix ([1 0 0 1 0
0]) because no transform matrix immediately precedes this element.

For the third rectangle, the CTM will also be [200 0 0 200 0 0].
For the third rectangle, GetTransform() returns ([20 0 0 20 0 0]) -
i.e. the transform matrix that immediately precedes this element.
Please note that the new CTM is the product of the old CTM and the new
GetTransform() (i.e. new_ctm = old_ctm *
element.GState().GetTransform()).

Although in most cases PDFNet users will want to use element.GetCTM(),
there are applications that also need to quickly determine the last
change in the CTM (and GetTransform can be used for this purpose).