Search in sources :

Example 1 with FontInfo

use of sun.java2d.loops.FontInfo in project jdk8u_jdk by JetBrains.

the class GlyphListPipe method drawString.

public void drawString(SunGraphics2D sg2d, String s, double x, double y) {
    FontInfo info = sg2d.getFontInfo();
    if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
        SurfaceData.outlineTextRenderer.drawString(sg2d, s, x, y);
        return;
    }
    float devx, devy;
    if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        double[] origin = { x + info.originX, y + info.originY };
        sg2d.transform.transform(origin, 0, origin, 0, 1);
        devx = (float) origin[0];
        devy = (float) origin[1];
    } else {
        devx = (float) (x + info.originX + sg2d.transX);
        devy = (float) (y + info.originY + sg2d.transY);
    }
    /* setFromString returns false if shaping is needed, and we then back
         * off to a TextLayout. Such text may benefit slightly from a lower
         * overhead in this approach over the approach in previous releases.
         */
    GlyphList gl = GlyphList.getInstance();
    if (gl.setFromString(info, s, devx, devy)) {
        drawGlyphList(sg2d, gl);
        gl.dispose();
    } else {
        // release this asap.
        gl.dispose();
        TextLayout tl = new TextLayout(s, sg2d.getFont(), sg2d.getFontRenderContext());
        tl.draw(sg2d, (float) x, (float) y);
    }
}
Also used : GlyphList(sun.font.GlyphList) FontInfo(sun.java2d.loops.FontInfo) TextLayout(java.awt.font.TextLayout)

Example 2 with FontInfo

use of sun.java2d.loops.FontInfo in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method checkFontInfo.

// cached state for various draw[String,Char,Byte] optimizations
public FontInfo checkFontInfo(FontInfo info, Font font, FontRenderContext frc) {
    /* Do not create a FontInfo object as part of construction of an
         * SG2D as its possible it may never be needed - ie if no text
         * is drawn using this SG2D.
         */
    if (info == null) {
        info = new FontInfo();
    }
    float ptSize = font.getSize2D();
    int txFontType;
    AffineTransform devAt, textAt = null;
    if (font.isTransformed()) {
        textAt = font.getTransform();
        textAt.scale(ptSize, ptSize);
        txFontType = textAt.getType();
        info.originX = (float) textAt.getTranslateX();
        info.originY = (float) textAt.getTranslateY();
        textAt.translate(-info.originX, -info.originY);
        if (transformState >= TRANSFORM_TRANSLATESCALE) {
            transform.getMatrix(info.devTx = new double[4]);
            devAt = new AffineTransform(info.devTx);
            textAt.preConcatenate(devAt);
        } else {
            info.devTx = IDENT_MATRIX;
            devAt = IDENT_ATX;
        }
        textAt.getMatrix(info.glyphTx = new double[4]);
        double shearx = textAt.getShearX();
        double scaley = textAt.getScaleY();
        if (shearx != 0) {
            scaley = Math.sqrt(shearx * shearx + scaley * scaley);
        }
        info.pixelHeight = (int) (Math.abs(scaley) + 0.5);
    } else {
        txFontType = AffineTransform.TYPE_IDENTITY;
        info.originX = info.originY = 0;
        if (transformState >= TRANSFORM_TRANSLATESCALE) {
            transform.getMatrix(info.devTx = new double[4]);
            devAt = new AffineTransform(info.devTx);
            info.glyphTx = new double[4];
            for (int i = 0; i < 4; i++) {
                info.glyphTx[i] = info.devTx[i] * ptSize;
            }
            textAt = new AffineTransform(info.glyphTx);
            double shearx = transform.getShearX();
            double scaley = transform.getScaleY();
            if (shearx != 0) {
                scaley = Math.sqrt(shearx * shearx + scaley * scaley);
            }
            info.pixelHeight = (int) (Math.abs(scaley * ptSize) + 0.5);
        } else {
            /* If the double represents a common integral, we
                 * may have pre-allocated objects.
                 * A "sparse" array be seems to be as fast as a switch
                 * even for 3 or 4 pt sizes, and is more flexible.
                 * This should perform comparably in single-threaded
                 * rendering to the old code which synchronized on the
                 * class and scale better on MP systems.
                 */
            int pszInt = (int) ptSize;
            if (ptSize == pszInt && pszInt >= MINALLOCATED && pszInt < TEXTARRSIZE) {
                info.glyphTx = textTxArr[pszInt];
                textAt = textAtArr[pszInt];
                info.pixelHeight = pszInt;
            } else {
                info.pixelHeight = (int) (ptSize + 0.5);
            }
            if (textAt == null) {
                info.glyphTx = new double[] { ptSize, 0, 0, ptSize };
                textAt = new AffineTransform(info.glyphTx);
            }
            info.devTx = IDENT_MATRIX;
            devAt = IDENT_ATX;
        }
    }
    info.font2D = FontUtilities.getFont2D(font);
    int fmhint = fractionalMetricsHint;
    if (fmhint == SunHints.INTVAL_FRACTIONALMETRICS_DEFAULT) {
        fmhint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
    }
    // conditionally set true in LCD mode.
    info.lcdSubPixPos = false;
    /* The text anti-aliasing hints that are set by the client need
         * to be interpreted for the current state and stored in the
         * FontInfo.aahint which is what will actually be used and
         * will be one of OFF, ON, LCD_HRGB or LCD_VRGB.
         * This is what pipe selection code should typically refer to, not
         * textAntialiasHint. This means we are now evaluating the meaning
         * of "default" here. Any pipe that really cares about that will
         * also need to consult that variable.
         * Otherwise these are being used only as args to getStrike,
         * and are encapsulated in that object which is part of the
         * FontInfo, so we do not need to store them directly as fields
         * in the FontInfo object.
         * That could change if FontInfo's were more selectively
         * revalidated when graphics state changed. Presently this
         * method re-evaluates all fields in the fontInfo.
         * The strike doesn't need to know the RGB subpixel order. Just
         * if its H or V orientation, so if an LCD option is specified we
         * always pass in the RGB hint to the strike.
         * frc is non-null only if this is a GlyphVector. For reasons
         * which are probably a historical mistake the AA hint in a GV
         * is honoured when we render, overriding the Graphics setting.
         */
    int aahint;
    if (frc == null) {
        aahint = textAntialiasHint;
    } else {
        aahint = ((SunHints.Value) frc.getAntiAliasingHint()).getIndex();
    }
    if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT) {
        if (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON) {
            aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
        } else {
            aahint = SunHints.INTVAL_TEXT_ANTIALIAS_OFF;
        }
    } else {
        /* If we are in checkFontInfo because a rendering hint has been
             * set then all pipes are revalidated. But we can also
             * be here because setFont() has been called when the 'gasp'
             * hint is set, as then the font size determines the text pipe.
             * See comments in SunGraphics2d.setFont(Font).
             */
        if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP) {
            if (info.font2D.useAAForPtSize(info.pixelHeight)) {
                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
            } else {
                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_OFF;
            }
        } else if (aahint >= SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB) {
            /* loops for default rendering modes are installed in the SG2D
                 * constructor. If there are none this will be null.
                 * Not all compositing modes update the render loops, so
                 * we also test that this is a mode we know should support
                 * this. One minor issue is that the loops aren't necessarily
                 * installed for a new rendering mode until after this
                 * method is called during pipeline validation. So it is
                 * theoretically possible that it was set to null for a
                 * compositing mode, the composite is then set back to Src,
                 * but the loop is still null when this is called and AA=ON
                 * is installed instead of an LCD mode.
                 * However this is done in the right order in SurfaceData.java
                 * so this is not likely to be a problem - but not
                 * guaranteed.
                 */
            if (!surfaceData.canRenderLCDText(this)) //                    loops.drawGlyphListLCDLoop == null ||
            //                    compositeState > COMP_ISCOPY ||
            //                    paintState > PAINT_ALPHACOLOR
            {
                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
            } else {
                info.lcdRGBOrder = true;
                /* Collapse these into just HRGB or VRGB.
                     * Pipe selection code needs only to test for these two.
                     * Since these both select the same pipe anyway its
                     * tempting to collapse into one value. But they are
                     * different strikes (glyph caches) so the distinction
                     * needs to be made for that purpose.
                     */
                if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HBGR) {
                    aahint = SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
                    info.lcdRGBOrder = false;
                } else if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VBGR) {
                    aahint = SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB;
                    info.lcdRGBOrder = false;
                }
                /* Support subpixel positioning only for the case in
                     * which the horizontal resolution is increased
                     */
                info.lcdSubPixPos = fmhint == SunHints.INTVAL_FRACTIONALMETRICS_ON && aahint == SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
            }
        }
    }
    info.aaHint = aahint;
    info.fontStrike = info.font2D.getStrike(font, devAt, textAt, aahint, fmhint);
    return info;
}
Also used : SunHints(sun.awt.SunHints) AffineTransform(java.awt.geom.AffineTransform) FontInfo(sun.java2d.loops.FontInfo) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 3 with FontInfo

use of sun.java2d.loops.FontInfo in project jdk8u_jdk by JetBrains.

the class GlyphListPipe method drawChars.

public void drawChars(SunGraphics2D sg2d, char[] data, int offset, int length, int ix, int iy) {
    FontInfo info = sg2d.getFontInfo();
    float x, y;
    if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
        SurfaceData.outlineTextRenderer.drawChars(sg2d, data, offset, length, ix, iy);
        return;
    }
    if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        double[] origin = { ix + info.originX, iy + info.originY };
        sg2d.transform.transform(origin, 0, origin, 0, 1);
        x = (float) origin[0];
        y = (float) origin[1];
    } else {
        x = ix + info.originX + sg2d.transX;
        y = iy + info.originY + sg2d.transY;
    }
    GlyphList gl = GlyphList.getInstance();
    if (gl.setFromChars(info, data, offset, length, x, y)) {
        drawGlyphList(sg2d, gl);
        gl.dispose();
    } else {
        // release this asap.
        gl.dispose();
        TextLayout tl = new TextLayout(new String(data, offset, length), sg2d.getFont(), sg2d.getFontRenderContext());
        tl.draw(sg2d, ix, iy);
    }
}
Also used : GlyphList(sun.font.GlyphList) FontInfo(sun.java2d.loops.FontInfo) TextLayout(java.awt.font.TextLayout)

Example 4 with FontInfo

use of sun.java2d.loops.FontInfo 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)

Example 5 with FontInfo

use of sun.java2d.loops.FontInfo in project jdk8u_jdk by JetBrains.

the class X11TextRenderer method drawGlyphVector.

/*
     * Override super class method to call the AA pipe if
     * AA is specified in the GlyphVector's FontRenderContext
     */
public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector g, float x, float y) {
    FontRenderContext frc = g.getFontRenderContext();
    FontInfo info = sg2d.getGVFontInfo(g.getFont(), frc);
    switch(info.aaHint) {
        case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
            super.drawGlyphVector(sg2d, g, x, y);
            return;
        case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
            sg2d.surfaceData.aaTextRenderer.drawGlyphVector(sg2d, g, x, y);
            return;
        case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
        case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
            sg2d.surfaceData.lcdTextRenderer.drawGlyphVector(sg2d, g, x, y);
            return;
        default:
    }
}
Also used : FontRenderContext(java.awt.font.FontRenderContext) FontInfo(sun.java2d.loops.FontInfo)

Aggregations

FontInfo (sun.java2d.loops.FontInfo)5 GlyphList (sun.font.GlyphList)3 FontRenderContext (java.awt.font.FontRenderContext)2 TextLayout (java.awt.font.TextLayout)2 GradientPaint (java.awt.GradientPaint)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 Paint (java.awt.Paint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 TexturePaint (java.awt.TexturePaint)1 AffineTransform (java.awt.geom.AffineTransform)1 SunHints (sun.awt.SunHints)1