R7.6: Windows and Linux print (#3)

Windows prints through the system dialog at the document's paper;
Linux through the desktop portal, the dialog's choices laid out by Ely.
Round 3 findings fixed without a further review, as the rules say.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-16 16:59:46 -04:00
1 parent de4a38e814
commit 13546ea899
26 files changed
+2544 -114

No files matched your search

+1 -1
View File
@@ -281,6 +281,6 @@
- [x] R7.3 装了宋体仍报缺少(#4,§7、§8):内核按 `宋体` 找到 SimSun,缺字检查却比较原名与所用字体的英文名,报为缺失;查明 Linux 上的版面是否真用 SimSun,一页变两页的根因(补丁 0048:缺字检查比较 `GetEnglishSearchFontName`;Windows 与 WSL 内核已重建;`navigate/tests.rs` 的 `DEJAVU SANS` 用例修前失败、修后通过,ElyDoc 单线程 55 项通过;Arch 容器装 0.1.5 包与 simsun.ttc:修前报缺宋体,正文实为 SimSun,一页;换上新内核不再报缺,仍一页。一页变两页未能复现,需报告者的文件 — 第 1 轮 PASS)
- [x] R7.4 打开 PDF 总说已损坏(#5,§11):画图块时 MuPDF 的任何警告都算损坏,未嵌入的中日韩字体(“non-embedded font using identity encoding”)即触发;损坏只认结构修复、读不出的对象与流、画不出的图片与内容
- [x] R7.5 ElyMark 打开的正文块变成一块深色框(§14,用户定):按下的段落保持原样,不加底色与内边距,不挪位置;代码块仍有自己的底板
- [ ] R7.6 Windows 与 Linux 不能打印(#3,§19.3):`print_pdf` 只有 macOS;Windows 用系统打印对话框,Linux 经 xdg 桌面门户的打印接口
- [x] R7.6 Windows 与 Linux 不能打印(#3,§19.3):`print_pdf` 只有 macOS;Windows 用系统打印对话框,Linux 经 xdg 桌面门户的打印接口
- [ ] R7.7 发布 0.1.6:版本号,三端建包、签名公证、上传,合集包一并上传,本机装上
- [ ] R7.8 答复 #3 至 #6:每条写已修于 0.1.6;#6 的工作区建议另开 [FEATURE REQUEST] 并链过去
+11
View File
@@ -0,0 +1,11 @@
FAIL
- crates/ely-platform/src/print/linux.rs:52 — The PreparePrint response is reduced to its token; returned page ranges and scaling are discarded before sending the original PDF. With a three-page document, selecting only page 2 and 50% scaling still prints all three pages at their original size through the GTK portal backend. The application probe confirmed unchanged bytes were sent; an independent GTK 3.24.52 Print to File job confirmed the resulting output was byte-for-byte identical to the three-page input (`.work/r76-review-r1/linux-probe.log`, `gtk-backend-result.log`). Follow the portal's prepare/format/print contract and apply the returned page selection and layout settings exactly once; test the resulting pages and geometry. See the [Print portal contract](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Print.html).
- crates/ely-platform/src/print/win/printer.rs:60 — Driver normalization silently replaces unsupported custom paper, and the accepted dimensions are never checked. Printing a 1000×600-point PDF through Microsoft Print to PDF produced an 842×595-point page, cutting off the right-hand content, while print_pdf returned true. The only indication was a log warning (`.work/r76-review-r1/windows-probe.log`). Correct the custom-paper configuration and validate the accepted paper dimensions; if the printer cannot honor them, surface that failure instead of reporting a successful, cropped print. Add a custom-paper output regression.
- crates/ely-platform/src/print/linux.rs:127 — Box coordinates are treated as points without applying the page's /UserUnit. A valid PDF with MediaBox [0 0 421 297.5] and UserUnit 2 is A4 landscape (842×595 points), but the public print path sent custom_105x149mm to the portal. The added probe failed the A4 assertion (`.work/r76-review-r1/linux-probe.log`); the existing MuPDF UserUnit test passed independently. Multiply box dimensions by the page's UserUnit before choosing paper and applying rotation, and cover this in the print tests so printed paper agrees with the preview.
- crates/ely-platform/src/print/win.rs:160 — Every job returned by the system dialog has output: None, discarding PD_PRINTTOFILE and the DEVNAMES output field. When the user selects an ordinary printer and enables Windows 11's “Print to file” switch, StartDocW receives a null output destination and submits to that printer instead of requesting an output filename. The current integration test bypasses this branch using ELY_PRINT_TO. Preserve the dialog's file-output selection and pass FILE: to DOCINFO.lpszOutput as required by the [PrintDlgEx contract](https://learn.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-printdlgexw); cover the dialog-result-to-job mapping.
- crates/ely-platform/src/print/linux.rs:47 — PreparePrint omits supported_output_file_formats, advertising support for PDF, PostScript and SVG even though this path always supplies PDF bytes. On the GTK portal, choosing PostScript in Print to File therefore writes a PDF under the requested .ps filename. The real GTK backend probe reproduced this: the .ps file began with %PDF-1.4 and was identical to the PDF input (`.work/r76-review-r1/gtk-backend-result.log`). Advertise only pdf in the portal options and verify that restriction in the portal test; the [portal contract](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Print.html) explicitly treats an omitted format list as support for all formats.
+13
View File
@@ -0,0 +1,13 @@
FAIL
- crates/ely-platform/src/print/win.rs:210; crates/ely-platform/src/print/linux/sheets.rs:199 — The 2 mm fit allowance still permits silent clipping, so round 1's paper-size finding is only partly fixed. A 600×842-point PDF containing a black mark at x=597–599 returns `Ok(true)` through Microsoft Print to PDF, which produces a 595.32-point-wide A4 page with that mark missing. Linux composition onto A4 also succeeds and removes the mark; an interior control square survives both paths (`.work/r76-review-r2/paper-comparison.log`). Separate paper-name matching tolerance from actual content fit: reject overflow beyond device-rounding error before submitting the job. Add a near-standard-size regression with content at the page edge.
- crates/ely-platform/src/print/linux/sheets.rs:332 — Printable annotations without `/AP` are silently omitted. A valid PDF 1.7 Square annotation with `/F 4`, `/Rect [50 100 150 180]`, red `/C` and `/IC`, and no appearance stream renders 8,000 colored pixels in the real PDF worker, with `damaged=false`. Its `print_copy` still has no `/AP`; composing that copy succeeds but produces a completely blank page (`.work/r76-review-r2/worker-probe.log`, `content-comparison.log`). Generate missing printable appearances before flattening, or use a renderer that synthesizes them. Test rendered output from the actual print-copy path, including an annotation without `/AP`.
- crates/ely-platform/src/print/linux/sheets.rs:321 — Annotation placement ignores the `NoRotate` flag. On a page with `/Rotate 90`, a printable Square annotation with `/F 20`, `/Rect [50 100 150 180]`, and a 100×80 appearance is rotated with the page instead of retaining its orientation about its anchor. The worker's print copy preserves the correct appearance, but the composed output moves it to a disjoint rectangle: 16,000 pixels differ, representing the missing original and incorrectly placed replacement (`.work/r76-review-r2/content-comparison.log`). Account for `NoRotate` when composing the annotation transform and add a rendered regression on a rotated page.
- crates/ely-platform/src/print/linux/sheets.rs:268 — Generated annotation resource names overwrite existing page XObjects. With an existing `/ElyAnnot0` drawing a blue square and one printable red annotation, `objects.set("ElyAnnot0", look)` redirects the original page's `/ElyAnnot0 Do` to the annotation appearance. Printing the real worker's copy replaces the blue square with another red rectangle; the ordinary annotation control renders unchanged (`.work/r76-review-r2/content-comparison.log`, `probe-source.log`). Allocate annotation names that are absent from the inherited resource dictionary, preserve existing bindings, and test both original content and the added annotation.
- crates/ely-platform/src/print/linux/choices.rs:70 — The page-setup parser expects `reverse_portrait` and `reverse_landscape`, but GTK serializes these orientations as `reverse-portrait` and `reverse-landscape`. Selecting either reverse orientation therefore fails before printing. Actual `Gtk.PageSetup.to_gvariant()` output and the exact-source parser reproduce both errors (`.work/r76-review-r2/gtk-settings.log`, `linux-exact-probe.log`); the existing test uses the wrong underscore spelling. Parse the page-setup values specified by the [portal contract](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Print.html) and test serialized GTK values.
- crates/ely-platform/src/print/linux/choices.rs:98 — Open-ended GTK ranges cannot be parsed. Entering `2-` in the dialog produces start=1, end=-1, serialized as `page-ranges="1--1"`; parsing the endpoint as `u32` fails with `invalid digit found in string`. GTK serialization and the exact-source parser reproduce this (`.work/r76-review-r2/gtk-settings.log`, `linux-exact-probe.log`). The existing tests supply `1-`, which is not GTK's serialization of that choice. Recognize GTK's -1 endpoint sentinel, expand it to the document's last page, and test the resulting printed pages.
+7
View File
@@ -0,0 +1,7 @@
FAIL
- crates/ely-platform/src/print/win.rs:287 — Windows prints annotations using screen visibility instead of their print flags. Passing the real worker's print copies through Microsoft Print to PDF returns `Ok(true)` for both a Square annotation with `/F 0` (not printable) and one with `/F 36` (Print + NoView), but the first prints 8,100 red pixels and the second prints none; the `/F 4` control prints correctly (`.work/r76-review-r3/windows-render.log`, `worker-probe.log`). These flags explicitly distinguish screen visibility from printing ([PDF reference, Table 8.11](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.4.pdf)). Render with print semantics, or prepare a copy containing only flattened printable appearances before using the screen renderer. Add rendered Windows regressions for both flags through `print_copy`.
- crates/ely-platform/src/print/linux.rs:69; crates/ely-platform/src/print/linux/sheets.rs:168 — Odd/even selection is applied locally and then applied again by the GTK/CUPS backend through the unchanged print token. For a four-page document with Even selected, the exact compositor submits original pages `[2, 4]`; the real GTK 3.24.52 CUPS backend still puts `cups-page-set=even` on its job (`.work/r76-review-r3/linux-probe.log`, `gtk-cups.log`). CUPS therefore selects only the second submitted sheet, losing original page 2. The [portal retains the chosen settings](https://github.com/flatpak/xdg-desktop-portal-gtk/blob/main/src/print.c), and [GTK forwards page-set to CUPS](https://github.com/GNOME/gtk/blob/gtk-3-24/modules/printbackends/cups/gtkprintbackendcups.c). Coordinate manual processing with backend processing so each setting is applied once, and cover the real CUPS backend as well as print-to-file; the current fake portal only records the supplied bytes.
- crates/ely-platform/src/print/linux/sheets.rs:40 — `Shown::of` uses CropBox without intersecting it with MediaBox, expanding the printed page and exposing clipped content. A PDF with MediaBox `[0 0 612 792]`, CropBox `[0 0 700 792]`, and a red square at x=650–680 opens with `damaged=false`; the worker's preview and print copy show a 612×792 page with only the interior blue control. Linux composition instead produces 700×792 and reveals the additional 900 red pixels (`.work/r76-review-r3/render-comparison.log`). PDF boundaries extending beyond MediaBox must be reduced to their intersection ([PDF reference, §8.6](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.3.pdf)). Use that effective rectangle consistently for sizing, placement, and the form's clipping box, with a rendered regression proving the outside content stays clipped.