diff --git a/src/resources/formats/typst/pandoc/quarto/typst-template.typ b/src/resources/formats/typst/pandoc/quarto/typst-template.typ index a1c80798c60..0a2e69bc55a 100644 --- a/src/resources/formats/typst/pandoc/quarto/typst-template.typ +++ b/src/resources/formats/typst/pandoc/quarto/typst-template.typ @@ -61,54 +61,61 @@ } } - place(top, float: true, scope: "parent", clearance: 4mm)[ - #if title != none { - align(center, block(inset: 2em)[ - #set par(leading: heading-line-height) if heading-line-height != none - #set text(font: heading-family) if heading-family != none - #set text(weight: heading-weight) - #set text(style: heading-style) if heading-style != "normal" - #set text(fill: heading-color) if heading-color != black + place( + top, + float: true, + scope: "parent", + clearance: 4mm, + block(below: 1em, width: 100%)[ - #text(size: title-size)[#title #if thanks != none { - footnote(thanks, numbering: "*") - counter(footnote).update(n => n - 1) - }] - #(if subtitle != none { - parbreak() - text(size: subtitle-size)[#subtitle] - }) - ]) - } + #if title != none { + align(center, block(inset: 2em)[ + #set par(leading: heading-line-height) if heading-line-height != none + #set text(font: heading-family) if heading-family != none + #set text(weight: heading-weight) + #set text(style: heading-style) if heading-style != "normal" + #set text(fill: heading-color) if heading-color != black + + #text(size: title-size)[#title #if thanks != none { + footnote(thanks, numbering: "*") + counter(footnote).update(n => n - 1) + }] + #(if subtitle != none { + parbreak() + text(size: subtitle-size)[#subtitle] + }) + ]) + } - #if authors != none and authors != () { - let count = authors.len() - let ncols = calc.min(count, 3) - grid( - columns: (1fr,) * ncols, - row-gutter: 1.5em, - ..authors.map(author => - align(center)[ - #author.name \ - #author.affiliation \ - #author.email - ] + #if authors != none and authors != () { + let count = authors.len() + let ncols = calc.min(count, 3) + grid( + columns: (1fr,) * ncols, + row-gutter: 1.5em, + ..authors.map(author => + align(center)[ + #author.name \ + #author.affiliation \ + #author.email + ] + ) ) - ) - } + } - #if date != none { - align(center)[#block(inset: 1em)[ - #date - ]] - } + #if date != none { + align(center)[#block(inset: 1em)[ + #date + ]] + } - #if abstract != none { - block(inset: 2em)[ - #text(weight: "semibold")[#abstract-title] #h(1em) #abstract - ] - } - ] + #if abstract != none { + block(inset: 2em)[ + #text(weight: "semibold")[#abstract-title] #h(1em) #abstract + ] + } + ] + ) if toc { let title = if toc_title == none { diff --git a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd index de3e923e0b5..8b2c0920952 100644 --- a/tests/docs/smoke-all/typst/columns/basic-two-column.qmd +++ b/tests/docs/smoke-all/typst/columns/basic-two-column.qmd @@ -12,10 +12,20 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Basic Two Column Layout" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 5 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd index fb33b2582f1..c9853ef144d 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-landscape.qmd @@ -22,7 +22,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' # Landscape page start - '#set page\(flipped: true\)' # Landscape page end @@ -30,6 +30,25 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Two Column with Landscape Section" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 22 + - subject: + text: "Testing Column Layout with Page Orientation Changes" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 22 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd index f7c2addf061..391d8029261 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-title-block.qmd @@ -30,7 +30,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' # Title passed to article() - 'title: \[Two Column with Full Title Block\]' # Subtitle passed to article() @@ -44,6 +44,25 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Two Column with Full Title Block" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 22 + - subject: + text: "Testing Column-Spanning Title Elements" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 22 --- ## Introduction diff --git a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd index e3e2f6c29a1..05b867a5a8d 100644 --- a/tests/docs/smoke-all/typst/columns/two-column-toc.qmd +++ b/tests/docs/smoke-all/typst/columns/two-column-toc.qmd @@ -16,7 +16,7 @@ _quarto: # Page columns set via set page() - 'columns: 2,' # Title block wrapped with place(scope: "parent") for column spanning - - 'place\(top, float: true, scope: "parent", clearance: 4mm\)' + - 'place\(\s+top,\s+float: true,\s+scope: "parent",\s+clearance: 4mm,\s+block\(below: 1em, width: 100%\)' # TOC enabled in article() call - 'toc: true' # TOC title passed @@ -28,6 +28,16 @@ _quarto: - # Patterns that must NOT be found # Should NOT have columns() function call wrapping doc at end of article() - 'columns\(cols, doc\)\n\}' + ensurePdfTextPositions: + - - subject: + text: "Two Column with Table of Contents" + edge: centerX + relation: leftAligned + object: + role: Page + page: 1 + edge: centerX + tolerance: 22 --- ## Introduction diff --git a/tests/smoke/verify/pdf-text-position.test.ts b/tests/smoke/verify/pdf-text-position.test.ts index 3a967b56b2f..2f40fa0e26d 100644 --- a/tests/smoke/verify/pdf-text-position.test.ts +++ b/tests/smoke/verify/pdf-text-position.test.ts @@ -53,6 +53,7 @@ testQuartoCmd("render", [fixtureQmd, "--to", "typst"], [], { await runDistanceConstraintTests(); await runDistanceConstraintErrorTests(); await runPageRoleWithEdgeTests(); + await runCenterEdgeTests(); // Cleanup if (safeExistsSync(fixturePdf)) { @@ -575,3 +576,39 @@ async function runPageRoleWithEdgeTests() { ]); await headerNearPageTop.verify([]); } + +/** + * Test centerX and centerY edge functionality + */ +async function runCenterEdgeTests() { + // Test: centerX - title's horizontal centre should be near page's horizontal centre (inset tolerance for minor misalignment) + const centerXPageTest = ensurePdfTextPositions(fixturePdf, [ + { + subject: { text: "FIXTURE_TITLE_TEXT", edge: "centerX" }, + relation: "leftAligned", + object: { role: "Page", page: 1, edge: "centerX" }, + tolerance: 35, + }, + ]); + await centerXPageTest.verify([]); + + // Test: centerY directional - header decoration's centerY should be above title's centerY + const centerYDirectionalTest = ensurePdfTextPositions(fixturePdf, [ + { + subject: { text: "FIXTURE_HEADER_TEXT", role: "Decoration", edge: "centerY" }, + relation: "above", + object: { text: "FIXTURE_TITLE_TEXT", edge: "centerY" }, + }, + ]); + await centerYDirectionalTest.verify([]); + + // Test: centerX directional - a left-aligned heading's centerX should be leftOf page centerX + const centerXDirectionalTest = ensurePdfTextPositions(fixturePdf, [ + { + subject: { text: "FIXTURE_H1_TEXT", edge: "centerX" }, + relation: "leftOf", + object: { role: "Page", page: 1, edge: "centerX" }, + }, + ]); + await centerXDirectionalTest.verify([]); +} diff --git a/tests/verify-pdf-text-position.ts b/tests/verify-pdf-text-position.ts index 7a60ee2ee9c..86dab3273f3 100644 --- a/tests/verify-pdf-text-position.ts +++ b/tests/verify-pdf-text-position.ts @@ -40,7 +40,7 @@ import { ExecuteOutput, Verify } from "./test.ts"; // ============================================================================ // Edge schema for precise bbox edge selection -export const EdgeSchema = z.enum(["left", "right", "top", "bottom"]); +export const EdgeSchema = z.enum(["left", "right", "top", "bottom", "centerX", "centerY"]); export type Edge = z.infer; // Relation schemas @@ -215,6 +215,10 @@ function getEdgeValue(bbox: BBox, edge: Edge): number { return bbox.y; case "bottom": return bbox.y + bbox.height; + case "centerX": + return bbox.x + bbox.width / 2; + case "centerY": + return bbox.y + bbox.height / 2; } }