--- C:/Users/nmische/Workspace/POI/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java (revision 663587) +++ C:/Users/nmische/Workspace/POI/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java (working copy) @@ -224,27 +224,25 @@ String fntname = rt.getFontName(); Font font = new Font(fntname, style, size); - float width = 0, height = 0; - String[] lines = txt.split("\r"); + 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(); + + // add leading to height + height += getMarginTop() + getMarginBottom() + leading; - /** - * Even if top and bottom margins are set to 0 PowerPoint - * always sets extra space between the text and its bounding box. - * - * The approximation height = ascent*2 works good enough in most cases - */ - height = Math.max(height, 2*layout.getAscent()); - } - - width += getMarginLeft() + getMarginRight(); - height += getMarginTop() + getMarginBottom(); - Rectangle2D anchor = getAnchor2D(); anchor.setRect(anchor.getX(), anchor.getY(), width, height); setAnchor(anchor);