Skip to content

Commit 8130c9d

Browse files
developer0hyeclaude
andcommitted
fix(render): use #set align() instead of #align()[] for reliable horizontal text alignment
In Typst 0.14, #align(center)[text] wrapping did not work reliably inside the #context + measure() pattern used for vertical centering in fixed-page text boxes. Changed to #block(width: 100%)[#set align(...)] which correctly propagates alignment through the layout pipeline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
1 parent 91ca0cc commit 8130c9d

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

crates/office2pdf/src/parser/pptx_shape_style_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ fn test_split_textbox_preserves_alignment() {
507507
// Verify Typst output contains #align(center)
508508
let typst_output = crate::render::typst_gen::generate_typst(&doc).unwrap();
509509
assert!(
510-
typst_output.source.contains("#align(center)"),
511-
"Typst output should contain #align(center) for centered paragraph, got:\n{}",
510+
typst_output.source.contains("#set align(center)"),
511+
"Typst output should contain #set align(center) for centered paragraph, got:\n{}",
512512
typst_output.source,
513513
);
514514
}

crates/office2pdf/src/render/typst_gen.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,14 +1086,16 @@ fn generate_fixed_text_paragraph(out: &mut String, para: &Paragraph) -> Result<(
10861086
Some(Alignment::Center) | Some(Alignment::Right) | Some(Alignment::Left)
10871087
);
10881088

1089+
// Use #block(width: 100%)[#set align(...); content] to ensure alignment
1090+
// works reliably inside #context + measure() vertical centering.
10891091
if use_align {
10901092
let align_str = match alignment {
10911093
Some(Alignment::Left) => "left",
10921094
Some(Alignment::Center) => "center",
10931095
Some(Alignment::Right) => "right",
10941096
_ => "left",
10951097
};
1096-
let _ = write!(out, "#align({align_str})[");
1098+
let _ = write!(out, "#block(width: 100%)[#set align({align_str})\n");
10971099
}
10981100

10991101
generate_runs_with_tabs(out, &para.runs, style.tab_stops.as_deref());

0 commit comments

Comments
 (0)