| 1 |
#[test] |
| 2 |
fn test_font_data_creation() { |
| 3 |
// Load a sample TTF font file from the test resources |
| 4 |
let font_file = std::fs::read("./tests/resources/fonts/Montserrat-Regular.ttf"); |
| 5 |
|
| 6 |
// Ensure the font file was read successfully |
| 7 |
assert!(font_file.is_ok(), "Failed to read font file"); |
| 8 |
|
| 9 |
// Unwrap the result to get the font file bytes |
| 10 |
let font_file = font_file.unwrap(); |
| 11 |
let mut font_data = lopdf::FontData::new(&font_file, "Montserrat-Regular".to_string()); |
| 12 |
|
| 13 |
// Create a new FontData instance |
| 14 |
font_data |
| 15 |
.set_font_bbox((0, -200, 1000, 800)) |
| 16 |
.set_italic_angle(10) |
| 17 |
.set_ascent(800) |
| 18 |
.set_descent(-200) |
| 19 |
.set_cap_height(700) |
| 20 |
.set_stem_v(100) |
| 21 |
.set_flags(4) |
| 22 |
.set_encoding("WinAnsiEncoding".to_string()); |
| 23 |
|
| 24 |
// Verify the properties of the FontData instance |
| 25 |
assert_eq!(font_data.font_bbox, (0, -200, 1000, 800)); |
| 26 |
assert_eq!(font_data.italic_angle, 10); |
| 27 |
assert_eq!(font_data.ascent, 800); |
| 28 |
assert_eq!(font_data.descent, -200); |
| 29 |
assert_eq!(font_data.cap_height, 700); |
| 30 |
assert_eq!(font_data.stem_v, 100); |
| 31 |
assert_eq!(font_data.flags, 4); |
| 32 |
assert_eq!(font_data.encoding, "WinAnsiEncoding"); |
| 33 |
assert!(!font_data.bytes().is_empty(), "Font data should not be empty"); |
| 34 |
} |