Embed and paint a sans paragraph face
This commit is contained in:
1 parent
1633e441de
commit
8468c36daa
5 files changed
+33
-6
No files matched your search
@@ -1939,6 +1939,21 @@ mod tests {
|
||||
assert!(text.trim_end().ends_with("%%EOF"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sans_paragraph_paints_with_the_sans_face() {
|
||||
let unit = Unit::paragraph_with_face(1, "sans face", ParagraphFont::Sans);
|
||||
let page = Page {
|
||||
items: unit.items,
|
||||
insertions: Vec::new(),
|
||||
marks: Vec::new(),
|
||||
floats: Vec::new(),
|
||||
sources: Vec::new(),
|
||||
hash: 0,
|
||||
};
|
||||
let svg = page.display_list().to_svg();
|
||||
assert!(svg.contains("font-family=\"sans-serif\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mono_paragraph_paints_with_a_mono_face() {
|
||||
let unit = Unit::paragraph_with_face(1, "code 123", ParagraphFont::Mono);
|
||||
|
||||
@@ -73,6 +73,7 @@ pub enum ParagraphFont {
|
||||
Bold,
|
||||
Italic,
|
||||
Mono,
|
||||
Sans,
|
||||
}
|
||||
|
||||
impl Default for ParagraphFont {
|
||||
|
||||
@@ -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} >> >>")
|
||||
|
||||
@@ -18,6 +18,7 @@ pub enum FontFace {
|
||||
Italic,
|
||||
BoldItalic,
|
||||
Mono,
|
||||
Sans,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -148,6 +149,8 @@ impl DisplayList {
|
||||
let size = *size as f64 / 65_536.0;
|
||||
let family = if matches!(font, FontFace::Mono) {
|
||||
"monospace"
|
||||
} else if matches!(font, FontFace::Sans) {
|
||||
"sans-serif"
|
||||
} else {
|
||||
"serif"
|
||||
};
|
||||
@@ -368,6 +371,7 @@ impl Page {
|
||||
ParagraphFont::Bold => FontFace::Bold,
|
||||
ParagraphFont::Italic => FontFace::Italic,
|
||||
ParagraphFont::Mono => FontFace::Mono,
|
||||
ParagraphFont::Sans => FontFace::Sans,
|
||||
};
|
||||
let lines = paragraph.lines.len().max(1) as i64;
|
||||
let line_height = (paragraph.height / lines).max(1);
|
||||
|
||||
+2
-2
@@ -252,7 +252,7 @@ M3 painter: `Page::display_list()` and `Halign::display_list()` produce absolute
|
||||
|
||||
PDF writer: `crates/texrra-tex-core/src/pdf.rs` writes multi-page PDF 1.4 with five embedded Liberation Type0/CID faces (Identity-H + ToUnicode + `/W` arrays), filled rectangles, diagonal rules, raw-RGB `/XObject` images, `/Annots` URI links and arbitrary `/special` operators. Ligature substitution and line-end italic correction are implemented; full NFSS family switching remains open.
|
||||
|
||||
M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and a monospace paragraph face are applied; true NFSS family switching remains open.
|
||||
M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; true NFSS family switching remains open.
|
||||
|
||||
M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments.
|
||||
|
||||
@@ -262,7 +262,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei
|
||||
|
||||
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits.
|
||||
|
||||
The crate currently has 136 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 219 tests (136 route-D unit, 1 route-D integration, 71 v1 integration, 6 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||
The crate currently has 137 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 220 tests (137 route-D unit, 1 route-D integration, 71 v1 integration, 6 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
Reference in new issue
Block a user