Carry paragraph font faces through the display list

This commit is contained in:
gloamxun committed 2026-10-20 18:32:33 +08:00
1 parent 96c88d2787
commit 6b74a17312
4 files changed
+54 -5

No files matched your search

+27 -2
View File
@@ -6,8 +6,8 @@ pub mod render;
pub use cmr10::Cmr10Metrics;
pub use paragraph::{
HorizontalBox, HorizontalItem, Paragraph, ParagraphStyle, layout_items, layout_paragraph,
layout_paragraph_with_font, text_items, text_items_with_font,
HorizontalBox, HorizontalItem, Paragraph, ParagraphFont, ParagraphStyle, layout_items,
layout_paragraph, layout_paragraph_with_font, text_items, text_items_with_font,
};
pub use render::{DisplayItem, DisplayList};
@@ -407,6 +407,15 @@ impl Unit {
Self::paragraph_with_style(id, source, ParagraphStyle::default())
}
/// Build a paragraph unit with an explicit font face.
pub fn paragraph_with_face(id: UnitId, source: impl Into<String>, font: ParagraphFont) -> Self {
let mut unit = Self::paragraph_with_style(id, source, ParagraphStyle::default());
if let Some(VerticalItem::Paragraph(paragraph)) = unit.items.first_mut() {
paragraph.font = font;
}
unit
}
pub fn paragraph_with_style(
id: UnitId,
source: impl Into<String>,
@@ -1599,6 +1608,22 @@ mod tests {
assert!(text.trim_end().ends_with("%%EOF"));
}
#[test]
fn bold_paragraph_paints_with_a_bold_face() {
let document = Document::new(
2_000_000,
vec![Unit::paragraph_with_face(1, "bold", ParagraphFont::Bold)],
);
let layout = Engine::layout(&document);
let list = layout.pages()[0].display_list();
assert!(list.items.iter().any(|item| matches!(
item,
crate::render::DisplayItem::Text {
font: crate::render::FontFace::Bold,
..
}
)));
}
#[test]
fn pdf_writer_uses_a_bold_font_resource() {
let mut list = crate::render::DisplayList::default();