From: Nick Burch Date: Sat, 12 Jul 2008 17:21:54 +0000 (+0000) Subject: Support for cloning one extended format record onto another, plus tests X-Git-Tag: REL_3_2_FINAL~245 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=69d508e3e2e5e879188399f859638d77bf159c0d;p=poi.git Support for cloning one extended format record onto another, plus tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@676203 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java b/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java index c668d5f876..ae98387671 100644 --- a/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java @@ -1814,6 +1814,27 @@ public class ExtendedFormatRecord { return sid; } + + /** + * Clones all the style information from another + * ExtendedFormatRecord, onto this one. This + * will then hold all the same style options. + * + * If The source ExtendedFormatRecord comes from + * a different Workbook, you will need to sort + * out the font and format indicies yourself! + */ + public void cloneStyleFrom(ExtendedFormatRecord source) { + field_1_font_index = source.field_1_font_index; + field_2_format_index = source.field_2_format_index; + field_3_cell_options = source.field_3_cell_options; + field_4_alignment_options = source.field_4_alignment_options; + field_5_indention_options = source.field_5_indention_options; + field_6_border_options = source.field_6_border_options; + field_7_palette_options = source.field_7_palette_options; + field_8_adtl_palette_options = source.field_8_adtl_palette_options; + field_9_fill_palette_options = source.field_9_fill_palette_options; + } public int hashCode() { final int prime = 31; diff --git a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java index e8d1cdf443..573f615782 100755 --- a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java +++ b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java @@ -61,6 +61,7 @@ public final class AllRecordTests { result.addTestSuite(TestEmbeddedObjectRefSubRecord.class); result.addTestSuite(TestEndSubRecord.class); result.addTestSuite(TestEscherAggregate.class); + result.addTestSuite(TestExtendedFormatRecord.class); result.addTestSuite(TestExternalNameRecord.class); result.addTestSuite(TestFontRecord.class); result.addTestSuite(TestFontBasisRecord.class); diff --git a/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java new file mode 100644 index 0000000000..5bbf05be77 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestExtendedFormatRecord.java @@ -0,0 +1,138 @@ +/* ==================================================================== + 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 junit.framework.TestCase; +/** + */ +public final class TestExtendedFormatRecord extends TestCase { + byte[] header = new byte[] { + 0xE0-256, 00, 0x14, 00 // sid=e0, 20 bytes long + }; + byte[] data = new byte[] { + 00, 00, // Font 0 + 00, 00, // Format 0 + 0xF5-256, 0xFF-256, // Cell opts ... + 0x20, 00, // Alignment 20 + 00, 00, // Ident 0 + 00, 00, // Border 0 + 00, 00, // Palette 0 + 00, 00, 00, 00, // ADTL Palette 0 + 0xC0-256, 0x20 // Fill Palette 20c0 + }; + + public TestExtendedFormatRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + ExtendedFormatRecord record = new ExtendedFormatRecord(new TestcaseRecordInputStream((short)0xe0, (short)data.length, data)); + assertEquals(0, record.getFontIndex()); + assertEquals(0, record.getFormatIndex()); + assertEquals(0xF5-256, record.getCellOptions()); + assertEquals(0x20, record.getAlignmentOptions()); + assertEquals(0, record.getIndentionOptions()); + assertEquals(0, record.getBorderOptions()); + assertEquals(0, record.getPaletteOptions()); + assertEquals(0, record.getAdtlPaletteOptions()); + assertEquals(0x20c0, record.getFillPaletteOptions()); + + assertEquals( 20 + 4, record.getRecordSize() ); + record.validateSid((short)0xe0); + } + + public void testStore() + { +// .fontindex = 0 +// .formatindex = 0 +// .celloptions = fffffff5 +// .islocked = true +// .ishidden = false +// .recordtype= 1 +// .parentidx = fff +// .alignmentoptions= 20 +// .alignment = 0 +// .wraptext = false +// .valignment= 2 +// .justlast = 0 +// .rotation = 0 +// .indentionoptions= 0 +// .indent = 0 +// .shrinktoft= false +// .mergecells= false +// .readngordr= 0 +// .formatflag= false +// .fontflag = false +// .prntalgnmt= false +// .borderflag= false +// .paternflag= false +// .celloption= false +// .borderoptns = 0 +// .lftln = 0 +// .rgtln = 0 +// .topln = 0 +// .btmln = 0 +// .paleteoptns = 0 +// .leftborder= 0 +// .rghtborder= 0 +// .diag = 0 +// .paleteoptn2 = 0 +// .topborder = 0 +// .botmborder= 0 +// .adtldiag = 0 +// .diaglnstyl= 0 +// .fillpattrn= 0 +// .fillpaloptn = 20c0 +// .foreground= 40 +// .background= 41 + + ExtendedFormatRecord record = new ExtendedFormatRecord(); + record.setFontIndex((short)0); + record.setFormatIndex((short)0); + + record.setLocked(true); + record.setHidden(false); + record.setXFType((short)1); + record.setParentIndex((short)0xfff); + + record.setVerticalAlignment((short)2); + + record.setFillForeground((short)0x40); + record.setFillBackground((short)0x41); + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } + + public void testCloneOnto() throws Exception { + ExtendedFormatRecord base = new ExtendedFormatRecord(new TestcaseRecordInputStream((short)0xe0, (short)data.length, data)); + + ExtendedFormatRecord other = new ExtendedFormatRecord(); + other.cloneStyleFrom(base); + + byte [] recordBytes = other.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +}