Skip to content

Commit

Permalink
text: Remove text parameter from char-bounds-related methods
Browse files Browse the repository at this point in the history
This parameter is not needed anymore as character positions are
calculated during relayout and the font doesn't have to be evaluated.
  • Loading branch information
kjarosh committed Oct 13, 2024
1 parent fc80ff8 commit 220c7d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
10 changes: 2 additions & 8 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,13 +1981,7 @@ impl<'gc> EditText<'gc> {

pub fn char_bounds(self, index: usize) -> Option<Rectangle<Twips>> {
let edit_text = self.0.read();
let text = edit_text.text_spans.text();

if index >= text.len() {
return None;
}

let bounds = edit_text.layout.char_bounds(index, text)?;
let bounds = edit_text.layout.char_bounds(index)?;
let padding = Twips::from_pixels(Self::INTERNAL_PADDING);
let bounds = Matrix::translate(padding, padding) * bounds;
Some(bounds)
Expand Down Expand Up @@ -2339,7 +2333,7 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {

let text = &self.text();
for i in 0..text.len() {
if let Some(bounds) = edit_text.layout.char_bounds(i, text) {
if let Some(bounds) = edit_text.layout.char_bounds(i) {
context.draw_rect_outline(Color::MAGENTA, bounds, Twips::ONE);
}
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::context::UpdateContext;
use crate::drawing::Drawing;
use crate::font::{EvalParameters, Font, FontType, Glyph};
use crate::font::{EvalParameters, Font, FontType};
use crate::html::dimensions::{BoxBounds, Position, Size};
use crate::html::text_format::{FormatSpans, TextFormat, TextSpan};
use crate::string::{utils as string_utils, WStr};
Expand Down Expand Up @@ -823,10 +823,10 @@ impl<'gc> Layout<'gc> {
}

/// Returns char bounds of the given char relative to this layout.
pub fn char_bounds(&self, position: usize, text: &WStr) -> Option<Rectangle<Twips>> {
pub fn char_bounds(&self, position: usize) -> Option<Rectangle<Twips>> {
let line_index = self.find_line_index_by_position(position)?;
let line = self.lines.get(line_index)?;
line.char_bounds(position, text)
line.char_bounds(position)
}
}

Expand Down Expand Up @@ -923,13 +923,13 @@ impl<'gc> LayoutLine<'gc> {
}

/// Returns char bounds of the given char relative to the whole layout.
pub fn char_bounds(&self, position: usize, text: &WStr) -> Option<Rectangle<Twips>> {
pub fn char_bounds(&self, position: usize) -> Option<Rectangle<Twips>> {
let box_index = self.find_box_index_by_position(position)?;
let layout_box = self.boxes.get(box_index)?;

let line_bounds = self.bounds();
let origin_x = layout_box.bounds().origin().x();
let x_bounds = layout_box.char_x_bounds(position, text)?;
let x_bounds = layout_box.char_x_bounds(position)?;

Some(Rectangle {
x_min: origin_x + x_bounds.0,
Expand Down Expand Up @@ -1355,7 +1355,7 @@ impl<'gc> LayoutBox<'gc> {
}

/// Return x-axis char bounds of the given char relative to this layout box.
pub fn char_x_bounds(&self, position: usize, text: &WStr) -> Option<(Twips, Twips)> {
pub fn char_x_bounds(&self, position: usize) -> Option<(Twips, Twips)> {
let relative_position = position.checked_sub(self.start())?;

let LayoutContent::Text { char_end_pos, .. } = &self.content else {
Expand Down

0 comments on commit 220c7d7

Please sign in to comment.