Carry paragraph font faces through the display list
This commit is contained in:
1 parent
96c88d2787
commit
6b74a17312
4 files changed
+54
-5
No files matched your search
@@ -6,8 +6,8 @@ pub mod render;
|
|||||||
|
|
||||||
pub use cmr10::Cmr10Metrics;
|
pub use cmr10::Cmr10Metrics;
|
||||||
pub use paragraph::{
|
pub use paragraph::{
|
||||||
HorizontalBox, HorizontalItem, Paragraph, ParagraphStyle, layout_items, layout_paragraph,
|
HorizontalBox, HorizontalItem, Paragraph, ParagraphFont, ParagraphStyle, layout_items,
|
||||||
layout_paragraph_with_font, text_items, text_items_with_font,
|
layout_paragraph, layout_paragraph_with_font, text_items, text_items_with_font,
|
||||||
};
|
};
|
||||||
pub use render::{DisplayItem, DisplayList};
|
pub use render::{DisplayItem, DisplayList};
|
||||||
|
|
||||||
@@ -407,6 +407,15 @@ impl Unit {
|
|||||||
Self::paragraph_with_style(id, source, ParagraphStyle::default())
|
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(
|
pub fn paragraph_with_style(
|
||||||
id: UnitId,
|
id: UnitId,
|
||||||
source: impl Into<String>,
|
source: impl Into<String>,
|
||||||
@@ -1599,6 +1608,22 @@ mod tests {
|
|||||||
assert!(text.trim_end().ends_with("%%EOF"));
|
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]
|
#[test]
|
||||||
fn pdf_writer_uses_a_bold_font_resource() {
|
fn pdf_writer_uses_a_bold_font_resource() {
|
||||||
let mut list = crate::render::DisplayList::default();
|
let mut list = crate::render::DisplayList::default();
|
||||||
|
|||||||
@@ -57,11 +57,27 @@ impl Default for ParagraphStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub enum ParagraphFont {
|
||||||
|
Roman,
|
||||||
|
Bold,
|
||||||
|
Italic,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ParagraphFont {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Roman
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Paragraph {
|
pub struct Paragraph {
|
||||||
pub lines: Vec<Vec<HorizontalItem>>,
|
pub lines: Vec<Vec<HorizontalItem>>,
|
||||||
pub height: i64,
|
pub height: i64,
|
||||||
pub width: i64,
|
pub width: i64,
|
||||||
|
#[serde(default)]
|
||||||
|
pub font: ParagraphFont,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Paragraph {
|
impl Paragraph {
|
||||||
@@ -118,6 +134,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
|||||||
lines: Vec::new(),
|
lines: Vec::new(),
|
||||||
height: 0,
|
height: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
|
font: ParagraphFont::Roman,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let mut breakpoints = vec![0_usize];
|
let mut breakpoints = vec![0_usize];
|
||||||
@@ -286,6 +303,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
|||||||
height: lines.len() as i64 * style.line_height,
|
height: lines.len() as i64 * style.line_height,
|
||||||
width: max_width,
|
width: max_width,
|
||||||
lines,
|
lines,
|
||||||
|
font: ParagraphFont::Roman,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
use crate::cmr10::Cmr10Metrics;
|
use crate::cmr10::Cmr10Metrics;
|
||||||
use crate::math::{self, MathAtom};
|
use crate::math::{self, MathAtom};
|
||||||
|
use crate::paragraph::ParagraphFont;
|
||||||
use crate::{FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
|
use crate::{FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
|
||||||
|
|
||||||
/// One absolute drawing primitive in scaled points.
|
/// One absolute drawing primitive in scaled points.
|
||||||
@@ -344,6 +345,11 @@ impl Page {
|
|||||||
y += *height + *depth;
|
y += *height + *depth;
|
||||||
}
|
}
|
||||||
VerticalItem::Paragraph(paragraph) => {
|
VerticalItem::Paragraph(paragraph) => {
|
||||||
|
let face = match paragraph.font {
|
||||||
|
ParagraphFont::Roman => FontFace::Roman,
|
||||||
|
ParagraphFont::Bold => FontFace::Bold,
|
||||||
|
ParagraphFont::Italic => FontFace::Italic,
|
||||||
|
};
|
||||||
let lines = paragraph.lines.len().max(1) as i64;
|
let lines = paragraph.lines.len().max(1) as i64;
|
||||||
let line_height = (paragraph.height / lines).max(1);
|
let line_height = (paragraph.height / lines).max(1);
|
||||||
let size = ((line_height as f64) * 0.7) as i64;
|
let size = ((line_height as f64) * 0.7) as i64;
|
||||||
@@ -355,7 +361,7 @@ impl Page {
|
|||||||
HorizontalItem::Box(box_) => {
|
HorizontalItem::Box(box_) => {
|
||||||
if let Some(character) = box_.character {
|
if let Some(character) = box_.character {
|
||||||
list.push(DisplayItem::Text {
|
list.push(DisplayItem::Text {
|
||||||
font: FontFace::Roman,
|
font: face,
|
||||||
x,
|
x,
|
||||||
y: baseline,
|
y: baseline,
|
||||||
size,
|
size,
|
||||||
|
|||||||
+1
-1
@@ -228,7 +228,7 @@ for a later overlaid slash.
|
|||||||
| M2 vertical/page builder | partial | vsize, topskip, insertions, marks, output hook, top/bottom floats, rules, vskip, penalties; interpreted `\output` and float pages absent |
|
| M2 vertical/page builder | partial | vsize, topskip, insertions, marks, output hook, top/bottom floats, rules, vskip, penalties; interpreted `\output` and float pages absent |
|
||||||
| M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter |
|
| M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter |
|
||||||
| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping |
|
| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping |
|
||||||
| M5 NFSS/TFM | partial | CMR10 widths, per-face Base-14 PDF resources, and SVG font-family/weight/style for Roman/Bold/Italic/Mono; TFM loading and font embedding absent |
|
| M5 NFSS/TFM | partial | CMR10 widths, per-face Base-14 PDF resources, and SVG font-family/weight/style for Roman/Bold/Italic/Mono; paragraph units carry a ParagraphFont face; TFM loading and font embedding absent |
|
||||||
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent |
|
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent |
|
||||||
| M7 incremental integration | partial | edit replay + page hashes, not wired into v1 preview |
|
| M7 incremental integration | partial | edit replay + page hashes, not wired into v1 preview |
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user