From 6762675bb5c2fa6ded5808a5cbf2ae3a8435f17b Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Mon, 2 Aug 2021 15:28:27 +0300 Subject: [PATCH] core: Fixes several text edit font and bullet issues (parts of #1167) --- core/src/html/layout.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index 53d54a83c..e775cbcab 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -279,7 +279,7 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { self.font_leading_adjustment() }; - if self.current_line_span.bullet { + if self.current_line_span.bullet && self.is_first_line { self.append_bullet(context, &self.current_line_span.clone()); } @@ -383,9 +383,10 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { fn newspan(&mut self, first_span: &TextSpan) { if self.is_start_of_line() { self.current_line_span = first_span.clone(); + self.max_font_size = Twips::from_pixels(first_span.size); + } else { + self.max_font_size = max(self.max_font_size, Twips::from_pixels(first_span.size)); } - - self.max_font_size = max(self.max_font_size, Twips::from_pixels(first_span.size)); } fn resolve_font( @@ -465,7 +466,10 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { { let mut bullet_cursor = self.cursor; - bullet_cursor.set_x(Twips::from_pixels(18.0)); + bullet_cursor.set_x( + Twips::from_pixels(18.0) + + Self::left_alignment_offset_without_bullet(span, self.is_first_line), + ); let params = EvalParameters::from_span(span); let text_size = Size::from(bullet_font.measure("\u{2022}", params, false)); @@ -487,6 +491,17 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { self.boxes.push(to_append); } + /// Calculate the left-align offset of a given line of text given the span + /// active at the start of the line and if we're at the start of a + /// paragraph. + fn left_alignment_offset_without_bullet(span: &TextSpan, is_first_line: bool) -> Twips { + if is_first_line { + Twips::from_pixels(span.left_margin + span.block_indent + span.indent) + } else { + Twips::from_pixels(span.left_margin + span.block_indent) + } + } + /// Calculate the left-align offset of a given line of text given the span /// active at the start of the line and if we're at the start of a /// paragraph. @@ -497,10 +512,8 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { } else { Twips::from_pixels(35.0 + span.left_margin + span.block_indent) } - } else if is_first_line { - Twips::from_pixels(span.left_margin + span.block_indent + span.indent) } else { - Twips::from_pixels(span.left_margin + span.block_indent) + Self::left_alignment_offset_without_bullet(span, is_first_line) } }