Search in sources :

Example 36 with FontRenderContext

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);
}
Also used : FontRenderContext(java.awt.font.FontRenderContext) EntryPoint(org.kie.api.runtime.rule.EntryPoint) TextLayout(java.awt.font.TextLayout)

Example 37 with FontRenderContext

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);
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext)

Example 38 with FontRenderContext

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;
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 39 with FontRenderContext

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();
    }
}
Also used : Shape(java.awt.Shape) FontRenderContext(java.awt.font.FontRenderContext)

Example 40 with FontRenderContext

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();
}
Also used : GlyphList(sun.font.GlyphList) FontRenderContext(java.awt.font.FontRenderContext) FontInfo(sun.java2d.loops.FontInfo)

Aggregations

FontRenderContext (java.awt.font.FontRenderContext)79 Font (java.awt.Font)27 TextLayout (java.awt.font.TextLayout)25 GlyphVector (java.awt.font.GlyphVector)18 Graphics2D (java.awt.Graphics2D)17 Rectangle2D (java.awt.geom.Rectangle2D)17 AttributedString (java.text.AttributedString)14 AffineTransform (java.awt.geom.AffineTransform)13 Paint (java.awt.Paint)8 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)7 AttributedCharacterIterator (java.text.AttributedCharacterIterator)7 Color (java.awt.Color)5 Shape (java.awt.Shape)5 LineMetrics (java.awt.font.LineMetrics)5 BufferedImage (java.awt.image.BufferedImage)5 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)4 BasicStroke (java.awt.BasicStroke)3 FontMetrics (java.awt.FontMetrics)3 Rectangle (java.awt.Rectangle)3