Debian Codegraph @

debian/missing-sources/ttf-parser/tests/bitmap.rs

raw
1 use ttf_parser::{RasterGlyphImage, RasterImageFormat};
2
3 // NOTE: Bitmap.otb is an incomplete example font that was created specifically for this test.
4 // It is under the same license as the other source files in the project.
5 static FONT_DATA: &[u8] = include_bytes!("fonts/bitmap.otb");
6
7 #[test]
8 fn bitmap_font() {
9 let face = ttf_parser::Face::parse(FONT_DATA, 0).unwrap();
10 assert_eq!(face.units_per_em(), 800);
11 assert_eq!(
12 face.glyph_hor_advance(face.glyph_index('a').unwrap()),
13 Some(500)
14 );
15 const W: u8 = 0;
16 const B: u8 = 255;
17 assert_eq!(
18 face.glyph_raster_image(face.glyph_index('a').unwrap(), 1),
19 Some(RasterGlyphImage {
20 x: 0,
21 y: 0,
22 width: 4,
23 height: 4,
24 pixels_per_em: 8,
25 format: RasterImageFormat::BitmapGray8,
26 #[rustfmt::skip]
27 data: &[
28 W, B, B, B,
29 B, W, W, B,
30 B, W, W, B,
31 W, B, B, B
32 ]
33 })
34 );
35 assert_eq!(
36 face.glyph_raster_image(face.glyph_index('d').unwrap(), 1),
37 Some(RasterGlyphImage {
38 x: 0,
39 y: 0,
40 width: 4,
41 height: 6,
42 pixels_per_em: 8,
43 format: RasterImageFormat::BitmapGray8,
44 #[rustfmt::skip]
45 data: &[
46 W, W, W, B,
47 W, W, W, B,
48 W, B, B, B,
49 B, W, W, B,
50 B, W, W, B,
51 W, B, B, B
52 ]
53 })
54 );
55 assert_eq!(
56 face.glyph_raster_image(face.glyph_index('\"').unwrap(), 1),
57 Some(RasterGlyphImage {
58 x: 1,
59 y: 4,
60 width: 3,
61 height: 2,
62 pixels_per_em: 8,
63 format: RasterImageFormat::BitmapGray8,
64 #[rustfmt::skip]
65 data: &[
66 B, W, B,
67 B, W, B,
68 ]
69 })
70 );
71 }