use of java.awt.font.FontRenderContext in project drools by kiegroup.
the class PongUI method drawScore.
public void drawScore(Player p, int x) {
// ui.getTablePanel().getTableG();
Graphics g = getGraphics();
int y = (pconf.boundedTop() + 60);
// background
g.setColor(Color.BLACK);
g.fillRect(x, y - 60, 90, 90);
FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
Font f = new Font("Monospaced", Font.BOLD, 70);
String s = "" + p.getScore();
TextLayout tl = new TextLayout(s, f, frc);
g.setColor(Color.WHITE);
tl.draw(((Graphics2D) g), x, y);
}
use of java.awt.font.FontRenderContext in project platform_frameworks_base by android.
the class BidiRenderer method render.
/**
* Renders the text to the right of the bounds with the given font.
* @param font The font to render the text with.
*/
private void render(int start, int limit, Font font, int flag, float[] advances, int advancesIndex, boolean draw) {
FontRenderContext frc;
if (mGraphics != null) {
frc = mGraphics.getFontRenderContext();
} else {
frc = Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
// Metrics obtained this way don't have anti-aliasing set. So,
// we create a new FontRenderContext with anti-aliasing set.
frc = new FontRenderContext(font.getTransform(), mPaint.isAntiAliased(), frc.usesFractionalMetrics());
}
GlyphVector gv = font.layoutGlyphVector(frc, mText, start, limit, flag);
int ng = gv.getNumGlyphs();
int[] ci = gv.getGlyphCharIndices(0, ng, null);
if (advances != null) {
for (int i = 0; i < ng; i++) {
int adv_idx = advancesIndex + ci[i];
advances[adv_idx] += gv.getGlyphMetrics(i).getAdvanceX();
}
}
if (draw && mGraphics != null) {
mGraphics.drawGlyphVector(gv, mBounds.right, mBaseline);
}
// Update the bounds.
Rectangle2D awtBounds = gv.getLogicalBounds();
RectF bounds = awtRectToAndroidRect(awtBounds, mBounds.right, mBaseline);
// coordinates from the bounds as an offset.
if (Math.abs(mBounds.right - mBounds.left) == 0) {
mBounds = bounds;
} else {
mBounds.union(bounds);
}
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method getFontRenderContext.
/**
* Get the rendering context of the font
* within this Graphics2D context.
*/
public FontRenderContext getFontRenderContext() {
if (cachedFRC == null) {
int aahint = textAntialiasHint;
if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT && antialiasHint == SunHints.INTVAL_ANTIALIAS_ON) {
aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
}
// Translation components should be excluded from the FRC transform
AffineTransform tx = null;
if (transformState >= TRANSFORM_TRANSLATESCALE) {
if (transform.getTranslateX() == 0 && transform.getTranslateY() == 0) {
tx = transform;
} else {
tx = new AffineTransform(transform.getScaleX(), transform.getShearY(), transform.getShearX(), transform.getScaleY(), 0, 0);
}
}
cachedFRC = new FontRenderContext(tx, SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING, aahint), SunHints.Value.get(SunHints.INTKEY_FRACTIONALMETRICS, fractionalMetricsHint));
}
return cachedFRC;
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class OutlineTextRenderer method drawGlyphVector.
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) {
Shape s = gv.getOutline(x, y);
int prevaaHint = -1;
FontRenderContext frc = gv.getFontRenderContext();
boolean aa = frc.isAntiAliased();
/* aa will be true if any AA mode has been specified.
* ie for LCD and 'gasp' modes too.
* We will check if 'gasp' has resolved AA to be "OFF", and
* in all other cases (ie AA ON and all LCD modes) use AA outlines.
*/
if (aa) {
if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) {
aa = false;
}
}
if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
g2d.validatePipe();
} else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
g2d.validatePipe();
}
g2d.fill(s);
if (prevaaHint != -1) {
g2d.antialiasHint = prevaaHint;
g2d.validatePipe();
}
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class GlyphListPipe method drawGlyphVector.
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector gv, float x, float y) {
FontRenderContext frc = gv.getFontRenderContext();
FontInfo info = sg2d.getGVFontInfo(gv.getFont(), frc);
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
SurfaceData.outlineTextRenderer.drawGlyphVector(sg2d, gv, x, y);
return;
}
if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
double[] origin = { x, y };
sg2d.transform.transform(origin, 0, origin, 0, 1);
x = (float) origin[0];
y = (float) origin[1];
} else {
// don't use the glyph info origin, already in gv.
x += sg2d.transX;
y += sg2d.transY;
}
GlyphList gl = GlyphList.getInstance();
gl.setFromGlyphVector(info, gv, x, y);
drawGlyphList(sg2d, gl, info.aaHint);
gl.dispose();
}
Aggregations