Centre blocks after a centering declaration
This commit is contained in:
1 parent
3d1ace51ae
commit
337f1f6de6
3 files changed
+34
-4
No files matched your search
+32
-2
@@ -9292,6 +9292,17 @@ fn build_document_with_labels(
|
||||
.to_string();
|
||||
}
|
||||
text = strip_noop_commands(&text);
|
||||
let mut centered = paragraph.centered;
|
||||
let mut right_aligned = paragraph.right_aligned;
|
||||
let trimmed = text.trim_start();
|
||||
if let Some(rest) = trimmed.strip_prefix("\\centering") {
|
||||
centered = true;
|
||||
text = rest.trim_start().to_string();
|
||||
} else if let Some(rest) = trimmed.strip_prefix("\\raggedleft") {
|
||||
right_aligned = true;
|
||||
text = rest.trim_start().to_string();
|
||||
}
|
||||
|
||||
text = strip_box_commands(&text);
|
||||
text = expand_math_spaces(&text);
|
||||
text = expand_ensuremath(&text);
|
||||
@@ -9332,8 +9343,8 @@ fn build_document_with_labels(
|
||||
let style = ParagraphStyle {
|
||||
line_width: paragraph.width.unwrap_or(line_width),
|
||||
left_skip,
|
||||
centered: paragraph.centered,
|
||||
right_aligned: paragraph.right_aligned,
|
||||
centered,
|
||||
right_aligned,
|
||||
looseness: geometry.looseness.unwrap_or(0),
|
||||
ragged_right: false,
|
||||
right_skip: geometry.right_skip.unwrap_or(0) + paragraph.right_skip * SCALE,
|
||||
@@ -13380,6 +13391,25 @@ A definition.
|
||||
assert_eq!(blocks[0].text, "See In body.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn centering_declaration_centres_the_block() {
|
||||
let blocks = paragraphs("\\centering Short.").expect("paragraphs");
|
||||
let document = build_document(&blocks, &PageGeometry::default());
|
||||
let engine = Engine::layout(&document);
|
||||
let x = engine
|
||||
.pages()
|
||||
.iter()
|
||||
.flat_map(|page| page.display_list().items)
|
||||
.find_map(|item| match item {
|
||||
texrra_tex_core::render::DisplayItem::Text { text, x, .. } if text == "S" => {
|
||||
Some(x)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("S glyph");
|
||||
assert!(x > 0, "centred text starts at {}", x);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn romannumeral_prints_a_register() {
|
||||
let (body, _geometry) =
|
||||
|
||||
Reference in new issue
Block a user