Package com.google.code.appengine.awt.font

Examples of com.google.code.appengine.awt.font.TextLayout


        // TextLayout draws the iterator as glyph vector
        // thats why we use it only in the case of TEXT_AS_SHAPES,
        // otherwise tagged strings are always written as glyphs
        if (isProperty(TEXT_AS_SHAPES)) {
            // draws all attributes
            TextLayout tl = new TextLayout(iterator, getFontRenderContext());
            tl.draw(this, x, y);
        } else {
            // reset to that font at the end
            Font font = getFont();

            // initial attributes, we us TextAttribute.equals() rather
            // than Font.equals() because using Font.equals() we do
            // not get a 'false' if underline etc. is changed
            Map/*<TextAttribute, ?>*/ attributes = FontUtilities.getAttributes(font);

            // stores all characters which are written with the same font
            // if font is changed the buffer will be written and cleared
            // after it
            StringBuffer sb = new StringBuffer();

            for (char c = iterator.first();
                 c != AttributedCharacterIterator.DONE;
                 c = iterator.next()) {

                // append c if font is not changed
                if (attributes.equals(iterator.getAttributes())) {
                    sb.append(c);

                } else {
                    // TextLayout does not like 0 length strings
                    if (sb.length() > 0) {
                        // draw sb if font is changed
                        drawString(sb.toString(), x, y);
   
                        // change the x offset for the next drawing
                        // FIXME: change y offset for vertical text
                        TextLayout tl = new TextLayout(
                            sb.toString(),
                            attributes,
                            getFontRenderContext());
   
                        // calculate real width
                        x = x + Math.max(
                            tl.getAdvance(),
                            (float)tl.getBounds().getWidth());
                    }
                   
                    // empty sb
                    sb = new StringBuffer();
                    sb.append(c);
View Full Code Here


     * @param font font for width calulation
     * @param x position of text
     * @param y position of text
     */
    protected void overLine(String text, Font font, float x, float y) {
        TextLayout layout = new TextLayout(text, font, getFontRenderContext());
        float width = Math.max(
            layout.getAdvance(),
            (float) layout.getBounds().getWidth());

        GeneralPath path = new GeneralPath();
        path.moveTo(x, y + (float) layout.getBounds().getY() - layout.getAscent());
        path.lineTo(x + width, y + (float) layout.getBounds().getY() - layout.getAscent() - layout.getAscent());
        draw(path);
    }
View Full Code Here

            if (_shape.getWordWrap() == TextShape.WrapNone) {
                wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
            }

            TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,
                    nextBreak == -1 ? paragraphEnd : nextBreak, true);
            if (textLayout == null) {
                textLayout = measurer.nextLayout(textWidth,
                    nextBreak == -1 ? paragraphEnd : nextBreak, false);
            }
            if(textLayout == null){
                logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+
                        "; text: " + rt.getText());
                measurer.setPosition(rt.getEndIndex());
                continue;
            }
            int endIndex = measurer.getPosition();

            float lineHeight = (float)textLayout.getBounds().getHeight();
            int linespacing = rt.getLineSpacing();
            if(linespacing == 0) linespacing = 100;

            TextElement el = new TextElement();
            if(linespacing >= 0){
                el.ascent = textLayout.getAscent()*linespacing/100;
            } else {
                el.ascent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
            }

            el._align = rt.getAlignment();
            el.advance = textLayout.getAdvance();
            el._textOffset = textOffset;
            el._text = new AttributedString(it, startIndex, endIndex);
            el.textStartIndex = startIndex;
            el.textEndIndex = endIndex;

            if (prStart){
                int sp = rt.getSpaceBefore();
                float spaceBefore;
                if(sp >= 0){
                    spaceBefore = lineHeight * sp/100;
                } else {
                    spaceBefore = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
                }
                el.ascent += spaceBefore;
            }

            float descent;
            if(linespacing >= 0){
                descent = (textLayout.getDescent() + textLayout.getLeading())*linespacing/100;
            } else {
                descent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
            }
            if (prStart){
                int sp = rt.getSpaceAfter();
View Full Code Here

   * @param title
   * @param axisTitleFont
   **********************************************************************************************/
  public final void computeAxisTitleDimensions( String title, ChartFont axisTitleFont )
  {
    TextLayout textLayout = new TextLayout( title,
                               axisTitleFont.getFont(),
                               this.getAxisChart().getGraphics2D().getFontRenderContext() );

    this.titleWidth = textLayout.getAdvance();
    this.titleHeight = textLayout.getAscent() + textLayout.getDescent();
  }
View Full Code Here

   * @param derivedFont is the transformed font
   * @param fontRenderContext
   **********************************************************************************************/
  public TextTag( String text, Font baseFont, Font derivedFont, FontRenderContext fontRenderContext )
  {
    this.textLayout = new TextLayout( text, baseFont, fontRenderContext );

    this.isDerived = (derivedFont != null);
    this.derivedFont = derivedFont;

    //---Dimensions
View Full Code Here

            // the size of the design grid on which glyphs are laid out
            result.append("units-per-em=\"");
            result.append(SVGGraphics2D.fixedPrecision(SVGGlyph.FONT_SIZE));
            result.append("\" ");

            TextLayout tl = new TextLayout("By", font, new FontRenderContext(new AffineTransform(), true, true));

            // The maximum unaccented height of the font within the font coordinate system.
            // If the attribute is not specified, the effect is as if the attribute were set
            // to the difference between the units-per-em value and the vert-origin-y value
            // for the corresponding font.
            result.append("ascent=\"");
            result.append(tl.getAscent());
            result.append("\" ");

            // The maximum unaccented depth of the font within the font coordinate system.
            // If the attribute is not specified, the effect is as if the attribute were set
            // to the vert-origin-y value for the corresponding font.
            result.append("desscent=\"");
            result.append(tl.getDescent());
            result.append("\" ");

            // For horizontally oriented glyph layouts, indicates the alignment
            // coordinate for glyphs to achieve alphabetic baseline alignment.
            // result.append("alphabetic=\"0\"
View Full Code Here

            int vertical, boolean framed, Color frameColor, double frameWidth,
            boolean banner, Color bannerColor) {

        // change the x offset for the next drawing
        // FIXME: change y offset for vertical text
        TextLayout tl = new TextLayout(
            str,
            FontUtilities.getAttributes(getFont()),
            getFontRenderContext());

        // draw the frame
View Full Code Here

    public void drawString(TagString str, double x, double y, int horizontal,
            int vertical, boolean framed, Color frameColor, double frameWidth,
            boolean banner, Color bannerColor) {

    GenericTagHandler tagHandler = new GenericTagHandler(this);
    TextLayout tl = tagHandler.createTextLayout(str, getFont().getSize2D() / 7.5);

        // draw the frame
        Point2D offset = drawFrameAndBanner(
            tl, x, y, horizontal, vertical,
            framed, frameColor, frameWidth, banner, bannerColor);
View Full Code Here

        //                layout.draw(g2, x, y);
        //            }

        if (path != null) {
            // do not use g2.drawString(str, x, y) to be aware of path
            TextLayout tl = new TextLayout(
                text,
                g2.getFont(),
                g2.getFontRenderContext());
            path.append(tl.getOutline(null), false);
        } else {
            g2.setPaint(textColor);
            g2.drawString(text, (int)x, (int)y);
        }
    }
View Full Code Here

        float width = 0, height = 0, leading = 0;
        String[] lines = txt.split("\n");
        for (int i = 0; i < lines.length; i++) {
            if(lines[i].length() == 0) continue;

            TextLayout layout = new TextLayout(lines[i], font, _frc);

            leading = Math.max(leading, layout.getLeading());
            width = Math.max(width, layout.getAdvance());
            height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
        }

        // add one character to width
        Rectangle2D charBounds = font.getMaxCharBounds(_frc);
        width += getMarginLeft() + getMarginRight() + charBounds.getWidth();
View Full Code Here

TOP

Related Classes of com.google.code.appengine.awt.font.TextLayout

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.