private static List<Rectangle> getBoxesAtYLevel(List<Rectangle> floatRendererAreas, float currY) { List<Rectangle> yLevelBoxes = new ArrayList<>(); for (Rectangle box : floatRendererAreas) { if (box.getBottom() + AbstractRenderer.EPS < currY && box.getTop() + AbstractRenderer.EPS >= currY) { yLevelBoxes.add(box); } } return yLevelBoxes; } }
private static List<Rectangle> getBoxesAtYLevel(List<Rectangle> floatRendererAreas, float currY) { List<Rectangle> yLevelBoxes = new ArrayList<>(); for (Rectangle box : floatRendererAreas) { if (box.getBottom() + AbstractRenderer.EPS < currY && box.getTop() + AbstractRenderer.EPS >= currY) { yLevelBoxes.add(box); } } return yLevelBoxes; } }
static void removeFloatsAboveRendererBottom(List<Rectangle> floatRendererAreas, IRenderer renderer) { if (!isRendererFloating(renderer)) { float bottom = renderer.getOccupiedArea().getBBox().getBottom(); for (int i = floatRendererAreas.size() - 1; i >= 0; i--) { if (floatRendererAreas.get(i).getBottom() >= bottom) { floatRendererAreas.remove(i); } } } }
static void removeFloatsAboveRendererBottom(List<Rectangle> floatRendererAreas, IRenderer renderer) { if (!isRendererFloating(renderer)) { float bottom = renderer.getOccupiedArea().getBBox().getBottom(); for (int i = floatRendererAreas.size() - 1; i >= 0; i--) { if (floatRendererAreas.get(i).getBottom() >= bottom) { floatRendererAreas.remove(i); } } } }
void fixOccupiedAreaIfOverflowedY(OverflowPropertyValue overflowY, Rectangle layoutBox) { if (isOverflowFit(overflowY)) { return; } if (occupiedArea.getBBox().getBottom() < layoutBox.getBottom()) { float difference = layoutBox.getBottom() - occupiedArea.getBBox().getBottom(); occupiedArea.getBBox().moveUp(difference).decreaseHeight(difference); } }
void fixOccupiedAreaIfOverflowedY(OverflowPropertyValue overflowY, Rectangle layoutBox) { if (isOverflowFit(overflowY)) { return; } if (occupiedArea.getBBox().getBottom() < layoutBox.getBottom()) { float difference = layoutBox.getBottom() - occupiedArea.getBBox().getBottom(); occupiedArea.getBBox().moveUp(difference).decreaseHeight(difference); } }
static Float calculateLineShiftUnderFloats(List<Rectangle> floatRendererAreas, Rectangle layoutBox) { List<Rectangle> boxesAtYLevel = getBoxesAtYLevel(floatRendererAreas, layoutBox.getTop()); if (boxesAtYLevel.isEmpty()) { return null; } Rectangle[] lastLeftAndRightBoxes = findLastLeftAndRightBoxes(layoutBox, boxesAtYLevel); float left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : layoutBox.getLeft(); float right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : layoutBox.getRight(); if (layoutBox.getLeft() < left || layoutBox.getRight() > right) { float maxLastFloatBottom; if (lastLeftAndRightBoxes[0] != null && lastLeftAndRightBoxes[1] != null) { maxLastFloatBottom = Math.max(lastLeftAndRightBoxes[0].getBottom(), lastLeftAndRightBoxes[1].getBottom()); } else if (lastLeftAndRightBoxes[0] != null) { maxLastFloatBottom = lastLeftAndRightBoxes[0].getBottom(); } else { maxLastFloatBottom = lastLeftAndRightBoxes[1].getBottom(); } return layoutBox.getTop() - maxLastFloatBottom + AbstractRenderer.EPS; } return null; }
static Float calculateLineShiftUnderFloats(List<Rectangle> floatRendererAreas, Rectangle layoutBox) { List<Rectangle> boxesAtYLevel = getBoxesAtYLevel(floatRendererAreas, layoutBox.getTop()); if (boxesAtYLevel.isEmpty()) { return null; } Rectangle[] lastLeftAndRightBoxes = findLastLeftAndRightBoxes(layoutBox, boxesAtYLevel); float left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : layoutBox.getLeft(); float right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : layoutBox.getRight(); if (layoutBox.getLeft() < left || layoutBox.getRight() > right) { float maxLastFloatBottom; if (lastLeftAndRightBoxes[0] != null && lastLeftAndRightBoxes[1] != null) { maxLastFloatBottom = Math.max(lastLeftAndRightBoxes[0].getBottom(), lastLeftAndRightBoxes[1].getBottom()); } else if (lastLeftAndRightBoxes[0] != null) { maxLastFloatBottom = lastLeftAndRightBoxes[0].getBottom(); } else { maxLastFloatBottom = lastLeftAndRightBoxes[1].getBottom(); } return layoutBox.getTop() - maxLastFloatBottom + AbstractRenderer.EPS; } return null; }
protected List<Point> rectangleToPointsList(Rectangle rect) { List<Point> points = new ArrayList<>(); points.addAll(Arrays.asList(new Point(rect.getLeft(), rect.getBottom()), new Point(rect.getRight(), rect.getBottom()), new Point(rect.getRight(), rect.getTop()), new Point(rect.getLeft(), rect.getTop()))); return points; }
protected List<Point> rectangleToPointsList(Rectangle rect) { List<Point> points = new ArrayList<>(); points.addAll(Arrays.asList(new Point(rect.getLeft(), rect.getBottom()), new Point(rect.getRight(), rect.getBottom()), new Point(rect.getRight(), rect.getTop()), new Point(rect.getLeft(), rect.getTop()))); return points; }
/** * Create a new PdfArray. The array is filled with the four values of the Rectangle in the * following order: left, bottom, right, top. * * @param rectangle Rectangle whose 4 values will be added to the PdfArray */ public PdfArray(Rectangle rectangle) { list = new ArrayList<>(4); add(new PdfNumber(rectangle.getLeft())); add(new PdfNumber(rectangle.getBottom())); add(new PdfNumber(rectangle.getRight())); add(new PdfNumber(rectangle.getTop())); }
protected LineRenderer adjustChildrenYLine() { float actualYLine = occupiedArea.getBBox().getY() + occupiedArea.getBBox().getHeight() - maxAscent; for (IRenderer renderer : childRenderers) { if (FloatingHelper.isRendererFloating(renderer)) { continue; } if (renderer instanceof ILeafElementRenderer) { float descent = ((ILeafElementRenderer) renderer).getDescent(); renderer.move(0, actualYLine - renderer.getOccupiedArea().getBBox().getBottom() + descent); } else { Float yLine = isInlineBlockChild(renderer) && renderer instanceof AbstractRenderer ? ((AbstractRenderer) renderer).getLastYLineRecursively() : null; renderer.move(0, actualYLine - (yLine == null ? renderer.getOccupiedArea().getBBox().getBottom() : (float) yLine)); } } return this; }
protected LineRenderer adjustChildrenYLine() { float actualYLine = occupiedArea.getBBox().getY() + occupiedArea.getBBox().getHeight() - maxAscent; for (IRenderer renderer : childRenderers) { if (FloatingHelper.isRendererFloating(renderer)) { continue; } if (renderer instanceof ILeafElementRenderer) { float descent = ((ILeafElementRenderer) renderer).getDescent(); renderer.move(0, actualYLine - renderer.getOccupiedArea().getBBox().getBottom() + descent); } else { Float yLine = isInlineBlockChild(renderer) && renderer instanceof AbstractRenderer ? ((AbstractRenderer) renderer).getLastYLineRecursively() : null; renderer.move(0, actualYLine - (yLine == null ? renderer.getOccupiedArea().getBBox().getBottom() : (float) yLine)); } } return this; }
AbstractRenderer applyMinHeight(OverflowPropertyValue overflowY, Rectangle layoutBox) { AbstractRenderer overflowRenderer = null; Float blockMinHeight = retrieveMinHeight(); if (!Boolean.TRUE.equals(getPropertyAsBoolean(Property.FORCED_PLACEMENT)) && null != blockMinHeight && blockMinHeight > occupiedArea.getBBox().getHeight()) { float blockBottom = occupiedArea.getBBox().getBottom() - ((float) blockMinHeight - occupiedArea.getBBox().getHeight()); if (isFixedLayout()) { occupiedArea.getBBox().setY(blockBottom).setHeight((float) blockMinHeight); } else { if (isOverflowFit(overflowY) && blockBottom < layoutBox.getBottom()) { float hDelta = occupiedArea.getBBox().getBottom() - layoutBox.getBottom(); occupiedArea.getBBox() .increaseHeight(hDelta) .setY(layoutBox.getBottom()); if (occupiedArea.getBBox().getHeight() < 0) { occupiedArea.getBBox().setHeight(0); } this.isLastRendererForModelElement = false; overflowRenderer = createOverflowRenderer(LayoutResult.PARTIAL); overflowRenderer.updateMinHeight(UnitValue.createPointValue((float) blockMinHeight - occupiedArea.getBBox().getHeight())); if (hasProperty(Property.HEIGHT)) { overflowRenderer.updateHeight(UnitValue.createPointValue((float) retrieveHeight() - occupiedArea.getBBox().getHeight())); } } else { occupiedArea.getBBox().setY(blockBottom).setHeight((float) blockMinHeight); } } } return overflowRenderer; }
private void updateMinHeightForAbsolutelyPositionedRenderer(IRenderer renderer, Rectangle parentRendererBox, Float top, Float bottom) { if (top != null && bottom != null && !renderer.hasProperty(Property.HEIGHT)) { UnitValue currentMaxHeight = getPropertyAsUnitValue(renderer, Property.MAX_HEIGHT); UnitValue currentMinHeight = getPropertyAsUnitValue(renderer, Property.MIN_HEIGHT); float resolvedMinHeight = Math.max(0, parentRendererBox.getTop() - (float) top - parentRendererBox.getBottom() - (float) bottom); Rectangle dummy = new Rectangle(0, 0); if (!isBorderBoxSizing(renderer)) { applyPaddings(dummy, getPaddings(renderer), true); applyBorderBox(dummy, getBorders(renderer), true); } applyMargins(dummy, getMargins(renderer), true); resolvedMinHeight -= dummy.getHeight(); if (currentMinHeight != null) { resolvedMinHeight = Math.max(resolvedMinHeight, currentMinHeight.getValue()); } if (currentMaxHeight != null) { resolvedMinHeight = Math.min(resolvedMinHeight, currentMaxHeight.getValue()); } renderer.setProperty(Property.MIN_HEIGHT, UnitValue.createPointValue((float) resolvedMinHeight)); } }
private void updateMinHeightForAbsolutelyPositionedRenderer(IRenderer renderer, Rectangle parentRendererBox, Float top, Float bottom) { if (top != null && bottom != null && !renderer.hasProperty(Property.HEIGHT)) { UnitValue currentMaxHeight = getPropertyAsUnitValue(renderer, Property.MAX_HEIGHT); UnitValue currentMinHeight = getPropertyAsUnitValue(renderer, Property.MIN_HEIGHT); float resolvedMinHeight = Math.max(0, parentRendererBox.getTop() - (float) top - parentRendererBox.getBottom() - (float) bottom); Rectangle dummy = new Rectangle(0, 0); if (!isBorderBoxSizing(renderer)) { applyPaddings(dummy, getPaddings(renderer), true); applyBorderBox(dummy, getBorders(renderer), true); } applyMargins(dummy, getMargins(renderer), true); resolvedMinHeight -= dummy.getHeight(); if (currentMinHeight != null) { resolvedMinHeight = Math.max(resolvedMinHeight, currentMinHeight.getValue()); } if (currentMaxHeight != null) { resolvedMinHeight = Math.min(resolvedMinHeight, currentMaxHeight.getValue()); } renderer.setProperty(Property.MIN_HEIGHT, UnitValue.createPointValue((float) resolvedMinHeight)); } }
protected void applyAbsolutePosition(Rectangle parentRect) { Float top = this.getPropertyAsFloat(Property.TOP); Float bottom = this.getPropertyAsFloat(Property.BOTTOM); Float left = this.getPropertyAsFloat(Property.LEFT); Float right = this.getPropertyAsFloat(Property.RIGHT); if (left == null && right == null && BaseDirection.RIGHT_TO_LEFT.equals(this.<BaseDirection>getProperty(Property.BASE_DIRECTION))) { right = 0f; } if (top == null && bottom == null) { top = 0f; } try { if (right != null) { move(parentRect.getRight() - (float) right - occupiedArea.getBBox().getRight(), 0); } if (left != null) { move(parentRect.getLeft() + (float) left - occupiedArea.getBBox().getLeft(), 0); } if (top != null) { move(0, parentRect.getTop() - (float) top - occupiedArea.getBBox().getTop()); } if (bottom != null) { move(0, parentRect.getBottom() + (float) bottom - occupiedArea.getBBox().getBottom()); } } catch (Exception exc) { Logger logger = LoggerFactory.getLogger(AbstractRenderer.class); logger.error(MessageFormatUtil.format(LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, "Absolute positioning might be applied incorrectly.")); } }
protected void applyAbsolutePosition(Rectangle parentRect) { Float top = this.getPropertyAsFloat(Property.TOP); Float bottom = this.getPropertyAsFloat(Property.BOTTOM); Float left = this.getPropertyAsFloat(Property.LEFT); Float right = this.getPropertyAsFloat(Property.RIGHT); if (left == null && right == null && BaseDirection.RIGHT_TO_LEFT.equals(this.<BaseDirection>getProperty(Property.BASE_DIRECTION))) { right = 0f; } if (top == null && bottom == null) { top = 0f; } try { if (right != null) { move(parentRect.getRight() - (float) right - occupiedArea.getBBox().getRight(), 0); } if (left != null) { move(parentRect.getLeft() + (float) left - occupiedArea.getBBox().getLeft(), 0); } if (top != null) { move(0, parentRect.getTop() - (float) top - occupiedArea.getBBox().getTop()); } if (bottom != null) { move(0, parentRect.getBottom() + (float) bottom - occupiedArea.getBBox().getBottom()); } } catch (Exception exc) { Logger logger = LoggerFactory.getLogger(AbstractRenderer.class); logger.error(MessageFormatUtil.format(LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, "Absolute positioning might be applied incorrectly.")); } }
private void adjustLineOnFloatPlaced(Rectangle layoutBox, int childPos, FloatPropertyValue kidFloatPropertyVal, Rectangle justPlacedFloatBox) { if (justPlacedFloatBox.getBottom() >= layoutBox.getTop() || justPlacedFloatBox.getTop() < layoutBox.getTop()) { return; } boolean ltr = true; // TODO handle it float floatWidth = justPlacedFloatBox.getWidth(); if (kidFloatPropertyVal.equals(FloatPropertyValue.LEFT)) { layoutBox.setWidth(layoutBox.getWidth() - floatWidth).moveRight(floatWidth); occupiedArea.getBBox().moveRight(floatWidth); if (ltr) { for (int i = 0; i < childPos; ++i) { IRenderer prevChild = childRenderers.get(i); if (!FloatingHelper.isRendererFloating(prevChild)) { prevChild.move(floatWidth, 0); } } } } else { layoutBox.setWidth(layoutBox.getWidth() - floatWidth); if (!ltr) { // TODO } } }
private void adjustLineOnFloatPlaced(Rectangle layoutBox, int childPos, FloatPropertyValue kidFloatPropertyVal, Rectangle justPlacedFloatBox) { if (justPlacedFloatBox.getBottom() >= layoutBox.getTop() || justPlacedFloatBox.getTop() < layoutBox.getTop()) { return; } boolean ltr = true; // TODO handle it float floatWidth = justPlacedFloatBox.getWidth(); if (kidFloatPropertyVal.equals(FloatPropertyValue.LEFT)) { layoutBox.setWidth(layoutBox.getWidth() - floatWidth).moveRight(floatWidth); occupiedArea.getBBox().moveRight(floatWidth); if (ltr) { for (int i = 0; i < childPos; ++i) { IRenderer prevChild = childRenderers.get(i); if (!FloatingHelper.isRendererFloating(prevChild)) { prevChild.move(floatWidth, 0); } } } } else { layoutBox.setWidth(layoutBox.getWidth() - floatWidth); if (!ltr) { // TODO } } }