]> source.dussan.org Git - poi.git/commitdiff
Method to check if two fonts have the same contents
authorNick Burch <nick@apache.org>
Tue, 15 Jul 2008 20:19:06 +0000 (20:19 +0000)
committerNick Burch <nick@apache.org>
Tue, 15 Jul 2008 20:19:06 +0000 (20:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@677028 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/FontRecord.java
src/testcases/org/apache/poi/hssf/record/TestFontRecord.java

index d6a5ce859fa721e6a1a258ffd915474bad1c34a1..11ba3aaa897d0ec0dd1fed71acebbbd0fcff2f31 100644 (file)
@@ -579,6 +579,31 @@ public class FontRecord
                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 -
index 6485f586f9818222ed1848cd669175b8b0a9d403..d5051e99150d101dcb88998edc892570734f9fb6 100644 (file)
@@ -121,4 +121,21 @@ public class TestFontRecord
         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));
+    }
 }