Commit 4b91046e authored by Alex Butler's avatar Alex Butler

Merge branch 'bench-compound-glyph-shape' into 'master'

Add benchmark test for compound glyph shape

See merge request !26
parents c960ee5d 1b5bd9f7
Pipeline #1261 passed with stages
in 2 minutes and 39 seconds
## master
* Remove all unsafe usage.
* Fix glyph positioning bug for compound glyphs (#18)
* Optimise compound glyph shape computation.
## 0.2.3
* Add `is_collection(&[u8]) -> bool`.
......
......@@ -8,6 +8,7 @@ use stb_truetype::*;
/// index map format 12
static DEJA_VU_MONO: &[u8] = include_bytes!("../fonts/DejaVuSansMono.ttf");
static ROBOTO: &[u8] = include_bytes!("../fonts/Roboto-Regular.ttf");
/// index map format 4
static GUDEA: &[u8] = include_bytes!("../fonts/Gudea-Regular.ttf");
......@@ -310,6 +311,44 @@ fn get_glyph_shape_gudea(b: &mut test::Bencher) {
);
}
#[bench]
fn get_glyph_shape_compound_glyph_roboto_colon(b: &mut test::Bencher) {
let font = FontInfo::new(&*ROBOTO, 0).unwrap();
let colon_index = font.find_glyph_index(':' as u32);
let mut shape = None;
b.iter(|| {
shape = font.get_glyph_shape(colon_index);
});
let shape: Vec<_> = shape.unwrap().iter().map(|v| vertex_to_tuple(*v)).collect();
assert_eq!(
shape,
vec![
(134, 97, -10, 0, 1),
(162, 177, 134, 145, 3),
(248, 209, 191, 209, 3),
(334, 177, 305, 209, 3),
(364, 97, 364, 145, 3),
(334, 20, 364, 51, 3),
(248, -11, 305, -11, 3),
(162, 20, 191, -11, 3),
(134, 97, 134, 51, 3),
(135, 980, -9, 883, 1),
(163, 1060, 135, 1028, 3),
(249, 1092, 192, 1092, 3),
(335, 1060, 306, 1092, 3),
(365, 980, 365, 1028, 3),
(335, 903, 365, 934, 3),
(249, 872, 306, 872, 3),
(163, 903, 192, 872, 3),
(135, 980, 135, 934, 3)
]
);
}
/// (advance_width, left_side_bearing)
fn h_metrics_to_tuple(h: HMetrics) -> (i32, i32) {
(h.advance_width, h.left_side_bearing)
......
......@@ -661,24 +661,21 @@ impl<Data: Deref<Target = [u8]>> FontInfo<Data> {
while more {
let mut mtx = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0];
let flags = BE::read_i16(comp);
comp = &comp[2..];
let gidx = BE::read_u16(comp);
comp = &comp[2..];
let [flags, gidx] = read_ints!(2, i16, comp);
comp = &comp[4..];
if flags & 2 != 0 {
// XY values
if flags & 1 != 0 {
// shorts
mtx[4] = BE::read_i16(comp) as f32;
comp = &comp[2..];
mtx[5] = BE::read_i16(comp) as f32;
comp = &comp[2..];
let [a, b] = read_ints!(2, i16, comp);
comp = &comp[4..];
mtx[4] = a as f32;
mtx[5] = b as f32;
} else {
mtx[4] = (comp[0] as i8) as f32;
comp = &comp[1..];
mtx[5] = (comp[0] as i8) as f32;
comp = &comp[1..];
mtx[5] = (comp[1] as i8) as f32;
comp = &comp[2..];
}
} else {
panic!("Matching points not supported.");
......@@ -692,22 +689,20 @@ impl<Data: Deref<Target = [u8]>> FontInfo<Data> {
mtx[3] = mtx[0];
} else if flags & (1 << 6) != 0 {
// WE_HAVE_AN_X_AND_YSCALE
mtx[0] = BE::read_i16(comp) as f32 / 16384.0;
comp = &comp[2..];
let [a, b] = read_ints!(2, i16, comp);
comp = &comp[4..];
mtx[0] = a as f32 / 16384.0;
mtx[1] = 0.0;
mtx[2] = 0.0;
mtx[3] = BE::read_i16(comp) as f32 / 16384.0;
comp = &comp[2..];
mtx[3] = b as f32 / 16384.0;
} else if flags & (1 << 7) != 0 {
// WE_HAVE_A_TWO_BY_TWO
mtx[0] = BE::read_i16(comp) as f32 / 16384.0;
comp = &comp[2..];
mtx[1] = BE::read_i16(comp) as f32 / 16384.0;
comp = &comp[2..];
mtx[2] = BE::read_i16(comp) as f32 / 16384.0;
comp = &comp[2..];
mtx[3] = BE::read_i16(comp) as f32 / 16384.0;
comp = &comp[2..];
let [a, b, c, d] = read_ints!(4, i16, comp);
comp = &comp[8..];
mtx[0] = a as f32 / 16384.0;
mtx[1] = b as f32 / 16384.0;
mtx[2] = c as f32 / 16384.0;
mtx[3] = d as f32 / 16384.0;
}
// Find transformation scales.
......
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