/** * Gets the string representation of rectangle. * * @return the string representation of rectangle. */ @Override public String toString() { return "Rectangle: " + getWidth() + 'x' + getHeight(); }
/** * Make the barcode occupy the specified width. * Usually this is achieved by adjusting bar widths. * @param width The width */ public void fitWidth(float width) { setX(x * width / getBarcodeSize().getWidth()); }
@Override public void fitWidth(float width) { byte[] bars = getBarsPostnet(code); float currentWidth = getBarcodeSize().getWidth(); x *= width / currentWidth; n = (width - x) / (bars.length - 1); }
protected ImageRenderer autoScale(LayoutArea layoutArea) { Rectangle area = layoutArea.getBBox().clone(); applyMargins(area, false); applyBorderBox(area, false); // if rotation was applied, width would be equal to the width of rectangle bounding the rotated image float angleScaleCoef = imageWidth / (float) width; if (width > angleScaleCoef * area.getWidth()) { updateHeight(UnitValue.createPointValue(area.getWidth() / (float)width * imageHeight)); updateWidth(UnitValue.createPointValue(angleScaleCoef * area.getWidth())); } return this; }
protected ImageRenderer autoScale(LayoutArea layoutArea) { Rectangle area = layoutArea.getBBox().clone(); applyMargins(area, false); applyBorderBox(area, false); // if rotation was applied, width would be equal to the width of rectangle bounding the rotated image float angleScaleCoef = imageWidth / (float) width; if (width > angleScaleCoef * area.getWidth()) { updateHeight(UnitValue.createPointValue(area.getWidth() / (float)width * imageHeight)); updateWidth(UnitValue.createPointValue(angleScaleCoef * area.getWidth())); } return this; }
protected float applyBordersPaddingsMargins(Rectangle parentBBox, Border[] borders, UnitValue[] paddings) { float parentWidth = parentBBox.getWidth(); applyMargins(parentBBox, false); applyBorderBox(parentBBox, borders, false); if (isFixedLayout()) { parentBBox.setX((float) this.getPropertyAsFloat(Property.LEFT)); } applyPaddings(parentBBox, paddings, false); return parentWidth - parentBBox.getWidth(); }
/** * Creates the copy of given {@link Rectangle} * * @param rect the copied {@link Rectangle} */ public Rectangle(Rectangle rect) { this(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); }
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()); } }
protected float applyBordersPaddingsMargins(Rectangle parentBBox, Border[] borders, UnitValue[] paddings) { float parentWidth = parentBBox.getWidth(); applyMargins(parentBBox, false); applyBorderBox(parentBBox, borders, false); if (isFixedLayout()) { parentBBox.setX((float) this.getPropertyAsFloat(Property.LEFT)); } applyPaddings(parentBBox, paddings, false); return parentWidth - parentBBox.getWidth(); }
/** * 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; }
/** * Utility method for calculating rotated width of area in a similar way to other calculations in this class. * * @param area the initial area * @param angle the rotation angle in radians * @return width of rotated area */ public static double calculateRotatedWidth(Rectangle area, double angle) { return area.getWidth() * cos(angle) + area.getHeight() * sin(angle); }
private static float calculatePaddingBorderWidth(AbstractRenderer renderer) { Rectangle dummy = new Rectangle(0, 0); renderer.applyBorderBox(dummy, true); renderer.applyPaddings(dummy, true); return dummy.getWidth(); }
/** * Adds {@code PdfImageXObject} to specified rectangle on canvas and scale it using the rectangle's width and height. * * @param image PdfImageXObject to add * @param rect rectangle containing x and y coordinates and scaling information * @return current canvas */ private PdfCanvas addImage(PdfImageXObject image, Rectangle rect) { return addImage(image, rect.getWidth(), 0, 0, rect.getHeight(), rect.getX(), rect.getY()); }
/** * Draws a rectangle. * * @param rectangle a rectangle to be drawn * @return current canvas. */ public PdfCanvas rectangle(Rectangle rectangle) { return rectangle(rectangle.getX(), rectangle.getY(), rectangle.getWidth(), rectangle.getHeight()); }
/** * Creates Image XObject from image and adds it to canvas. * * @param image * @param rect * @param asInline true if to add image as in-line. * @return created XObject or null in case of in-line image (asInline = true). */ public PdfXObject addImage(ImageData image, Rectangle rect, boolean asInline) { return addImage(image, rect.getWidth(), 0, 0, rect.getHeight(), rect.getX(), rect.getY(), asInline); }
@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(); }
@Override public void draw(PdfCanvas canvas, Rectangle drawArea) { canvas.saveState() .setLineWidth(lineWidth) .setStrokeColor(color) .setLineDash(2, 2) .moveTo(drawArea.getX(), drawArea.getY() + lineWidth / 2) .lineTo(drawArea.getX() + drawArea.getWidth(), drawArea.getY() + lineWidth / 2) .stroke() .restoreState(); }
@Override public void draw(PdfCanvas canvas, Rectangle drawArea) { canvas.saveState() .setLineWidth(lineWidth) .setStrokeColor(color) .setLineDash(0, gap, gap / 2) .setLineCapStyle(PdfCanvasConstants.LineCapStyle.ROUND) .moveTo(drawArea.getX(), drawArea.getY() + lineWidth / 2) .lineTo(drawArea.getX() + drawArea.getWidth(), drawArea.getY() + lineWidth / 2) .stroke() .restoreState(); }
public static MinMaxWidth countDefaultMinMaxWidth(IRenderer renderer) { LayoutResult result = renderer.layout(new LayoutContext(new LayoutArea(1, new Rectangle(getInfWidth(), getInfHeight())))); return result.getStatus() == LayoutResult.NOTHING ? new MinMaxWidth() : new MinMaxWidth(0, result.getOccupiedArea().getBBox().getWidth(), 0); }
@Override public LayoutResult layout(LayoutContext layoutContext) { LayoutArea area = layoutContext.getArea(); Float width = retrieveWidth(area.getBBox().getWidth()); UnitValue height = this.<UnitValue>getProperty(Property.MIN_HEIGHT); occupiedArea = new LayoutArea(area.getPageNumber(), new Rectangle(area.getBBox().getX(), area.getBBox().getY() + area.getBBox().getHeight(),(float) width, (float) height.getValue())); return new LayoutResult(LayoutResult.FULL, occupiedArea, null, null); }