Skip to content

Fix English text and form layout offsets - #215

Merged
Vantalens merged 1 commit into
mainfrom
codex/214-layout-offset-repair
Sep 24, 2026
Merged

Vantalens merged 1 commit into
mainfrom
codex/214-layout-offset-repair

Conversation

@Vantalens

Copy link
Copy Markdown
Owner

Summary

  • Preserve TXT line breaks, indentation, and underscore identifiers.
  • Use measured PDF text geometry for English spacing and restore repeated two-column reading order.
  • Preserve supported DOCX page geometry, paragraph formatting, tab stops, table widths, and cell merges through DOCX/PDF/HTML output, with explicit layout degradation warnings.
  • Add layout fidelity reporting and synthetic regression coverage.

Verification

ode scripts/layout-offset-regression-test.js passed.

  • Core format, snapshot, capability, integrity, and regression scripts passed.
  • Full
    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.
  • No anonymized user DOCX/PDF sample was available; layout regression uses generated fixtures.

Closes #214

@Vantalens
Vantalens merged commit 4f567e0 into main Sep 24, 2026
8 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +627 to +631
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +33 to +35
function getDocumentPaperSize(model, paperFormat) {
if (paperFormat) return getPaperSize(paperFormat);
const layout = model.metadata?.ooxml?.pageLayout;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +206 to +211
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Bug】跨格式转换导致英文文本与表单字段错位

1 participant