int startIndex = measurer.getPosition();\r
int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);\r
\r
- int rtIdx = startIndex == 0 ? 0 : startIndex + 1;\r
- if(startIndex == 0 || startIndex == text.length() - 1) rtIdx = startIndex;\r
- else rtIdx = startIndex + 1;\r
+ boolean prStart = text.charAt(startIndex) == '\n';\r
+ if(prStart) measurer.setPosition(startIndex++);\r
\r
- RichTextRun rt = getRichTextRunAt(rtIdx);\r
+ RichTextRun rt = getRichTextRunAt(startIndex);\r
if(rt == null) {\r
- logger.log(POILogger.WARN, "RichTextRun not found at pos" + (startIndex + 1) + "; text.length: " + text.length());\r
+ logger.log(POILogger.WARN, "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());\r
break;\r
}\r
\r
int endIndex = measurer.getPosition();\r
\r
TextElement el = new TextElement();\r
+ el.ascent = textLayout.getAscent();\r
el._startIndex = startIndex;\r
el._endIndex = endIndex;\r
el._align = rt.getAlignment();\r
el._text = textLayout;\r
el._textOffset = rt.getTextOffset();\r
\r
- boolean prStart = text.charAt(startIndex) == '\n' || startIndex == 0;\r
- if (text.charAt(startIndex) == '\n'){\r
+ textHeight += textLayout.getAscent();\r
+ if (prStart || startIndex == 0){\r
int spaceBefore = rt.getSpaceBefore();\r
if (spaceBefore != 0) {\r
- float val = (textLayout.getAscent() + textLayout.getDescent()) * spaceBefore/100;\r
+ float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceBefore/100;\r
textHeight += val;\r
+ el.ascent += val;\r
}\r
}\r
- if(rt.isBullet() && prStart){\r
+\r
+ if(rt.isBullet() && (prStart || startIndex == 0)){\r
it.setIndex(startIndex);\r
\r
AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()), it.getAttributes());\r
}\r
}\r
\r
- textHeight += textLayout.getAscent() + textLayout.getDescent();\r
\r
+ float descent = textLayout.getDescent();\r
int lineSpacing = rt.getLineSpacing();\r
- if(lineSpacing != 0) el._spacing = textLayout.getLeading()*lineSpacing/100;\r
- else el._spacing = textLayout.getLeading();\r
-\r
- textHeight += el._spacing;\r
+ if(lineSpacing != 0) descent += textLayout.getLeading()*lineSpacing/100;\r
+ else descent = textLayout.getLeading();\r
+ textHeight += descent;\r
+\r
+ el.descent = descent;\r
+ if (prStart){\r
+ int spaceAfter = rt.getSpaceAfter();\r
+ if (spaceAfter != 0) {\r
+ float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceAfter/100;\r
+ textHeight += val;\r
+ el.descent += val;\r
+ }\r
+ }\r
\r
lines.add(el);\r
}\r
int valign = _shape.getVerticalAlignment();\r
double y0 = anchor.getY();\r
switch (valign){\r
- case TextBox.AnchorTopBaseline:\r
- case TextBox.AnchorTop:\r
+ case TextShape.AnchorTopBaseline:\r
+ case TextShape.AnchorTop:\r
y0 += _shape.getMarginTop();\r
break;\r
- case TextBox.AnchorBottom:\r
+ case TextShape.AnchorBottom:\r
y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();\r
break;\r
default:\r
- case TextBox.AnchorMiddle:\r
+ case TextShape.AnchorMiddle:\r
float delta = (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();\r
y0 += _shape.getMarginTop() + delta/2;\r
break;\r
//finally draw the text fragments\r
for (int i = 0; i < lines.size(); i++) {\r
TextElement elem = (TextElement)lines.get(i);\r
- y0 += elem._text.getAscent();\r
+ y0 += elem.ascent;\r
\r
Point2D.Double pen = new Point2D.Double();\r
pen.y = y0;\r
switch (elem._align) {\r
+ default:\r
case TextShape.AlignLeft:\r
pen.x = anchor.getX() + _shape.getMarginLeft();\r
break;\r
pen.x = anchor.getX() + _shape.getMarginLeft() +\r
(anchor.getWidth() - elem._text.getAdvance() - _shape.getMarginLeft() - _shape.getMarginRight());\r
break;\r
- default:\r
- pen.x = anchor.getX() + _shape.getMarginLeft();\r
- break;\r
}\r
if(elem._bullet != null){\r
elem._bullet.draw(graphics, (float)(pen.x + elem._bulletOffset), (float)pen.y);\r
}\r
elem._text.draw(graphics, (float)(pen.x + elem._textOffset), (float)pen.y);\r
\r
- y0 += elem._text.getDescent();\r
- y0 += elem._text.getLeading();\r
-\r
- y0 += elem._spacing;\r
+ y0 += elem.descent;\r
}\r
}\r
\r
\r
- public static class TextElement {\r
+ static class TextElement {\r
public TextLayout _text;\r
public int _textOffset;\r
public TextLayout _bullet;\r
public int _startIndex;\r
public int _endIndex;\r
public float _spacing;\r
+ public float ascent, descent;\r
}\r
}\r
int val = getParaTextPropVal("spacebefore");
return val == -1 ? 0 : val;
}
+
+ /**
+ * Sets spacing after a paragraph.
+ * <p>
+ * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
+ * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
+ * </p>
+ */
+ public void setSpaceAfter(int val) {
+ setParaTextPropVal("spaceafter", val);
+ }
+
+ /**
+ * Returns spacing after a paragraph
+ * <p>
+ * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
+ * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
+ * </p>
+ *
+ * @return the spacing before a paragraph
+ */
+ public int getSpaceAfter() {
+ int val = getParaTextPropVal("spaceafter");
+ return val == -1 ? 0 : val;
+ }
// --------------- Internal HSLF methods, not intended for end-user use! -------
/**