aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTextFragment.java13
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTextParagraph.java7
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTextShape.java13
3 files changed, 23 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextFragment.java b/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
index 178983d5e1..0eceb93643 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
@@ -69,12 +69,21 @@ public class DrawTextFragment implements Drawable {
/**
* @return full height of this text run which is sum of ascent, descent and leading
*/
- public float getHeight(){
- double h = Math.ceil(layout.getAscent()) + Math.ceil(layout.getDescent()) + layout.getLeading();
+ public float getHeight(){
+ double h = Math.ceil(layout.getAscent()) + Math.ceil(layout.getDescent()) + getLeading();
return (float)h;
}
/**
+ * @return the leading height before/after a text line
+ */
+ public float getLeading() {
+ // fix invalid leadings (leading == 0) by fallback to descent
+ double l = layout.getLeading();
+ return (float)(l == 0 ? layout.getDescent() : l);
+ }
+
+ /**
*
* @return width if this text run
*/
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
index d978b3c371..10d4edfd62 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
@@ -215,6 +215,10 @@ public class DrawTextParagraph implements Drawable {
y = penY - y;
}
+ public float getFirstLineLeading() {
+ return (lines.isEmpty()) ? 0 : lines.get(0).getLeading();
+ }
+
public float getFirstLineHeight() {
return (lines.isEmpty()) ? 0 : lines.get(0).getHeight();
}
@@ -253,7 +257,8 @@ public class DrawTextParagraph implements Drawable {
for (;;) {
int startIndex = measurer.getPosition();
- double wrappingWidth = getWrappingWidth(lines.size() == 0, graphics) + 1; // add a pixel to compensate rounding errors
+ // add a pixel to compensate rounding errors
+ double wrappingWidth = getWrappingWidth(lines.isEmpty(), graphics) + 1;
// shape width can be smaller that the sum of insets (this was proved by a test file)
if(wrappingWidth < 0) {
wrappingWidth = 1;
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextShape.java b/src/java/org/apache/poi/sl/draw/DrawTextShape.java
index 89f85a2f02..cffffb4a88 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTextShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTextShape.java
@@ -137,10 +137,7 @@ public class DrawTextShape extends DrawSimpleShape {
DrawFactory fact = DrawFactory.getInstance(graphics);
double y0 = y;
- //noinspection RedundantCast
- @SuppressWarnings("cast")
- Iterator<? extends TextParagraph<?,?,? extends TextRun>> paragraphs =
- (Iterator<? extends TextParagraph<?,?,? extends TextRun>>) getShape().iterator();
+ Iterator<? extends TextParagraph<?,?,? extends TextRun>> paragraphs = getShape().iterator();
boolean isFirstLine = true;
for (int autoNbrIdx=0; paragraphs.hasNext(); autoNbrIdx++){
@@ -158,7 +155,9 @@ public class DrawTextShape extends DrawSimpleShape {
dp.setAutoNumberingIdx(autoNbrIdx);
dp.breakText(graphics);
- if (!isFirstLine) {
+ if (isFirstLine) {
+ y += dp.getFirstLineLeading();
+ } else {
// the amount of vertical white space before the paragraph
Double spaceBefore = p.getSpaceBefore();
if (spaceBefore == null) spaceBefore = 0d;
@@ -221,7 +220,7 @@ public class DrawTextShape extends DrawSimpleShape {
}
@Override
- protected TextShape<?,?> getShape() {
- return (TextShape<?,?>)shape;
+ protected TextShape<?,? extends TextParagraph<?,?,? extends TextRun>> getShape() {
+ return (TextShape<?,? extends TextParagraph<?,?,? extends TextRun>>)shape;
}
}