Reserve top_skip at the start of each page
This commit is contained in:
1 parent
252963f0fa
commit
6af137b17e
2 files changed
+43
-8
No files matched your search
@@ -61,11 +61,23 @@ impl Unit {
|
|||||||
pub struct Document {
|
pub struct Document {
|
||||||
pub units: Vec<Unit>,
|
pub units: Vec<Unit>,
|
||||||
pub page_goal: i64,
|
pub page_goal: i64,
|
||||||
|
/// TeX-like `\topskip`: distance from the page top to the first baseline.
|
||||||
|
#[serde(default)]
|
||||||
|
pub top_skip: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Document {
|
impl Document {
|
||||||
pub fn new(page_goal: i64, units: Vec<Unit>) -> Self {
|
pub fn new(page_goal: i64, units: Vec<Unit>) -> Self {
|
||||||
Self { units, page_goal }
|
Self {
|
||||||
|
units,
|
||||||
|
page_goal,
|
||||||
|
top_skip: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_top_skip(mut self, top_skip: i64) -> Self {
|
||||||
|
self.top_skip = top_skip;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +143,7 @@ impl Engine {
|
|||||||
sources: Vec::new(),
|
sources: Vec::new(),
|
||||||
hash: 0,
|
hash: 0,
|
||||||
};
|
};
|
||||||
let mut used = 0_i64;
|
let mut used = document.top_skip;
|
||||||
for (unit_index, unit) in document.units.iter().enumerate() {
|
for (unit_index, unit) in document.units.iter().enumerate() {
|
||||||
checkpoints.push(Checkpoint {
|
checkpoints.push(Checkpoint {
|
||||||
unit_index,
|
unit_index,
|
||||||
@@ -153,7 +165,7 @@ impl Engine {
|
|||||||
hash: 0,
|
hash: 0,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
used = 0;
|
used = document.top_skip;
|
||||||
}
|
}
|
||||||
used += vertical_box.height;
|
used += vertical_box.height;
|
||||||
current.items.push(item.clone());
|
current.items.push(item.clone());
|
||||||
@@ -279,7 +291,7 @@ impl Engine {
|
|||||||
hash: 0,
|
hash: 0,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
used = 0;
|
used = next.top_skip;
|
||||||
}
|
}
|
||||||
used += vertical_box.height;
|
used += vertical_box.height;
|
||||||
current.items.push(item.clone());
|
current.items.push(item.clone());
|
||||||
@@ -376,6 +388,29 @@ mod tests {
|
|||||||
assert!(engine.recomputed_pages() >= 1);
|
assert!(engine.recomputed_pages() >= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn top_skip_consumes_space_on_each_page() {
|
||||||
|
let unit = |id| Unit {
|
||||||
|
id,
|
||||||
|
source: "boxes".to_owned(),
|
||||||
|
items: vec![
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 10,
|
||||||
|
height: 50,
|
||||||
|
}),
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 10,
|
||||||
|
height: 50,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
let plain = Engine::layout(&Document::new(100, vec![unit(0)]));
|
||||||
|
assert_eq!(plain.layout.pages.len(), 1);
|
||||||
|
|
||||||
|
let with_top_skip = Engine::layout(&Document::new(100, vec![unit(1)]).with_top_skip(10));
|
||||||
|
assert_eq!(with_top_skip.layout.pages.len(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn vertical_penalty_can_force_a_page_break() {
|
fn vertical_penalty_can_force_a_page_break() {
|
||||||
let unit = Unit {
|
let unit = Unit {
|
||||||
|
|||||||
+4
-4
@@ -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 |
|
| 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 |
|
| 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 | one-column article matches reference pages |
|
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties; `\output`/insertions next |
|
||||||
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
|
| 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 |
|
| 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 |
|
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
|
||||||
@@ -101,9 +101,9 @@ overfull ratio 4.11, badness 6942. TeX rejects the underfull candidate under
|
|||||||
its tolerance but still emits the moderately overfull 5-word line. Reproducing
|
its tolerance but still emits the moderately overfull 5-word line. Reproducing
|
||||||
this needs a two-pass tolerance algorithm with an emergency overfull pass, not
|
this needs a two-pass tolerance algorithm with an emergency overfull pass, not
|
||||||
a single cost function.
|
a single cost function.
|
||||||
- Page breaking handles vertical boxes/glue and forced vertical penalties
|
- Page breaking handles vertical boxes/glue, `Document::top_skip` and forced
|
||||||
(`penalty <= -10000`); positive penalties are recorded but not yet part of
|
vertical penalties (`penalty <= -10000`); positive penalties are recorded
|
||||||
page badness.
|
but not yet part of page badness. There is no `\output` routine yet.
|
||||||
- No macro state, output routine, math, fonts or PDF output in the new core 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.
|
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user