[ 
https://issues.apache.org/jira/browse/PDFBOX-4126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16375700#comment-16375700
 ] 

Alexandre edited comment on PDFBOX-4126 at 2/24/18 6:06 PM:
------------------------------------------------------------

More generally...
{code:java}
import org.apache.mahout.math.QRDecomposition;
import org.apache.mahout.math.DenseMatrix;
import org.apache.mahout.math.*;
import org.apache.pdfbox.text.TextPosition;

public class TextPositionAdvanced {
        TextPosition _textPosition;
        DenseMatrix _denseMatrix;
        QRDecomposition _qr;
        
        public TextPositionAdvanced(TextPosition textPosition) {
                _textPosition = textPosition;
                org.apache.pdfbox.util.Matrix matrix = 
_textPosition.getTextMatrix();
                
                _denseMatrix = new DenseMatrix(3,3);
                _denseMatrix.set(0, 0, matrix.getScaleX()); // a
                _denseMatrix.set(0, 1, matrix.getShearY()); // b
                _denseMatrix.set(0, 2, 0);
                _denseMatrix.set(1, 0, matrix.getShearX()); // c
                _denseMatrix.set(1, 1, matrix.getScaleY()); // d
                _denseMatrix.set(1, 2, 0);
                _denseMatrix.set(2, 0, matrix.getTranslateX()); // tx
                _denseMatrix.set(2, 1, matrix.getTranslateY()); // ty
                _denseMatrix.set(2, 2, 1);
        
                _qr = new QRDecomposition(_denseMatrix.transpose());
        }
        
        public String toString() {
                return _textPosition.toString() + "angle: " + this.getAngle();
        }
        
        public double getAngle() {
                return this.getEulerAngles(_qr.getQ());
        }
        
        public double getEulerAngles(Matrix R) {
                return Math.toDegrees(Math.atan2(-R.get(0, 1), R.get(0, 0)));
        }
}

{code}


was (Author: arelaxend):
More generally...
{code:java}
import org.apache.mahout.math.QRDecomposition;

import org.apache.mahout.math.DenseMatrix;

import org.apache.mahout.math.*;

import org.apache.pdfbox.text.TextPosition;



public class TextPositionAdvanced {

TextPosition _textPosition;

DenseMatrix _denseMatrix;

QRDecomposition _qr;


public TextPositionAdvanced(TextPosition textPosition) {

_textPosition = textPosition;

org.apache.pdfbox.util.Matrix matrix = _textPosition.getTextMatrix();


_denseMatrix = new DenseMatrix(3,3);

_denseMatrix.set(0, 0, matrix.getScaleX()); // a

_denseMatrix.set(0, 1, matrix.getShearY()); // b

_denseMatrix.set(0, 2, 0);

_denseMatrix.set(1, 0, matrix.getShearX()); // c

_denseMatrix.set(1, 1, matrix.getScaleY()); // d

_denseMatrix.set(1, 2, 0);

_denseMatrix.set(2, 0, matrix.getTranslateX()); // tx

_denseMatrix.set(2, 1, matrix.getTranslateY()); // ty

_denseMatrix.set(2, 2, 1);

        

_qr = new QRDecomposition(_denseMatrix.transpose());

}


public String toString() {

return _textPosition.toString() + "angle: " + this.getAngle();

}


public double getAngle() {

return this.getEulerAngles(_qr.getQ());

}


public double getEulerAngles(Matrix R) {

return Math.toDegrees(Math.atan2(-R.get(0, 1), R.get(0, 0)));

}

}
{code}

> TextPosition exact angle position
> ---------------------------------
>
>                 Key: PDFBOX-4126
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4126
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: Text extraction
>    Affects Versions: 2.0.8
>            Reporter: Alexandre
>            Priority: Minor
>         Attachments: test_rotation.pdf
>
>
> Dear Apache contributors,
> Is there an efficient way to get the exact angle in radians or degrees of a 
> TextPosition, not only the ranges (0, 90, 180, 270). Basically, what we have 
> currently uses the following information.
>  
> {code:java}
> float a = textMatrix.getScaleY();
> float b = textMatrix.getShearY();
> float c = textMatrix.getShearX();
> float d = textMatrix.getScaleX();
> {code}
> Hagd, A.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to