avm2: Don't round text metrics (`textWidth` and `textHeight`)

This commit is contained in:
David Wendt 2021-03-03 21:25:03 -05:00 committed by Mike Welsh
parent f908eb65fc
commit f5268198b0
2 changed files with 6 additions and 5 deletions

View File

@ -6,6 +6,7 @@ use crate::avm1::property::Attribute;
use crate::avm1::{AvmString, Object, ScriptObject, TObject, Value};
use crate::avm_error;
use crate::display_object::{AutoSizeMode, EditText, TDisplayObject, TextSelection};
use crate::font::round_down_to_pixel;
use crate::html::TextFormat;
use gc_arena::MutationContext;
@ -489,7 +490,7 @@ pub fn text_width<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
) -> Result<Value<'gc>, Error<'gc>> {
let metrics = this.measure_text(&mut activation.context);
Ok(metrics.0.to_pixels().into())
Ok(round_down_to_pixel(metrics.0).to_pixels().into())
}
pub fn text_height<'gc>(
@ -497,7 +498,7 @@ pub fn text_height<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
) -> Result<Value<'gc>, Error<'gc>> {
let metrics = this.measure_text(&mut activation.context);
Ok(metrics.1.to_pixels().into())
Ok(round_down_to_pixel(metrics.1).to_pixels().into())
}
pub fn multiline<'gc>(

View File

@ -14,7 +14,7 @@ use crate::context::{RenderContext, UpdateContext};
use crate::display_object::{DisplayObjectBase, TDisplayObject};
use crate::drawing::Drawing;
use crate::events::{ButtonKeyCode, ClipEvent, ClipEventResult, KeyCode};
use crate::font::{round_down_to_pixel, Glyph, TextRenderSettings};
use crate::font::{Glyph, TextRenderSettings};
use crate::html::{BoxBounds, FormatSpans, LayoutBox, LayoutContent, TextFormat};
use crate::prelude::*;
use crate::shape_utils::DrawCommand;
@ -820,8 +820,8 @@ impl<'gc> EditText<'gc> {
let edit_text = self.0.read();
(
round_down_to_pixel(edit_text.intrinsic_bounds.width()),
round_down_to_pixel(edit_text.intrinsic_bounds.height()),
edit_text.intrinsic_bounds.width(),
edit_text.intrinsic_bounds.height(),
)
}