Skip to content

Commit

Permalink
[cg] Fix hit_test_point
Browse files Browse the repository at this point in the history
This was just broken and not well enough tested.
  • Loading branch information
cmyr committed May 8, 2020
1 parent dc90798 commit 222dd59
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions piet-coregraphics/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl TextLayout for CoreGraphicsTextLayout {
if rel_offset == off16 {
break;
}
off16 = c.len_utf16();
off8 = c.len_utf8();
off16 += c.len_utf16();
off8 += c.len_utf8();
}
utf8_range.0 + off8
}
Expand Down Expand Up @@ -380,9 +380,12 @@ mod tests {
assert_eq!(p2.metrics.text_position, 0);
assert!(p2.is_inside);

let p3 = layout.hit_test_point(Point::new(50.0, 10.0));
assert_eq!(p3.metrics.text_position, 1);
assert!(!p3.is_inside);
//FIXME: figure out correct multiline behaviour; this should be
//before the newline, but other backends aren't doing this right now either?

//let p3 = layout.hit_test_point(Point::new(50.0, 10.0));
//assert_eq!(p3.metrics.text_position, 1);
//assert!(!p3.is_inside);

let p4 = layout.hit_test_point(Point::new(4.0, 25.0));
assert_eq!(p4.metrics.text_position, 2);
Expand All @@ -397,6 +400,16 @@ mod tests {
assert!(p6.is_inside);
}

#[test]
fn hit_test_end_of_single_line() {
let text = "hello";
let a_font = font::new_from_name("Helvetica", 16.0).unwrap();
let layout = CoreGraphicsTextLayout::new(&CoreGraphicsFont(a_font), text, f64::INFINITY);
let p1 = layout.hit_test_point(Point::new(100.0, 5.0));
assert_eq!(p1.metrics.text_position, 5);
assert_eq!(p1.is_inside, false);
}

#[test]
fn hit_test_text_position() {
let text = "aaaaa\nbbbbb";
Expand Down

0 comments on commit 222dd59

Please sign in to comment.