Skip to content

Commit c49e9ac

Browse files
committed
text: Fix x/y scaling of device text glyphs
Device text in FP cannot be scaled independently in x/y. Only the y scale is applied, and the x scale is set so that the aspect ratio of characters is preserved. It's used only for calculating metrics and sizing bounds.
1 parent 7df9ee2 commit c49e9ac

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

core/src/display_object/edit_text.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,22 @@ impl<'gc> EditText<'gc> {
791791
/// coordinate space into this object's local space.
792792
fn layout_to_local_matrix(self) -> Matrix {
793793
let bounds = self.0.bounds.get();
794-
Matrix::translate(
794+
let matrix = Matrix::translate(
795795
bounds.x_min + Self::GUTTER - Twips::from_pixels(self.0.hscroll.get()),
796796
bounds.y_min + Self::GUTTER - self.0.vertical_scroll_offset(),
797-
)
797+
);
798+
799+
if self.font_type() == FontType::Device {
800+
// Device text cannot be scaled independently in x/y.
801+
// Here we have to make sure the independent x/y scale applied for
802+
// the local coordinate space is reversed, leaving only y scale
803+
// and keeping the original aspect ratio in x.
804+
let m = self.local_to_global_matrix();
805+
let device_font_scale_x = m.d / m.a;
806+
matrix * Matrix::scale(device_font_scale_x, 1.0f32)
807+
} else {
808+
matrix
809+
}
798810
}
799811

800812
/// Returns the matrix for transforming from this object's

0 commit comments

Comments
 (0)