diff options
author | Nick Burch <nick@apache.org> | 2007-11-12 21:49:37 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2007-11-12 21:49:37 +0000 |
commit | 9f606116cbe5c5db1d90b03ce7f9703f7fdb2e82 (patch) | |
tree | f9350f17902e58003975b89471aec049eeef18e8 | |
parent | f9ebc1ae74d290098127f945b960556d2a64c0f9 (diff) | |
download | poi-9f606116cbe5c5db1d90b03ce7f9703f7fdb2e82.tar.gz poi-9f606116cbe5c5db1d90b03ce7f9703f7fdb2e82.zip |
Add support for Chart Title Format records (bug #43721)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@594307 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/documentation/content/xdocs/changes.xml | 1 | ||||
-rw-r--r-- | src/documentation/content/xdocs/status.xml | 1 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/ChartTitleFormatRecord.java | 146 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/RecordFactory.java | 3 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/data/WithFormattedGraphTitle.xls | bin | 0 -> 14336 bytes | |||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java | 87 |
6 files changed, 237 insertions, 1 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index f88c1582f6..ca6a475253 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ <!-- Don't forget to update status.xml too! --> <release version="3.0.2-FINAL" date="2007-??-??"> + <action dev="POI-DEVELOPERS" type="add">43721 - [PATCH] Support for Chart Title Format records</action> <action dev="POI-DEVELOPERS" type="fix">42794 - [PATCH] Fix for BOF records from things like Access</action> <action dev="POI-DEVELOPERS" type="fix">43648 - Fix for IntPtg and short vs int</action> <action dev="POI-DEVELOPERS" type="fix">43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn</action> diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 1dc3b60bcd..2b561f5549 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ <!-- Don't forget to update changes.xml too! --> <changes> <release version="3.0.2-FINAL" date="2007-??-??"> + <action dev="POI-DEVELOPERS" type="add">43721 - [PATCH] Support for Chart Title Format records</action> <action dev="POI-DEVELOPERS" type="fix">42794 - [PATCH] Fix for BOF records from things like Access</action> <action dev="POI-DEVELOPERS" type="fix">43648 - Fix for IntPtg and short vs int</action> <action dev="POI-DEVELOPERS" type="fix">43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn</action> diff --git a/src/java/org/apache/poi/hssf/record/ChartTitleFormatRecord.java b/src/java/org/apache/poi/hssf/record/ChartTitleFormatRecord.java new file mode 100644 index 0000000000..a9ec81e97a --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/ChartTitleFormatRecord.java @@ -0,0 +1,146 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +/* + * HSSF Chart Title Format Record Type + */ +package org.apache.poi.hssf.record; + +import org.apache.poi.util.LittleEndian; + +import java.util.ArrayList; + +/** + * Describes the formatting runs associated with a chart title. + */ +public class ChartTitleFormatRecord extends Record { + public static final short sid = 0x1050; + + private int m_recs; + + private class CTFormat { + private short m_offset; + private short m_fontIndex; + + protected CTFormat(short offset,short fontIdx){ + m_offset = offset; + m_fontIndex = fontIdx; + } + + public short getOffset(){ + return m_offset; + } + public void setOffset(short newOff){ + m_offset = newOff; + } + public short getFontIndex() { + return m_fontIndex; + } + } + + private ArrayList m_formats; + + public ChartTitleFormatRecord() { + super(); + } + + public ChartTitleFormatRecord(RecordInputStream in) { + super(in); + } + + protected void validateSid(short id) { + if (id != sid) + { + throw new RecordFormatException("NOT A CHARTTITLEFORMAT RECORD"); + } + } + + protected void fillFields(RecordInputStream in) { + m_recs = in.readUShort(); + int idx; + CTFormat ctf; + if (m_formats == null){ + m_formats = new ArrayList(m_recs); + } + for(idx=0;idx<m_recs;idx++) { + ctf = new CTFormat(in.readShort(),in.readShort()); + m_formats.add(ctf); + } + } + + public int serialize(int offset, byte [] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, + ( short ) (getRecordSize() - 4)); + int idx; + CTFormat ctf; + LittleEndian.putShort(data, 4 + offset,(short)m_formats.size()); + for(idx=0;idx<m_formats.size();idx++){ + ctf = (CTFormat)m_formats.get(idx); + LittleEndian.putShort(data, 6 + (idx * 4) + offset, ctf.getOffset()); + LittleEndian.putShort(data, 8 + (idx * 4) + offset, ctf.getFontIndex()); + } + + return getRecordSize(); + } + + public int getRecordSize() + { + return 4 + 2 + (4 * m_formats.size()); + } + + public short getSid() { + return sid; + } + + public int getFormatCount() { + return m_formats.size(); + } + + public void modifyFormatRun(short oldPos,short newLen) { + short shift = (short)0; + for(int idx=0;idx < m_formats.size();idx++) { + CTFormat ctf = (CTFormat)m_formats.get(idx); + if (shift != 0) { + ctf.setOffset((short)(ctf.getOffset() + shift)); + } else if ((oldPos == ctf.getOffset()) && (idx < (m_formats.size() - 1))){ + CTFormat nextCTF = (CTFormat)m_formats.get(idx + 1); + shift = (short)(newLen - (nextCTF.getOffset() - ctf.getOffset())); + } + } + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[CHARTTITLEFORMAT]\n"); + buffer.append(" .format_runs = ").append(m_recs) + .append("\n"); + int idx; + CTFormat ctf; + for(idx=0;idx<m_formats.size();idx++){ + ctf = (CTFormat)m_formats.get(idx); + buffer.append(" .char_offset= ").append(ctf.getOffset()); + buffer.append(",.fontidx= ").append(ctf.getFontIndex()); + buffer.append("\n"); + } + buffer.append("[/CHARTTITLEFORMAT]\n"); + return buffer.toString(); + } +} diff --git a/src/java/org/apache/poi/hssf/record/RecordFactory.java b/src/java/org/apache/poi/hssf/record/RecordFactory.java index 8f78212616..398576dc7c 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactory.java @@ -74,7 +74,8 @@ public class RecordFactory PaletteRecord.class, StringRecord.class, RecalcIdRecord.class, SharedFormulaRecord.class, HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class, WriteProtectRecord.class, FilePassRecord.class, PaneRecord.class, - NoteRecord.class, ObjectProtectRecord.class, ScenarioProtectRecord.class, FileSharingRecord.class + NoteRecord.class, ObjectProtectRecord.class, ScenarioProtectRecord.class, + FileSharingRecord.class, ChartTitleFormatRecord.class }; } private static Map recordsMap = recordsToMap(records); diff --git a/src/testcases/org/apache/poi/hssf/data/WithFormattedGraphTitle.xls b/src/testcases/org/apache/poi/hssf/data/WithFormattedGraphTitle.xls Binary files differnew file mode 100644 index 0000000000..477b1f6a15 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/data/WithFormattedGraphTitle.xls diff --git a/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java new file mode 100644 index 0000000000..d9931ef7f5 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestChartTitleFormatRecord.java @@ -0,0 +1,87 @@ + +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + + +package org.apache.poi.hssf.record; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; + +import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; +import org.apache.poi.hssf.eventusermodel.HSSFListener; +import org.apache.poi.hssf.eventusermodel.HSSFRequest; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + +import junit.framework.TestCase; + +public class TestChartTitleFormatRecord extends TestCase +{ + private String _test_file_path; + private static final String _test_file_path_property = "HSSF.testdata.path"; + + public TestChartTitleFormatRecord() + { + super(); + _test_file_path = System.getProperty( _test_file_path_property ) + + File.separator + "WithFormattedGraphTitle.xls"; + } + + public void testRecord() throws Exception { + POIFSFileSystem fs = new POIFSFileSystem( + new FileInputStream(_test_file_path) + ); + + // Check we can open the file via usermodel + HSSFWorkbook hssf = new HSSFWorkbook(fs); + + // Now process it through eventusermodel, and + // look out for the title records + ChartTitleFormatRecordGrabber grabber = + new ChartTitleFormatRecordGrabber(); + InputStream din = fs.createDocumentInputStream("Workbook"); + HSSFRequest req = new HSSFRequest(); + req.addListenerForAllRecords(grabber); + HSSFEventFactory factory = new HSSFEventFactory(); + factory.processEvents(req, din); + din.close(); + + // Should've found one + assertEquals(1, grabber.chartTitleFormatRecords.size()); + // And it should be of something interesting + ChartTitleFormatRecord r = + (ChartTitleFormatRecord)grabber.chartTitleFormatRecords.get(0); + assertEquals(3, r.getFormatCount()); + } + + public static class ChartTitleFormatRecordGrabber implements HSSFListener { + private ArrayList chartTitleFormatRecords = new ArrayList(); + + public void processRecord(Record record) { + if(record instanceof ChartTitleFormatRecord) { + chartTitleFormatRecords.add( + record + ); + } + } + + } +} |