Java Code Examples for java.awt.geom.Rectangle2D#Float
The following examples show how to use
java.awt.geom.Rectangle2D#Float .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedTextSourceLabel.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public Rectangle2D createItalicBounds() { float ia = cm.italicAngle; Rectangle2D lb = getLogicalBounds(); float l = (float)lb.getMinX(); float t = -cm.ascent; float r = (float)lb.getMaxX(); float b = cm.descent; if (ia != 0) { if (ia > 0) { l -= ia * (b - cm.ssOffset); r -= ia * (t - cm.ssOffset); } else { l -= ia * (t - cm.ssOffset); r -= ia * (b - cm.ssOffset); } } return new Rectangle2D.Float(l, t, r - l, b - t); }
Example 2
Source File: RenderTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private TexturePaint makeTexturePaint(int size, boolean alpha) { int s2 = size / 2; int type = alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; BufferedImage img = new BufferedImage(size, size, type); Color[] colors = makeGradientColors(4, alpha); Graphics2D g2d = img.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.setColor(colors[0]); g2d.fillRect(0, 0, s2, s2); g2d.setColor(colors[1]); g2d.fillRect(s2, 0, s2, s2); g2d.setColor(colors[3]); g2d.fillRect(0, s2, s2, s2); g2d.setColor(colors[2]); g2d.fillRect(s2, s2, s2, s2); g2d.dispose(); Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size); return new TexturePaint(img, bounds); }
Example 3
Source File: RenderTests.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private TexturePaint makeTexturePaint(int size, boolean alpha) { int s2 = size / 2; int type = alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; BufferedImage img = new BufferedImage(size, size, type); Color[] colors = makeGradientColors(4, alpha); Graphics2D g2d = img.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.setColor(colors[0]); g2d.fillRect(0, 0, s2, s2); g2d.setColor(colors[1]); g2d.fillRect(s2, 0, s2, s2); g2d.setColor(colors[3]); g2d.fillRect(0, s2, s2, s2); g2d.setColor(colors[2]); g2d.fillRect(s2, s2, s2, s2); g2d.dispose(); Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size); return new TexturePaint(img, bounds); }
Example 4
Source File: ParticleFeeder.java From energy2d with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ParticleFeeder duplicate() { float x = 0; float y = 0; Shape s = getShape(); if (s instanceof Rectangle2D.Float) { Rectangle2D.Float r = (Rectangle2D.Float) s; x = r.x + 0.5f * r.width; y = r.y + 0.5f * r.height; } ParticleFeeder pf = new ParticleFeeder(x, y); pf.mass = mass; pf.radius = radius; pf.period = period; pf.maximum = maximum; pf.color = color; pf.velocityColor = velocityColor; return pf; }
Example 5
Source File: Thermometer.java From energy2d with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Thermometer duplicate() { float x = 0; float y = 0; if (getShape() instanceof Rectangle2D.Float) { Rectangle2D.Float r = (Rectangle2D.Float) getShape(); x = r.x + 0.5f * r.width; y = r.y + 0.5f * r.height; } else { // TODO: none-rectangular shape } return new Thermometer(x, y); }
Example 6
Source File: SVGImageExporter.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override @Nonnull public Rectangle2D getStringBounds(@Nonnull final String str) { if (str.isEmpty()) { return this.context.getFontMetrics().getStringBounds("", this.context); } else { final TextLayout textLayout = new TextLayout(str, this.context.getFont(), this.context.getFontRenderContext()); return new Rectangle2D.Float(0, -textLayout.getAscent(), textLayout.getAdvance(), textLayout.getAscent() + textLayout.getDescent() + textLayout.getLeading()); } }
Example 7
Source File: AffineTransformOp.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns the bounding box of the transformed destination. The * rectangle returned will be the actual bounding box of the * transformed points. The coordinates of the upper-left corner * of the returned rectangle might not be (0, 0). * * @param src The <CODE>Raster</CODE> to be transformed. * * @return The <CODE>Rectangle2D</CODE> representing the destination's * bounding box. */ public final Rectangle2D getBounds2D (Raster src) { int w = src.getWidth(); int h = src.getHeight(); // Get the bounding box of the src and transform the corners float[] pts = {0, 0, w, 0, w, h, 0, h}; xform.transform(pts, 0, pts, 0, 4); // Get the min, max of the dst float fmaxX = pts[0]; float fmaxY = pts[1]; float fminX = pts[0]; float fminY = pts[1]; for (int i=2; i < 8; i+=2) { if (pts[i] > fmaxX) { fmaxX = pts[i]; } else if (pts[i] < fminX) { fminX = pts[i]; } if (pts[i+1] > fmaxY) { fmaxY = pts[i+1]; } else if (pts[i+1] < fminY) { fminY = pts[i+1]; } } return new Rectangle2D.Float(fminX, fminY, fmaxX-fminX, fmaxY-fminY); }
Example 8
Source File: Font.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns the bounds for the character with the maximum * bounds as defined in the specified <code>FontRenderContext</code>. * <p>Note: The returned bounds is in baseline-relative coordinates * (see {@link java.awt.Font class notes}). * @param frc the specified <code>FontRenderContext</code> * @return a <code>Rectangle2D</code> that is the bounding box * for the character with the maximum bounds. */ public Rectangle2D getMaxCharBounds(FontRenderContext frc) { float [] metrics = new float[4]; getFont2D().getFontMetrics(this, frc, metrics); return new Rectangle2D.Float(0, -metrics[0], metrics[3], metrics[0] + metrics[1] + metrics[2]); }
Example 9
Source File: AbstractBlock.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Creates a new block. */ protected AbstractBlock() { this.id = null; this.width = 0.0; this.height = 0.0; this.bounds = new Rectangle2D.Float(); this.margin = RectangleInsets.ZERO_INSETS; this.frame = BlockBorder.NONE; this.padding = RectangleInsets.ZERO_INSETS; }
Example 10
Source File: TransformedPaintTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private Paint createPaint(PaintType type, int startx, int starty, int w, int h) { // make sure that the blue color doesn't show up when filling a // w by h rect w++; h++; int endx = startx + w; int endy = starty + h; Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h); switch (type) { case COLOR: return Color.red; case GRADIENT: return new GradientPaint(startx, starty, Color.red, endx, endy, Color.green); case LINEAR_GRADIENT: return new LinearGradientPaint(startx, starty, endx, endy, new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue }); case RADIAL_GRADIENT: return new RadialGradientPaint(startx, starty, (float)Math.sqrt(w * w + h * h), new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue }, CycleMethod.NO_CYCLE); case TEXTURE: { BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h)); g.fillRect(0, 0, w, h); return new TexturePaint(bi, r); } } return Color.green; }
Example 11
Source File: FileFontStrike.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) { if (boundsMap == null) { boundsMap = new ConcurrentHashMap<Integer, Rectangle2D.Float>(); } Integer key = Integer.valueOf(glyphCode); Rectangle2D.Float bounds = boundsMap.get(key); if (bounds == null) { bounds = fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode); boundsMap.put(key, bounds); } return bounds; }
Example 12
Source File: FileFont.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext, int glyphCode) { try { return getScaler().getGlyphOutlineBounds(pScalerContext, glyphCode); } catch (FontScalerException fe) { scaler = FontScaler.getNullScaler(); return getGlyphOutlineBounds(pScalerContext, glyphCode); } }
Example 13
Source File: AbstractBlock.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Creates a new block. */ protected AbstractBlock() { this.id = null; this.width = 0.0; this.height = 0.0; this.bounds = new Rectangle2D.Float(); this.margin = RectangleInsets.ZERO_INSETS; this.frame = BlockBorder.NONE; this.padding = RectangleInsets.ZERO_INSETS; }
Example 14
Source File: PSPathGraphics.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** Redraw a rectanglular area using a proxy graphics * To do this we need to know the rectangular area to redraw and * the transform & clip in effect at the time of the original drawImage * */ public void redrawRegion(Rectangle2D region, double scaleX, double scaleY, Shape savedClip, AffineTransform savedTransform) throws PrinterException { PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob(); Printable painter = getPrintable(); PageFormat pageFormat = getPageFormat(); int pageIndex = getPageIndex(); /* Create a buffered image big enough to hold the portion * of the source image being printed. */ BufferedImage deepImage = new BufferedImage( (int) region.getWidth(), (int) region.getHeight(), BufferedImage.TYPE_3BYTE_BGR); /* Get a graphics for the application to render into. * We initialize the buffer to white in order to * match the paper and then we shift the BufferedImage * so that it covers the area on the page where the * caller's Image will be drawn. */ Graphics2D g = deepImage.createGraphics(); ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob); proxy.setColor(Color.white); proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight()); proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight()); proxy.translate(-region.getX(), -region.getY()); /* Calculate the resolution of the source image. */ float sourceResX = (float)(psPrinterJob.getXRes() / scaleX); float sourceResY = (float)(psPrinterJob.getYRes() / scaleY); /* The application expects to see user space at 72 dpi. * so change user space from image source resolution to * 72 dpi. */ proxy.scale(sourceResX / DEFAULT_USER_RES, sourceResY / DEFAULT_USER_RES); proxy.translate( -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper()) / psPrinterJob.getXRes() * DEFAULT_USER_RES, -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper()) / psPrinterJob.getYRes() * DEFAULT_USER_RES); /* NB User space now has to be at 72 dpi for this calc to be correct */ proxy.transform(new AffineTransform(getPageFormat().getMatrix())); proxy.setPaint(Color.black); painter.print(proxy, pageFormat, pageIndex); g.dispose(); /* In PSPrinterJob images are printed in device space * and therefore we need to set a device space clip. */ psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip)); /* Scale the bounding rectangle by the scale transform. * Because the scaling transform has only x and y * scaling components it is equivalent to multiply * the x components of the bounding rectangle by * the x scaling factor and to multiply the y components * by the y scaling factor. */ Rectangle2D.Float scaledBounds = new Rectangle2D.Float( (float) (region.getX() * scaleX), (float) (region.getY() * scaleY), (float) (region.getWidth() * scaleX), (float) (region.getHeight() * scaleY)); /* Pull the raster data from the buffered image * and pass it along to PS. */ ByteComponentRaster tile = (ByteComponentRaster)deepImage.getRaster(); psPrinterJob.drawImageBGR(tile.getDataStorage(), scaledBounds.x, scaledBounds.y, scaledBounds.width, scaledBounds.height, 0f, 0f, deepImage.getWidth(), deepImage.getHeight(), deepImage.getWidth(), deepImage.getHeight()); }
Example 15
Source File: NativeFont.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext, int glyphCode) { return new Rectangle2D.Float(0f, 0f, 0f, 0f); }
Example 16
Source File: Decoration.java From hottub with GNU General Public License v2.0 | 4 votes |
public void drawTextAndDecorations(Label label, Graphics2D g2d, float x, float y) { if (fgPaint == null && bgPaint == null && swapColors == false) { drawTextAndEmbellishments(label, g2d, x, y); } else { Paint savedPaint = g2d.getPaint(); Paint foreground, background; if (swapColors) { background = fgPaint==null? savedPaint : fgPaint; if (bgPaint == null) { if (background instanceof Color) { Color bg = (Color)background; // 30/59/11 is standard weights, tweaked a bit int brightness = 33 * bg.getRed() + 53 * bg.getGreen() + 14 * bg.getBlue(); foreground = brightness > 18500 ? Color.BLACK : Color.WHITE; } else { foreground = Color.WHITE; } } else { foreground = bgPaint; } } else { foreground = fgPaint==null? savedPaint : fgPaint; background = bgPaint; } if (background != null) { Rectangle2D bgArea = label.getLogicalBounds(); bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(), y + (float)bgArea.getY(), (float)bgArea.getWidth(), (float)bgArea.getHeight()); g2d.setPaint(background); g2d.fill(bgArea); } g2d.setPaint(foreground); drawTextAndEmbellishments(label, g2d, x, y); g2d.setPaint(savedPaint); } }
Example 17
Source File: NativeStrike.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) { return null; }
Example 18
Source File: NullFontScaler.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
Rectangle2D.Float getGlyphOutlineBounds(long pContext, int glyphCode) { return new Rectangle2D.Float(0, 0, 0, 0); }
Example 19
Source File: FreetypeFontScaler.java From hottub with GNU General Public License v2.0 | 4 votes |
private native Rectangle2D.Float getGlyphOutlineBoundsNative(Font2D font, long pScalerContext, long pScaler, int glyphCode);
Example 20
Source File: PeekGraphics.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void addDrawingRect(float x, float y, float width, float height) { Rectangle2D.Float bbox = new Rectangle2D.Float(x, y, width, height); addDrawingRect(bbox); }