Turn TeX hyphen runs into en and em dashes
This commit is contained in:
1 parent
ff97f386da
commit
95760e4a1c
2 files changed
+35
-1
No files matched your search
@@ -575,7 +575,7 @@ default until the new core reaches layout parity. See `docs/TEX_CORE.md`.
|
||||
The first M7 service integration is available as `POST /api/route-d/preview`, with PDF export at `POST /api/route-d/pdf`.
|
||||
It accepts blank-line-separated source with a small `\section`/`\textbf`/`\emph`/display-math/list subset, lays it out with the route-D page
|
||||
builder, and returns the v1-compatible preview shape plus per-page hashes and
|
||||
SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures, and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. `Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page. The v1 `/preview` and project APIs are unchanged and remain the default.
|
||||
SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures; runs of two or three hyphens become en/em dashes, and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. `Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page. The v1 `/preview` and project APIs are unchanged and remain the default.
|
||||
|
||||
Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages and a one-paragraph edit returns the changed/recomputed page set. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D
|
||||
document and returns the same page list plus `changedPages` and
|
||||
|
||||
@@ -353,6 +353,10 @@ pub fn text_items_with_font(
|
||||
let mut items = Vec::new();
|
||||
let hyphenator = hyphenate::Hyphenator::plain_tex_en_us();
|
||||
let caser = hyphenate::AsciiLowerCaser::default();
|
||||
// TeX's text fonts turn runs of hyphens into en/em dashes. cmr10's TFM
|
||||
// does not carry these ligatures, so apply the same mapping before
|
||||
// shaping the paragraph.
|
||||
let text = text.replace("---", "\u{2014}").replace("--", "\u{2013}");
|
||||
let words: Vec<&str> = text.split_whitespace().collect();
|
||||
let mut previous_box: Option<usize> = None;
|
||||
let mut previous_character: Option<char> = None;
|
||||
@@ -569,6 +573,36 @@ mod tests {
|
||||
assert!(paragraph.lines.len() > 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_hyphen_becomes_one_en_dash_box() {
|
||||
let font = crate::cmr10::Cmr10Metrics::new();
|
||||
let style = ParagraphStyle::default();
|
||||
let items = text_items_with_font("--", &style, &font);
|
||||
let boxes: Vec<_> = items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
HorizontalItem::Box(horizontal) => horizontal.character,
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(boxes, vec!['\u{2013}']);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn triple_hyphen_becomes_one_em_dash_box() {
|
||||
let font = crate::cmr10::Cmr10Metrics::new();
|
||||
let style = ParagraphStyle::default();
|
||||
let items = text_items_with_font("---", &style, &font);
|
||||
let boxes: Vec<_> = items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
HorizontalItem::Box(horizontal) => horizontal.character,
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(boxes, vec!['\u{2014}']);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fi_ligature_reduces_character_boxes() {
|
||||
let font = crate::cmr10::Cmr10Metrics::new();
|
||||
|
||||
Reference in new issue
Block a user