/** * Sets the rectangle that represent the position and dimension of * the signature field in the page. * * @param pageRect The rectangle that represents the position and * dimension of the signature field in the page. */ public PdfSignatureAppearance setPageRect(Rectangle pageRect) { this.pageRect = new Rectangle(pageRect); this.rect = new Rectangle(pageRect.getWidth(), pageRect.getHeight()); return this; }
do { if (lastLeftAndRightBoxes != null) { float bottomLeft = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getBottom() : Float.MAX_VALUE; float bottomRight = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getBottom() : Float.MAX_VALUE; float updatedHeight = Math.min(bottomLeft, bottomRight) - layoutBox.getY(); topShift = layoutBox.getHeight() - updatedHeight; List<Rectangle> boxesAtYLevel = getBoxesAtYLevel(floatRendererAreas, layoutBox.getTop() - topShift); if (boxesAtYLevel.isEmpty()) { applyClearance(layoutBox, marginsCollapseHandler, topShift, false); 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(); if (left < layoutBox.getLeft()) { left = layoutBox.getLeft(); if (layoutBox.getWidth() > right - left) { layoutBox.setX(left).setWidth(right - left);
private void restoreLayoutBoxAfterFailedLayoutAttempt(Rectangle layoutBox) { layoutBox.setX(backupLayoutBox.getX()).setY(backupLayoutBox.getY()) .setWidth(backupLayoutBox.getWidth()).setHeight(backupLayoutBox.getHeight()); backupCollapseInfo.copyTo(collapseInfo); backupLayoutBox = null; backupCollapseInfo = null; }
void fixOccupiedAreaIfOverflowedX(OverflowPropertyValue overflowX, Rectangle layoutBox) { if (isOverflowFit(overflowX)) { return; } if ((occupiedArea.getBBox().getWidth() > layoutBox.getWidth() || occupiedArea.getBBox().getLeft() < layoutBox.getLeft())) { occupiedArea.getBBox().setX(layoutBox.getX()).setWidth(layoutBox.getWidth()); } }
if (floatRendererAreas.get(floatRendererAreas.size() - 1).getTop() < layoutBox.getTop()) { currY = floatRendererAreas.get(floatRendererAreas.size() - 1).getTop(); } else { currY = layoutBox.getTop(); if (lastLeftAndRightBoxes != null) { if (isFloatLeft) { currY = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getBottom() : lastLeftAndRightBoxes[1].getBottom(); } else { currY = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getBottom() : lastLeftAndRightBoxes[0].getBottom(); layoutBox.setHeight(currY - layoutBox.getY()); List<Rectangle> yLevelBoxes = getBoxesAtYLevel(floatRendererAreas, currY); if (yLevelBoxes.isEmpty()) { left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : layoutBox.getLeft(); right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : layoutBox.getRight(); layoutBox.setX(left); layoutBox.setWidth(right - left);
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; }
outerBorderBox.getTop(), outerBorderBox.getRight(), outerBorderBox.getBottom(), outerBorderBox.getLeft() }; float[] horizontalRadii = calculateRadii(borderRadii, outerBorderBox, true); for (int i = 0; i < 4; i++) { verticalRadii[i] = Math.min(verticalRadii[i], outerBorderBox.getHeight() / 2); horizontalRadii[i] = Math.min(horizontalRadii[i], outerBorderBox.getWidth() / 2); if (!hasNotNullRadius && (0 != verticalRadii[i] || 0 != horizontalRadii[i])) { hasNotNullRadius = true;
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)); } }
/** * Gets the maximum area that the barcode and the text, if * any, will occupy. The lower left corner is always (0, 0). * * @return the size the barcode occupies. */ public Rectangle getBarcodeSize() { Rectangle rect = ean.getBarcodeSize(); rect.setWidth(rect.getWidth() + supp.getBarcodeSize().getWidth() + n); return rect; }
@Override public void draw(PdfCanvas canvas, Rectangle drawArea) { canvas.saveState() .setStrokeColor(color) .setLineWidth(lineWidth) .moveTo(drawArea.getX(), drawArea.getY() + lineWidth / 2) .lineTo(drawArea.getX() + drawArea.getWidth(), drawArea.getY() + lineWidth / 2) .stroke() .restoreState(); }
AffineTransform calculateTransformation(SvgDrawContext context){ Rectangle viewPort = context.getCurrentViewPort(); float horizontal = viewPort.getX(); float vertical = viewPort.getY() + viewPort.getHeight(); // flip coordinate space vertically and translate on the y axis with the viewport height AffineTransform transform = AffineTransform.getTranslateInstance(0,0); //Identity-transform transform.concatenate(AffineTransform.getTranslateInstance(horizontal,vertical)); transform.concatenate(new AffineTransform(1,0,0,-1,0,0)); return transform; }
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 } } }
/** * Gets the copy of this rectangle. * * @return the copied rectangle. */ public Rectangle clone() { return new Rectangle(x, y, width, height); }
static LayoutArea adjustResultOccupiedAreaForFloatAndClear(IRenderer renderer, List<Rectangle> floatRendererAreas, Rectangle parentBBox, float clearHeightCorrection, boolean marginsCollapsingEnabled) { LayoutArea occupiedArea = renderer.getOccupiedArea(); LayoutArea editedArea = occupiedArea; if (isRendererFloating(renderer)) { editedArea = occupiedArea.clone(); if (occupiedArea.getBBox().getWidth() > 0) { floatRendererAreas.add(occupiedArea.getBBox()); } editedArea.getBBox().setY(parentBBox.getTop()); editedArea.getBBox().setHeight(0); } else if (clearHeightCorrection > 0 && !marginsCollapsingEnabled) { editedArea = occupiedArea.clone(); editedArea.getBBox().increaseHeight(clearHeightCorrection); } return editedArea; }
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; }
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; }