Package java.awt.font

Examples of java.awt.font.GlyphVector


    private void appendLine(CharSequence characters, int start, int end,
        Font font, FontRenderContext fontRenderContext) {
        CharSequenceCharacterIterator line = new CharSequenceCharacterIterator(characters,
            start, end, start);
        GlyphVector glyphVector = font.createGlyphVector(fontRenderContext, line);
        rows.add(new Row(glyphVector, start));

        Rectangle2D textBounds = glyphVector.getLogicalBounds();
        width = Math.max(width, (float)textBounds.getWidth());
        height += textBounds.getHeight();
    }
View Full Code Here


        this.font = font;

        int missingGlyphCode = font.getMissingGlyphCode();
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();

        GlyphVector missingGlyphVector = font.createGlyphVector(fontRenderContext,
            new int[] {missingGlyphCode});
        Rectangle2D textBounds = missingGlyphVector.getLogicalBounds();

        Rectangle2D maxCharBounds = font.getMaxCharBounds(fontRenderContext);
        averageCharacterSize = new Dimensions((int)Math.ceil(textBounds.getWidth()),
            (int)Math.ceil(maxCharBounds.getHeight()));
View Full Code Here

                false, false);

        // Only a single line
        if (_string.indexOf('\n') < 0) {
            // Get the shape
            GlyphVector gv = _font.createGlyphVector(frc, _string);
            _shape = gv.getOutline();

            // If the string is only whitespace, then the drawing stuff
            // won't work properly. So we set the bounding box to a special
            // value.
            if (_string.trim().equals("")) {
                _bounds = new Rectangle2D.Float(0.0f, 0.0f, 1.0f, 1.0f);
            } else {
                _bounds = _shape.getBounds2D();
            }
        } else {
            // Multiple lines, so generate a compound shape
            double dy = _font.getMaxCharBounds(frc).getHeight();
            StringTokenizer lines = new StringTokenizer(_string, "\n", true);
            _shape = null;

            int count = 0;

            while (lines.hasMoreTokens()) {
                String line = lines.nextToken();

                if (line.equals("\n")) {
                    // Note that leading or trailing newlines are ignored.
                    count++;
                } else if (!line.trim().equals("")) {
                    GlyphVector gv = _font.createGlyphVector(frc, line);
                    Shape s = gv.getOutline();

                    if (_shape == null) {
                        _shape = s;
                    } else {
                        // Translate each line and append to the previous shape
View Full Code Here

    }

    @Override
    public Shape createStrokedShape( Shape shape ) {
        FontRenderContext frc = new FontRenderContext(null, true, true);
        GlyphVector glyphVector = font.createGlyphVector(frc, text);

        GeneralPath result = new GeneralPath();
        PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS );
        float points[] = new float[6];
        float moveX = 0, moveY = 0;
        float lastX = 0, lastY = 0;
        float thisX = 0, thisY = 0;
        int type = 0;
        float next = 0;
        int currentChar = 0;
        int length = glyphVector.getNumGlyphs();

        if ( length == 0 )
            return result;

        float factor = stretchToFit ? measurePathLength( shape )/(float)glyphVector.getLogicalBounds().getWidth() : 1.0f;
        float nextAdvance = 0;

        while ( currentChar < length && !it.isDone() ) {
            type = it.currentSegment( points );
            switch( type ){
            case PathIterator.SEG_MOVETO:
                moveX = lastX = points[0];
                moveY = lastY = points[1];
                result.moveTo( moveX, moveY );
                nextAdvance = glyphVector.getGlyphMetrics( currentChar ).getAdvance() * 0.5f;
                next = nextAdvance;
                break;

            case PathIterator.SEG_CLOSE:
                points[0] = moveX;
                points[1] = moveY;
                // Fall into....

                //$FALL-THROUGH$
            case PathIterator.SEG_LINETO:
                thisX = points[0];
                thisY = points[1];
                float dx = thisX-lastX;
                float dy = thisY-lastY;
                float distance = (float)Math.sqrt( dx*dx + dy*dy );
                if ( distance >= next ) {
                    float r = 1.0f/distance;
                    float angle = (float)Math.atan2( dy, dx );
                    while ( currentChar < length && distance >= next ) {
                        Shape glyph = glyphVector.getGlyphOutline( currentChar );
                        Point2D p = glyphVector.getGlyphPosition(currentChar);
                        float px = (float)p.getX();
                        float py = (float)p.getY();
                        float x = lastX + next*dx*r;
                        float y = lastY + next*dy*r;
                        float advance = nextAdvance;
                        nextAdvance = currentChar < length-1 ? glyphVector.getGlyphMetrics(currentChar+1).getAdvance() * 0.5f : 0;
                        t.setToTranslation( x, y );
                        t.rotate( angle );
                        t.translate( -px-advance, -py );
                        result.append( t.createTransformedShape( glyph ), false );
                        next += (advance+nextAdvance) * factor;
 
View Full Code Here

            if (line.equals("\n")) {
                // Note that leading or trailing newlines are ignored.
                y += dy;
            } else {
                GlyphVector gv = _font.createGlyphVector(frc, line);

                // Get the shape and bounds. Work around JDK1.4 bug.
                Shape s = gv.getOutline();
                Rectangle2D b;
                s = _transform.createTransformedShape(s);
                b = s.getBounds2D();

                if (_bounds == null) {
View Full Code Here

    public void drawString( String string, int[] codePoints, Graphics g, float fontSize,
            AffineTransform at, float x, float y ) throws IOException
    {
        Font awtFont = getawtFont();
        FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
        GlyphVector glyphs = null;
        boolean useCodepoints = codePoints != null && isType0Font();
        PDFont descendantFont = useCodepoints ? ((PDType0Font)this).getDescendantFont() : null;
        // symbolic fonts may trigger the same fontmanager.so/dll error as described below
        if (useCodepoints && !descendantFont.getFontDescriptor().isSymbolic())
        {
View Full Code Here

     *
     ***************************************************************************/

    @Override
    public void drawString(AttributedCharacterIterator iterator, float x, float y) {
        GlyphVector gv = font.createGlyphVector(frc, iterator);
        drawGlyphVector(gv, x, y);
    }
View Full Code Here

     *
     ***************************************************************************/

    @Override
    public void drawString(AttributedCharacterIterator iterator, float x, float y) {
        GlyphVector gv = font.createGlyphVector(frc, iterator);
        drawGlyphVector(gv, x, y);
    }
View Full Code Here

                = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                             SVG_MISSING_GLYPH_TAG);

            int missingGlyphCode[] = new int[1];
            missingGlyphCode[0] = commonSizeFont.getMissingGlyphCode();
            GlyphVector gv = commonSizeFont.createGlyphVector(frc, 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,
                                               "" + 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,  "" + gm.getAdvance());

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

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

        //
        // add any new glyphs to the fontDef here
        //

        // 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);
            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(""+c)) {
                        foundGlyph = true;
                        break;
                    }
                }
            }
            if (!foundGlyph) {
                // need to create one
                Element glyphElement
                    = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                 SVG_GLYPH_TAG);

                GlyphVector gv = commonSizeFont.createGlyphVector(frc, ""+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);
View Full Code Here

    public GVTGlyphVector createGlyphVector(FontRenderContext frc,
                                            char[] chars) {

        StringCharacterIterator sci =
            new StringCharacterIterator(new String(chars));
        GlyphVector gv = awtFont.createGlyphVector(frc, chars);
        return new AWTGVTGlyphVector(gv, this, scale, sci);
    }
View Full Code Here

TOP

Related Classes of java.awt.font.GlyphVector

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.