Search in sources :

Example 26 with GlyphVector

use of java.awt.font.GlyphVector in project processing by processing.

the class PFont method getShape.

public PShape getShape(char ch, float detail) {
    Font font = (Font) getNative();
    if (font == null) {
        throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
    }
    PShape s = new PShape(PShape.PATH);
    // six element array received from the Java2D path iterator
    float[] iterPoints = new float[6];
    // array passed to createGylphVector
    char[] textArray = new char[] { ch };
    //Graphics2D graphics = (Graphics2D) this.getGraphics();
    //FontRenderContext frc = graphics.getFontRenderContext();
    @SuppressWarnings("deprecation") FontRenderContext frc = Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
    GlyphVector gv = font.createGlyphVector(frc, textArray);
    Shape shp = gv.getOutline();
    // make everything into moveto and lineto
    PathIterator iter = (detail == 0) ? // maintain curves
    shp.getPathIterator(null) : // convert to line segments
    shp.getPathIterator(null, detail);
    int contours = 0;
    //    boolean contour = false;
    while (!iter.isDone()) {
        int type = iter.currentSegment(iterPoints);
        switch(type) {
            case // 1 point (2 vars) in textPoints
            PathIterator.SEG_MOVETO:
                //        if (!contour) {
                if (contours == 0) {
                    s.beginShape();
                } else {
                    s.beginContour();
                //          contour = true;
                }
                contours++;
                s.vertex(iterPoints[0], iterPoints[1]);
                break;
            case // 1 point
            PathIterator.SEG_LINETO:
                //        System.out.println("lineto");
                //        PApplet.println(PApplet.subset(iterPoints, 0, 2));
                s.vertex(iterPoints[0], iterPoints[1]);
                break;
            case // 2 points
            PathIterator.SEG_QUADTO:
                //        System.out.println("quadto");
                //        PApplet.println(PApplet.subset(iterPoints, 0, 4));
                s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3]);
                break;
            case // 3 points
            PathIterator.SEG_CUBICTO:
                //        System.out.println("cubicto");
                //        PApplet.println(iterPoints);
                s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3], iterPoints[4], iterPoints[5]);
                break;
            case PathIterator.SEG_CLOSE:
                //        System.out.println("close");
                if (contours > 1) {
                    //        contours--;
                    //        if (contours == 0) {
                    ////          s.endShape();
                    //        } else {
                    s.endContour();
                }
                break;
        }
        //      PApplet.println(iterPoints);
        iter.next();
    }
    s.endShape(CLOSE);
    return s;
}
Also used : GlyphVector(java.awt.font.GlyphVector) PathIterator(java.awt.geom.PathIterator) FontRenderContext(java.awt.font.FontRenderContext)

Example 27 with GlyphVector

use of java.awt.font.GlyphVector in project scriptographer by scriptographer.

the class AbstractGraphics2D method drawString.

public void drawString(String s, float x, float y) {
    if (textAsShapes) {
        GlyphVector gv = getFont().createGlyphVector(getFontRenderContext(), s);
        drawGlyphVector(gv, x, y);
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Example 28 with GlyphVector

use of java.awt.font.GlyphVector in project intellij-community by JetBrains.

the class TextPainter method drawStringToGraphics.

private double drawStringToGraphics(Graphics2D g, String s, double x, double y) {
    if (!myPrintSettings.PRINT_AS_GRAPHICS) {
        if (myPerformActualDrawing) {
            g.drawString(s, (float) x, (float) y);
        }
        return g.getFontMetrics().stringWidth(s);
    } else {
        GlyphVector v = g.getFont().createGlyphVector(g.getFontRenderContext(), s);
        if (myPerformActualDrawing) {
            g.translate(x, y);
            g.fill(v.getOutline());
            g.translate(-x, -y);
        }
        return v.getLogicalBounds().getWidth();
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Example 29 with GlyphVector

use of java.awt.font.GlyphVector in project intellij-community by JetBrains.

the class TextPainter method getStringWidth.

private static double getStringWidth(Graphics2D g, char[] text, int start, int count) {
    String s = new String(text, start, count);
    GlyphVector v = g.getFont().createGlyphVector(g.getFontRenderContext(), s);
    return v.getLogicalBounds().getWidth();
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Example 30 with GlyphVector

use of java.awt.font.GlyphVector in project intellij-community by JetBrains.

the class TextIcon method getTextBounds.

private Rectangle getTextBounds() {
    if (myTextBounds == null && myFont != null && myText != null && !myText.isEmpty()) {
        GlyphVector vector = myFont.createGlyphVector(CONTEXT, myText);
        myTextBounds = vector.getPixelBounds(CONTEXT, 0, 0);
    }
    return myTextBounds;
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Aggregations

GlyphVector (java.awt.font.GlyphVector)36 FontRenderContext (java.awt.font.FontRenderContext)18 Font (java.awt.Font)8 Graphics2D (java.awt.Graphics2D)8 Rectangle (java.awt.Rectangle)7 Rectangle2D (java.awt.geom.Rectangle2D)7 BufferedImage (java.awt.image.BufferedImage)5 Shape (java.awt.Shape)3 AffineTransform (java.awt.geom.AffineTransform)3 BasicStroke (java.awt.BasicStroke)2 FontMetrics (java.awt.FontMetrics)2 Image (java.awt.Image)2 Paint (java.awt.Paint)2 TextLayout (java.awt.font.TextLayout)2 Point2D (java.awt.geom.Point2D)2 Map (java.util.Map)2 Texture (com.badlogic.gdx.graphics.Texture)1 FontInfo (com.intellij.openapi.editor.impl.FontInfo)1 AbstractMockGlyphVector (com.intellij.testFramework.AbstractMockGlyphVector)1 MockFontLayoutService (com.intellij.testFramework.MockFontLayoutService)1