poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r677028 - in /poi/trunk/src: java/org/apache/poi/hssf/record/FontRecord.java testcases/org/apache/poi/hssf/record/TestFontRecord.java
Date Tue, 15 Jul 2008 20:19:06 GMT
Author: nick
Date: Tue Jul 15 13:19:06 2008
New Revision: 677028

URL: http://svn.apache.org/viewvc?rev=677028&view=rev
Log:
Method to check if two fonts have the same contents

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/FontRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.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=677028&r1=677027&r2=677028&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 Tue Jul 15 13:19:06 2008
@@ -579,6 +579,31 @@
 		result = prime * result + field_10_font_name_len;
 		return result;
 	}
+	
+	/**
+	 * Does this FontRecord have all the same font
+	 *  properties as the supplied FontRecord?
+	 * Note that {@link #equals(Object)} will check
+	 *  for exact objects, while this will check
+	 *  for exact contents, because normally the
+	 *  font record's position makes a big
+	 *  difference too.  
+	 */
+	public boolean sameProperties(FontRecord other) {
+		return 
+		field_1_font_height         == other.field_1_font_height &&
+		field_2_attributes          == other.field_2_attributes &&
+		field_3_color_palette_index == other.field_3_color_palette_index &&
+		field_4_bold_weight         == other.field_4_bold_weight &&
+		field_5_super_sub_script    == other.field_5_super_sub_script &&
+		field_6_underline           == other.field_6_underline &&
+		field_7_family              == other.field_7_family &&
+		field_8_charset             == other.field_8_charset &&
+		field_9_zero                == other.field_9_zero &&
+		field_10_font_name_len      == other.field_10_font_name_len &&
+		field_11_font_name.equals(other.field_11_font_name)
+		;
+	}
 
 	/**
 	 * Only returns two for the same exact object -

Modified: 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=677028&r1=677027&r2=677028&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java Tue Jul 15 13:19:06
2008
@@ -121,4 +121,21 @@
         for (int i = 0; i < data.length; i++)
             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
     }
+    
+    public void testSameProperties() throws Exception {
+        FontRecord f1 = new FontRecord(new TestcaseRecordInputStream((short)0x31, (short)data.length,
data));
+        FontRecord f2 = new FontRecord(new TestcaseRecordInputStream((short)0x31, (short)data.length,
data));
+    	
+        assertTrue(f1.sameProperties(f2));
+        
+        f2.setFontName("Arial2");
+        assertFalse(f1.sameProperties(f2));
+        f2.setFontName("Arial");
+        assertTrue(f1.sameProperties(f2));
+        
+        f2.setFontHeight((short)11);
+        assertFalse(f1.sameProperties(f2));
+        f2.setFontHeight((short)0xc8);
+        assertTrue(f1.sameProperties(f2));
+    }
 }



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


Mime
View raw message