diff --git a/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/LayoutGridService.java b/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/LayoutGridService.java index 92ff832..87a85bf 100644 --- a/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/LayoutGridService.java +++ b/layoutparser-service/layoutparser-service-processor/src/main/java/com/knecon/fforesight/service/layoutparser/processor/services/visualization/LayoutGridService.java @@ -110,11 +110,13 @@ public class LayoutGridService { return; } for (Page page : table.getPages()) { + Optional optionalFirstRowOnPage = table.streamCol(0).filter(tableCell -> tableCell.isOnPage(page.getNumber())).map(TableCell::getRow).findFirst(); if (optionalFirstRowOnPage.isEmpty()) { continue; } int firstRowOnPage = optionalFirstRowOnPage.get(); + Stream xStream = switch (page.getRotation()) { case 90 -> streamBBoxOfCellsOnPage(table.streamCol(0), page).map(RectangularShape::getMinX); case 180 -> streamBBoxOfCellsOnPage(table.streamRow(firstRowOnPage), page).map(RectangularShape::getMaxX); @@ -123,6 +125,7 @@ public class LayoutGridService { }; List xs = xStream.collect(Collectors.toList()); xs.remove(0); + Stream yStream = switch (page.getRotation()) { case 90 -> streamBBoxOfCellsOnPage(table.streamRow(firstRowOnPage), page).map(RectangularShape::getMinY); case 180 -> streamBBoxOfCellsOnPage(table.streamCol(0), page).map(RectangularShape::getMinY); @@ -132,7 +135,7 @@ public class LayoutGridService { List ys = yStream.collect(Collectors.toList()); ys.remove(0); - Rectangle2D tableBBox = table.getBBox().get(table.getFirstPage()); + Rectangle2D tableBBox = table.getBBox().get(page); List coloredLines = layoutGrid.getVisualizationsPerPages().get(page.getNumber() - 1).getColoredLines(); xs.forEach(x -> { Line2D line = new Line2D.Double(new Point2D.Double(x, tableBBox.getMaxY()), new Point2D.Double(x, tableBBox.getMinY()));