use of java.awt.font.FontRenderContext in project processing by processing.
the class Toolkit method getAscent.
/**
* Synthesized replacement for FontMetrics.getAscent(), which is dreadfully
* inaccurate and inconsistent across platforms.
*/
public static double getAscent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
FontRenderContext frc = g2.getFontRenderContext();
//return new TextLayout("H", font, frc).getBounds().getHeight();
return new TextLayout("H", g.getFont(), frc).getBounds().getHeight();
}
use of java.awt.font.FontRenderContext 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.FontRenderContext in project playn by threerings.
the class JavaTextLayout method layoutText.
public static JavaTextLayout layoutText(JavaGraphics gfx, String text, TextFormat format) {
// we do some fiddling to work around the fact that TextLayout chokes on the empty string
AttributedString astring = new AttributedString(text.length() == 0 ? " " : text);
if (format.font != null) {
astring.addAttribute(TextAttribute.FONT, ((JavaFont) format.font).jfont);
}
FontRenderContext frc = format.antialias ? gfx.aaFontContext : gfx.aFontContext;
return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc));
}
use of java.awt.font.FontRenderContext in project limelight by slagyr.
the class TextPanel method getRenderContext.
public static FontRenderContext getRenderContext() {
if (staticFontRenderingContext == null) {
AffineTransform affineTransform = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform();
staticFontRenderingContext = new FontRenderContext(affineTransform, true, false);
}
return staticFontRenderingContext;
}
use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.
the class DefaultEditorTextRepresentationHelper method updateContext.
public void updateContext() {
FontRenderContext oldContext = myFontRenderContext;
myFontRenderContext = FontInfo.getFontRenderContext(myEditor.getContentComponent());
if (!myFontRenderContext.equals(oldContext))
clearSymbolWidthCache();
}
Aggregations