Expand newcolumntype letters in table specs
This commit is contained in:
1 parent
97e883f51d
commit
9d57ca604e
3 files changed
+76
-3
No files matched your search
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||
PDF opt-in with `?engine=route-d`). 940 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 941 workspace tests are green and no oracle
|
||||
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
||||
environments route-D cannot lay out and control words that survived layout, so
|
||||
unsupported source is reported instead of being silently typeset.
|
||||
|
||||
+1
-1
@@ -367,7 +367,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`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||
|
||||
The crate currently has 427 unit tests plus ten route-D integration tests and thirty-eight oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 940 tests (430 route-D unit, 325 engine binary unit, 10 route-D integration, 39 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 427 unit tests plus ten route-D integration tests and thirty-eight oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 941 tests (430 route-D unit, 326 engine binary unit, 10 route-D integration, 39 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
+74
-1
@@ -159,6 +159,8 @@ struct PageGeometry {
|
||||
linespread: Option<i64>,
|
||||
/// `\tabcolsep` on each side of a tabular column.
|
||||
tab_col_sep: Option<i64>,
|
||||
/// Custom column letters declared with `\newcolumntype`.
|
||||
column_types: Vec<(char, String)>,
|
||||
/// `\itemsep` between list items, as width/stretch/shrink.
|
||||
item_sep: Option<(i64, i64, i64)>,
|
||||
/// `\topsep` above a list, as width/stretch/shrink.
|
||||
@@ -2094,6 +2096,35 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(rest) = trimmed.strip_prefix("\\newcolumntype") {
|
||||
let rest = rest.trim_start();
|
||||
let rest = if rest.starts_with('[') {
|
||||
rest.find(']')
|
||||
.map(|close| rest[close + 1..].trim_start())
|
||||
.unwrap_or(rest)
|
||||
} else {
|
||||
rest
|
||||
};
|
||||
if let Some((name, used)) = braced_group(rest) {
|
||||
let after = rest[used..].trim_start();
|
||||
let after = if after.starts_with('[') {
|
||||
after
|
||||
.find(']')
|
||||
.map(|close| after[close + 1..].trim_start())
|
||||
.unwrap_or(after)
|
||||
} else {
|
||||
after
|
||||
};
|
||||
if let Some((spec, _)) = braced_group(after) {
|
||||
if let Some(letter) = name.trim().chars().next() {
|
||||
geometry
|
||||
.column_types
|
||||
.push((letter, spec.trim().to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if trimmed.starts_with("\\newsavebox")
|
||||
|| trimmed.starts_with("\\sbox")
|
||||
|| trimmed.starts_with("\\savebox")
|
||||
@@ -2759,6 +2790,36 @@ fn expand_tabular_template(template: &str, source: &str, target: Option<i64>) ->
|
||||
out
|
||||
}
|
||||
|
||||
/// Substitute `\newcolumntype` letters at the top level of a column spec.
|
||||
fn expand_column_types(template: &str, types: &[(char, String)]) -> String {
|
||||
if types.is_empty() {
|
||||
return template.to_string();
|
||||
}
|
||||
let mut out = String::new();
|
||||
let mut depth = 0_usize;
|
||||
for character in template.chars() {
|
||||
match character {
|
||||
'{' => {
|
||||
depth += 1;
|
||||
out.push(character);
|
||||
}
|
||||
'}' => {
|
||||
depth = depth.saturating_sub(1);
|
||||
out.push(character);
|
||||
}
|
||||
_ if depth == 0 => {
|
||||
if let Some((_, spec)) = types.iter().find(|(letter, _)| *letter == character) {
|
||||
out.push_str(spec);
|
||||
} else {
|
||||
out.push(character);
|
||||
}
|
||||
}
|
||||
_ => out.push(character),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn tabular_unit(
|
||||
geometry: &PageGeometry,
|
||||
id: u64,
|
||||
@@ -2767,8 +2828,9 @@ fn tabular_unit(
|
||||
target: Option<i64>,
|
||||
) -> Unit {
|
||||
let separator = geometry.tab_col_sep.unwrap_or(6 * SCALE);
|
||||
let template = expand_column_types(template, &geometry.column_types);
|
||||
let inner_target = target.map(|target| (target - 2 * 6 * SCALE).max(10 * 65_536));
|
||||
let template = expand_tabular_template(template, source, inner_target);
|
||||
let template = expand_tabular_template(&template, source, inner_target);
|
||||
let mut unit = Unit::halign_from_source_with_template_and_tabskips(
|
||||
id,
|
||||
&engine_template(&template),
|
||||
@@ -12090,6 +12152,17 @@ See \ref{fig:a} and \ref{tab:b}.";
|
||||
assert!(json.contains(">S</text>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newcolumntype_expands_in_templates() {
|
||||
let source = "\\newcolumntype{L}{>{\\centering}p{20mm}}\n\n\\begin{tabular}{Ll}\nalpha beta & right \\\\\n\\end{tabular}";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(geometry.column_types.len(), 1);
|
||||
assert!(!body.contains("newcolumntype"));
|
||||
let json = preview_json(source).expect("preview");
|
||||
assert!(json.contains("\"warnings\":[]"), "warnings: {json}");
|
||||
assert!(!json.contains("centering"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_column_modifiers_stay_out_of_the_text() {
|
||||
let source =
|
||||
|
||||
Reference in new issue
Block a user