<!-- 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>
<!-- 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>
--- /dev/null
+/* ====================================================================
+ 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();
+ }
+}
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);
--- /dev/null
+
+/* ====================================================================
+ 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
+ );
+ }
+ }
+
+ }
+}