RSS-83: More improvements for section detection 2

This commit is contained in:
deiflaender 2022-10-10 09:15:40 +02:00
parent d669f92a7d
commit 2ca8a4cf6b
2 changed files with 7 additions and 19 deletions

View File

@ -44,10 +44,9 @@ public class ClassificationService {
for (Page page : document.getPages()) {
Rectangle btf = page.isLandscape() ? landscapeBodyTextFrame : bodyTextFrame;
// if (page.getRotation() == 180 || page.getRotation() == 270){
System.out.println(btf);
btf = getRectangle(btf, page.getRotation(), page.getCropbox());
// }
if (!page.isLandscape() && page.getRotation() == 270){
btf = getRectangle(btf, page.getCropbox());
}
System.out.println("CropBoxArea" + page.getCropBoxArea());
page.setBodyTextFrame(btf);
classifyPage(btf, page, document, headlineFontSizes);
@ -56,11 +55,10 @@ public class ClassificationService {
public Rectangle getRectangle(Rectangle rectangle, int rotation, PDRectangle cropbox) {
public Rectangle getRectangle(Rectangle rectangle, PDRectangle cropbox) {
Point2D bottomLeft = new Point2D.Double(rectangle.getMinX(), rectangle.getMinY());
Point2D topRight = new Point2D.Double(rectangle.getMaxX(), rectangle.getMaxY());
AffineTransform transform = new AffineTransform();
@ -70,19 +68,9 @@ public class ClassificationService {
transform.rotate(Math.toRadians(180), 0, 0);
transform.translate(-ty, -ty);
bottomLeft = transform.transform(bottomLeft, null);
topRight = transform.transform(topRight, null);
// var r = new Rectangle((float)bottomLeft.getX(),(float) rectangle.getX() + (float) rectangle.getWidth(), (float)topRight.getX()- (float)bottomLeft.getX(), (float)topRight.getY()-(float) bottomLeft.getY());
var r = new Rectangle((float)bottomLeft.getX() - (float) rectangle.getHeight(),(float) rectangle.getX(), (float) rectangle.getWidth(), (float) rectangle.getHeight());
System.out.println(r);
return r;
return new Rectangle((float)bottomLeft.getX() - (float) rectangle.getHeight(),(float) rectangle.getX(), (float) rectangle.getWidth(), (float) rectangle.getHeight());
}

View File

@ -37,10 +37,10 @@ public class PositionUtils {
return false;
}
if ((textBlock.getRotation() == 0 || textBlock.getRotation() == 180) && textBlock.getMinX() < btf.getX()) {
if ((textBlock.getRotation() == 0 || textBlock.getRotation() == 180) && textBlock.getMinY() > btf.getY() + btf.getHeight()) {
// Its very strange, P{0,0} is on top left in this case, instead of lower left.
return true;
} else if ((textBlock.getRotation() == 90 || textBlock.getRotation() == 270) && textBlock.getMinY() > btf.getY() + btf.getHeight()) {
} else if ((textBlock.getRotation() == 90 || textBlock.getRotation() == 270) && textBlock.getMinX() < btf.getX()) {
return true;
} else {
return false;