AffineTransform trans = new AffineTransform(); trans.concatenate(AffineTransform.getRotateInstance(style.getRotation()*2.0*Math.PI/360.0)); trans.concatenate( AffineTransform.getScaleInstance(1, fontHeightMultiple) ); bounds = layout.getOutline(trans).getBounds(); } else { bounds = layout.getBounds(); final double frameWidth = bounds.getX() + bounds.getWidth(); return Math.max(minWidth, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention());
final Rectangle2D bounds = shape.getBounds2D(); final double ww = bounds.getMaxX() - bounds.getMinX(); final double hh = bounds.getMaxY() - bounds.getMinY(); destination = new BufferedImage((int) w, (int) h, BufferedImage.TYPE_INT_ARGB); final Graphics2D gg = destination.createGraphics(); gg.scale(dpiFactor, dpiFactor); gg.translate(deltaShadow - bounds.getMinX(), deltaShadow - bounds.getMinY()); final boolean isLine = shape instanceof Line2D.Double; if (isLine) { gg.setColor(colorLine); gg.draw(shape); } else {
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; float moveX = 0, moveY = 0; / (float) glyphVector.getLogicalBounds().getWidth() : 1.0f; float height = (float) glyphVector.getLogicalBounds().getHeight(); float nextAdvance = 0; while (currentChar < length && !it.isDone()) { type = it.currentSegment(points); switch (type) { case PathIterator.SEG_MOVETO: Shape glyph = glyphVector.getGlyphOutline(currentChar); Point2D p = glyphVector.getGlyphPosition(currentChar); float px = (float) p.getX(); float py = (float) p.getY(); float x = lastX + next * dx * r; float y = lastY + next * dy * r; break; it.next();
pieBounds.getX() + pieBounds.getWidth() / 2 - annotationRectangle.getWidth() / 2; double yCenter = pieBounds.getY() + pieBounds.getHeight() / 2 + annotationRectangle.getHeight() / 2; Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); g.setColor(pieStyler.getChartFontColor()); g.setFont(pieStyler.getAnnotationsFont()); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); at.translate(xOffset, yOffset); at.translate( xOffset - Math.sin(Math.toRadians(angle - 90)) * annotationWidth / 2 + 3, yOffset);
boolean isScaledUp = pdImage.getWidth() < Math.round(at.getScaleX()) || pdImage.getHeight() < Math.round(at.getScaleY()); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); Rectangle2D bounds = at.createTransformedShape(unitRect).getBounds2D(); BufferedImage renderedPaint = new BufferedImage((int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight()), BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) renderedPaint.getGraphics(); g.translate(-bounds.getMinX(), -bounds.getMinY()); g.setPaint(paint); g.fill(bounds); g.dispose();
AffineTransform temp = graphics.getTransform(); try { IconStyle2D icoStyle = (IconStyle2D) style; Icon icon = icoStyle.getIcon(); graphics.setComposite(icoStyle.getComposite()); AffineTransform at = new AffineTransform(temp); while (!(citer.isDone())) { if (citer.currentSegment(coords) != PathIterator.SEG_MOVETO) { at.setTransform(temp); at.translate(x, y); -(icon.getIconWidth() * icoStyle.getAnchorPointX()), (icon.getIconHeight() * (icoStyle.getAnchorPointY() - 1))); graphics.setTransform(at); new Rectangle2D.Double( x, y, icon.getIconWidth(), icon.getIconHeight())); citer.next(); labelCache.put(transformedShape.getBounds2D());
Rectangle clipBounds = g.getClipBounds(); double leftEdge = clipBounds.getX() + MARGIN; double rightEdge = clipBounds.getMaxX() - MARGIN * 2; double topEdge = clipBounds.getY() + MARGIN; double bottomEdge = clipBounds.getMaxY() - MARGIN * 2; startAngle = styler.getStartAngleInDegrees() + 90; Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); double annotationHeight = annotationBounds.getHeight(); double yOffset = yCenter - sin * yDiameter; Line2D.Double line = new Line2D.Double(xCenter, yCenter, xOffset, yOffset); g.setColor(styler.getPlotGridLinesColor()); g.setStroke(styler.getPlotGridLinesStroke()); g.draw(line); g.setFont(styler.getAnnotationsFont()); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); at.translate(labelX[i], labelY[i]);
g.setFont(styler.getAxisTickLabelsFont()); g.setColor(styler.getAxisTickLabelsColor()); && flippedTickLocation > yOffset Rectangle2D tickLabelBounds = shape.getBounds(); AffineTransform at = new AffineTransform(); xPos = xOffset; at.translate(xPos, flippedTickLocation + tickLabelBounds.getHeight() / 2.0); bounds = new Rectangle2D.Double(xOffset, yOffset, maxTickLabelWidth, height); AffineTransform.getRotateInstance( -1 * Math.toRadians(styler.getXAxisLabelRotation()), 0, 0); Shape shape = textLayout.getOutline(rot); Rectangle2D tickLabelBounds = shape.getBounds2D(); -1 * Math.toRadians(styler.getXAxisLabelRotation()), 0, 0); Shape shape = textLayout.getOutline(rot); Rectangle2D tickLabelBounds = shape.getBounds2D(); new Rectangle2D.Double(xOffset, yOffset - maxTickLabelHeight, width, maxTickLabelHeight); bounds = new Rectangle2D.Double();
clip.intersect(new Area(transformedBox)); Rectangle2D clipRect = clip.getBounds2D(); if (clipRect.isEmpty()) return; this.bbox = new PDRectangle((float)clipRect.getX(), (float)clipRect.getY(), (float)clipRect.getWidth(), (float)clipRect.getHeight()); AffineTransform dpiTransform = AffineTransform.getScaleInstance(Math.abs(m.getScalingFactorX()), Math.abs(m.getScalingFactorY())); Rectangle2D bounds = dpiTransform.createTransformedShape(clip.getBounds2D()).getBounds2D(); minX = (int) Math.floor(bounds.getMinX()); g.drawImage(backdropImage, 0, 0, width, height, backdropX, backdropY, backdropX + width, backdropY + height, null); g = new GroupGraphics(image, g); g.setBackground(new Color(backdropColor.toRGB())); g.clearRect(0, 0, width, height); xform = AffineTransform.getScaleInstance(Math.abs(m.getScalingFactorX()), Math.abs(m.getScalingFactorY())); PDRectangle pageSizeOriginal = pageSize; pageSize = new PDRectangle(minX / Math.abs(m.getScalingFactorX()),
private BufferedImage adjustImage(BufferedImage gray) throws IOException { AffineTransform at = new AffineTransform(xform); Matrix m = new Matrix(at); at.scale(1.0 / Math.abs(m.getScalingFactorX()), 1.0 / Math.abs(m.getScalingFactorY())); Rectangle originalBounds = new Rectangle(gray.getWidth(), gray.getHeight()); Rectangle2D transformedBounds = at.createTransformedShape(originalBounds).getBounds2D(); at.preConcatenate(AffineTransform.getTranslateInstance(-transformedBounds.getMinX(), -transformedBounds.getMinY())); int width = (int) Math.ceil(transformedBounds.getWidth()); int height = (int) Math.ceil(transformedBounds.getHeight()); BufferedImage transformedGray = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2 = (Graphics2D) transformedGray.getGraphics(); g2.drawImage(gray, at, null); g2.dispose(); return transformedGray; }
g2.setFont(getTickLabelFont(tick.getCategory())); g2.setPaint(getTickLabelPaint(tick.getCategory())); x1 = x0 - state.getMax(); Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); if(r==null || !r.intersects(area)) { Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor()); TextBlock block = tick.getLabel(); block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); Shape bounds = block.calculateBounds(g2, r = bounds.getBounds2D(); r.add(r.getMaxX() + r.getWidth()/2, r.getCenterY()); r.add(r.getMinX() - r.getWidth()/2, r.getCenterY()); r.add(r.getCenterX(), r.getMinY() - r.getHeight()/2);
&& line.getLength() < textBounds.getWidth()) return labelCount > 0; AffineTransform tx = new AffineTransform(); while (Math.abs(currOffset) <= labelOffset * 2 && !painted) { tx.setToIdentity(); Rectangle2D labelEnvelope; double maxAngleChange = 0; double startOrdinate = cursor.getCurrentOrdinate() - textBounds.getWidth() / 2; double endOrdinate = cursor.getCurrentOrdinate() + textBounds.getWidth() / 2; labelEnvelope = tx.createTransformedShape(textBounds).getBounds2D(); } else { labelEnvelope = tx.createTransformedShape(textBounds).getBounds2D(); if ((displayArea.contains(labelEnvelope) || labelItem.isPartialsEnabled()) && !(labelItem.isConflictResolutionEnabled() && paintedBounds.labelsWithinDistance( if (labelItem.isConflictResolutionEnabled()) { if (DEBUG_CACHE_BOUNDS) { painter.graphics.setStroke(new BasicStroke()); painter.graphics.setColor(Color.RED); painter.graphics.draw(labelEnvelope);
double x2 = anchor.getX() + anchor.getWidth(), y2 = anchor.getY() + anchor.getHeight(); double alpha = Math.atan(anchor.getHeight() / anchor.getWidth()); AffineTransform at = new AffineTransform(); java.awt.Shape tailShape = null; Path p = null; p = new Path(); tailShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY); bounds = tailShape.getBounds2D(); at.translate(x2 - bounds.getWidth() / 2, y2 - bounds.getHeight() / 2); at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2); break; case STEALTH:
graphics.setComposite(composite); if (transformedShape != null) { if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.fill(transformedShape); labelCache.put(transformedShape.getBounds2D()); Icon icon = icons.getIcon(); AffineTransform markAT = new AffineTransform(graphics.getTransform()); markAT.translate(x, y); markAT.rotate(rotation); new Rectangle2D.Double( x + dx, y + dy, icon.getIconWidth(), icon.getIconHeight()));
ArrayList<Shape> regions = new ArrayList<Shape>(); PathIterator pi = shape.getPathIterator(null); int ii = 0; GeneralPath gp = new GeneralPath(); while (!pi.isDone()) { double[] coords = new double[6]; int pathSegmentType = pi.currentSegment(coords); int windingRule = pi.getWindingRule(); gp.setWindingRule(windingRule); if (pathSegmentType == PathIterator.SEG_MOVETO) { Rectangle r = shape1.getBounds(); System.out.println("shape rect: " + r); int spaceX = sz - r.width; int spaceY = sz - r.height; AffineTransform trans = AffineTransform.getTranslateInstance( -r.x + (spaceX / 2), -r.y + (spaceY / 2)); System.out.println("Box2D " + trans); Shape shapeCentered = trans.createTransformedShape(shape1); Rectangle r1 = region.getBounds(); if (r1.getX() < 0.001 && r1.getY() < 0.001) { } else { g.setColor(bgColor);
at.concatenate(font.getFontMatrix().createAffineTransform()); at.scale(pdfWidth / fontWidth, 1); Shape glyph = at.createTransformedShape(path); bbox = glyph.getBounds2D(); Color color = graphics.getColor(); Stroke stroke = graphics.getStroke(); Shape clip = graphics.getClip();
AffineTransform tx = graphics == null ? null : (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); if (tx == null) { tx = new AffineTransform(); final Rectangle2D anchorO = tx.createTransformedShape(shapeAnchor).getBounds2D(); final double centerX = anchorO.getCenterX(); final double centerY = anchorO.getCenterY(); final AffineTransform txs2 = new AffineTransform(); anchorT = txs2.createTransformedShape(shapeAnchor).getBounds2D(); final double scaleX2 = safeScale(anchorO.getWidth(), anchorT.getWidth()); final double scaleY2 = safeScale(anchorO.getHeight(), anchorT.getHeight()); txs2.translate(-centerX, -centerY); normalizedShape = txs2.createTransformedShape(shapeAnchor).getBounds2D(); final java.awt.Shape anc = tx.createTransformedShape(normalizedShape); return (anc != null) ? anc.getBounds2D() : normalizedShape;
Graphics2D graphics, Shape shape, Style2D graphicFill, double scale) { Rectangle2D boundsShape = shape.getBounds2D(); final Shape markShape = ms2d.getShape(); double size = ms2d.getSize(); Rectangle2D boundsFill = markShape.getBounds2D(); double aspect = (boundsFill.getHeight() > 0 && boundsFill.getWidth() > 0) ? boundsFill.getWidth() / boundsFill.getHeight() : 1.0; stippleSize = new Rectangle2D.Double(0, 0, size * aspect, size); clippedGraphics.clip(shape); LineStyle2D lineStyle = new LineStyle2D(); lineStyle.setStroke(ms2d.getStroke()); lineStyle.setContourComposite(ms2d.getContourComposite()); lineStyle.setGraphicStroke(ms2d.getGraphicStroke()); filler.fillRectangle(shape.getBounds2D(), this, clippedGraphics, lineStyle); return; Graphics2D g = (Graphics2D) graphics.create(); Rectangle2D boundsClip = clipShape.getBounds2D(); AffineTransform2D identityTransf = new AffineTransform2D(new AffineTransform()); Decimator nullDecimator = new Decimator(-1, -1);
public boolean drawImage(Image img, int x, int y, ImageObserver observer) { Image image = null; if (transformer instanceof ShapeFlatnessTransformer) { Rectangle2D r = new Rectangle2D.Double(x, y, img.getWidth(observer), img.getHeight(observer)); Rectangle2D s = ((ShapeTransformer) transformer).transform(r).getBounds2D(); image = img.getScaledInstance((int) s.getWidth(), (int) s.getHeight(), Image.SCALE_SMOOTH); x = (int) s.getMinX(); y = (int) s.getMinY(); } else { image = img; } return delegate.drawImage(image, x, y, observer); }
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.black); g2d.setTransform( AffineTransform.getTranslateInstance( -shp.getBounds().getMinX(), -shp.getBounds().getMinY())); g2d.draw(shp); g2d.dispose(); } }