Author: kiwiwings
Date: Sat Jun 17 00:00:49 2017
New Revision: 1798986
URL: http://svn.apache.org/viewvc?rev=1798986&view=rev
Log:
#61169 - Text with Japanese characters overflows textbox
Modified:
poi/site/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextShape.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
Modified: poi/site/src/documentation/content/xdocs/status.xml
URL:
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1798986&r1=1798985&r2=1798986&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sat Jun 17 00:00:49 2017
@@ -58,6 +58,7 @@
<release version="3.17-beta1" date="2017-07-??">
<actions>
+ <action dev="PD" type="fix" fixes-bug="61169" module="SL Common">Text
with Japanese characters overflows textbox</action>
<action dev="PD" type="add" module="XSSF">XSSFTable improved support
for creating columns and setting table areas, without needing to use CT
classes</action>
<action dev="PD" type="fix" module="XSSF">XSSFTable should format
numeric/date cells when used as Column Header names as Excel does</action>
<action dev="PD" type="add" fixes-bug="61162"
module="HWPF">En-/decryption support for HWPF</action>
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java?rev=1798986&r1=1798985&r2=1798986&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java Sat Jun 17
00:00:49 2017
@@ -69,12 +69,21 @@ public class DrawTextFragment implements
/**
* @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
*/
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java?rev=1798986&r1=1798985&r2=1798986&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java Sat Jun 17
00:00:49 2017
@@ -215,6 +215,10 @@ public class DrawTextParagraph implement
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 implement
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;
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextShape.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextShape.java?rev=1798986&r1=1798985&r2=1798986&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextShape.java Sat Jun 17
00:00:49 2017
@@ -137,10 +137,7 @@ public class DrawTextShape extends DrawS
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 DrawS
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 DrawS
}
@Override
- protected TextShape<?,?> getShape() {
- return (TextShape<?,?>)shape;
+ protected TextShape<?,? extends TextParagraph<?,?,? extends TextRun>>
getShape() {
+ return (TextShape<?,? extends TextParagraph<?,?,? extends
TextRun>>)shape;
}
}
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java?rev=1798986&r1=1798985&r2=1798986&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
Sat Jun 17 00:00:49 2017
@@ -67,6 +67,7 @@ public abstract class XSLFTextShape exte
}
}
+ @Override
public Iterator<XSLFTextParagraph> iterator(){
return getTextParagraphs().iterator();
}
@@ -75,7 +76,9 @@ public abstract class XSLFTextShape exte
public String getText() {
StringBuilder out = new StringBuilder();
for (XSLFTextParagraph p : _paragraphs) {
- if (out.length() > 0) out.append('\n');
+ if (out.length() > 0) {
+ out.append('\n');
+ }
out.append(p.getText());
}
return out.toString();
@@ -109,7 +112,9 @@ public abstract class XSLFTextShape exte
@Override
public XSLFTextRun appendText(String text, boolean newParagraph) {
- if (text == null) return null;
+ if (text == null) {
+ return null;
+ }
// copy properties from last paragraph / textrun or paragraph end
marker
CTTextParagraphProperties otherPPr = null;
@@ -202,7 +207,9 @@ public abstract class XSLFTextShape exte
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
if(anchor == null) {
- if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor();
+ if(bodyPr.isSetAnchor()) {
+ bodyPr.unsetAnchor();
+ }
} else {
bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1));
}
@@ -212,6 +219,7 @@ public abstract class XSLFTextShape exte
@Override
public VerticalAlignment getVerticalAlignment(){
PropertyFetcher<VerticalAlignment> fetcher = new
TextBodyPropertyFetcher<VerticalAlignment>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetAnchor()){
int val = props.getAnchor().intValue();
@@ -230,7 +238,9 @@ public abstract class XSLFTextShape exte
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
if (isCentered == null) {
- if (bodyPr.isSetAnchorCtr()) bodyPr.unsetAnchorCtr();
+ if (bodyPr.isSetAnchorCtr()) {
+ bodyPr.unsetAnchorCtr();
+ }
} else {
bodyPr.setAnchorCtr(isCentered);
}
@@ -240,6 +250,7 @@ public abstract class XSLFTextShape exte
@Override
public boolean isHorizontalCentered(){
PropertyFetcher<Boolean> fetcher = new
TextBodyPropertyFetcher<Boolean>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetAnchorCtr()){
setValue(props.getAnchorCtr());
@@ -257,7 +268,9 @@ public abstract class XSLFTextShape exte
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
if(orientation == null) {
- if(bodyPr.isSetVert()) bodyPr.unsetVert();
+ if(bodyPr.isSetVert()) {
+ bodyPr.unsetVert();
+ }
} else {
bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1));
}
@@ -315,6 +328,7 @@ public abstract class XSLFTextShape exte
*/
public double getBottomInset(){
PropertyFetcher<Double> fetcher = new
TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetBIns()){
double val = Units.toPoints(props.getBIns());
@@ -338,6 +352,7 @@ public abstract class XSLFTextShape exte
*/
public double getLeftInset(){
PropertyFetcher<Double> fetcher = new
TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetLIns()){
double val = Units.toPoints(props.getLIns());
@@ -361,6 +376,7 @@ public abstract class XSLFTextShape exte
*/
public double getRightInset(){
PropertyFetcher<Double> fetcher = new
TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetRIns()){
double val = Units.toPoints(props.getRIns());
@@ -383,6 +399,7 @@ public abstract class XSLFTextShape exte
*/
public double getTopInset(){
PropertyFetcher<Double> fetcher = new
TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetTIns()){
double val = Units.toPoints(props.getTIns());
@@ -406,8 +423,11 @@ public abstract class XSLFTextShape exte
public void setBottomInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetBIns();
- else bodyPr.setBIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetBIns();
+ } else {
+ bodyPr.setBIns(Units.toEMU(margin));
+ }
}
}
@@ -420,8 +440,11 @@ public abstract class XSLFTextShape exte
public void setLeftInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetLIns();
- else bodyPr.setLIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetLIns();
+ } else {
+ bodyPr.setLIns(Units.toEMU(margin));
+ }
}
}
@@ -434,8 +457,11 @@ public abstract class XSLFTextShape exte
public void setRightInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetRIns();
- else bodyPr.setRIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetRIns();
+ } else {
+ bodyPr.setRIns(Units.toEMU(margin));
+ }
}
}
@@ -448,8 +474,11 @@ public abstract class XSLFTextShape exte
public void setTopInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetTIns();
- else bodyPr.setTIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetTIns();
+ } else {
+ bodyPr.setTIns(Units.toEMU(margin));
+ }
}
}
@@ -470,6 +499,7 @@ public abstract class XSLFTextShape exte
@Override
public boolean getWordWrap(){
PropertyFetcher<Boolean> fetcher = new
TextBodyPropertyFetcher<Boolean>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetWrap()){
setValue(props.getWrap() == STTextWrappingType.SQUARE);
@@ -500,9 +530,15 @@ public abstract class XSLFTextShape exte
public void setTextAutofit(TextAutofit value){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit();
- if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit();
- if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit();
+ if(bodyPr.isSetSpAutoFit()) {
+ bodyPr.unsetSpAutoFit();
+ }
+ if(bodyPr.isSetNoAutofit()) {
+ bodyPr.unsetNoAutofit();
+ }
+ if(bodyPr.isSetNormAutofit()) {
+ bodyPr.unsetNormAutofit();
+ }
switch(value){
case NONE: bodyPr.addNewNoAutofit(); break;
@@ -519,9 +555,13 @@ public abstract class XSLFTextShape exte
public TextAutofit getTextAutofit(){
CTTextBodyProperties bodyPr = getTextBodyPr();
if (bodyPr != null) {
- if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE;
- else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL;
- else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE;
+ if(bodyPr.isSetNoAutofit()) {
+ return TextAutofit.NONE;
+ } else if (bodyPr.isSetNormAutofit()) {
+ return TextAutofit.NORMAL;
+ } else if (bodyPr.isSetSpAutoFit()) {
+ return TextAutofit.SHAPE;
+ }
}
return TextAutofit.NORMAL;
}
@@ -551,7 +591,9 @@ public abstract class XSLFTextShape exte
public Placeholder getTextType(){
CTPlaceholder ph = getCTPlaceholder();
- if (ph == null) return null;
+ if (ph == null) {
+ return null;
+ }
int val = ph.getType().intValue();
return Placeholder.lookupOoxml(val);
@@ -571,12 +613,15 @@ public abstract class XSLFTextShape exte
*/
public Rectangle2D resizeToFitText(){
Rectangle2D anchor = getAnchor();
- if(anchor.getWidth() == 0.) throw new POIXMLException(
- "Anchor of the shape was not set.");
+
+ if(anchor.getWidth() == 0.) {
+ throw new POIXMLException("Anchor of the shape was not set.");
+ }
double height = getTextHeight();
height += 1; // add a pixel to compensate rounding errors
- anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(),
height);
+ Insets2D insets = getInsets();
+ anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(),
height+insets.top+insets.bottom);
setAnchor(anchor);
return anchor;
@@ -596,7 +641,9 @@ public abstract class XSLFTextShape exte
thisTB.setBodyPr((CTTextBodyProperties)otherTB.getBodyPr().copy());
- if (thisTB.isSetLstStyle()) thisTB.unsetLstStyle();
+ if (thisTB.isSetLstStyle()) {
+ thisTB.unsetLstStyle();
+ }
if (otherTB.isSetLstStyle()) {
thisTB.setLstStyle((CTTextListStyle)otherTB.getLstStyle().copy());
}
@@ -665,7 +712,9 @@ public abstract class XSLFTextShape exte
@Override
public TextPlaceholder getTextPlaceholder() {
Placeholder ph = getTextType();
- if (ph == null) return TextPlaceholder.BODY;
+ if (ph == null) {
+ return TextPlaceholder.BODY;
+ }
switch (ph) {
case BODY: return TextPlaceholder.BODY;
case TITLE: return TextPlaceholder.TITLE;
@@ -679,9 +728,9 @@ public abstract class XSLFTextShape exte
* Helper method to allow subclasses to provide their own text paragraph
*
* @param p the xml reference
- *
+ *
* @return a new text paragraph
- *
+ *
* @since POI 3.15-beta2
*/
protected XSLFTextParagraph newTextParagraph(CTTextParagraph p) {
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java?rev=1798986&r1=1798985&r2=1798986&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
(original)
+++
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
Sat Jun 17 00:00:49 2017
@@ -329,7 +329,8 @@ implements TextShape<HSLFShape,HSLFTextP
double height = getTextHeight();
height += 1; // add a pixel to compensate rounding errors
- anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(),
height);
+ Insets2D insets = getInsets();
+ anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(),
height+insets.top+insets.bottom);
setAnchor(anchor);
return anchor;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]