Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text: Remove layout line & layout box interior bounds #18476

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/src/debug_ui/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,7 @@ impl DisplayObjectWindow {
("Text Exterior", LayoutDebugBoxesFlag::TEXT_EXTERIOR),
("Text", LayoutDebugBoxesFlag::TEXT),
("Line", LayoutDebugBoxesFlag::LINE),
("Line Interior", LayoutDebugBoxesFlag::LINE_INTERIOR),
("Box", LayoutDebugBoxesFlag::BOX),
("Box Interior", LayoutDebugBoxesFlag::BOX_INTERIOR),
("Character", LayoutDebugBoxesFlag::CHAR),
] {
let old_value = object.layout_debug_boxes_flag(flag);
Expand Down
22 changes: 4 additions & 18 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,21 +906,11 @@ impl<'gc> EditText<'gc> {
}
}
}
if flags.contains(LayoutDebugBoxesFlag::BOX_INTERIOR) {
for lbox in layout.boxes_iter() {
context.draw_rect_outline(Color::RED, lbox.interior_bounds().into(), Twips::ONE);
}
}
if flags.contains(LayoutDebugBoxesFlag::BOX) {
for lbox in layout.boxes_iter() {
context.draw_rect_outline(Color::RED, lbox.bounds().into(), Twips::ONE);
}
}
if flags.contains(LayoutDebugBoxesFlag::LINE_INTERIOR) {
for line in layout.lines() {
context.draw_rect_outline(Color::BLUE, line.interior_bounds().into(), Twips::ONE);
}
}
if flags.contains(LayoutDebugBoxesFlag::LINE) {
for line in layout.lines() {
context.draw_rect_outline(Color::BLUE, line.bounds().into(), Twips::ONE);
Expand All @@ -942,7 +932,7 @@ impl<'gc> EditText<'gc> {

/// Render a layout box, plus its children.
fn render_layout_box(self, context: &mut RenderContext<'_, 'gc>, lbox: &LayoutBox<'gc>) {
let origin = lbox.interior_bounds().origin();
let origin = lbox.bounds().origin();

let edit_text = self.0.read();

Expand Down Expand Up @@ -1345,9 +1335,7 @@ impl<'gc> EditText<'gc> {
let mut closest_layout_box: Option<&LayoutBox<'gc>> = None;
for layout_box in line.boxes_iter() {
if layout_box.is_text_box() {
if position.x >= layout_box.interior_bounds().offset_x()
|| closest_layout_box.is_none()
{
if position.x >= layout_box.bounds().offset_x() || closest_layout_box.is_none() {
closest_layout_box = Some(layout_box);
} else {
break;
Expand All @@ -1356,7 +1344,7 @@ impl<'gc> EditText<'gc> {
}

if let Some(layout_box) = closest_layout_box {
let origin = layout_box.interior_bounds().origin();
let origin = layout_box.bounds().origin();
let mut matrix = Matrix::translate(origin.x(), origin.y());
matrix = matrix.inverse().expect("Invertible layout matrix");
let local_position = matrix * position;
Expand Down Expand Up @@ -2097,7 +2085,7 @@ impl<'gc> EditText<'gc> {
text.layout.boxes_iter().any(|layout| {
layout.is_link()
&& layout
.interior_bounds()
.bounds()
.contains(Position::from((position.x, position.y)))
})
}
Expand Down Expand Up @@ -2783,9 +2771,7 @@ bitflags::bitflags! {
const TEXT_EXTERIOR = 1 << 1;
const TEXT = 1 << 2;
const LINE = 1 << 3;
const LINE_INTERIOR = 1 << 4;
const BOX = 1 << 5;
const BOX_INTERIOR = 1 << 6;
const CHAR = 1 << 7;
}
}
Expand Down
60 changes: 8 additions & 52 deletions core/src/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
(starting_pos, underline_color)
{
if tf.underline.unwrap_or(false)
&& underline_baseline + linebox.interior_bounds().origin().y()
&& underline_baseline + linebox.bounds().origin().y()
== starting_pos.y()
&& underline_color == color
{
//Underline is at the same baseline, extend it
current_width =
Some(linebox.interior_bounds().extent_x() - starting_pos.x());
current_width = Some(linebox.bounds().extent_x() - starting_pos.x());

line_extended = true;
}
Expand All @@ -213,10 +212,10 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {

if tf.underline.unwrap_or(false) {
starting_pos = Some(
linebox.interior_bounds().origin()
linebox.bounds().origin()
+ Position::from((Twips::ZERO, underline_baseline)),
);
current_width = Some(linebox.interior_bounds().width());
current_width = Some(linebox.bounds().width());
underline_color = Some(color);
}
}
Expand Down Expand Up @@ -273,9 +272,6 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {

//Flash ignores trailing spaces when aligning lines, so should we
if self.current_line_span.align != swf::TextAlign::Left {
linebox.interior_bounds = linebox
.interior_bounds
.with_size(font.measure(text.trim_end(), params).into());
linebox.bounds = linebox
.bounds
.with_width(font.measure(text.trim_end(), params).0);
Expand Down Expand Up @@ -337,11 +333,9 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
left_adjustment + align_adjustment + (interim_adjustment * box_count),
baseline_adjustment,
));
layout_box.interior_bounds += position;
layout_box.bounds += position;
} else if layout_box.is_bullet() {
let position = Position::from((Twips::ZERO, baseline_adjustment));
layout_box.interior_bounds += position;
layout_box.bounds += position;
}

Expand Down Expand Up @@ -370,12 +364,6 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
let boxes = mem::take(&mut self.boxes);
let first_box = boxes.first().unwrap();
let start = first_box.start();
let interior_bounds = boxes
.iter()
.filter(|b| b.is_text_box())
.fold(first_box.interior_bounds, |bounds, b| {
bounds + b.interior_bounds
});
let bounds = boxes
.iter()
.filter(|b| b.is_text_box())
Expand All @@ -390,7 +378,6 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {

self.lines.push(LayoutLine {
index: self.current_line_index,
interior_bounds,
bounds,
start,
end,
Expand All @@ -403,9 +390,9 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {

// Update layout bounds
if let Some(lb) = &mut self.bounds {
*lb += interior_bounds;
*lb += bounds;
} else {
self.bounds = Some(interior_bounds);
self.bounds = Some(bounds);
}
}

Expand Down Expand Up @@ -627,7 +614,6 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
let box_origin = self.cursor - (Twips::ZERO, ascent).into();

let mut new_box = LayoutBox::from_text(text, start, end, font, span);
new_box.interior_bounds = BoxBounds::from_position_and_size(box_origin, text_size);
new_box.bounds = BoxBounds::from_position_and_size(
box_origin,
Size::from((text_size.width(), ascent + descent)),
Expand Down Expand Up @@ -666,7 +652,6 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {

let pos = self.last_box_end_position();
let mut new_bullet = LayoutBox::from_bullet(pos, bullet_font, span);
new_bullet.interior_bounds = BoxBounds::from_position_and_size(box_origin, text_size);
new_bullet.bounds = BoxBounds::from_position_and_size(
box_origin,
Size::from((text_size.width(), ascent + descent)),
Expand Down Expand Up @@ -869,16 +854,6 @@ pub struct LayoutLine<'gc> {
#[collect(require_static)]
bounds: BoxBounds<Twips>,

/// Interior line bounds.
///
/// It is a union of interior bounds of all layout
/// boxes contained within this line.
///
/// TODO This probably shouldn't be used, we should
/// always prefer bounds, not interior_bounds.
#[collect(require_static)]
interior_bounds: BoxBounds<Twips>,

/// The start position of the line (inclusive).
start: usize,

Expand Down Expand Up @@ -911,10 +886,6 @@ impl<'gc> LayoutLine<'gc> {
self.bounds
}

pub fn interior_bounds(&self) -> BoxBounds<Twips> {
self.interior_bounds
}

pub fn start(&self) -> usize {
self.start
}
Expand Down Expand Up @@ -944,11 +915,11 @@ impl<'gc> LayoutLine<'gc> {
}

pub fn offset_y(&self) -> Twips {
self.interior_bounds().offset_y()
self.bounds().offset_y()
}

pub fn extent_y(&self) -> Twips {
self.interior_bounds().extent_y()
self.bounds().extent_y()
}

pub fn boxes_iter(&self) -> Iter<'_, LayoutBox<'gc>> {
Expand Down Expand Up @@ -1001,14 +972,6 @@ pub struct LayoutBox<'gc> {
#[collect(require_static)]
bounds: BoxBounds<Twips>,

/// The rectangle corresponding to the bounds of the rendered content,
/// i.e. the smallest rectangle that contains all glyphs.
///
/// TODO Currently, only text boxes have meaningful bounds.
/// TODO [KJ] Can't we replace it with bounds?
#[collect(require_static)]
interior_bounds: BoxBounds<Twips>,

/// What content is contained by the content box.
content: LayoutContent<'gc>,
}
Expand Down Expand Up @@ -1138,7 +1101,6 @@ impl<'gc> LayoutBox<'gc> {
});

Self {
interior_bounds: Default::default(),
bounds: Default::default(),
content: LayoutContent::Text {
start,
Expand All @@ -1157,7 +1119,6 @@ impl<'gc> LayoutBox<'gc> {
let params = EvalParameters::from_span(span);

Self {
interior_bounds: Default::default(),
bounds: Default::default(),
content: LayoutContent::Bullet {
position,
Expand All @@ -1172,7 +1133,6 @@ impl<'gc> LayoutBox<'gc> {
/// Construct a drawing.
pub fn from_drawing(position: usize, drawing: Drawing) -> Self {
Self {
interior_bounds: Default::default(),
bounds: Default::default(),
content: LayoutContent::Drawing { position, drawing },
}
Expand Down Expand Up @@ -1314,10 +1274,6 @@ impl<'gc> LayoutBox<'gc> {
self.bounds
}

pub fn interior_bounds(&self) -> BoxBounds<Twips> {
self.interior_bounds
}

pub fn content(&self) -> &LayoutContent<'gc> {
&self.content
}
Expand Down