Package java.awt.font

Examples of java.awt.font.GlyphMetrics


            int advance = 0;

            GlyphVector gv = font.createGlyphVector(frc, new char[]{referenceChar});
            java.awt.Shape glyphOutline = gv.getGlyphOutline(0);

            GlyphMetrics metrics = gv.getGlyphMetrics(0);
            advance = (int)Math.rint(metrics.getAdvance()); //Do not scale here, DefineText needs values unscaled

            java.awt.Shape scaledShape = scaleTransform.createTransformedShape(glyphOutline);
            swfShape = createGlyphShape(scaledShape);

            GlyphEntry ge = new GlyphEntry();
View Full Code Here


            float[] metrics = getGlyphMetrics(glyphPointer);
           
//            System.out.println("x = " + metrics[0] + ", y = " + metrics[1]);
//            System.out.println("after x = " + Math.round(metrics[0]) + ", y = " + Math.round(metrics[1]));
           
            this.glMetrics = new GlyphMetrics(
                    true,
                    Math.round(metrics[0]),//metrics[0],
                    Math.round(metrics[1]),//metrics[1],
                    //new Rectangle2D.Double(initOutline().getBounds2D().getMinX(), initOutline().getBounds2D().getMinY(), initOutline().getBounds2D().getMaxX() + 5, initOutline().getBounds2D().getMaxY()),                   
                    initOutline().getBounds2D(),//new Rectangle2D.Float(metrics[2], -metrics[5]-1,metrics[4]- metrics[2] + 1, metrics[5] - metrics[3] + 1),
View Full Code Here

    public void drawString(Graphics2D g, String str, float x, float y) {       
        char[] input = str.toCharArray();
        Character ch;
        Glyph glyph;
        DLInfo info;
        GlyphMetrics glMetrics;
        Color col = g.getColor();
        Font font = g.getFont();       
        int lenght = str.length();
        FontPeerImpl peer = ((FontPeerImpl)font.getPeer());
        AffineTransform fontAT = (AffineTransform)font.getTransform().clone();
        Point.Float pos = new Point.Float();
        Paint paint = g.getPaint();
        boolean isAntialias = g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING) == RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
       
        try {
            fontAT.inverseTransform(new Point.Double(x + fontAT.getTranslateX(), y + fontAT.getTranslateY()), pos);
        } catch (NoninvertibleTransformException e) {  
//          TODO determinant equals 0 => point or line
            g.fill(font.createGlyphVector(g.getFontRenderContext(), str).getOutline(x, y));
            return;
        }
       
        fontAT.translate(pos.x,pos.y);
        g.transform(fontAT);
       
        HashCode hash = new HashCode();
        hash.append(peer);
        hash.append(getFactor(g.getTransform()));
        hash.append(paint);
        hash.append(isAntialias);
        Integer intHash = new Integer(hash.hashCode());
       
        GlyphHashtable glyphHash =
            intHash2glyphHash.containsKey(intHash) ?
                    (GlyphHashtable) intHash2glyphHash.get(intHash) : null;
        if ( glyphHash == null) {
            glyphHash = new GlyphHashtable();
            intHash2glyphHash. put(intHash, glyphHash);
        }
       
        activateVars();       
       
        for (int i = 0; i - lenght < 0; i ++) {
            ch = new Character(input[i]);
            if (ESCAPE.contains(ch)) continue;
            glyph = peer.getGlyph(input[i]);
           
            if (ch == ' ') {
                glMetrics = glyph.getGlyphPointMetrics();
                gl.glTranslated(
                        glMetrics.getAdvanceX(),
                        glMetrics.getAdvanceY(),
                        0
                );
                continue;
            }
           
            info = glyphHash.containsKey(ch) ? (DLInfo)glyphHash.get(ch) : null;
           
            if (info == null || !info.isValid()) {
                createColorGlyphDL(g, glyph, glyphHash, font, ch, col, isAntialias);
            } else {
                gl.glCallList(info.getDL());
            }           
           
            glMetrics = glyph.getGlyphPointMetrics();
            gl.glTranslated(
                    glMetrics.getAdvanceX(),
                    glMetrics.getAdvanceY(),
                    0
            );           
           
        }
        deactivateVars();
View Full Code Here

        Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                        -pxlMetrics[1],
                                                        pxlMetrics[4],
                                                        pxlMetrics[5]);

        this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
        this.glMetrics = new GlyphMetrics((float)Math.ceil(pxlMetrics[2]), rct, (byte)0);

    }
View Full Code Here

        Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                        -metrics[1],
                                                        metrics[4],
                                                        metrics[5]);
        this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

        this.glCode = glyphIndex;
        this.glChar = c;

        Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                        -pxlMetrics[1],
                                                        pxlMetrics[4],
                                                        pxlMetrics[5]);
        this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
    }
View Full Code Here

        Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                        -metrics[1],
                                                        metrics[4],
                                                        metrics[5]);
        this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);
        this.glCode = glyphIndex;
        this.glChar = c;

        Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                        -pxlMetrics[1],
                                                        pxlMetrics[4],
                                                        pxlMetrics[5]);
        this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
    }
View Full Code Here

        Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                        -metrics[1],
                                                        metrics[4],
                                                        metrics[5]);
        this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

        this.glCode = glyphIndex;
        this.glChar = c;

        Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                        -pxlMetrics[1],
                                                        pxlMetrics[4],
                                                        pxlMetrics[5]);
        this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
    }
View Full Code Here

        int xBaseLine = x;
        int yBaseLine = y;

        for (char element : chars) {
            Glyph gl = font.getGlyph(element);
            GlyphMetrics pointMetrics = gl.getGlyphPointMetrics();
            if (gl.getWidth() == 0) {
                xBaseLine += pointMetrics.getAdvanceX();
                continue;
            }

            byte[] data = gl.getBitmap();
            if (data == null) {
                xBaseLine += pointMetrics.getAdvanceX();
            } else {

                xSrcSurf = 0;
                ySrcSurf = 0;

                xDstSurf = Math.round(xBaseLine + gl.getGlyphPointMetrics().getLSB());
                yDstSurf = yBaseLine - gl.bmp_top;

                int textWidth = gl.bmp_width;
                int textHeight = gl.getPointHeight();

                // if Regions don't intersect
                if ((xDstSurf > cMaxX) || (yDstSurf > cMaxY) || (xDstSurf + textWidth < cMinX)
                        || (yDstSurf + textHeight < cMinY)) {
                    // Nothing to do
                } else {
                    if (xDstSurf >= cMinX) {
                        clWidth = Math.min(textWidth, cMaxX - xDstSurf);
                    } else {
                        xSrcSurf += cMinX - xDstSurf;
                        clWidth = Math.min(cMaxX - cMinX, textWidth - (cMinX - xDstSurf));
                        xDstSurf = cMinX;
                    }
                    if (yDstSurf >= cMinY) {
                        clHeight = Math.min(textHeight, cMaxY - yDstSurf);
                    } else {
                        ySrcSurf += cMinY - yDstSurf;
                        clHeight = Math.min(cMaxY - cMinY, textHeight - (cMinY - yDstSurf));
                        yDstSurf = cMinY;
                    }

                    // Drawing on the Raster
                    for (int h=0; h<clHeight; h++){
                        for (int w=0; w < clWidth ; w++) {
                            byte currByte = data[(ySrcSurf + h)*gl.bmp_pitch + (xSrcSurf+w)/8];
                            boolean emptyByte = ((currByte & (1 << (7 - ((xSrcSurf+w) % 8)))) != 0);
                            if (emptyByte) {
                                raster.setDataElements(xDstSurf+w, yDstSurf+h, color);
                            } else {
                                // Nothing to do
                            }
                        }
                    }
                }
                xBaseLine += pointMetrics.getAdvanceX();
            }
        }
    }
View Full Code Here

     * @param y start Y position to draw
     */
    @Override
    public void drawString(Graphics2D g, String str, float x, float y) {       
        final char[] input = str.toCharArray();
        GlyphMetrics glMetrics;
        Color col = g.getColor();
        Font font = g.getFont();       
        int length = str.length();
        @SuppressWarnings("deprecation")
        final FontPeerImpl peer = ((FontPeerImpl)font.getPeer());
        AffineTransform fontAT = (AffineTransform)font.getTransform().clone();
        Point.Float pos = new Point.Float();
        Paint paint = g.getPaint();
        boolean isAntialias = g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING) == RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
       
        try {
            fontAT.inverseTransform(new Point.Double(x + fontAT.getTranslateX(), y + fontAT.getTranslateY()), pos);
        } catch (NoninvertibleTransformException e) {  
//          TODO determinant equals 0 => point or line
            g.fill(font.createGlyphVector(g.getFontRenderContext(), str).getOutline(x, y));
            return;
        }
       
        fontAT.translate(pos.x,pos.y);
        g.transform(fontAT);
       
        HashCode hash = new HashCode();
        hash.append(peer);
        hash.append(getFactor(g.getTransform()));
        hash.append(paint);
        hash.append(isAntialias);
        Integer intHash = Integer.valueOf(hash.hashCode());
       
        GlyphHashtable glyphHash =
            (GlyphHashtable) (intHash2glyphHash.containsKey(intHash) ?
                intHash2glyphHash.get(intHash) : null);
        if ( glyphHash == null) {
            glyphHash = new GlyphHashtable();
            intHash2glyphHash.put(intHash, glyphHash);
        }
       
        activateVars();
       
        for (int i = 0; i - length < 0; i ++) {
            final char c = input[i];
            final Character ch = Character.valueOf(c);
            if (ESCAPE.contains(ch)) {
                continue;
            }
            final Glyph glyph = peer.getGlyph(input[i]);
           
            if (c == ' ') {
                glMetrics = glyph.getGlyphPointMetrics();
                gl.glTranslated(
                        glMetrics.getAdvanceX(),
                        glMetrics.getAdvanceY(),
                        0
                );
                continue;
            }
           
            final DLInfo info = glyphHash.containsKey(ch) ? (DLInfo)glyphHash.get(ch) : null;
           
            if (info == null || !info.isValid()) {
                createColorGlyphDL(g, glyph, glyphHash, font, ch, col, isAntialias);
            } else {
                gl.glCallList(info.getDL());
            }           
           
            glMetrics = glyph.getGlyphPointMetrics();
            gl.glTranslated(glMetrics.getAdvanceX(), glMetrics.getAdvanceY(), 0);
        }
        deactivateVars();
        cleanLists();
    }
View Full Code Here

        Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                        -pxlMetrics[1],
                                                        pxlMetrics[4],
                                                        pxlMetrics[5]);

        this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
        this.glMetrics = new GlyphMetrics((float)Math.ceil(pxlMetrics[2]), rct, (byte)0);

    }
View Full Code Here

TOP

Related Classes of java.awt.font.GlyphMetrics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.