From 422935b7b976d6f530aaa06e8db57d0cc53c30b4 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Mon, 4 Nov 2024 14:52:00 +0100 Subject: [PATCH 1/4] text: Use proper bounds for text bounds calculation --- core/src/html/layout.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index 82c3dd26458c..f46791588083 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -403,9 +403,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); } } From e2810efb392d39d981eb9cbfa2e5f45eb86e756f Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Mon, 4 Nov 2024 14:41:46 +0100 Subject: [PATCH 2/4] text: Use proper bounds for layout lines --- core/src/html/layout.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index f46791588083..a44e653a3a6f 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -944,11 +944,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>> { From 894a831b5fb75d346db934f780d4b1eceaa49570 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Mon, 4 Nov 2024 13:57:38 +0100 Subject: [PATCH 3/4] text: Use proper bounds for layout boxes --- core/src/display_object/edit_text.rs | 10 ++++------ core/src/html/layout.rs | 9 ++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index c3294f7fa86e..64498fca99fc 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -942,7 +942,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(); @@ -1345,9 +1345,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; @@ -1356,7 +1354,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; @@ -2097,7 +2095,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))) }) } diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index a44e653a3a6f..c9d1145edbc2 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -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; } @@ -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); } } From 52d2269cfe8405f5f91f8555c096847235c6a4fb Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Mon, 4 Nov 2024 14:44:25 +0100 Subject: [PATCH 4/4] text: Remove layout line & layout box interior bounds --- core/src/debug_ui/display_object.rs | 2 -- core/src/display_object/edit_text.rs | 12 -------- core/src/html/layout.rs | 43 ---------------------------- 3 files changed, 57 deletions(-) diff --git a/core/src/debug_ui/display_object.rs b/core/src/debug_ui/display_object.rs index b6e7861b795e..0ab6304ff170 100644 --- a/core/src/debug_ui/display_object.rs +++ b/core/src/debug_ui/display_object.rs @@ -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); diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index 64498fca99fc..a3b12fff2234 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -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); @@ -2781,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; } } diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index c9d1145edbc2..e916a3d1d3a4 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -272,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); @@ -336,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; } @@ -369,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()) @@ -389,7 +378,6 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { self.lines.push(LayoutLine { index: self.current_line_index, - interior_bounds, bounds, start, end, @@ -626,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)), @@ -665,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)), @@ -868,16 +854,6 @@ pub struct LayoutLine<'gc> { #[collect(require_static)] bounds: BoxBounds, - /// 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, - /// The start position of the line (inclusive). start: usize, @@ -910,10 +886,6 @@ impl<'gc> LayoutLine<'gc> { self.bounds } - pub fn interior_bounds(&self) -> BoxBounds { - self.interior_bounds - } - pub fn start(&self) -> usize { self.start } @@ -1000,14 +972,6 @@ pub struct LayoutBox<'gc> { #[collect(require_static)] bounds: BoxBounds, - /// 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, - /// What content is contained by the content box. content: LayoutContent<'gc>, } @@ -1137,7 +1101,6 @@ impl<'gc> LayoutBox<'gc> { }); Self { - interior_bounds: Default::default(), bounds: Default::default(), content: LayoutContent::Text { start, @@ -1156,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, @@ -1171,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 }, } @@ -1313,10 +1274,6 @@ impl<'gc> LayoutBox<'gc> { self.bounds } - pub fn interior_bounds(&self) -> BoxBounds { - self.interior_bounds - } - pub fn content(&self) -> &LayoutContent<'gc> { &self.content }