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
This commit is contained in:
Nick Burch 2008-07-15 20:19:06 +00:00
parent 2765285706
commit 775fa5ed25
2 changed files with 42 additions and 0 deletions

View File

@ -580,6 +580,31 @@ public class FontRecord
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 -
* creating a second FontRecord with the same

View 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));
}
}