Skip to content

Commit

Permalink
core: Fixes several text edit font and bullet issues (parts of #1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
hatal175 authored and Herschel committed Aug 3, 2021
1 parent 0c6f710 commit 6762675
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions core/src/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand All @@ -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.
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 6762675

Please sign in to comment.