Embed and paint a sans paragraph face

This commit is contained in:
gloamxun committed 2026-10-20 21:37:37 +08:00
1 parent 1633e441de
commit 8468c36daa
5 files changed
+33 -6

No files matched your search

+11 -4
View File
@@ -17,7 +17,7 @@ struct PdfFace {
font: OnceLock<Font<'static>>,
}
static FACES: [PdfFace; 5] = [
static FACES: [PdfFace; 6] = [
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset/LiberationSerif-Regular.ttf"),
base: "LiberationSerif",
@@ -48,6 +48,12 @@ static FACES: [PdfFace; 5] = [
italic_angle: 0,
font: OnceLock::new(),
},
PdfFace {
bytes: include_bytes!("../../../assets/fonts-subset/LiberationSans-Regular.ttf"),
base: "LiberationSans",
italic_angle: 0,
font: OnceLock::new(),
},
];
fn face(font: FontFace) -> &'static PdfFace {
@@ -136,6 +142,7 @@ fn font_resource(font: FontFace) -> &'static str {
FontFace::Italic => "F3",
FontFace::BoldItalic => "F4",
FontFace::Mono => "F5",
FontFace::Sans => "F6",
}
}
@@ -230,7 +237,7 @@ pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec<u8>
let mut objects: Vec<Vec<u8>> = Vec::new();
objects.push(b"<< /Type /Catalog /Pages 2 0 R >>".to_vec());
objects.push(Vec::new()); // pages object filled below
let mut font_ids = [0usize; 5];
let mut font_ids = [0usize; 6];
for (slot, face) in FACES.iter().enumerate() {
let type0_id = objects.len() + 1;
let cid_id = type0_id + 1;
@@ -294,8 +301,8 @@ pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec<u8>
.collect::<Vec<_>>()
.join(" ");
let fonts = format!(
"/F1 {} 0 R /F2 {} 0 R /F3 {} 0 R /F4 {} 0 R /F5 {} 0 R",
font_ids[0], font_ids[1], font_ids[2], font_ids[3], font_ids[4]
"/F1 {} 0 R /F2 {} 0 R /F3 {} 0 R /F4 {} 0 R /F5 {} 0 R /F6 {} 0 R",
font_ids[0], font_ids[1], font_ids[2], font_ids[3], font_ids[4], font_ids[5]
);
let resources = if used.is_empty() {
format!("<< /Font << {fonts} >> >>")