Honour noindent at the start of a paragraph
This commit is contained in:
1 parent
eaa0122901
commit
0b4c2ec394
4 files changed
+44
-8
No files matched your search
+40
-4
@@ -5083,6 +5083,15 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
unit.space_shrink = paragraph.space_shrink;
|
||||
return unit;
|
||||
}
|
||||
let mut text = paragraph.text.clone();
|
||||
let no_indent = text.trim_start().starts_with("\\noindent");
|
||||
if no_indent {
|
||||
text = text
|
||||
.trim_start()
|
||||
.trim_start_matches("\\noindent")
|
||||
.trim_start()
|
||||
.to_string();
|
||||
}
|
||||
let class_size = paragraph
|
||||
.font_size
|
||||
.or(geometry.base_font_size)
|
||||
@@ -5123,7 +5132,11 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
baselineskip,
|
||||
lineskip: geometry.lineskip.unwrap_or(65536),
|
||||
lineskiplimit: geometry.lineskiplimit.unwrap_or(0),
|
||||
par_indent: geometry.par_indent.unwrap_or(0),
|
||||
par_indent: if no_indent {
|
||||
0
|
||||
} else {
|
||||
geometry.par_indent.unwrap_or(0)
|
||||
},
|
||||
emergencystretch: geometry.emergency_stretch.unwrap_or(0),
|
||||
pretolerance: geometry.pretolerance.unwrap_or(100),
|
||||
tolerance: geometry.tolerance.unwrap_or(200),
|
||||
@@ -5149,11 +5162,11 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
space_skip: geometry.space_skip,
|
||||
xspace_skip: geometry.xspace_skip,
|
||||
};
|
||||
let plain = strip_hrefs(¶graph.text);
|
||||
let mut unit = match inline_math_segments(¶graph.text, paragraph.font, &style) {
|
||||
let plain = strip_hrefs(&text);
|
||||
let mut unit = match inline_math_segments(&text, paragraph.font, &style) {
|
||||
Some(segments) => Unit::paragraph_with_style_and_segments(
|
||||
index as u64,
|
||||
paragraph.text.clone(),
|
||||
text.clone(),
|
||||
style.clone(),
|
||||
segments,
|
||||
),
|
||||
@@ -5900,6 +5913,29 @@ mod source_tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noindent_starts_the_paragraph_flush() {
|
||||
let blocks = paragraphs("\\noindent Alpha\n\nBeta").expect("paragraphs");
|
||||
let mut geometry = PageGeometry::default();
|
||||
geometry.par_indent = Some(20 * SCALE);
|
||||
let document = build_document(&blocks, &geometry);
|
||||
assert_eq!(document.units[0].source, "Alpha");
|
||||
assert_eq!(
|
||||
document.units[0]
|
||||
.paragraph_style
|
||||
.as_ref()
|
||||
.map(|style| style.par_indent),
|
||||
Some(0)
|
||||
);
|
||||
assert_eq!(
|
||||
document.units[1]
|
||||
.paragraph_style
|
||||
.as_ref()
|
||||
.map(|style| style.par_indent),
|
||||
Some(20 * SCALE)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_numbers_are_centered_in_previews() {
|
||||
let json = preview_json("Alpha").expect("preview");
|
||||
|
||||
Reference in new issue
Block a user