From be51a8e7ed665de9b1ef2de467848671698e1fea Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Thu, 12 Oct 2023 21:11:32 +0200 Subject: [PATCH 1/2] Fix area line margin-top of first line after page break (#1443) --- .../engine/nLayout/area/impl/AreaFactory.java | 3 - .../nLayout/area/impl/BlockContainerArea.java | 66 +++++++++---------- .../nLayout/area/impl/ContainerArea.java | 11 +++- .../engine/nLayout/area/impl/LineArea.java | 7 ++ 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/AreaFactory.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/AreaFactory.java index 2e72927138b..422aabfa72e 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/AreaFactory.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/AreaFactory.java @@ -151,9 +151,6 @@ protected AbstractArea createNewArea(ContainerArea parent, LayoutContext context } else { area = new BlockContainerArea(parent, context, content); } - if (context.isFixedLayout()) { - area.setPageBreakInside(IStyle.AVOID_VALUE); - } return area; case IContent.IMAGE_CONTENT: diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/BlockContainerArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/BlockContainerArea.java index 4246a2a7b19..e872fe87167 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/BlockContainerArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/BlockContainerArea.java @@ -290,45 +290,45 @@ protected SplitResult _split(int height, boolean force) throws BirtException { result.add(current); continue; } - contentHeight -= ah; - int childSplitHeight = cheight - contentHeight; - SplitResult splitResult = current.split(childSplitHeight, force && !isValidResult(result)); - if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_PART) { - ContainerArea splitChildArea = splitResult.getResult(); - result.add(splitChildArea); - status = SplitResult.SPLIT_SUCCEED_WITH_PART; - contentHeight += splitChildArea.getAllocatedHeight(); - break; - } else if (splitResult.status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) { - if (force) { - if (result.size() > 0) { - status = SplitResult.SPLIT_SUCCEED_WITH_PART; - } + contentHeight -= ah; + int childSplitHeight = cheight - contentHeight; + SplitResult splitResult = current.split(childSplitHeight, force && !isValidResult(result)); + if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_PART) { + ContainerArea splitChildArea = splitResult.getResult(); + result.add(splitChildArea); + status = SplitResult.SPLIT_SUCCEED_WITH_PART; + contentHeight += splitChildArea.getAllocatedHeight(); + break; + } else if (splitResult.status == SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL) { + if (force) { + if (result.size() > 0) { + status = SplitResult.SPLIT_SUCCEED_WITH_PART; } - break; - } else if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_NULL) { - if (isValidResult(result)) { - if (force) { - status = SplitResult.SPLIT_SUCCEED_WITH_PART; - break; - } - if (previous.isPageBreakAfterAvoid()) { - status = SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL; - break; - } + } + break; + } else if (splitResult.status == SplitResult.SPLIT_SUCCEED_WITH_NULL) { + if (isValidResult(result)) { + if (force) { status = SplitResult.SPLIT_SUCCEED_WITH_PART; break; - } else if (force) { - // error status - status = SplitResult.SPLIT_SUCCEED_WITH_PART; + } + if (previous.isPageBreakAfterAvoid()) { + status = SplitResult.SPLIT_BEFORE_AVOID_WITH_NULL; break; - } else { - if (isPageBreakBeforeAvoid()) { - return SplitResult.BEFORE_AVOID_WITH_NULL; - } - return SplitResult.SUCCEED_WITH_NULL; } + status = SplitResult.SPLIT_SUCCEED_WITH_PART; + break; + } else if (force) { + // error status + status = SplitResult.SPLIT_SUCCEED_WITH_PART; + break; + } else { + if (isPageBreakBeforeAvoid()) { + return SplitResult.BEFORE_AVOID_WITH_NULL; + } + return SplitResult.SUCCEED_WITH_NULL; } + } } // split height is larger than content height.(cell) if (result.size() == children.size()) { diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java index 10c1d617796..b5463bb73af 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java @@ -617,13 +617,22 @@ public void setAllocatedHeight(int aHeight) { } /** - * Get content height + * Get content height, that is the height available for the content. + * + * This is computed as allocatedHeight minus bottom/top margin/border/padding. * * * @param allocatedHeight * @return Return the content height */ public int getContentHeight(int allocatedHeight) { if (hasStyle) { + int contentheight = (allocatedHeight - localProperties.getPaddingBottom() - localProperties.getPaddingTop() + - localProperties.getMarginTop() - localProperties.getMarginBottom() + - boxStyle.getBottomBorderWidth() - boxStyle.getTopBorderWidth()); + if (contentheight < 0) { + + System.out.println("kleiner 0: h = " + contentheight); + } return allocatedHeight - localProperties.getPaddingBottom() - localProperties.getPaddingTop() - localProperties.getMarginTop() - localProperties.getMarginBottom() - boxStyle.getBottomBorderWidth() - boxStyle.getTopBorderWidth(); diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java index 79873553a2c..d5ed8e783a0 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java @@ -552,6 +552,13 @@ public SplitResult split(int height, boolean force) throws BirtException { result.addChild(splitChildArea); splitChildArea.setParent(result); } else { + // reset the line height due to negative height caused by page break. + // Otherwise the first line could be rendered too far down. + // See (old) BIRT bug 562873 and + // https://github.com/eclipse-birt/birt/issues/1443. + if (height < 0) { + height = 0; + } child.setY(Math.max(0, child.getY() - height)); } } From 40a8501dd54c02a560ae3e182a48e2290e8d0718 Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Thu, 12 Oct 2023 21:33:54 +0200 Subject: [PATCH 2/2] Remove debug comment --- .../report/engine/nLayout/area/impl/ContainerArea.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java index b5463bb73af..86a2bfcd45b 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java @@ -626,13 +626,6 @@ public void setAllocatedHeight(int aHeight) { */ public int getContentHeight(int allocatedHeight) { if (hasStyle) { - int contentheight = (allocatedHeight - localProperties.getPaddingBottom() - localProperties.getPaddingTop() - - localProperties.getMarginTop() - localProperties.getMarginBottom() - - boxStyle.getBottomBorderWidth() - boxStyle.getTopBorderWidth()); - if (contentheight < 0) { - - System.out.println("kleiner 0: h = " + contentheight); - } return allocatedHeight - localProperties.getPaddingBottom() - localProperties.getPaddingTop() - localProperties.getMarginTop() - localProperties.getMarginBottom() - boxStyle.getBottomBorderWidth() - boxStyle.getTopBorderWidth();