Add dotted leaders to generated contents entries

This commit is contained in:
gloamxun committed 2026-10-19 14:20:30 +08:00
1 parent 1b0ce27ed3
commit 6d4aa37189
8 files changed
+79 -18

No files matched your search

+24 -5
View File
@@ -1228,6 +1228,18 @@ fn boxworks_line_break(
previous_font_id = None;
}
for character in run.text.chars() {
if character == texrra_core::document::CONTENTS_LEADER_MARKER {
horizontal.push(
ds::Char {
char: character,
font: null_font_id,
}
.into(),
);
previous_character = None;
previous_font_id = None;
continue;
}
if inline_markers.contains_key(&character) {
horizontal.push(
ds::Char {
@@ -1423,9 +1435,14 @@ fn boxworks_line_break(
}
}
let mut line_items = Vec::new();
let mut leader_pending = false;
for item in &line_box.list {
match item {
ds::Horizontal::Char(character) => {
if character.char == texrra_core::document::CONTENTS_LEADER_MARKER {
leader_pending = true;
continue;
}
if let Some(marker) = inline_markers.get(&character.char) {
match marker {
InlineMarker::RaiseStart(raise) => {
@@ -1472,11 +1489,13 @@ fn boxworks_line_break(
}
}
ds::Horizontal::Glue(glue) => {
line_items.push(text_layout::LineItem::Glue(paragraph_glue_width(
&glue.value,
line_box.glue_order,
ratio,
)));
let width = paragraph_glue_width(&glue.value, line_box.glue_order, ratio);
if leader_pending {
leader_pending = false;
line_items.push(text_layout::LineItem::Leader(width));
} else {
line_items.push(text_layout::LineItem::Glue(width));
}
}
ds::Horizontal::Kern(kern) => {
line_items.push(text_layout::LineItem::Kern(kern.width));
+41
View File
@@ -42,6 +42,7 @@ pub(super) enum LineItem {
},
Kern(Scaled),
Glue(Scaled),
Leader(Scaled),
}
struct TextSpan {
@@ -105,6 +106,7 @@ enum TextLineItem {
},
Kern(Mm),
Glue(Mm),
Leader(Mm),
}
pub(super) struct PositionedRule {
@@ -245,6 +247,18 @@ impl TextLine {
);
items.push(TextLineItem::Glue(scaled_to_mm(*width)));
}
LineItem::Leader(width) => {
flush_text(
&mut items,
&mut text,
&mut text_style,
cjk_family,
monospace_family,
sans_family,
font_size,
);
items.push(TextLineItem::Leader(scaled_to_mm(*width)));
}
LineItem::Kern(width) => {
flush_text(
&mut items,
@@ -311,6 +325,7 @@ impl TextLine {
}
TextLineItem::Glue(_) if index < last_content => x += natural_space,
TextLineItem::Glue(_) => {}
TextLineItem::Leader(width) => x += *width,
TextLineItem::Kern(width) => x += *width,
TextLineItem::Rule { width, .. } => x += *width,
TextLineItem::Frame { width, .. } => x += *width,
@@ -393,6 +408,32 @@ impl TextLine {
natural_space
};
}
TextLineItem::Leader(width) => {
let style = Style::new().with_font_size(self.font_size);
let dot = style.str_width(fonts, ".");
let space = style.str_width(fonts, " ");
let unit = f64::from(dot + space);
let width_mm = f64::from(*width);
let count = ((width_mm / unit).floor() as usize).max(1);
let mut leader = String::new();
for index in 0..count {
if index > 0 {
leader.push(' ');
}
leader.push('.');
}
let text_width = style.str_width(fonts, &leader);
spans.push(PositionedSpan {
text: leader,
style,
x,
y_offset: Mm::from(0.0),
});
x += text_width;
if text_width < *width {
x += *width - text_width;
}
}
TextLineItem::Kern(width) => x += *width,
}
}