From: Nick Burch Date: Tue, 15 Jul 2008 20:19:06 +0000 (+0000) Subject: Method to check if two fonts have the same contents X-Git-Tag: REL_3_2_FINAL~239 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d526a30313ac2e9ce801092500a560872b41f961;p=poi.git Method to check if two fonts have the same contents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@677028 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/FontRecord.java b/src/java/org/apache/poi/hssf/record/FontRecord.java index d6a5ce859f..11ba3aaa89 100644 --- a/src/java/org/apache/poi/hssf/record/FontRecord.java +++ b/src/java/org/apache/poi/hssf/record/FontRecord.java @@ -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 - diff --git a/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java index 6485f586f9..d5051e9915 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFontRecord.java @@ -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)); + } }