float margin = 72; float width = mediabox.getWidth() - 2*margin; float startX = mediabox.getLowerLeftX() + margin; float startY = mediabox.getUpperRightY() - margin;
float margin = 72; float width = mediabox.getWidth() - 2*margin; float startX = mediabox.getLowerLeftX() + margin; float startY = mediabox.getUpperRightY() - margin;
/** * This will get the width of this rectangle as calculated by * upperRightX - lowerLeftX. * * @return The width of this rectangle. */ public float getWidth() { return getUpperRightX() - getLowerLeftX(); }
protected boolean isNonZeroBoundingBox (PDRectangle bbox) { return bbox != null && ( Float.compare(bbox.getLowerLeftX(), 0) != 0 || Float.compare(bbox.getLowerLeftY(), 0) != 0 || Float.compare(bbox.getUpperRightX(), 0) != 0 || Float.compare(bbox.getUpperRightY(), 0) != 0 ); }
/** * Returns a general path equivalent to this rectangle. This method avoids the problems * caused by Rectangle2D not working well with -ve rectangles. */ public GeneralPath toGeneralPath() { float x1 = getLowerLeftX(); float y1 = getLowerLeftY(); float x2 = getUpperRightX(); float y2 = getUpperRightY(); GeneralPath path = new GeneralPath(); path.moveTo(x1, y1); path.lineTo(x2, y1); path.lineTo(x2, y2); path.lineTo(x1, y2); path.closePath(); return path; }
public Rectangle2D getBounds() { Point2D size = new Point2D.Double(pageSize.getWidth(), pageSize.getHeight()); // apply the underlying Graphics2D device's DPI transform and y-axis flip Matrix m = new Matrix(xform); AffineTransform dpiTransform = AffineTransform.getScaleInstance(Math.abs(m.getScalingFactorX()), Math.abs(m.getScalingFactorY())); size = dpiTransform.transform(size, size); // Flip y return new Rectangle2D.Double(minX - pageSize.getLowerLeftX() * Math.abs(m.getScalingFactorX()), size.getY() - minY - height + pageSize.getLowerLeftY() * Math.abs(m.getScalingFactorY()), width, height); } }
protected ObjectExtractorStreamEngine(PDPage page) { super(page); this.log = LoggerFactory.getLogger(ObjectExtractorStreamEngine.class); this.rulings = new ArrayList<>(); this.pageTransform = null; // calculate page transform PDRectangle cb = this.getPage().getCropBox(); int rotation = this.getPage().getRotation(); this.pageTransform = new AffineTransform(); if (Math.abs(rotation) == 90 || Math.abs(rotation) == 270) { this.pageTransform = AffineTransform.getRotateInstance(rotation * (Math.PI / 180.0), 0, 0); this.pageTransform.concatenate(AffineTransform.getScaleInstance(1, -1)); } else { this.pageTransform.concatenate(AffineTransform.getTranslateInstance(0, cb.getHeight())); this.pageTransform.concatenate(AffineTransform.getScaleInstance(1, -1)); } this.pageTransform.translate(-cb.getLowerLeftX(), -cb.getLowerLeftY()); }
private void setTransformationMatrix(PDAppearanceStream appearanceStream) { PDRectangle bbox = getRectangle(); appearanceStream.setBBox(bbox); AffineTransform transform = AffineTransform.getTranslateInstance(-bbox.getLowerLeftX(), -bbox.getLowerLeftY()); appearanceStream.setMatrix(transform); }
/** * This will return a string representation of this rectangle. * * @return This object as a string. */ @Override public String toString() { return "[" + getLowerLeftX() + "," + getLowerLeftY() + "," + getUpperRightX() + "," + getUpperRightY() +"]"; } }
/** * Method to determine if the x/y point is inside this rectangle. * @param x The x-coordinate to test. * @param y The y-coordinate to test. * @return True if the point is inside this rectangle. */ public boolean contains( float x, float y ) { float llx = getLowerLeftX(); float urx = getUpperRightX(); float lly = getLowerLeftY(); float ury = getUpperRightY(); return x >= llx && x <= urx && y >= lly && y <= ury; }
/** * Clips the given box to the bounds of the media box. */ private PDRectangle clipToMediaBox(PDRectangle box) { PDRectangle mediaBox = getMediaBox(); PDRectangle result = new PDRectangle(); result.setLowerLeftX(Math.max(mediaBox.getLowerLeftX(), box.getLowerLeftX())); result.setLowerLeftY(Math.max(mediaBox.getLowerLeftY(), box.getLowerLeftY())); result.setUpperRightX(Math.min(mediaBox.getUpperRightX(), box.getUpperRightX())); result.setUpperRightY(Math.min(mediaBox.getUpperRightY(), box.getUpperRightY())); return result; }
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null && (Float.compare(bbox.getLowerLeftX(), 0) != 0 || Float.compare(bbox.getLowerLeftY(), 0) != 0 || Float.compare(bbox.getUpperRightX(), 0) != 0 || Float.compare(bbox.getUpperRightY(), 0) != 0)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return ttf.getFontBBox(); }
/** * Get a padded rectangle. * * <p>Creates a new rectangle with padding applied to each side. * . * @param rectangle the rectangle. * @param padding the padding to apply. * @return the padded rectangle. */ PDRectangle getPaddedRectangle(PDRectangle rectangle, float padding) { return new PDRectangle(rectangle.getLowerLeftX() + padding, rectangle.getLowerLeftY() + padding, rectangle.getWidth() - 2 * padding, rectangle.getHeight() - 2 * padding); }
/** * Apply padding to a box. * * @param box box * @return the padded box. */ private PDRectangle applyPadding(PDRectangle box, float padding) { return new PDRectangle(box.getLowerLeftX() + padding, box.getLowerLeftY() + padding, box.getWidth() - 2 * padding, box.getHeight() - 2 * padding); } }
/** * Returns the updated <code>RD</code> entry for Square and Circle annotations. * * @return Annotation <code>RD</code> value. */ PDRectangle getRectDifference() { if (annotRect == null) { float d = (float)lineWidth / 2; return new PDRectangle(d, d, (float)lineWidth, (float)lineWidth); } PDRectangle re = (rectWithDiff != null) ? rectWithDiff : annotRect; float left = re.getLowerLeftX() - (float)bboxMinX; float bottom = re.getLowerLeftY() - (float)bboxMinY; float right = (float)bboxMaxX - re.getUpperRightX(); float top = (float)bboxMaxY - re.getUpperRightY(); return new PDRectangle(left, bottom, right - left, top - bottom); }
/** * Creates a cloudy border for a Circle annotation. * The ellipse is specified by the <code>RD</code> entry and the * <code>Rect</code> entry that was passed in to the constructor. * * @param rd entry <code>RD</code>, or null if the entry does not exist * @throws IOException If there is an error writing to the stream. */ void createCloudyEllipse(PDRectangle rd) throws IOException { rectWithDiff = applyRectDiff(rd, 0); double left = rectWithDiff.getLowerLeftX(); double bottom = rectWithDiff.getLowerLeftY(); double right = rectWithDiff.getUpperRightX(); double top = rectWithDiff.getUpperRightY(); cloudyEllipseImpl(left, bottom, right, top); finish(); }
/** * This will find the CropBox with rotation applied, for this page by looking up the hierarchy * until it finds them. * * @return The CropBox at this level in the hierarchy. */ static PDRectangle getRotatedCropBox(PDPage page) { PDRectangle cropBox = page.getCropBox(); int rotationAngle = page.getRotation(); if (rotationAngle == 90 || rotationAngle == 270) { return new PDRectangle(cropBox.getLowerLeftY(), cropBox.getLowerLeftX(), cropBox.getHeight(), cropBox.getWidth()); } else { return cropBox; } }
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return ttf.getFontBBox(); }
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (isNonZeroBoundingBox(bbox)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return genericFont.getFontBBox(); }
private BoundingBox generateBoundingBox() throws IOException { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (isNonZeroBoundingBox(bbox)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } return genericFont.getFontBBox(); }