Commit Graph

4 Commits (0ab3768c5a616d93b93901f2f9b1fd8c3dcea112)

Author SHA1 Message Date
mula.liu df35111326 release: prepare Shift 0.1.8 2026-10-27 18:45:32 +08:00
mula.liu 19602b79f0 fix(docx): keep figures when a DOCX is printed to PDF
Two bugs, both visible in 平台技术方案(带图测试专用).docx: one figure, eleven
tables and 357 paragraphs, whose PDF came out as a text-only document.

First, AppKit's OOXML reader returns the text of a DOCX and silently drops every
inline drawing - an attributed string with zero attachments for a document with a
picture in it. That is not a rendering loss, it is a parse loss, so no margin,
print setting or layout change can recover the figure: by the time the page is
drawn, the picture is simply not in the attributed string. A DOCX whose body
contains an image is now converted by Pandoc into HTML with its media extracted
beside it, and the HTML - which Pandoc reads faithfully, headings, tables and
pictures - goes to the same printer. Image-only DOCX files keep the existing
page-scan path, which runs first, and a machine without Pandoc falls back to the
old text-only behaviour rather than failing.

Second, once pictures could arrive they printed as a cropped fragment of
themselves. The layout sizes an attachment from the density header inside the
file, assumes 72 dpi when there is none, and ignores both bounds and CSS width: a
1600 px screenshot at 96 dpi asks for 1200 points and lands on a 595 pt page.
Measured across PNG pHYs and JPEG JFIF, the placed width is exactly
pixels / dpi * 64. A plain NSTextAttachment does honour bounds, so the renderer
now replaces any oversized attachment with one that fits the text column; the
print operation scales it to the page with the text, landing at 499pt, which is
the printable width the body text already uses. Nothing is resampled, only the
size the layout asks for changes. This also fixes Markdown and HTML documents
with wide images, which had the same overflow.

Both halves are pinned by tests, and both fail against the previous build:
keeps_pictures_when_rendering_a_text_docx_to_pdf sees no image at all, and
fits_a_wide_picture_onto_the_page reports a picture placed 1066.77pt wide on a
595pt page. The second reads the Form XObject's /BBox, so it needs no content
stream decoded and no pixel compared.
2026-10-26 14:50:52 +08:00
mula.liu c6eff4e131 修复bug 2026-10-25 12:24:05 +08:00
Shift 0eb75595c6 baseline: capture workspace state (bug fixes in progress) 2026-10-21 08:54:54 +08:00