/** * Get the rectangle representation of the intersection between this rectangle and the passed rectangle * * @param rect the rectangle to find the intersection with * @return the intersection rectangle if the passed rectangles intersects with this rectangle, * a rectangle representing a line if the intersection is along an edge or * a rectangle representing a point if the intersection is a single point, * null otherwise */ public Rectangle getIntersection(Rectangle rect) { Rectangle result = null; //Calculate possible lower-left corner and upper-right corner float llx = Math.max(x, rect.x); float lly = Math.max(y, rect.y); float urx = Math.min(getRight(), rect.getRight()); float ury = Math.min(getTop(), rect.getTop()); //If width or height is non-negative, there is overlap and we can construct the intersection rectangle float width = urx - llx; float height = ury - lly; if (Float.compare(width, 0) >= 0 && Float.compare(height, 0) >= 0) { if (Float.compare(width, 0) < 0) width = 0; if (Float.compare(height, 0) < 0) height = 0; result = new Rectangle(llx, lly, width, height); } return result; }
private static void adjustBoxForFloatRight(Rectangle layoutBox, float blockWidth) { layoutBox.setX(layoutBox.getRight() - blockWidth); layoutBox.setWidth(blockWidth); }
private static void adjustBoxForFloatRight(Rectangle layoutBox, float blockWidth) { layoutBox.setX(layoutBox.getRight() - blockWidth); layoutBox.setWidth(blockWidth); }
private static Rectangle[] findLastLeftAndRightBoxes(Rectangle layoutBox, List<Rectangle> yLevelBoxes) { Rectangle lastLeftFloatAtY = null; Rectangle lastRightFloatAtY = null; float left = layoutBox.getLeft(); for (Rectangle box : yLevelBoxes) { if (box.getLeft() < left) { left = box.getLeft(); } } for (Rectangle box : yLevelBoxes) { if (left >= box.getLeft() && left < box.getRight()) { lastLeftFloatAtY = box; left = box.getRight(); } else { lastRightFloatAtY = box; } } return new Rectangle[] {lastLeftFloatAtY, lastRightFloatAtY}; }
private static Rectangle[] findLastLeftAndRightBoxes(Rectangle layoutBox, List<Rectangle> yLevelBoxes) { Rectangle lastLeftFloatAtY = null; Rectangle lastRightFloatAtY = null; float left = layoutBox.getLeft(); for (Rectangle box : yLevelBoxes) { if (box.getLeft() < left) { left = box.getLeft(); } } for (Rectangle box : yLevelBoxes) { if (left >= box.getLeft() && left < box.getRight()) { lastLeftFloatAtY = box; left = box.getRight(); } else { lastRightFloatAtY = box; } } return new Rectangle[] {lastLeftFloatAtY, lastRightFloatAtY}; }
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; }
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; }
private void applyRotation(PdfPage page) { Rectangle rectangle = page.getPageSizeWithRotation(); int rotation = page.getRotation(); switch (rotation) { case 90: concatMatrix(0, 1, -1, 0, rectangle.getTop(), 0); break; case 180: concatMatrix(-1, 0, 0, -1, rectangle.getRight(), rectangle.getTop()); break; case 270: concatMatrix(0, -1, 1, 0, 0, rectangle.getRight()); break; } }
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; }
left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : Float.MIN_VALUE; right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : Float.MAX_VALUE; if (left > right || left > layoutBox.getRight() || right < layoutBox.getLeft()) { left = layoutBox.getLeft(); right = left; } else { if (right > layoutBox.getRight()) { right = layoutBox.getRight();
left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : Float.MIN_VALUE; right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : Float.MAX_VALUE; if (left > right || left > layoutBox.getRight() || right < layoutBox.getLeft()) { left = layoutBox.getLeft(); right = left; } else { if (right > layoutBox.getRight()) { right = layoutBox.getRight();
/** * 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 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.")); } }
outerBorderBox.getRight(), outerBorderBox.getBottom(), outerBorderBox.getLeft()