Scale inline math proportionally
Inline math in a 12pt paragraph kept 10pt glyphs because paint_math advances with 10pt metrics. Paint the math atom into a temporary display list at the 10pt baseline and scale that list as a unit (text sizes and positions, rule widths/heights, line endpoints) to the paragraph size before translating it to the baseline. The box no longer pins its size, so a scaled math glyph now reports font-size 12.000 in a 12pt paragraph. The twelve-point test now also asserts that an italic math glyph is rendered at the paragraph size; the sized-paragraph test still expects a math box and no literal dollars.
This commit is contained in:
1 parent
b3fbbc8dda
commit
88a03ec1a1
5 files changed
+61
-16
No files matched your search
@@ -2055,7 +2055,7 @@ pub fn layout_paragraph_segments(segments: &[InlineSegment], style: &ParagraphSt
|
|||||||
italic: 0,
|
italic: 0,
|
||||||
font: None,
|
font: None,
|
||||||
math: Some(Box::new(atom.clone())),
|
math: Some(Box::new(atom.clone())),
|
||||||
size: Some(655_360),
|
size: None,
|
||||||
raise: 0,
|
raise: 0,
|
||||||
color: None,
|
color: None,
|
||||||
background: None,
|
background: None,
|
||||||
|
|||||||
@@ -747,16 +747,58 @@ impl Page {
|
|||||||
}
|
}
|
||||||
let glyph_size = box_.size.unwrap_or(size);
|
let glyph_size = box_.size.unwrap_or(size);
|
||||||
let glyph_y = baseline - box_.raise;
|
let glyph_y = baseline - box_.raise;
|
||||||
|
let x0_math = |value: i64, positioned: &dyn Fn(i64) -> i64| {
|
||||||
|
x + positioned(value)
|
||||||
|
};
|
||||||
if let Some(math) = &box_.math {
|
if let Some(math) = &box_.math {
|
||||||
let math_font = Cmr10Metrics::default();
|
let math_font = Cmr10Metrics::default();
|
||||||
Self::paint_math(
|
let mut raw = Vec::new();
|
||||||
math,
|
Self::paint_math(math, &math_font, 0, 0, 655_360, &mut raw);
|
||||||
&math_font,
|
let ratio = glyph_size as f64 / 655_360.0;
|
||||||
|
let positioned = |value: i64| (value as f64 * ratio) as i64;
|
||||||
|
for item in raw {
|
||||||
|
let item = match item {
|
||||||
|
DisplayItem::Text {
|
||||||
x,
|
x,
|
||||||
glyph_y,
|
y,
|
||||||
glyph_size,
|
size,
|
||||||
&mut list.items,
|
text,
|
||||||
);
|
font,
|
||||||
|
} => DisplayItem::Text {
|
||||||
|
x: x0_math(x, &positioned),
|
||||||
|
y: glyph_y + positioned(y),
|
||||||
|
size: positioned(size).max(1),
|
||||||
|
text,
|
||||||
|
font,
|
||||||
|
},
|
||||||
|
DisplayItem::Rule {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
} => DisplayItem::Rule {
|
||||||
|
x: x0_math(x, &positioned),
|
||||||
|
y: glyph_y + positioned(y),
|
||||||
|
width: positioned(width),
|
||||||
|
height: positioned(height).max(1),
|
||||||
|
},
|
||||||
|
DisplayItem::Line {
|
||||||
|
x1,
|
||||||
|
y1,
|
||||||
|
x2,
|
||||||
|
y2,
|
||||||
|
width,
|
||||||
|
} => DisplayItem::Line {
|
||||||
|
x1: x0_math(x1, &positioned),
|
||||||
|
y1: glyph_y + positioned(y1),
|
||||||
|
x2: x0_math(x2, &positioned),
|
||||||
|
y2: glyph_y + positioned(y2),
|
||||||
|
width: positioned(width).max(1),
|
||||||
|
},
|
||||||
|
other => other,
|
||||||
|
};
|
||||||
|
list.items.push(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(character) = box_.character {
|
if let Some(character) = box_.character {
|
||||||
list.push(DisplayItem::Text {
|
list.push(DisplayItem::Text {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
|||||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
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
|
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||||
PDF opt-in with `?engine=route-d`; flat `/preview` and project previews now
|
PDF opt-in with `?engine=route-d`; flat `/preview` and project previews now
|
||||||
prefer route-D with a v1 fallback). 1012 workspace tests are green and no oracle
|
prefer route-D with a v1 fallback). 1013 workspace tests are green and no oracle
|
||||||
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
||||||
environments route-D cannot lay out and control words that survived layout, so
|
environments route-D cannot lay out and control words that survived layout, so
|
||||||
unsupported source is reported instead of being silently typeset.
|
unsupported source is reported instead of being silently typeset.
|
||||||
|
|||||||
+6
-6
@@ -370,7 +370,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.
|
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 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1012 tests (437 route-D unit, 385 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 62 server, 4 engine unit, 1 core unit), with none ignored. The flat `/preview` endpoint and the project preview/PDF endpoints now try route-D first and fall back to v1 on error (`?engine=v1` or `TEXRRA_ENGINE=v1` forces v1; the flat response carries `X-Preview-Engine`, naming the engine used). A geometry-less project now defaults to Letter, matching pdfLaTeX, where the old v1 path used A4.
|
The crate currently has 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1013 tests (437 route-D unit, 386 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 62 server, 4 engine unit, 1 core unit), with none ignored. The flat `/preview` endpoint and the project preview/PDF endpoints now try route-D first and fall back to v1 on error (`?engine=v1` or `TEXRRA_ENGINE=v1` forces v1; the flat response carries `X-Preview-Engine`, naming the engine used). A geometry-less project now defaults to Letter, matching pdfLaTeX, where the old v1 path used A4.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
@@ -520,7 +520,7 @@ deliberately open rather than approximated:
|
|||||||
|
|
||||||
## Limits and remaining gaps
|
## Limits and remaining gaps
|
||||||
|
|
||||||
The suite currently stands at 1012 passing tests, with the workspace clean.
|
The suite currently stands at 1013 passing tests, with the workspace clean.
|
||||||
Route-D serves both flat `/preview` and project preview/PDF requests by default
|
Route-D serves both flat `/preview` and project preview/PDF requests by default
|
||||||
(automatic v1 fallback; `?engine=v1` or `TEXRRA_ENGINE=v1` opts out). The
|
(automatic v1 fallback; `?engine=v1` or `TEXRRA_ENGINE=v1` opts out). The
|
||||||
objective's areas are implemented to the limits below; complex-script shaping is
|
objective's areas are implemented to the limits below; complex-script shaping is
|
||||||
@@ -602,7 +602,7 @@ are:
|
|||||||
closest engine face by name (sans/mono/serif). Complex scripts such as
|
closest engine face by name (sans/mono/serif). Complex scripts such as
|
||||||
Devanagari, Thai and emoji have no shaping fallback and render as missing
|
Devanagari, Thai and emoji have no shaping fallback and render as missing
|
||||||
glyphs; arbitrary external font families remain open.
|
glyphs; arbitrary external font families remain open.
|
||||||
- **Inline runs**: colour/link/sized runs split at any base size; inline math
|
- **Inline runs**: colour/link/sized runs split at any base size. Inline math
|
||||||
also renders at any base size, with its glyphs pinned to the 10pt metric size
|
renders at any base size: the 10pt math display list is scaled as a unit
|
||||||
inside a larger paragraph (the box width scales with the paragraph), so 12pt
|
(glyphs, advances, rules and delimiters) to the paragraph size, so 12pt and
|
||||||
documents no longer print literal `$` delimiters.
|
`\large` documents keep formulas in proportion with no literal `$`.
|
||||||
+4
-1
@@ -16775,7 +16775,10 @@ left & right \\
|
|||||||
value["warnings"]
|
value["warnings"]
|
||||||
);
|
);
|
||||||
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
||||||
assert!(svg.contains("font-style=\"italic\""), "{svg}");
|
let scaled_math = svg.split("<text").any(|chunk| {
|
||||||
|
chunk.contains("font-style=\"italic\"") && chunk.contains("font-size=\"12.000\"")
|
||||||
|
});
|
||||||
|
assert!(scaled_math, "math glyph was not scaled: {svg}");
|
||||||
assert!(!svg.contains('$'), "{svg}");
|
assert!(!svg.contains('$'), "{svg}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user