You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/09/16 18:01:13 UTC
svn commit: r997811 - in /poi/trunk/src:
documentation/content/xdocs/status.xml
ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
Author: nick
Date: Thu Sep 16 16:01:12 2010
New Revision: 997811
URL: http://svn.apache.org/viewvc?rev=997811&view=rev
Log:
Fix bug #49941 - Correctly handle space preservation of XSSFRichTextRuns when applying fonts to parts of the string
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=997811&r1=997810&r2=997811&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Sep 16 16:01:12 2010
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta3" date="2010-??-??">
+ <action dev="poi-developers" type="fix">49941 - Correctly handle space preservation of XSSFRichTextRuns when applying fonts to parts of the string</action>
<action dev="poi-developers" type="fix">Correct XWPFRun detection of bold/italic in a paragraph with multiple runs of different styles</action>
<action dev="poi-developers" type="add">Link XWPFPicture to XWPFRun, so that embedded pictures can be access from where they live in the text stream</action>
<action dev="poi-developers" type="fix">Improve handling of Hyperlinks inside XWPFParagraph objects through XWPFHyperlinkRun</action>
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=997811&r1=997810&r2=997811&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Thu Sep 16 16:01:12 2010
@@ -193,6 +193,7 @@ public class XSSFRichTextString implemen
c.setT(txt);
runs.add(c);
pos += txt.length();
+ preserveSpaces(c.xgetT());
}
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=997811&r1=997810&r2=997811&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Thu Sep 16 16:01:12 2010
@@ -26,7 +26,16 @@ import org.apache.poi.hssf.usermodel.HSS
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.FormulaError;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
@@ -432,6 +441,84 @@ public final class TestXSSFBugs extends
}
/**
+ * Creating a rich string of "hello world" and applying
+ * a font to characters 1-5 means we have two strings,
+ * "hello" and " world". As such, we need to apply
+ * preserve spaces to the 2nd bit, lest we end up
+ * with something like "helloworld" !
+ */
+ public void test49941() throws Exception {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet s = wb.createSheet();
+ XSSFRow r = s.createRow(0);
+ XSSFCell c = r.createCell(0);
+
+ // First without fonts
+ c.setCellValue(
+ new XSSFRichTextString(" with spaces ")
+ );
+ assertEquals(" with spaces ", c.getRichStringCellValue().toString());
+ assertEquals(0, c.getRichStringCellValue().getCTRst().sizeOfRArray());
+ assertEquals(true, c.getRichStringCellValue().getCTRst().isSetT());
+ // Should have the preserve set
+ assertEquals(
+ 1,
+ c.getRichStringCellValue().getCTRst().xgetT().getDomNode().getAttributes().getLength()
+ );
+ assertEquals(
+ "preserve",
+ c.getRichStringCellValue().getCTRst().xgetT().getDomNode().getAttributes().item(0).getNodeValue()
+ );
+
+ // Save and check
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ s = wb.getSheetAt(0);
+ r = s.getRow(0);
+ c = r.getCell(0);
+ assertEquals(" with spaces ", c.getRichStringCellValue().toString());
+ assertEquals(0, c.getRichStringCellValue().getCTRst().sizeOfRArray());
+ assertEquals(true, c.getRichStringCellValue().getCTRst().isSetT());
+
+ // Change the string
+ c.setCellValue(
+ new XSSFRichTextString("hello world")
+ );
+ assertEquals("hello world", c.getRichStringCellValue().toString());
+ // Won't have preserve
+ assertEquals(
+ 0,
+ c.getRichStringCellValue().getCTRst().xgetT().getDomNode().getAttributes().getLength()
+ );
+
+ // Apply a font
+ XSSFFont f = wb.createFont();
+ f.setBold(true);
+ c.getRichStringCellValue().applyFont(0, 5, f);
+ assertEquals("hello world", c.getRichStringCellValue().toString());
+ // Does need preserving on the 2nd part
+ assertEquals(2, c.getRichStringCellValue().getCTRst().sizeOfRArray());
+ assertEquals(
+ 0,
+ c.getRichStringCellValue().getCTRst().getRArray(0).xgetT().getDomNode().getAttributes().getLength()
+ );
+ assertEquals(
+ 1,
+ c.getRichStringCellValue().getCTRst().getRArray(1).xgetT().getDomNode().getAttributes().getLength()
+ );
+ assertEquals(
+ "preserve",
+ c.getRichStringCellValue().getCTRst().getRArray(1).xgetT().getDomNode().getAttributes().item(0).getNodeValue()
+ );
+
+ // Save and check
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ s = wb.getSheetAt(0);
+ r = s.getRow(0);
+ c = r.getCell(0);
+ assertEquals("hello world", c.getRichStringCellValue().toString());
+ }
+
+ /**
* Repeatedly writing the same file which has styles
* TODO Currently failing
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org