Commit 3a88c927 authored by Alex Butler's avatar Alex Butler

Merge branch 'exo2-ttf-vs-otf' into 'master'

Exo2 ttf vs otf

See merge request !152
parents 683c55e8 d1574998
Pipeline #7312 passed with stages
in 5 minutes and 13 seconds
......@@ -8,9 +8,12 @@ static DEJA_VU_MONO: Lazy<Font<'static>> = Lazy::new(|| {
static OPEN_SANS_ITALIC: Lazy<Font<'static>> = Lazy::new(|| {
Font::try_from_bytes(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf") as &[u8]).unwrap()
});
static EXO2_OFT: Lazy<Font<'static>> = Lazy::new(|| {
static EXO2_OTF: Lazy<Font<'static>> = Lazy::new(|| {
Font::try_from_bytes(include_bytes!("../fonts/Exo2-Light.otf") as &[u8]).unwrap()
});
static EXO2_TTF: Lazy<Font<'static>> = Lazy::new(|| {
Font::try_from_bytes(include_bytes!("../fonts/Exo2-Light.ttf") as &[u8]).unwrap()
});
fn draw_big_biohazard(c: &mut Criterion) {
let glyph = DEJA_VU_MONO
......@@ -90,8 +93,8 @@ fn draw_iota(c: &mut Criterion) {
});
}
fn draw_oft_tailed_e(c: &mut Criterion) {
let glyph = EXO2_OFT
fn draw_otf_tailed_e(c: &mut Criterion) {
let glyph = EXO2_OTF
.glyph('ę')
.scaled(Scale::uniform(300.0))
.positioned(point(0.0, 0.0));
......@@ -106,7 +109,33 @@ fn draw_oft_tailed_e(c: &mut Criterion) {
);
let mut target = [0u8; WIDTH * HEIGHT];
c.bench_function("draw_oft_tailed_e", |b| {
c.bench_function("draw_otf_tailed_e", |b| {
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
});
});
}
fn draw_ttf_tailed_e(c: &mut Criterion) {
let glyph = EXO2_TTF
.glyph('ę')
.scaled(Scale::uniform(300.0))
.positioned(point(0.0, 0.0));
const WIDTH: usize = 106;
const HEIGHT: usize = 177;
let bounds = glyph.pixel_bounding_box().unwrap();
assert_eq!(
(bounds.width() as usize, bounds.height() as usize),
(WIDTH, HEIGHT)
);
let mut target = [0u8; WIDTH * HEIGHT];
c.bench_function("draw_ttf_tailed_e", |b| {
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
......@@ -121,7 +150,8 @@ criterion_group!(
draw_big_biohazard,
draw_w,
draw_iota,
draw_oft_tailed_e,
draw_otf_tailed_e,
draw_ttf_tailed_e,
);
criterion_main!(draw_benches);
......@@ -9,11 +9,10 @@ fn bench_layout_a_sentence(c: &mut Criterion) {
conveying a statement, question, exclamation, or command, and consisting of a main \
clause and sometimes one or more subordinate clauses.";
let font =
Font::try_from_bytes(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf") as &[u8])
.unwrap();
c.bench_function("layout_a_sentence", |b| {
let font =
Font::try_from_bytes(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf") as &[u8])
.unwrap();
let mut glyphs = vec![];
b.iter(|| {
......@@ -41,9 +40,10 @@ fn bench_layout_a_sentence(c: &mut Criterion) {
);
});
let font = Font::try_from_vec(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf").to_vec())
.unwrap();
c.bench_function("layout_a_sentence (vec)", |b| {
c.bench_function("layout_a_sentence (try_from_vec)", |b| {
let font =
Font::try_from_vec(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf").to_vec())
.unwrap();
let mut glyphs = vec![];
b.iter(|| {
......@@ -70,6 +70,64 @@ fn bench_layout_a_sentence(c: &mut Criterion) {
"c2a3483ddf5598ec869440c62d17efa5a4fe72f9893bcc05dd17be2adcaa7629"
);
});
c.bench_function("layout_a_sentence (exo2-otf)", |b| {
let font = Font::try_from_bytes(include_bytes!("../fonts/Exo2-Light.otf")).unwrap();
let mut glyphs = vec![];
b.iter(|| {
glyphs.clear();
glyphs.extend(font.layout(SENTENCE, Scale::uniform(25.0), point(100.0, 25.0)))
});
// verify the layout result against static reference hash
let mut hash = Blake2s::default();
for g in glyphs {
write!(
hash,
"{id}:{scale_x}:{scale_y}:{pos_x}:{pos_y}",
id = g.id().0,
scale_x = g.scale().x,
scale_y = g.scale().y,
pos_x = g.position().x,
pos_y = g.position().y,
)
.unwrap();
}
assert_eq!(
format!("{:x}", hash.result()),
"255381ba7ae154c0208f8e73a8620f78dcc2728b15fb9ec952026a99797d4ddc"
);
});
c.bench_function("layout_a_sentence (exo2-ttf)", |b| {
let font = Font::try_from_bytes(include_bytes!("../fonts/Exo2-Light.ttf")).unwrap();
let mut glyphs = vec![];
b.iter(|| {
glyphs.clear();
glyphs.extend(font.layout(SENTENCE, Scale::uniform(25.0), point(100.0, 25.0)))
});
// verify the layout result against static reference hash
let mut hash = Blake2s::default();
for g in glyphs {
write!(
hash,
"{id}:{scale_x}:{scale_y}:{pos_x}:{pos_y}",
id = g.id().0,
scale_x = g.scale().x,
scale_y = g.scale().y,
pos_x = g.position().x,
pos_y = g.position().y,
)
.unwrap();
}
assert_eq!(
format!("{:x}", hash.result()),
"255381ba7ae154c0208f8e73a8620f78dcc2728b15fb9ec952026a99797d4ddc"
);
});
}
criterion_group!(
......
No preview for this file type
dev/tests/reference_otf_tailed_e.png

2.37 KB | W: | H:

dev/tests/reference_otf_tailed_e.png

2.37 KB | W: | H:

dev/tests/reference_otf_tailed_e.png
dev/tests/reference_otf_tailed_e.png
dev/tests/reference_otf_tailed_e.png
dev/tests/reference_otf_tailed_e.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment