text: Move lower_from_text_spans to module level

This commit is contained in:
Kamil Jarosz 2024-06-19 20:53:20 +02:00 committed by Nathan Adams
parent 43b2cced0a
commit d2f5b78503
3 changed files with 107 additions and 106 deletions

View File

@ -21,6 +21,7 @@ use crate::display_object::{DisplayObjectBase, DisplayObjectPtr};
use crate::drawing::Drawing; use crate::drawing::Drawing;
use crate::events::{ClipEvent, ClipEventResult, TextControlCode}; use crate::events::{ClipEvent, ClipEventResult, TextControlCode};
use crate::font::{round_down_to_pixel, FontType, Glyph, TextRenderSettings}; use crate::font::{round_down_to_pixel, FontType, Glyph, TextRenderSettings};
use crate::html;
use crate::html::{ use crate::html::{
BoxBounds, FormatSpans, LayoutBox, LayoutContent, LayoutMetrics, Position, TextFormat, BoxBounds, FormatSpans, LayoutBox, LayoutContent, LayoutMetrics, Position, TextFormat,
}; };
@ -287,7 +288,7 @@ impl<'gc> EditText<'gc> {
FontType::Device FontType::Device
}; };
let (layout, intrinsic_bounds) = LayoutBox::lower_from_text_spans( let (layout, intrinsic_bounds) = html::lower_from_text_spans(
&text_spans, &text_spans,
context, context,
swf_movie.clone(), swf_movie.clone(),
@ -848,7 +849,7 @@ impl<'gc> EditText<'gc> {
FontType::Embedded FontType::Embedded
}; };
let (new_layout, intrinsic_bounds) = LayoutBox::lower_from_text_spans( let (new_layout, intrinsic_bounds) = html::lower_from_text_spans(
&edit_text.text_spans, &edit_text.text_spans,
context, context,
movie, movie,

View File

@ -7,7 +7,7 @@ mod text_format;
pub use dimensions::BoxBounds; pub use dimensions::BoxBounds;
pub use dimensions::Position; pub use dimensions::Position;
pub use layout::{LayoutBox, LayoutContent, LayoutMetrics}; pub use layout::{lower_from_text_spans, LayoutBox, LayoutContent, LayoutMetrics};
pub use stylesheet::{transform_dashes_to_camel_case, CssStream}; pub use stylesheet::{transform_dashes_to_camel_case, CssStream};
pub use text_format::{FormatSpans, TextDisplay, TextFormat, TextSpan}; pub use text_format::{FormatSpans, TextDisplay, TextFormat, TextSpan};

View File

@ -807,19 +807,20 @@ impl<'gc> LayoutBox<'gc> {
content: LayoutContent::Drawing(drawing), content: LayoutContent::Drawing(drawing),
} }
} }
}
/// Construct a new layout hierarchy from text spans. /// Construct a new layout hierarchy from text spans.
/// ///
/// The returned bounds will include both the text bounds itself, as well /// The returned bounds will include both the text bounds itself, as well
/// as left and right margins on any of the lines. /// as left and right margins on any of the lines.
pub fn lower_from_text_spans( pub fn lower_from_text_spans<'gc>(
fs: &FormatSpans, fs: &FormatSpans,
context: &mut UpdateContext<'_, 'gc>, context: &mut UpdateContext<'_, 'gc>,
movie: Arc<SwfMovie>, movie: Arc<SwfMovie>,
bounds: Twips, bounds: Twips,
is_word_wrap: bool, is_word_wrap: bool,
font_type: FontType, font_type: FontType,
) -> (Vec<LayoutBox<'gc>>, BoxBounds<Twips>) { ) -> (Vec<LayoutBox<'gc>>, BoxBounds<Twips>) {
let mut layout_context = LayoutContext::new(movie, bounds, fs.displayed_text()); let mut layout_context = LayoutContext::new(movie, bounds, fs.displayed_text());
for (span_start, _end, span_text, span) in fs.iter_spans() { for (span_start, _end, span_text, span) in fs.iter_spans() {
@ -867,10 +868,8 @@ impl<'gc> LayoutBox<'gc> {
) { ) {
// This ensures that the space causing the line break // This ensures that the space causing the line break
// is included in the line it broke. // is included in the line it broke.
let next_breakpoint = string_utils::next_char_boundary( let next_breakpoint =
text, string_utils::next_char_boundary(text, last_breakpoint + breakpoint);
last_breakpoint + breakpoint,
);
// If text doesn't fit at the start of a line, it // If text doesn't fit at the start of a line, it
// won't fit on the next either, abort and put the // won't fit on the next either, abort and put the
@ -941,8 +940,9 @@ impl<'gc> LayoutBox<'gc> {
} }
layout_context.end_layout(context, fs, font_type) layout_context.end_layout(context, fs, font_type)
} }
impl<'gc> LayoutBox<'gc> {
pub fn bounds(&self) -> BoxBounds<Twips> { pub fn bounds(&self) -> BoxBounds<Twips> {
self.bounds self.bounds
} }