From: Nick Burch Date: Sun, 21 Sep 2008 17:49:20 +0000 (+0000) Subject: Fix bug #45784 - Support long chart titles in SeriesTextRecords X-Git-Tag: REL_3_2_FINAL~37 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d6250721e0099f847a3c6f3e3358c5c0d61291aa;p=poi.git Fix bug #45784 - Support long chart titles in SeriesTextRecords git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@697562 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index eb5ae733f3..815bbb0952 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45784 - Support long chart titles in SeriesTextRecords 45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out 45844 - Addtional diagnostics for HSLF SlideShowRecordDumper 45829 - HSSFPicture.getImageDimension() failed when DPI of image is zero diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 1718ff8411..3388499148 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45784 - Support long chart titles in SeriesTextRecords 45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out 45844 - Addtional diagnostics for HSLF SlideShowRecordDumper 45829 - HSSFPicture.getImageDimension() failed when DPI of image is zero diff --git a/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java b/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java index 1271ef8764..66c26b3214 100644 --- a/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java +++ b/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java @@ -75,7 +75,8 @@ public class SeriesTextRecord field_1_id = in.readShort(); field_2_textLength = in.readByte(); field_3_undocumented = in.readByte(); - field_4_text = in.readUnicodeLEString(field_2_textLength); + field_4_text = in.readUnicodeLEString( + LittleEndian.ubyteToInt(field_2_textLength)); } public String toString() @@ -163,18 +164,34 @@ public class SeriesTextRecord /** * Get the text length field for the SeriesText record. */ - public byte getTextLength() + public int getTextLength() { - return field_2_textLength; + return LittleEndian.ubyteToInt(field_2_textLength); } /** * Set the text length field for the SeriesText record. + * Needs to be wrapped. */ public void setTextLength(byte field_2_textLength) { this.field_2_textLength = field_2_textLength; } + /** + * Set the text length field for the SeriesText record. + */ + public void setTextLength(int field_2_textLength) + { + if(field_2_textLength > 255) { + throw new IllegalArgumentException("Length must be 0-255"); + } + if(field_2_textLength > 127) { + this.field_2_textLength = (byte) + (field_2_textLength-256); + } else { + this.field_2_textLength = (byte)field_2_textLength; + } + } /** * Get the undocumented field for the SeriesText record. diff --git a/src/testcases/org/apache/poi/hssf/data/45784.xls b/src/testcases/org/apache/poi/hssf/data/45784.xls new file mode 100644 index 0000000000..f0d25fddfb Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45784.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 4a43006997..cc3bf573d2 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1474,4 +1474,14 @@ public final class TestBugs extends TestCase { fail(); } catch(IllegalArgumentException e) {} } + + /** + * Charts with long titles + */ + public void test45784() { + // This used to break + HSSFWorkbook wb = openSample("45784.xls"); + assertEquals(1, wb.getNumberOfSheets()); + + } }