diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2017-06-17 00:00:49 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2017-06-17 00:00:49 +0000 |
commit | 7d31871ce58051a5be476ebbb63f3fccf3c848bf (patch) | |
tree | a7aede39c8bc5a4539c71fe0d16795655d1bfa20 /src/java/org/apache/poi | |
parent | 334a7b87b4b49e8efd964dea23e643425085b071 (diff) | |
download | poi-7d31871ce58051a5be476ebbb63f3fccf3c848bf.tar.gz poi-7d31871ce58051a5be476ebbb63f3fccf3c848bf.zip |
#61169 - Text with Japanese characters overflows textbox
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1798986 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawTextFragment.java | 13 | ||||
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawTextParagraph.java | 7 | ||||
-rw-r--r-- | src/java/org/apache/poi/sl/draw/DrawTextShape.java | 13 |
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; } } |