/** * Calculate the transformation for the viewport based on the context. Only used by elements that can create viewports * * @param context the SVG draw context * @return the transformation that needs to be applied to this renderer */ AffineTransform calculateViewPortTranslation(SvgDrawContext context) { Rectangle viewPort = context.getCurrentViewPort(); AffineTransform transform; transform = AffineTransform.getTranslateInstance(viewPort.getX(), viewPort.getY()); return transform; }
/** * 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()); }
/** * Adds {@code PdfFormXObject} to specified rectangle on canvas and scale it using the rectangle's width and height. * * @param form PdfFormXObject to add * @param rect rectangle containing x and y coordinates and scaling information * @return current canvas. */ private PdfCanvas addForm(PdfFormXObject form, Rectangle rect) { return addForm(form, rect.getWidth(), 0, 0, rect.getHeight(), rect.getX(), rect.getY()); }
/** * 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()); }
/** * Moves the vertical position to the parameter's value. * * @param y the new vertical position of the Text */ public void moveYLineTo(float y) { float curYLine = getYLine(); float delta = y - curYLine; occupiedArea.getBBox().setY(occupiedArea.getBBox().getY() + delta); }
/** * 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); }
void correctFixedLayout(Rectangle layoutBox) { if (isFixedLayout()) { float y = (float) this.getPropertyAsFloat(Property.BOTTOM); move(0, y - occupiedArea.getBBox().getY()); } }
/** * Appends a rectangle to the current path as a complete subpath. */ public void rectangle(Rectangle rect) { rectangle(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); }
/** * Moves the vertical position to the parameter's value. * * @param y the new vertical position of the Text */ public void moveYLineTo(float y) { float curYLine = getYLine(); float delta = y - curYLine; occupiedArea.getBBox().setY(occupiedArea.getBBox().getY() + delta); }
@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(); }
private void applyFixedXOrYPosition(boolean isXPosition, Rectangle layoutBox) { if (isPositioned()) { if (isFixedLayout()) { if (isXPosition) { float x = (float) this.getPropertyAsFloat(Property.LEFT); layoutBox.setX(x); } else { float y = (float) this.getPropertyAsFloat(Property.BOTTOM); move(0, y - occupiedArea.getBBox().getY()); } } } }
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; }
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 restoreLayoutBoxAfterFailedLayoutAttempt(Rectangle layoutBox) { layoutBox.setX(backupLayoutBox.getX()).setY(backupLayoutBox.getY()) .setWidth(backupLayoutBox.getWidth()).setHeight(backupLayoutBox.getHeight()); backupCollapseInfo.copyTo(collapseInfo); backupLayoutBox = null; backupCollapseInfo = null; }
private void applyConcatMatrix(DrawContext drawContext, Float angle) { AffineTransform rotationTransform = AffineTransform.getRotateInstance((float) angle); Rectangle rect = getBorderAreaBBox(); List<Point> rotatedPoints = transformPoints(rectangleToPointsList(rect), rotationTransform); float[] shift = calculateShiftToPositionBBoxOfPointsAt(rect.getX(), rect.getY() + rect.getHeight(), rotatedPoints); double[] matrix = new double[6]; rotationTransform.getMatrix(matrix); drawContext.getCanvas().concatMatrix(matrix[0], matrix[1], matrix[2], matrix[3], shift[0], shift[1]); }
private void applyConcatMatrix(DrawContext drawContext, Float angle) { AffineTransform rotationTransform = AffineTransform.getRotateInstance((float) angle); Rectangle rect = getBorderAreaBBox(); List<Point> rotatedPoints = transformPoints(rectangleToPointsList(rect), rotationTransform); float[] shift = calculateShiftToPositionBBoxOfPointsAt(rect.getX(), rect.getY() + rect.getHeight(), rotatedPoints); double[] matrix = new double[6]; rotationTransform.getMatrix(matrix); drawContext.getCanvas().concatMatrix(matrix[0], matrix[1], matrix[2], matrix[3], shift[0], shift[1]); }
@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); }
@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); }