Skip to content

Commit ecf7acb

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 3e371e5 commit ecf7acb

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(
@@ -1601,7 +1598,7 @@ impl<'gc> EditText<'gc> {
16011598
/// Characters are divided in half, the last line is extended, etc.
16021599
pub fn screen_position_to_index(self, position: Point<Twips>) -> Option<usize> {
16031600
let position = self.global_to_local(position)?;
1604-
let position = self.local_to_layout(position);
1601+
let position = self.local_to_layout(position)?;
16051602

16061603
// TODO We can use binary search for both y and x here
16071604

@@ -2315,7 +2312,7 @@ impl<'gc> EditText<'gc> {
23152312
return None;
23162313
}
23172314

2318-
let position = self.local_to_layout(position);
2315+
let position = self.local_to_layout(position)?;
23192316

23202317
Some(
23212318
self.0

0 commit comments

Comments
 (0)