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;
}
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);
}
}
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();
}
}
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();
}
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;
}
Aggregations