[
https://issues.apache.org/jira/browse/PDFBOX-1960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13922210#comment-13922210
]
John Hewson commented on PDFBOX-1960:
-------------------------------------
Oh, I see what's happening here, the matrices of AffineTransform and Matrix are
transposed. Rows in one are columns in the other. They are performing the same
mathematics but the switched rows and columns also switches the meaning of
pre/post-multiply.
So a pre-multiply using the Matrix class produces the same result as a
post-multiply (concatenate) using the AffineTransform class. This explains why
the results of concatenate and preConcatenate seemed to be reversed.
{quote}
Suggestion: we add a concatenate method to Matrix with the order of the
multiply reversed, which will give the same results as AffineTransform. To
match AffineTransform we could also add a preConcatenate method. The JavaDocs
would then be added so we explain that these two operations are meant to match
AffineTransform and aid to help getting the coordinates for AWT.
{quote}
As per my comment above, the "concatenate" method of AffineTransform provides
the same result as "multiply" so we don't need a new method. Actually,
performing "multiply" in the reverse order is a meaningless operation in PDF
but the Matrix class makes it easy to make this mistake.
Perhaps we should remove the Matrix#multiply method and replace it with a
concatenate method which performs a premultiply? I've found an example of a
backwards multiplication in PDGraphicsState:
{code}
//Compensate for offset
this.currentTransformationMatrix = this.currentTransformationMatrix.multiply(
Matrix.getTranslatingInstance(-page.getLowerLeftX(),
-page.getLowerLeftY()));
{code}
This performs CTM = CTM * m, but it should be CTM = m * CTM.
> Matrix is wrong
> ---------------
>
> Key: PDFBOX-1960
> URL: https://issues.apache.org/jira/browse/PDFBOX-1960
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 1.8.4, 2.0.0
> Reporter: John Hewson
> Assignee: Maruan Sahyoun
> Priority: Critical
>
> I've been driven insane recently by trying to get pattern fills to render
> correctly. Patterns have their own matrix which is concatenated to the CTM
> and no matter how I applied the transformation, the results were wrong.
> It turns out that org.apache.pdfbox.util.Matrix is not behaving as expected,
> here's an example from a pattern I'm working on. I performed the same
> concatenation (i.e. multiplication) using our Matrix and Java's
> AffineTransform, the results are as follows:
> Java AffineTransform:
> [[2.0, 0.0, 1.251E-12], [0.0, 2.0, 1684.0]] *
> [[0.6, 0.0, 302.6], [0.0, 0.6, 1091.38]] =
> [[1.2, 0.0, 605.2000000000013], [0.0, 1.2, 3866.76]]
> PDFBox Matrix:
> [[2.0,0.0,0.0][0.0,2.0,0.0][1.251E-12,1684.0,1.0]] *
> [[0.6,0.0,0.0][0.0,0.6,0.0][302.6,1091.38,1.0]] =
> [[1.2,0.0,0.0][0.0,1.2,0.0][302.6,2101.78,1.0]]
> I suggest that we remove Matrix and replace it with AffineTransform.
--
This message was sent by Atlassian JIRA
(v6.2#6252)