Right-align route-D paragraphs and preview flushright blocks
This commit is contained in:
1 parent
6714591704
commit
40ed26e339
5 files changed
+43
-2
No files matched your search
@@ -45,6 +45,8 @@ pub struct ParagraphStyle {
|
||||
/// Center each line in the measure instead of justifying it.
|
||||
#[serde(default)]
|
||||
pub centered: bool,
|
||||
#[serde(default)]
|
||||
pub right_aligned: bool,
|
||||
pub par_indent: i64,
|
||||
pub line_height: i64,
|
||||
pub char_width: i64,
|
||||
@@ -60,6 +62,7 @@ impl Default for ParagraphStyle {
|
||||
left_skip: 0,
|
||||
right_skip: 0,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
par_indent: 0,
|
||||
line_height: 12,
|
||||
char_width: 10,
|
||||
@@ -97,6 +100,8 @@ pub struct Paragraph {
|
||||
pub left_skip: i64,
|
||||
#[serde(default)]
|
||||
pub centered: bool,
|
||||
#[serde(default)]
|
||||
pub right_aligned: bool,
|
||||
}
|
||||
|
||||
impl Paragraph {
|
||||
@@ -157,6 +162,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
font: ParagraphFont::Roman,
|
||||
left_skip: style.left_skip,
|
||||
centered: style.centered,
|
||||
right_aligned: style.right_aligned,
|
||||
};
|
||||
}
|
||||
let mut breakpoints = vec![0_usize];
|
||||
@@ -334,6 +340,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
font: ParagraphFont::Roman,
|
||||
left_skip: style.left_skip,
|
||||
centered: style.centered,
|
||||
right_aligned: style.right_aligned,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -389,6 +389,8 @@ impl Page {
|
||||
.sum();
|
||||
let mut x = if paragraph.centered {
|
||||
paragraph.left_skip + ((paragraph.width - natural) / 2).max(0)
|
||||
} else if paragraph.right_aligned {
|
||||
paragraph.left_skip + (paragraph.width - natural).max(0)
|
||||
} else {
|
||||
paragraph.left_skip
|
||||
};
|
||||
|
||||
+2
-2
@@ -234,7 +234,7 @@ for a later overlaid slash.
|
||||
| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping |
|
||||
| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; only faces used on a page are embedded, and ASCII documents use the 110-glyph minimal tier (one-page Roman PDF is about 21 KB); no Base-14 dependency; SVG carries family/weight/style |
|
||||
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent |
|
||||
| M7 incremental integration | partial | route-D preview/PDF/edit endpoints with content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center mapping; editor integration and inline math pending |
|
||||
| M7 incremental integration | partial | route-D preview/PDF/edit endpoints with content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center/flushright mapping; editor integration and inline math pending |
|
||||
|
||||
v1 remains the production renderer; the route-D core is additive and tested independently.
|
||||
|
||||
@@ -264,7 +264,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 138 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 233 tests (139 route-D unit, 1 route-D integration, 71 v1 integration, 17 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||
The crate currently has 138 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 234 tests (139 route-D unit, 1 route-D integration, 71 v1 integration, 18 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ pub fn edit_json(source: &str, unit: usize) -> Result<String, String> {
|
||||
struct SourceParagraph {
|
||||
text: String,
|
||||
centered: bool,
|
||||
right_aligned: bool,
|
||||
font: ParagraphFont,
|
||||
line_height: i64,
|
||||
math: bool,
|
||||
@@ -132,6 +133,7 @@ fn parse_blocks(raw: &str) -> Vec<SourceParagraph> {
|
||||
math: false,
|
||||
left_skip: 12,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -152,6 +154,7 @@ fn parse_blocks(raw: &str) -> Vec<SourceParagraph> {
|
||||
math: false,
|
||||
left_skip: 12,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -181,6 +184,7 @@ fn parse_blocks(raw: &str) -> Vec<SourceParagraph> {
|
||||
math: false,
|
||||
left_skip: 12,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -210,6 +214,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
math: true,
|
||||
left_skip: 0,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
};
|
||||
}
|
||||
let candidates = [
|
||||
@@ -226,6 +231,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
math: false,
|
||||
left_skip: 0,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -236,6 +242,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
math: false,
|
||||
left_skip: 0,
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,6 +262,7 @@ fn build_document(paragraphs: &[SourceParagraph]) -> Document {
|
||||
line_width: 480 * SCALE,
|
||||
left_skip: paragraph.left_skip * SCALE,
|
||||
centered: paragraph.centered,
|
||||
right_aligned: paragraph.right_aligned,
|
||||
right_skip: 0,
|
||||
par_indent: 0,
|
||||
line_height: paragraph.line_height * SCALE,
|
||||
|
||||
@@ -554,6 +554,30 @@ fn route_d_renders_center_blocks() {
|
||||
assert!(x > 50.0, "{x}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn route_d_renders_flushright_blocks() {
|
||||
let server = TestServer::start("route-d-flushright");
|
||||
let response = server.request(
|
||||
"POST",
|
||||
"/api/route-d/preview",
|
||||
b"\\begin{flushright}Right\\end{flushright}",
|
||||
"text/plain",
|
||||
);
|
||||
assert_eq!(response.status, 200, "{}", response.text());
|
||||
let value: Value = serde_json::from_slice(&response.body).expect("route-D JSON");
|
||||
let svg = value["pages"][0]["svg"].as_str().unwrap();
|
||||
let index = svg.find(">R</text>").expect("right R");
|
||||
let prefix = &svg[..index];
|
||||
let start = prefix.rfind("<text x=\"").expect("text x");
|
||||
let x: f64 = prefix[start + 9..]
|
||||
.split('"')
|
||||
.next()
|
||||
.unwrap()
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert!(x > 100.0, "{x}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edits_route_d_preview_pages() {
|
||||
let server = TestServer::start("route-d-edit");
|
||||
|
||||
Reference in new issue
Block a user