Package java.awt.font

Examples of java.awt.font.GlyphMetrics


    /*
     * Test method for 'java.awt.font.GlyphMetrics.getAdvance()'
     */
    public final void testGetAdvance() {
        GlyphMetrics gm = new GlyphMetrics(advance, bounds, glyphType);
        assertEquals(advance, gm.getAdvance(), 0F);
    }
View Full Code Here


        // iterate through the GlyphVector placing each glyph

        for (int i = 0; i < glyphs.getNumGlyphs(); i++) {

            GlyphMetrics gm = glyphs.getGlyphMetrics(i);

            float charAdvance = gm.getAdvance();

            Shape glyph = glyphs.getGlyphOutline(i);

            // if lengthAdjust was GLYPHS, then scale the glyph
            // by the lengthRatio in the X direction
View Full Code Here

            int[] missingGlyphCode = new int[1];
            missingGlyphCode[0] = commonSizeFont.getMissingGlyphCode();
            GlyphVector gv;
            gv = commonSizeFont.createGlyphVector(localFRC, missingGlyphCode);
            Shape missingGlyphShape = gv.getGlyphOutline(0);
            GlyphMetrics gm = gv.getGlyphMetrics(0);

            // need to turn the missing glyph upside down to be in the font
            // coordinate system (i.e Y axis up)
            AffineTransform at = AffineTransform.getScaleInstance(1, -1);
            missingGlyphShape = at.createTransformedShape(missingGlyphShape);

            missingGlyphElement.setAttributeNS(null, SVG_D_ATTRIBUTE,
                                    SVGPath.toSVGPathData(missingGlyphShape, generatorContext));
            missingGlyphElement.setAttributeNS(null, SVG_HORIZ_ADV_X_ATTRIBUTE, String.valueOf( gm.getAdvance() ) );
            fontDef.appendChild(missingGlyphElement);

            // set the font's default horizontal advance to be the same as
            // the missing glyph
            fontDef.setAttributeNS(null, SVG_HORIZ_ADV_X_ATTRIBUTE, String.valueOf( gm.getAdvance() ) );

            // set the ascent and descent attributes
            LineMetrics lm = commonSizeFont.getLineMetrics("By", localFRC);
            fontFace.setAttributeNS(null, SVG_ASCENT_ATTRIBUTE,  String.valueOf( lm.getAscent() ) );
            fontFace.setAttributeNS(null, SVG_DESCENT_ATTRIBUTE, String.valueOf( lm.getDescent() ) );

            //
            // Font ID
            //
            fontDef.setAttributeNS(null, SVG_ID_ATTRIBUTE,  generatorContext.idGenerator.generateID(ID_PREFIX_FONT));
        }

        //
        // add any new glyphs to the fontDef here
        //
        String textUsingFont = clh.getNewChars();
        clh.clearNewChars();

        // process the characters in textUsingFont backwards since the new chars
        // are at the end, can stop when find a char that already has a glyph
        for (int i = textUsingFont.length()-1; i >= 0; i--) {
            char c = textUsingFont.charAt(i);
            String searchStr = String.valueOf( c );
            boolean foundGlyph = false;
            NodeList fontChildren = fontDef.getChildNodes();
            for (int j = 0; j < fontChildren.getLength(); j++) {
                if (fontChildren.item(j) instanceof Element) {
                    Element childElement = (Element)fontChildren.item(j);
                    if (childElement.getAttributeNS(null, SVG_UNICODE_ATTRIBUTE).equals( searchStr )) {
                        foundGlyph = true;
                        break;
                    }
                }
            }
            if (!foundGlyph) {
                // need to create one
                Element glyphElement
                    = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                 SVG_GLYPH_TAG);

                GlyphVector gv;
                gv = commonSizeFont.createGlyphVector(localFRC, ""+c);
                Shape glyphShape = gv.getGlyphOutline(0);
                GlyphMetrics gm = gv.getGlyphMetrics(0);

                // need to turn the glyph upside down to be in the font
                // coordinate system (i.e Y axis up)
                AffineTransform at = AffineTransform.getScaleInstance(1, -1);
                glyphShape = at.createTransformedShape(glyphShape);

                glyphElement.setAttributeNS(null, SVG_D_ATTRIBUTE,
                                            SVGPath.toSVGPathData(glyphShape, generatorContext));
                glyphElement.setAttributeNS(null, SVG_HORIZ_ADV_X_ATTRIBUTE, String.valueOf( gm.getAdvance() ) );
                glyphElement.setAttributeNS(null, SVG_UNICODE_ATTRIBUTE,     String.valueOf( c ) );

                fontDef.appendChild(glyphElement);
            } else {
                // have reached the chars in textUsingFont that already
View Full Code Here

     * @param x the x coordinate of the point to be tested.
     * @param y the y coordinate of the point to be tested.
     */
    public TextHit hitTestChar(float x, float y) {
        TextHit textHit = null;
        GlyphMetrics gm;

        // if this layout is transformed, need to apply the inverse
        // transform to the point
        if (transform != null) {
            try {
View Full Code Here

        int currentChar = aci.getBeginIndex();

        // iterate through the GlyphVector placing each glyph
        for (int i = 0; i < gv.getNumGlyphs(); i++) {

            GlyphMetrics gm = gv.getGlyphMetrics(i);

            float glyphAdvance = gm.getAdvance();
            Point2D defaultGlyphPosition = gv.getDefaultGlyphPosition(i);
            Point2D currentGlyphPosition = gv.getGlyphPosition(i);
            float offsetX = (float)(currentGlyphPosition.getX()
                            - (defaultGlyphPosition.getX() + offset.getX()));
            float offsetY = (float)(currentGlyphPosition.getY()
View Full Code Here

     *
     * @return The glyph metrics.
     */
    public GlyphMetrics getGlyphMetrics() {
        if (metrics == null) {
            metrics = new GlyphMetrics(getHorizAdvX(),
                                       glyphNode.getOutline(null).getBounds2D(),
                                       GlyphMetrics.COMPONENT );
        }
        return metrics;
    }
View Full Code Here

     *
     * @param kern The kerning value to apply when calculating the glyph metrics.
     * @return The kerned glyph metics.
     */
    public GlyphMetrics getGlyphMetrics(float kern) {
        return new GlyphMetrics(getHorizAdvX() - (kern * kernScale),
                                glyphNode.getOutline(null).getBounds2D(),
                                GlyphMetrics.COMPONENT );

    }
View Full Code Here

        for (int i = 0; i < getNumGlyphs(); i++) {

            if (glyphVisible[i]) {
                AffineTransform glyphTransform = getGlyphTransform(i);
                GlyphMetrics glyphMetrics = getGlyphMetrics(i);

                if (glyphTransform == null && ascent != 0) {

                    float glyphX = (float)getGlyphPosition(i).getX();
                    float glyphY =  (float)getGlyphPosition(i).getY() - ascent;
                    float glyphWidth = glyphMetrics.getAdvance();
                    float glyphHeight = ascent + descent;

                    glyphLogicalBounds[i] = new Rectangle2D.Double(glyphX, glyphY, glyphWidth, glyphHeight);

                } else {
                    Shape glyphBounds = glyphMetrics.getBounds2D();
                    AffineTransform tr = AffineTransform.getTranslateInstance(getGlyphPosition(i).getX(),
                                                                          getGlyphPosition(i).getY());
                    if (glyphTransform != null) {
                        tr.concatenate(glyphTransform);
                    }
View Full Code Here

                AffineTransform glyphTransform = getGlyphTransform(i);

                if (glyphTransform == null) {

                    GlyphMetrics glyphMetrics = getGlyphMetrics(i);

                    float glyphX = (float)(getGlyphPosition(i).getX());
                    float glyphY =  (float)getGlyphPosition(i).getY() - ascent;
                    float glyphWidth = glyphMetrics.getAdvance();
                    float glyphHeight = ascent + descent;

                    glyphLogicalBounds[i] = new Rectangle2D.Double(glyphX, glyphY,
                                                     glyphWidth, glyphHeight);
View Full Code Here

  // iterate through the GlyphVector placing each glyph

  for (int i = 0; i < glyphs.getNumGlyphs(); i++) {
     
      GlyphMetrics gm = glyphs.getGlyphMetrics(i);

      float charAdvance = gm.getAdvance();

      Shape glyph = glyphs.getGlyphOutline(i);

      // if lengthAdjust was GLYPHS, then scale the glyph
      // by the lengthRatio in the X direction
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.