Repository navigation
Fix English text and form layout offsets - #215
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2cd0038b5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const contentWidth = CONTENT_WIDTH - (line.indent || 0); | ||
| const lineWidth = line.segments.reduce((sum, seg) => sum + (seg.width != null ? seg.width : String(seg.text || "").length * line.fontSize * 0.5), 0); | ||
| const alignOffset = line.alignment === "center" ? Math.max(0, (contentWidth - lineWidth) / 2) | ||
| : line.alignment === "right" ? Math.max(0, contentWidth - lineWidth) | ||
| : 0; |
There was a problem hiding this comment.
Propagate paragraph formatting through the active PDF layout path
For DOCX paragraphs with alignment: "center"/"right" or spacingBefore, these branches never take effect because buildPdfBytes() uses blockToLinesLocal(), whose emitted line objects omit both alignment and marginBefore; only the unused top-level blockToLines() propagates them. Consequently, renderLineLocal() always sees an undefined alignment and zero pre-spacing—for example, a centered paragraph is still emitted at the left margin.
Useful? React with 👍 / 👎.
| function getDocumentPaperSize(model, paperFormat) { | ||
| if (paperFormat) return getPaperSize(paperFormat); | ||
| const layout = model.metadata?.ooxml?.pageLayout; |
There was a problem hiding this comment.
Honor source page geometry in workbench PDF conversions
When converting DOCX to PDF through the workbench, public/app.js:1736-1739 always supplies the A4 or Letter selector value, so this early return runs before inspecting model.metadata.ooxml.pageLayout. The newly parsed source dimensions and margins are therefore never used in the main user flow, and landscape or custom-size forms are silently reformatted to the selector's default paper size unless callers invoke the writer directly without paperFormat.
Useful? React with 👍 / 👎.
| const indentLeft = Number(format.indentLeft) || 0; | ||
| const firstLine = Number(format.firstLineIndent) || 0; | ||
| const hanging = Number(format.hangingIndent) || 0; | ||
| return { | ||
| ...layout, | ||
| indent: layout.indent + Math.max(0, indentLeft + firstLine - hanging) / 20, |
There was a problem hiding this comment.
Apply first-line and hanging indents per wrapped line
For a paragraph that wraps, Word's firstLineIndent applies only to the first line, while hangingIndent shifts the first line relative to subsequent lines. Collapsing all three values into one layout.indent applies the same offset to every generated line; for example, indentLeft: 720, hangingIndent: 360 renders every line at 18 pt instead of rendering continuation lines at 36 pt. Preserve separate first-line and continuation indents when constructing the PDF lines.
Useful? React with 👍 / 👎.
Summary
Verification
ode scripts/layout-offset-regression-test.js passed.
pm test reaches the existing Puppeteer UI E2E script, where this Windows environment's Chrome exits with code 3 under the repository's default launch args. Remaining non-browser scripts were run separately; Linux CI will run the E2E path.
Closes #214