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/05/28 15:44:45 UTC
svn commit: r949177 - in /poi/trunk/src: documentation/content/xdocs/
ooxml/java/org/apache/poi/xssf/model/
ooxml/java/org/apache/poi/xssf/usermodel/
ooxml/testcases/org/apache/poi/xssf/usermodel/
Author: nick
Date: Fri May 28 13:44:45 2010
New Revision: 949177
URL: http://svn.apache.org/viewvc?rev=949177&view=rev
Log:
Fix bug #48718 - Make the creation of multiple, un-modified fonts in a row in XSSF match the old HSSF behaviour
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.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=949177&r1=949176&r2=949177&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri May 28 13:44:45 2010
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">48718 - Make the creation of multiple, un-modified fonts in a row in XSSF match the old HSSF behaviour</action>
<action dev="POI-DEVELOPERS" type="fix">44916 - Allow access to the HSSFPatriarch from HSSFSheet once created</action>
<action dev="POI-DEVELOPERS" type="add">48779 - Allow you to get straight from a CellStyle to a Color, irrespective of if the Color is indexed or inline-defined</action>
<action dev="POI-DEVELOPERS" type="add">48924 - Allow access of the HWPF DateAndTime underlying date values</action>
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=949177&r1=949176&r2=949177&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Fri May 28 13:44:45 2010
@@ -176,14 +176,29 @@ public class StylesTable extends POIXMLD
return fonts.get(idx);
}
- public int putFont(XSSFFont font) {
- int idx = fonts.indexOf(font);
+ /**
+ * Records the given font in the font table.
+ * Will re-use an existing font index if this
+ * font matches another, EXCEPT if forced
+ * registration is requested.
+ * This allows people to create several fonts
+ * then customise them later.
+ */
+ public int putFont(XSSFFont font, boolean forceRegistration) {
+ int idx = -1;
+ if(!forceRegistration) {
+ idx = fonts.indexOf(font);
+ }
+
if (idx != -1) {
return idx;
}
fonts.add(font);
return fonts.size() - 1;
}
+ public int putFont(XSSFFont font) {
+ return putFont(font, false);
+ }
public XSSFCellStyle getStyleAt(int idx) {
int styleXfId = 0;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=949177&r1=949176&r2=949177&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Fri May 28 13:44:45 2010
@@ -85,7 +85,7 @@ public class XSSFFont implements Font {
setFontName(DEFAULT_FONT_NAME);
setFontHeight((double)DEFAULT_FONT_SIZE);
}
-
+
/**
* get the underlying CTFont font
*/
@@ -516,10 +516,11 @@ public class XSSFFont implements Font {
/**
- * Register ourselfs in the style table
+ * Perform a registration of ourselves
+ * to the style table
*/
- public long putFont(StylesTable styles) {
- short idx = (short)styles.putFont(this);
+ public long registerTo(StylesTable styles) {
+ short idx = (short)styles.putFont(this, true);
this._index = idx;
return idx;
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=949177&r1=949176&r2=949177&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Fri May 28 13:44:45 2010
@@ -453,7 +453,7 @@ public class XSSFWorkbook extends POIXML
*/
public XSSFFont createFont() {
XSSFFont font = new XSSFFont();
- font.putFont(stylesSource);
+ font.registerTo(stylesSource);
return font;
}
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=949177&r1=949176&r2=949177&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 Fri May 28 13:44:45 2010
@@ -20,14 +20,17 @@ package org.apache.poi.xssf.usermodel;
import java.util.List;
import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.BaseTestBugzillaIssues;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Font;
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;
@@ -259,4 +262,39 @@ public final class TestXSSFBugs extends
assertEquals(null, cs.getFillBackgroundXSSFColor().getARGBHex());
assertEquals(null, cs.getFillBackgroundColorColor().getARGBHex());
}
+
+ /**
+ * With HSSF, if you create a font, don't change it, and
+ * create a 2nd, you really do get two fonts that you
+ * can alter as and when you want.
+ * With XSSF, that wasn't the case, but this verfies
+ * that it now is again
+ */
+ public void test48718() throws Exception {
+ // Verify the HSSF behaviour
+ // Then ensure the same for XSSF
+ Workbook[] wbs = new Workbook[] {
+ new HSSFWorkbook(),
+ new XSSFWorkbook()
+ };
+ int[] initialFonts = new int[] { 4, 1 };
+ for(int i=0; i<wbs.length; i++) {
+ Workbook wb = wbs[i];
+ int startingFonts = initialFonts[i];
+
+ assertEquals(startingFonts, wb.getNumberOfFonts());
+
+ // Get a font, and slightly change it
+ Font a = wb.createFont();
+ assertEquals(startingFonts+1, wb.getNumberOfFonts());
+ a.setFontHeightInPoints((short)23);
+ assertEquals(startingFonts+1, wb.getNumberOfFonts());
+
+ // Get two more, unchanged
+ Font b = wb.createFont();
+ assertEquals(startingFonts+2, wb.getNumberOfFonts());
+ Font c = wb.createFont();
+ assertEquals(startingFonts+3, wb.getNumberOfFonts());
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org