Draw paged top floats with their text float separation
This commit is contained in:
1 parent
aa081e3dc6
commit
c5b3493998
3 files changed
+31
-9
No files matched your search
@@ -5181,6 +5181,26 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_float_reserves_text_float_sep_in_the_display_list() {
|
||||
let mut document = Document::new(
|
||||
100,
|
||||
vec![
|
||||
Unit::float(1, FloatPlacement::Top, 100, 20),
|
||||
Unit::rule(2, 100, 10),
|
||||
],
|
||||
);
|
||||
document.text_float_sep = 10;
|
||||
let engine = Engine::layout_paged(&document).expect("paged floats build");
|
||||
let list =
|
||||
engine.pages()[0].display_list_with_layout(document.page_goal, document.text_float_sep);
|
||||
let body = list.items.iter().find_map(|item| match item {
|
||||
crate::render::DisplayItem::Rule { y, height, .. } if *height == 10 => Some(*y),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(body, Some(30));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_defers_a_late_top_float() {
|
||||
let mut document = Document::new(
|
||||
|
||||
+4
-3
@@ -248,8 +248,9 @@ oracle fixture is ignored.
|
||||
consecutive paragraph units and is discarded when it would start a page,
|
||||
matching TeX's paragraph spacing in vertical lists. The routine cannot yet
|
||||
change page goals. The paged builder places top `Float` material at the top
|
||||
of a page and defers a late float to the next page; bottom floats reserve
|
||||
height on the current page and must satisfy
|
||||
of a page, defers a late float to the next page, and route-D preview/PDF
|
||||
draw pages through `display_list_with_layout` so the body clears
|
||||
`\textfloatsep`; bottom floats reserve height on the current page and must satisfy
|
||||
`Document.text_fraction_percent` (default 50%); a page holding only floats
|
||||
is sealed once it leaves less than that fraction for text.
|
||||
- No macro state, output routine, math, fonts or PDF output in the new core yet.
|
||||
@@ -338,7 +339,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
||||
|
||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||
|
||||
The crate currently has 243 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 361 tests (243 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 244 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 362 tests (244 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
+7
-6
@@ -81,7 +81,7 @@ pub fn project_preview_json(project_id: &str, source: &str) -> Result<String, St
|
||||
(engine, changed, recomputed)
|
||||
}
|
||||
};
|
||||
let json = render_json(&engine, Some((&changed, recomputed)));
|
||||
let json = render_json(&document, &engine, Some((&changed, recomputed)));
|
||||
sessions.insert(
|
||||
project_id.to_string(),
|
||||
ProjectSession { paragraphs, engine },
|
||||
@@ -138,7 +138,7 @@ pub fn preview_json(source: &str) -> Result<String, String> {
|
||||
let paragraphs = paragraphs(source)?;
|
||||
let document = build_document(¶graphs);
|
||||
let engine = Engine::layout(&document);
|
||||
let json = render_json(&engine, None);
|
||||
let json = render_json(&document, &engine, None);
|
||||
// Keep the layout so a following `/edit` request can diff against it and
|
||||
// reuse page checkpoints instead of starting from a no-op document.
|
||||
ROUTE_D_SESSION.with(|slot| {
|
||||
@@ -159,7 +159,8 @@ pub fn pdf_bytes(source: &str) -> Result<Vec<u8>, String> {
|
||||
.pages()
|
||||
.iter()
|
||||
.map(|page| {
|
||||
let mut list = page.display_list();
|
||||
let mut list =
|
||||
page.display_list_with_layout(document.page_goal, document.text_float_sep);
|
||||
list.width = list.width.max(PAGE_WIDTH_PT * SCALE);
|
||||
list.height = list.height.max(PAGE_HEIGHT_PT * SCALE);
|
||||
list
|
||||
@@ -195,7 +196,7 @@ pub fn edit_json(source: &str, unit: usize) -> Result<String, String> {
|
||||
engine.edit(&next, unit as u64, paragraphs[unit].text.clone());
|
||||
let changed = engine.changed_pages().to_vec();
|
||||
let recomputed = engine.recomputed_pages();
|
||||
let json = render_json(&engine, Some((&changed, recomputed)));
|
||||
let json = render_json(&next, &engine, Some((&changed, recomputed)));
|
||||
*slot = Some((next, engine));
|
||||
Ok(json)
|
||||
})
|
||||
@@ -430,11 +431,11 @@ fn build_document(paragraphs: &[SourceParagraph]) -> Document {
|
||||
Document::new(700 * SCALE, units)
|
||||
}
|
||||
|
||||
fn render_json(engine: &Engine, edit: Option<(&[usize], usize)>) -> String {
|
||||
fn render_json(document: &Document, engine: &Engine, edit: Option<(&[usize], usize)>) -> String {
|
||||
let mut json = String::new();
|
||||
json.push_str("{\"status\":\"ok\",\"pageWidthMm\":215.90,\"pageHeightMm\":279.40,\"pages\":[");
|
||||
for (index, page) in engine.pages().iter().enumerate() {
|
||||
let mut list = page.display_list();
|
||||
let mut list = page.display_list_with_layout(document.page_goal, document.text_float_sep);
|
||||
list.width = list.width.max(PAGE_WIDTH_PT * SCALE);
|
||||
list.height = list.height.max(PAGE_HEIGHT_PT * SCALE);
|
||||
if index > 0 {
|
||||
|
||||
Reference in new issue
Block a user