Collect running marks per page
This commit is contained in:
1 parent
112a700c9b
commit
bef442684e
2 files changed
+65
-2
No files matched your search
@@ -24,6 +24,7 @@ pub enum VerticalItem {
|
||||
Glue(i64),
|
||||
Penalty(i64),
|
||||
Insertion(Insertion),
|
||||
Mark(Mark),
|
||||
}
|
||||
|
||||
/// Vertical material reserved at the bottom of a page (footnotes etc.).
|
||||
@@ -34,6 +35,13 @@ pub struct Insertion {
|
||||
pub items: Vec<VerticalItem>,
|
||||
}
|
||||
|
||||
/// Running mark material for headers and footers.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Mark {
|
||||
pub class: u8,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Unit {
|
||||
pub id: UnitId,
|
||||
@@ -95,6 +103,8 @@ pub struct Page {
|
||||
pub items: Vec<VerticalItem>,
|
||||
#[serde(default)]
|
||||
pub insertions: Vec<Insertion>,
|
||||
#[serde(default)]
|
||||
pub marks: Vec<Mark>,
|
||||
pub sources: Vec<(UnitId, u64)>,
|
||||
pub hash: u64,
|
||||
}
|
||||
@@ -104,6 +114,7 @@ impl Page {
|
||||
Self {
|
||||
items: Vec::new(),
|
||||
insertions: Vec::new(),
|
||||
marks: Vec::new(),
|
||||
sources: Vec::new(),
|
||||
hash: 0,
|
||||
}
|
||||
@@ -113,6 +124,7 @@ impl Page {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
self.items.hash(&mut hasher);
|
||||
self.insertions.hash(&mut hasher);
|
||||
self.marks.hash(&mut hasher);
|
||||
self.sources.hash(&mut hasher);
|
||||
self.hash = hasher.finish();
|
||||
}
|
||||
@@ -140,6 +152,9 @@ pub struct Checkpoint {
|
||||
/// Total insertion height already reserved on the current page.
|
||||
#[serde(default)]
|
||||
pub insertion_height: i64,
|
||||
/// Running marks already collected on the current page.
|
||||
#[serde(default)]
|
||||
pub page_marks: Vec<Mark>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
@@ -176,6 +191,7 @@ impl Engine {
|
||||
page_items: current.items.clone(),
|
||||
page_insertions: current.insertions.clone(),
|
||||
insertion_height,
|
||||
page_marks: current.marks.clone(),
|
||||
});
|
||||
for item in &unit.items {
|
||||
match item {
|
||||
@@ -215,6 +231,9 @@ impl Engine {
|
||||
insertion_height += insertion.height;
|
||||
current.insertions.push(insertion.clone());
|
||||
}
|
||||
VerticalItem::Mark(mark) => {
|
||||
current.marks.push(mark.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,6 +293,7 @@ impl Engine {
|
||||
page_items: Vec::new(),
|
||||
page_insertions: Vec::new(),
|
||||
insertion_height: 0,
|
||||
page_marks: Vec::new(),
|
||||
});
|
||||
let edited_height: i64 = next.units[unit_index]
|
||||
.items
|
||||
@@ -283,6 +303,7 @@ impl Engine {
|
||||
VerticalItem::Glue(height) => *height,
|
||||
VerticalItem::Penalty(_) => 0,
|
||||
VerticalItem::Insertion(insertion) => insertion.height,
|
||||
VerticalItem::Mark(_) => 0,
|
||||
})
|
||||
.sum();
|
||||
if checkpoint.used + edited_height > next.page_goal && !checkpoint.page_items.is_empty() {
|
||||
@@ -295,6 +316,7 @@ impl Engine {
|
||||
let mut current = Page {
|
||||
items: checkpoint.page_items,
|
||||
insertions: checkpoint.page_insertions,
|
||||
marks: checkpoint.page_marks,
|
||||
sources: Vec::new(),
|
||||
hash: 0,
|
||||
};
|
||||
@@ -310,6 +332,7 @@ impl Engine {
|
||||
page_items: current.items.clone(),
|
||||
page_insertions: current.insertions.clone(),
|
||||
insertion_height,
|
||||
page_marks: current.marks.clone(),
|
||||
});
|
||||
for item in &unit.items {
|
||||
match item {
|
||||
@@ -348,6 +371,9 @@ impl Engine {
|
||||
insertion_height += insertion.height;
|
||||
current.insertions.push(insertion.clone());
|
||||
}
|
||||
VerticalItem::Mark(mark) => {
|
||||
current.marks.push(mark.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,6 +532,41 @@ mod tests {
|
||||
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_are_attached_to_pages_and_affect_the_hash() {
|
||||
let document = |text: &str| {
|
||||
Document::new(
|
||||
100,
|
||||
vec![Unit {
|
||||
id: 0,
|
||||
source: text.to_owned(),
|
||||
items: vec![
|
||||
VerticalItem::Box(VerticalBox {
|
||||
width: 10,
|
||||
height: 10,
|
||||
}),
|
||||
VerticalItem::Mark(Mark {
|
||||
class: 0,
|
||||
text: text.to_owned(),
|
||||
}),
|
||||
VerticalItem::Penalty(-10_000),
|
||||
VerticalItem::Box(VerticalBox {
|
||||
width: 10,
|
||||
height: 10,
|
||||
}),
|
||||
],
|
||||
}],
|
||||
)
|
||||
};
|
||||
let first = Engine::layout(&document("even page"));
|
||||
let second = Engine::layout(&document("odd page"));
|
||||
assert_eq!(first.layout.pages[0].marks[0].text, "even page");
|
||||
assert_ne!(
|
||||
first.layout.pages[0].hash, second.layout.pages[0].hash,
|
||||
"running marks must participate in the page hash"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkpoint_round_trips_through_serde() {
|
||||
let engine = Engine::layout(&document());
|
||||
|
||||
+4
-2
@@ -71,7 +71,7 @@ next paragraph milestones.
|
||||
| --- | --- | --- |
|
||||
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
|
||||
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, pdfTeX fixture and minimum line fill; hyphenation next |
|
||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, page-bottom `Insertion` reserve; `\output`/float placements next |
|
||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, page-bottom `Insertion` reserve, running `Mark`s; `\output`/float placements next |
|
||||
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
|
||||
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap |
|
||||
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
|
||||
@@ -105,7 +105,9 @@ a single cost function.
|
||||
vertical penalties (`penalty <= -10000`); positive penalties are recorded
|
||||
but not yet part of page badness. `VerticalItem::Insertion` material is
|
||||
attached to `Page::insertions` and reserves height from the page goal.
|
||||
There is no `\output` routine and no `\insert`/float wiring yet.
|
||||
`VerticalItem::Mark` material is collected into `Page::marks` and included
|
||||
in the page hash, as a base for running headers. There is no executable
|
||||
`\output` routine and no `\insert`/float wiring yet.
|
||||
- No macro state, output routine, math, fonts or PDF output in the new core yet.
|
||||
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
|
||||
|
||||
|
||||
Reference in new issue
Block a user