Example usage for java.awt.font GlyphVector getOutline

List of usage examples for java.awt.font GlyphVector getOutline

Introduction

In this page you can find the example usage for java.awt.font GlyphVector getOutline.

Prototype

public abstract Shape getOutline();

Source Link

Document

Returns a Shape whose interior corresponds to the visual representation of this GlyphVector .

Usage

From source file:Main.java

public static boolean isVectorFont(Font font) {
    GlyphVector gv = font.createGlyphVector(new FontRenderContext(null, true, false), "Test");
    Shape fontShape = gv.getOutline();
    Rectangle2D bounds = fontShape.getBounds2D();
    return !(bounds.getWidth() == 0 && bounds.getHeight() == 0);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//  ww w. ja v  a  2 s.  c  om

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getOutline());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:D20140128.ApacheXMLGraphicsTest.TilingPatternExample.java

private void paintText(Graphics2D g2d) {
    g2d.setPaint(paint);/*from www  .  jav  a  2s .  c o m*/
    Font font = new Font("serif", Font.BOLD, 80);
    GlyphVector gv = font.createGlyphVector(g2d.getFontRenderContext(), "Java");
    g2d.translate(100, 180);
    g2d.fill(gv.getOutline());
}

From source file:CustomStrokes.java

/** Draw the example */
public void paint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    // Get a shape to work with. Here we'll use the letter B
    Font f = new Font("Serif", Font.BOLD, 200);
    GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "B");
    Shape shape = gv.getOutline();

    // Set drawing attributes and starting position
    g.setColor(Color.black);/* www  .  j a v a  2s.  c  o  m*/
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.translate(10, 175);

    // Draw the shape once with each stroke
    for (int i = 0; i < strokes.length; i++) {
        g.setStroke(strokes[i]); // set the stroke
        g.draw(shape); // draw the shape
        g.translate(140, 0); // move to the right
    }
}