poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r676201 - in /poi/trunk/src: java/org/apache/poi/hssf/record/FontRecord.java testcases/org/apache/poi/hssf/record/AllRecordTests.java testcases/org/apache/poi/hssf/record/TestFontRecord.java
Date Sat, 12 Jul 2008 16:56:55 GMT
Author: nick
Date: Sat Jul 12 09:56:55 2008
New Revision: 676201

URL: http://svn.apache.org/viewvc?rev=676201&view=rev
Log:
Support for cloning one font record onto another, plus tests

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java?rev=676201&r1=676200&r2=676201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java Sat Jul 12 09:56:55 2008
@@ -531,6 +531,8 @@
 
     public int getRecordSize()
     {
+    	// Note - no matter the original, we always
+    	//  re-serialise the font name as unicode
         return (getFontNameLength() * 2) + 20;
     }
 
@@ -538,6 +540,25 @@
     {
         return sid;
     }
+    
+    /**
+     * Clones all the font style information from another
+     *  FontRecord, onto this one. This 
+     *  will then hold all the same font style options.
+     */
+    public void cloneStyleFrom(FontRecord source) {
+        field_1_font_height         = source.field_1_font_height; 
+        field_2_attributes          = source.field_2_attributes;
+        field_3_color_palette_index = source.field_3_color_palette_index;
+        field_4_bold_weight         = source.field_4_bold_weight;
+        field_5_super_sub_script    = source.field_5_super_sub_script;
+        field_6_underline           = source.field_6_underline;
+        field_7_family              = source.field_7_family;
+        field_8_charset             = source.field_8_charset;
+        field_9_zero                = source.field_9_zero;
+        field_10_font_name_len      = source.field_10_font_name_len;
+        field_11_font_name          = source.field_11_font_name;
+    }
 
 	public int hashCode() {
 		final int prime = 31;

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=676201&r1=676200&r2=676201&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Sat Jul 12 09:56:55
2008
@@ -62,6 +62,7 @@
 		result.addTestSuite(TestEndSubRecord.class);
 		result.addTestSuite(TestEscherAggregate.class);
 		result.addTestSuite(TestExternalNameRecord.class);
+		result.addTestSuite(TestFontRecord.class);
 		result.addTestSuite(TestFontBasisRecord.class);
 		result.addTestSuite(TestFontIndexRecord.class);
 		result.addTestSuite(TestFormulaRecord.class);

Added: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java?rev=676201&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java Sat Jul 12 09:56:55
2008
@@ -0,0 +1,124 @@
+
+/* ====================================================================
+   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;
+
+/**
+ * Tests the serialization and deserialization of the FontRecord
+ * class works correctly.  Test data taken directly from a real
+ * Excel file.
+ */
+public class TestFontRecord
+        extends TestCase
+{
+	byte[] header = new byte[] {
+    		0x31, 00, 0x1a, 00, // sid=31, 26 bytes long
+	};
+    byte[] data = new byte[] {
+    		0xC8-256, 00,       // font height = xc8
+    		00, 00,             // attrs = 0 
+    		0xFF-256, 0x7F,     // colour palette = x7fff 
+    		0x90-256, 0x01,     // bold weight = x190
+    		00, 00,  // supersubscript
+    		00, 00,  // underline, family
+    		00, 00,  // charset, padding
+    		05, 01,  // name length, unicode flag
+    		0x41, 0x00, 0x72, 0x00, 0x69, // Arial, as unicode 
+    		0x00, 0x61, 0x00, 0x6C, 0x00
+    };
+
+    public TestFontRecord(String name)
+    {
+        super(name);
+    }
+
+    public void testLoad()
+            throws Exception
+    {
+
+        FontRecord record = new FontRecord(new TestcaseRecordInputStream((short)0x31, (short)data.length,
data));
+        assertEquals( 0xc8, record.getFontHeight());
+        assertEquals( 0x00, record.getAttributes());
+        assertFalse( record.isItalic());
+        assertFalse( record.isStruckout());
+        assertFalse( record.isMacoutlined());
+        assertFalse( record.isMacshadowed());
+        assertEquals( 0x7fff, record.getColorPaletteIndex());
+        assertEquals( 0x190, record.getBoldWeight());
+        assertEquals( 0x00, record.getSuperSubScript());
+        assertEquals( 0x00, record.getUnderline());
+        assertEquals( 0x00, record.getFamily());
+        assertEquals( 0x00, record.getCharset());
+        assertEquals( 0x05, record.getFontNameLength());
+        assertEquals( "Arial", record.getFontName());
+
+
+        assertEquals( 26 + 4, record.getRecordSize() );
+        record.validateSid((short)0x31);
+    }
+
+    public void testStore()
+    {
+//      .fontheight      = c8
+//      .attributes      = 0
+//           .italic     = false
+//           .strikout   = false
+//           .macoutlined= false
+//           .macshadowed= false
+//      .colorpalette    = 7fff
+//      .boldweight      = 190
+//      .supersubscript  = 0
+//      .underline       = 0
+//      .family          = 0
+//      .charset         = 0
+//      .namelength      = 5
+//      .fontname        = Arial
+
+        FontRecord record = new FontRecord();
+        record.setFontHeight((short)0xc8);
+        record.setAttributes((short)0);
+        record.setColorPaletteIndex((short)0x7fff);
+        record.setBoldWeight((short)0x190);
+        record.setSuperSubScript((short)0);
+        record.setUnderline((byte)0);
+        record.setFamily((byte)0);
+        record.setCharset((byte)0);
+        record.setFontNameLength((byte)5);
+        record.setFontName("Arial");
+
+        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 {
+        FontRecord base = new FontRecord(new TestcaseRecordInputStream((short)0x31, (short)data.length,
data));
+    	
+        FontRecord other = new FontRecord();
+        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]);
+    }
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message