Example usage for java.awt.font GlyphVector getNumGlyphs

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

Introduction

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

Prototype

public abstract int getNumGlyphs();

Source Link

Document

Returns the number of glyphs in this GlyphVector .

Usage

From source file:RotatedText.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "111111111111111111111111111111";

    Font font = new Font("Courier", Font.PLAIN, 12);
    g2d.translate(20, 20);//from w w  w  . j  a  v  a2  s.c o  m

    FontRenderContext frc = g2d.getFontRenderContext();

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    System.out.println(length);

}

From source file:RollingText.java

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

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

    String s = "Java Source and Support.";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//from   w  ww .j ava  2  s.c o m

    GlyphVector gv = font.createGlyphVector(frc, s);
    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:RotatedText.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "111111111111111111111111111111";

    Font font = new Font("Courier", Font.PLAIN, 12);
    g2d.translate(20, 20);/*  w  w w . j  a  v  a  2  s.c  om*/

    FontRenderContext frc = g2d.getFontRenderContext();

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate((double) i / (double) (length - 1) * Math.PI / 3);

        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2d.fill(transformedGlyph);
    }
}

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);/*from  w  w  w .j  av  a  2  s  .  co  m*/

    GlyphVector gv = font.createGlyphVector(frc, s);
    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: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);/*w w w  . j  a  v  a  2 s.com*/

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

    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: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);/* w  ww.  j a  v a 2s  .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: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 a2s . com*/

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

    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: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);// w  ww .  j a  v a2s .  c o  m

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

    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:com.jhlabs.awt.TextStroke.java

public Shape createStrokedShape(Shape shape) {
    FontRenderContext frc = new FontRenderContext(null, true, true);
    GlyphVector glyphVector = font.createGlyphVector(frc, text);

    GeneralPath result = new GeneralPath();
    PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
    float points[] = new float[6];
    float moveX = 0, moveY = 0;
    float lastX = 0, lastY = 0;
    float thisX = 0, thisY = 0;
    int type = 0;
    float next = 0;
    int currentChar = 0;
    int length = glyphVector.getNumGlyphs();

    if (length == 0)
        return result;

    float factor = stretchToFit ? measurePathLength(shape) / (float) glyphVector.getLogicalBounds().getWidth()
            : 1.0f;/*from www  .  j  a  v  a2  s  . c  o m*/
    float height = (float) glyphVector.getLogicalBounds().getHeight();
    float nextAdvance = 0;

    while (currentChar < length && !it.isDone()) {
        type = it.currentSegment(points);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            moveX = lastX = points[0];
            moveY = lastY = points[1];
            result.moveTo(moveX, moveY);
            nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f;
            next = nextAdvance;
            break;

        case PathIterator.SEG_CLOSE:
            points[0] = moveX;
            points[1] = moveY;
            // Fall into....

        case PathIterator.SEG_LINETO:
            thisX = points[0];
            thisY = points[1];
            float dx = thisX - lastX;
            float dy = thisY - lastY;
            float distance = (float) FastMath.sqrt(dx * dx + dy * dy);
            if (distance >= next) {
                float r = 1.0f / distance;
                float angle = (float) FastMath.atan2(dy, dx);
                while (currentChar < length && distance >= next) {
                    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;
                    float advance = nextAdvance;
                    nextAdvance = currentChar < length - 1
                            ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f
                            : 0;
                    t.setToTranslation(x, y);
                    t.rotate(angle);
                    t.translate(-px - advance, -py + height * factor / 2.0f);
                    result.append(t.createTransformedShape(glyph), false);
                    next += (advance + nextAdvance) * factor;
                    currentChar++;
                    if (repeat)
                        currentChar %= length;
                }
            }
            next -= distance;
            lastX = thisX;
            lastY = thisY;
            break;
        }
        it.next();
    }

    return result;
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public void drawGlyphVector(GlyphVector glyph, float x, float y) {
    translate(x, y);/*w  w w .  j a  va 2  s . co m*/
    Element currentElement = dom.createElement("g");//$NON-NLS-1$
    Element transElement = createElement("g"); //$NON-NLS-1$
    currentElement.appendChild(transElement);
    // need to defer clipping for each glyph
    setFillColor(transElement, true);
    for (int idx = 0; idx < glyph.getNumGlyphs(); idx++) {
        Element glyphElem = createShape(glyph.getGlyphOutline(idx));

        transElement.appendChild(glyphElem);
    }
    // should add clipping to the group element that is not transformed
    if (clip != null)
        currentElement.setAttribute("clip-path", "url(#clip" + clip.hashCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    appendChild(currentElement);
    translate(-x, -y);
}