Capture four marked PdfCraft sheets through both Windows drawing routes

This commit is contained in:
Codex committed 2026-12-03 00:36:17 +01:00
1 parent c8c6dc5357
commit 2b8a626822
2 files changed
+109 -4

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
name: Verify PdfCraft drawn Windows output
on:
push:
branches: [verify/pdfcraft-drawn-output-4859]
permissions:
contents: read
jobs:
capture:
runs-on: windows-2025
timeout-minutes: 120
env:
CARGO_PROFILE_TEST_DEBUG: '0'
CARGO_PROFILE_DEV_DEBUG: '0'
CARGO_INCREMENTAL: '0'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- uses: storytold/craft-common-actions/actions/checkout-craft-fonts@58848078cd09e3ca182891a8b76ee979f1eb6e1c
with:
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
- name: Confirm the virtual printer and use the largest available build volume
run: |
Get-PrinterDriver -Name "Microsoft Print To PDF" -ErrorAction Stop | Format-Table Name,Manufacturer
if (-not (Get-Printer -Name 'Microsoft Print to PDF' -ErrorAction SilentlyContinue)) {
Add-Printer -Name 'Microsoft Print to PDF' -DriverName 'Microsoft Print To PDF' -PortName 'PORTPROMPT:' -ErrorAction Stop
}
$disk = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Free -gt 0 -and $_.Root -match '^[A-Za-z]:\\$' } | Sort-Object -Descending Free | Select-Object -First 1
"CARGO_TARGET_DIR=$(Join-Path $disk.Root "drawn-$env:GITHUB_RUN_ID")" >> $env:GITHUB_ENV
$capture = New-Item -ItemType Directory -Path evidence
"PDFCRAFT_DRAWN_PRINT_OUT=$($capture.FullName)" >> $env:GITHUB_ENV
- name: Verify the contributor's current dependency revisions before drawing
shell: python
run: |
import json, pathlib, subprocess
graph = json.loads(subprocess.check_output(["cargo","metadata","--locked","--format-version","1","--filter-platform","x86_64-pc-windows-msvc"]))
for name in ("craft-print", "craft-pdf", "craft-winprint-gdi"):
sources = sorted({p["source"] for p in graph["packages"] if p["name"]==name})
print(name, sources)
assert len(sources) == 1
if name == "craft-winprint-gdi":
assert sources[0].endswith("#41ab251670d32aaaa859228baf4d8c83dbb0b933")
else:
assert sources[0].endswith("#0eca480ddf7e9f794eed4cf06cc09aca67beae8d")
- name: Print four marked sheets using both real app drawing routes
shell: bash
run: |
set -euo pipefail
cargo test --locked -p pdfcraft-engine --lib the_vector_route_draws_opaque_sheets_as_vectors_and_translucent_ones_as_pixels -- --nocapture | tee "$RUNNER_TEMP/drawn.log"
grep -E 'test .*the_vector_route_draws_opaque_sheets_as_vectors_and_translucent_ones_as_pixels .*ok' "$RUNNER_TEMP/drawn.log"
test -s evidence/vector.pdf && test -s evidence/image.pdf
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
if: always()
with:
name: drawn-windows-pdfs
path: evidence/*.pdf
if-no-files-found: warn
inspect:
runs-on: ubuntu-24.04
needs: capture
timeout-minutes: 10
steps:
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
with:
name: drawn-windows-pdfs
path: evidence
- uses: storytold/craft-common-actions/actions/install-apt-packages@58848078cd09e3ca182891a8b76ee979f1eb6e1c
with:
packages: poppler-utils qpdf python3-pil
- name: Check stock, order, late sheets and marker positions independently
run: |
set -euo pipefail
cd evidence
for variant in source vector image; do
qpdf --check "$variant.pdf"
test "$(qpdf --show-npages "$variant.pdf")" = 4
pdftoppm -r 72 -png "$variant.pdf" "$variant"
done
/usr/bin/python3 - <<'PY'
from PIL import Image, ImageChops
from statistics import median
for page in range(1,5):
source = Image.open(f"source-{page}.png").convert("RGB")
ref = source.getpixel((170,140))
assert max(ref)-min(ref) >= 55, (page,ref)
for variant in ("vector","image"):
got = Image.open(f"{variant}-{page}.png").convert("RGB")
assert got.size == source.size == (612,792), (variant,page,got.size)
sample = got.crop((145,125,195,155))
centre = tuple(int(median(ch.getdata())) for ch in sample.split())
assert max(abs(a-b) for a,b in zip(ref,centre)) <= 25, (variant,page,ref,centre)
def bounds(im):
return ImageChops.difference(im,Image.new("RGB",im.size,"white")).convert("L").point(lambda x: 255 if x>38 else 0).crop((0,0,500,260)).getbbox()
a,b=bounds(source),bounds(got)
assert a and b and max(abs(x-y) for x,y in zip(a,b))<=8,(variant,page,a,b)
print(variant,page,got.size,centre,b)
PY
+12 -4
View File
@@ -50,13 +50,21 @@ fn the_vector_route_draws_opaque_sheets_as_vectors_and_translucent_ones_as_pixel
let opaque = "1 0 0 rg 72 600 200 100 re f 0 0 1 RG 3 w 72 500 m 540 500 l S BT /F1 36 Tf 0 g 72 400 Td (Vector) Tj ET";
let translucent = "/Half gs 0 0.6 0 rg 72 600 200 100 re f";
let job = Job { printer: Some("Microsoft Print to PDF".into()), title: "drawn route".into(), ..Default::default() };
let sheets = pdf(&[opaque, translucent], resources);
let blue = "0 0 1 rg 72 600 200 100 re f";
let magenta = "1 0 1 rg 72 600 200 100 re f";
let sheets = pdf(&[opaque, translucent, blue, magenta], resources);
let evidence = std::path::Path::new(&folder);
std::fs::write(evidence.join("source.pdf"), &sheets).unwrap();
let receipt = submit(&sheets, &job, Route::Vector, out.to_str(), &mut |_, _| {}).unwrap();
assert!(receipt.contains("pixels"), "the receipt says a sheet went as pixels: {receipt}");
assert_eq!(pages_with_images(written(&out)), [false, true]);
// The image route draws both sheets as pictures.
let captured = written(&out);
std::fs::write(evidence.join("vector.pdf"), &captured).unwrap();
assert_eq!(pages_with_images(captured), [false, true, false, false]);
// The image route draws all four sheets as pictures.
submit(&sheets, &job, Route::Image, out.to_str(), &mut |_, _| {}).unwrap();
assert_eq!(pages_with_images(written(&out)), [true, true]);
let captured = written(&out);
std::fs::write(evidence.join("image.pdf"), &captured).unwrap();
assert_eq!(pages_with_images(captured), [true; 4]);
}
/// The file the in-box PDF printer writes at `out` once the spooled job has printed, taken away so