Lines 224-250
Link Here
|
224 |
String fntname = rt.getFontName(); |
224 |
String fntname = rt.getFontName(); |
225 |
Font font = new Font(fntname, style, size); |
225 |
Font font = new Font(fntname, style, size); |
226 |
|
226 |
|
227 |
float width = 0, height = 0; |
227 |
float width = 0, height = 0, leading = 0; |
228 |
String[] lines = txt.split("\r"); |
228 |
String[] lines = txt.split("\n"); |
229 |
for (int i = 0; i < lines.length; i++) { |
229 |
for (int i = 0; i < lines.length; i++) { |
230 |
if(lines[i].length() == 0) continue; |
230 |
if(lines[i].length() == 0) continue; |
231 |
|
231 |
|
232 |
TextLayout layout = new TextLayout(lines[i], font, _frc); |
232 |
TextLayout layout = new TextLayout(lines[i], font, _frc); |
233 |
|
233 |
|
|
|
234 |
leading = Math.max(leading, layout.getLeading()); |
234 |
width = Math.max(width, layout.getAdvance()); |
235 |
width = Math.max(width, layout.getAdvance()); |
|
|
236 |
height = Math.max(height, (height + (layout.getDescent() + layout.getAscent()))); |
237 |
} |
238 |
|
239 |
// add one character to width |
240 |
Rectangle2D charBounds = font.getMaxCharBounds(_frc); |
241 |
width += getMarginLeft() + getMarginRight() + charBounds.getWidth(); |
242 |
|
243 |
// add leading to height |
244 |
height += getMarginTop() + getMarginBottom() + leading; |
235 |
|
245 |
|
236 |
/** |
|
|
237 |
* Even if top and bottom margins are set to 0 PowerPoint |
238 |
* always sets extra space between the text and its bounding box. |
239 |
* |
240 |
* The approximation height = ascent*2 works good enough in most cases |
241 |
*/ |
242 |
height = Math.max(height, 2*layout.getAscent()); |
243 |
} |
244 |
|
245 |
width += getMarginLeft() + getMarginRight(); |
246 |
height += getMarginTop() + getMarginBottom(); |
247 |
|
248 |
Rectangle2D anchor = getAnchor2D(); |
246 |
Rectangle2D anchor = getAnchor2D(); |
249 |
anchor.setRect(anchor.getX(), anchor.getY(), width, height); |
247 |
anchor.setRect(anchor.getX(), anchor.getY(), width, height); |
250 |
setAnchor(anchor); |
248 |
setAnchor(anchor); |