Skip to content

Commit 4ce34f5

Browse files
committed
text: Simplify font base transform while evaluating
The ty value of the base transform is pretty straightforward: it's the baseline, as glyphs are rendered at the baseline. It was unnecessarily quite complicated before this patch.
1 parent 8ced87a commit 4ce34f5

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

core/src/display_object/edit_text.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -826,16 +826,9 @@ impl<'gc> EditText<'gc> {
826826
/// This `text_transform` is separate from and relative to the base
827827
/// transform that this `EditText` automatically gets by virtue of being a
828828
/// `DisplayObject`.
829-
pub fn text_transform(self, color: Color, baseline_adjustment: Twips) -> Transform {
829+
pub fn text_transform(self, color: Color) -> Transform {
830830
let mut transform: Transform = Default::default();
831831
transform.color_transform.set_mult_color(color);
832-
833-
// TODO MIKE: This feels incorrect here but is necessary for correct vertical position;
834-
// the glyphs are rendered relative to the baseline. This should be taken into account either
835-
// by the layout code earlier (cursor should start at the baseline, not 0,0) and/or by
836-
// font.evaluate (should return transforms relative to the baseline).
837-
transform.matrix.ty = baseline_adjustment;
838-
839832
transform
840833
}
841834

@@ -1273,12 +1266,11 @@ impl<'gc> EditText<'gc> {
12731266
{
12741267
let baseline = font.get_baseline_for_height(params.height());
12751268
let descent = font.get_descent_for_height(params.height());
1276-
let baseline_adjustment = baseline - params.height();
12771269
let caret_height = baseline + descent;
12781270
let mut caret_x = Twips::ZERO;
12791271
font.evaluate(
12801272
text,
1281-
self.text_transform(color, baseline_adjustment),
1273+
self.text_transform(color),
12821274
params,
12831275
|pos, transform, glyph: &Glyph, advance, x| {
12841276
if let Some(glyph_shape_handle) = glyph.shape_handle(context.renderer) {
@@ -1633,11 +1625,9 @@ impl<'gc> EditText<'gc> {
16331625
layout_box.as_renderable_text(self.0.text_spans.borrow().text())
16341626
{
16351627
let mut result = 0;
1636-
let baseline_adjustment =
1637-
font.get_baseline_for_height(params.height()) - params.height();
16381628
font.evaluate(
16391629
text,
1640-
self.text_transform(color, baseline_adjustment),
1630+
self.text_transform(color),
16411631
params,
16421632
|pos, _transform, _glyph: &Glyph, advance, x| {
16431633
if local_position.x >= x {

core/src/font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ pub trait FontLike<'gc> {
739739
) where
740740
FGlyph: FnMut(usize, &Transform, &Glyph, Twips, Twips),
741741
{
742-
transform.matrix.ty += params.height;
742+
transform.matrix.ty = self.get_baseline_for_height(params.height);
743743

744744
// TODO [KJ] I'm not sure whether we should iterate over characters here or over code units.
745745
// I suspect Flash Player does not support full UTF-16 when displaying and laying out text.

0 commit comments

Comments
 (0)