Skip to content

Commit e7cff9a

Browse files
committed
text: Implement proper layout_to_local_matrix inverse
Device text requires non-translation-only transformations in the layout_to_local_matrix, which requires the generic inverse() function to be called when calculating its inverse.
1 parent 3530930 commit e7cff9a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

core/src/display_object/edit_text.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -799,15 +799,12 @@ impl<'gc> EditText<'gc> {
799799

800800
/// Returns the matrix for transforming from this object's
801801
/// local space into its layout coordinate space.
802-
fn local_to_layout_matrix(self) -> Matrix {
803-
// layout_to_local contains only a translation,
804-
// no need to inverse the matrix generically.
805-
let Matrix { tx, ty, .. } = self.layout_to_local_matrix();
806-
Matrix::translate(-tx, -ty)
802+
fn local_to_layout_matrix(self) -> Option<Matrix> {
803+
self.layout_to_local_matrix().inverse()
807804
}
808805

809-
fn local_to_layout(self, local: Point<Twips>) -> Point<Twips> {
810-
self.local_to_layout_matrix() * local
806+
fn local_to_layout(self, local: Point<Twips>) -> Option<Point<Twips>> {
807+
Some(self.local_to_layout_matrix()? * local)
811808
}
812809

813810
pub fn replace_text(
@@ -1593,7 +1590,7 @@ impl<'gc> EditText<'gc> {
15931590
/// Characters are divided in half, the last line is extended, etc.
15941591
pub fn screen_position_to_index(self, position: Point<Twips>) -> Option<usize> {
15951592
let position = self.global_to_local(position)?;
1596-
let position = self.local_to_layout(position);
1593+
let position = self.local_to_layout(position)?;
15971594

15981595
// TODO We can use binary search for both y and x here
15991596

@@ -2305,7 +2302,7 @@ impl<'gc> EditText<'gc> {
23052302
return None;
23062303
}
23072304

2308-
let position = self.local_to_layout(position);
2305+
let position = self.local_to_layout(position)?;
23092306

23102307
Some(
23112308
self.0

0 commit comments

Comments
 (0)