Font font = new Font(Font.SANS_SERIF, Font.BOLD, 250); GlyphVector gv = font.createGlyphVector(frc, "Cat"); Rectangle2D box = gv.getVisualBounds(); int xOff = 25+(int)-box.getX(); int yOff = 80+(int)-box.getY();
Rectangle2D getVisualBounds() { if (visualBounds == null) { visualBounds = gv.getVisualBounds(); } return visualBounds; }
@Override public int getTextHeight(String text) { Graphics2D graphics2d = bufferedImage.createGraphics(); FontMetrics fontMetrics = graphics2d.getFontMetrics(this.font); graphics2d.dispose(); return (int) this.font.createGlyphVector(fontMetrics.getFontRenderContext(), text).getVisualBounds().getHeight(); }
double getLineHeight() { double height = Float.NEGATIVE_INFINITY; for (LineComponent component : components) { double ch = component.getGlyphVector().getVisualBounds().getHeight() - component.getLayout().getDescent(); if (ch > height) { height = ch; } } return height; }
Rectangle2D getBounds() { Rectangle2D vb = null; for (LineComponent lineComponent : components) { Rectangle2D componentVisualBounds = lineComponent.getGlyphVector().getVisualBounds(); Rectangle2D componentLogicalBounds = lineComponent.getGlyphVector().getLogicalBounds(); // the logical bounds include the spaces, we want them in the horizontal direction // in order to compose the element in the row, but we need the visual bounds for // vertical alignment Rectangle2D componentBounds = new Rectangle2D.Double( componentLogicalBounds.getX(), componentVisualBounds.getY(), componentLogicalBounds.getWidth(), componentVisualBounds.getHeight()); if (vb == null) { vb = componentBounds; } else { Rectangle2D other = new Rectangle2D.Double( vb.getMaxX(), vb.getMinY(), componentBounds.getWidth(), componentBounds.getHeight()); vb = vb.createUnion(other); } } return vb; }
final int irn = Math.min(ir, in); final GlyphVector line = font.createGlyphVector(context, message.substring(i, irn)); final Rectangle2D rect = line.getVisualBounds(); final double w = rect.getWidth(); if (w > width) width = w;
Rectangle2D box = gv.getVisualBounds(); box = gv.getVisualBounds();
Rectangle2D box1 = gv.getVisualBounds();
Rectangle2D box1 = gv.getVisualBounds();
@Override public Rectangle2D getGeometricBounds() { return this.vec.getVisualBounds(); }
@Override public Rectangle2D getBounds(final GlyphVector gv, final FontRenderContext frc) { return gv.getVisualBounds(); }
/** * Returns the line height for this label in pixels (for multiline labels, * it's the height of the first line) * * @return */ public double getLineHeight() { return lines.get(0).gv.getVisualBounds().getHeight() - lines.get(0).layout.getDescent(); }
/** * Ensures that the ascent of a capital M has been computed. * * @param frc the font render context used to create the glyph vector */ private void ensureCapitalMAscentComputed(FontRenderContext frc) { if (capitalMAscent > 0) { return; } GlyphVector mGlyphVector = font.createGlyphVector(frc, "M"); capitalMAscent = (float) - mGlyphVector.getVisualBounds().getY(); }
public static Shape generateShapeFromText(Font font, String string) { BufferedImage img = new BufferedImage(100,100,BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); try { GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string); Shape shape = vect.getOutline(0f,(float)-vect.getVisualBounds().getY()); return shape; } finally { g2.dispose(); } } }
@Override public int getTextHeight(String text) { Graphics2D graphics2d = bufferedImage.createGraphics(); FontMetrics fontMetrics = graphics2d.getFontMetrics(this.font); graphics2d.dispose(); return (int) this.font.createGlyphVector(fontMetrics.getFontRenderContext(), text).getVisualBounds().getHeight(); }
@Override public void drawGlyphVector(GlyphVector g, float x, float y) { Rectangle2D bounds = g.getVisualBounds(); // expand the rectangle by a single pixel width to allow for // rasterizing round-off errors // (see apidocs for Graphics2D.drawGlyphVector) bounds.setFrame(bounds.getMinX() - 1, bounds.getMinY() - 1, bounds.getWidth() + 2, bounds.getHeight() + 2); doDraw(OpType.DRAW_GLYPH_VECTOR, bounds, g, x, y); }
@Override public void drawGlyphVector(GlyphVector g, float x, float y) { Rectangle2D bounds = g.getVisualBounds(); // expand the rectangle by a single pixel width to allow for // rasterizing round-off errors // (see apidocs for Graphics2D.drawGlyphVector) bounds.setFrame(bounds.getMinX() - 1, bounds.getMinY() - 1, bounds.getWidth() + 2, bounds.getHeight() + 2); doDraw(OpType.DRAW_GLYPH_VECTOR, bounds, g, x, y); }
public static Shape generateShapeFromText(Font font, String string) { BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(1, 1); Graphics2D g2 = img.createGraphics(); try { GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string); Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY()); return shape; } finally { g2.dispose(); } }
public static Shape generateShapeFromText(Font font, String string) { BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(1, 1); Graphics2D g2 = img.createGraphics(); try { GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string); Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY()); return shape; } finally { g2.dispose(); } }
public static Shape generateShapeFromText(Font font, String string) { BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(1, 1); Graphics2D g2 = img.createGraphics(); try { GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string); Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY()); return shape; } finally { g2.dispose(); } }