mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-02 20:20:35 -05:00
Compare both Windows GDI providers on the same numbered source
This commit is contained in:
1 parent
8071b6ee39
commit
b68cb410bf
3 files changed
+166
No files matched your search
@@ -0,0 +1,44 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
. "$PSScriptRoot/windows-local-port.ps1"
|
||||
Start-Service Spooler
|
||||
$driver = 'Microsoft Print To PDF'
|
||||
if (!(Get-PrinterDriver -Name $driver -ErrorAction SilentlyContinue)) {
|
||||
$feature = Get-WindowsOptionalFeature -Online -FeatureName Printing-PrintToPDFServices-Features -ErrorAction SilentlyContinue
|
||||
if ($feature -and $feature.State -ne 'Enabled') {
|
||||
Enable-WindowsOptionalFeature -Online -FeatureName $feature.FeatureName -NoRestart | Out-Host
|
||||
}
|
||||
Add-PrinterDriver -Name $driver
|
||||
}
|
||||
$output = New-Item -ItemType Directory -Path captured
|
||||
$port = Join-Path $output.FullName 'incoming.pdf'
|
||||
$queue = "Craft capture $env:GITHUB_RUN_ID-$env:GITHUB_RUN_ATTEMPT"
|
||||
Add-PrinterPort -Name $port
|
||||
try {
|
||||
Add-Printer -Name $queue -DriverName $driver -PortName $port
|
||||
try {
|
||||
Set-PrintConfiguration -PrinterName $queue -PaperSize Letter
|
||||
foreach ($case in 'four-sheets') {
|
||||
if (Test-Path -LiteralPath $port) { throw 'Output from previous job is still present' }
|
||||
$bin = Join-Path $env:CARGO_TARGET_DIR 'debug/examples/compare_gdi.exe'
|
||||
& $bin $queue (Resolve-Path fixture/numbered.pdf).Path
|
||||
if ($LASTEXITCODE) { throw "Submission failed: $case" }
|
||||
$deadline = [DateTime]::UtcNow.AddSeconds(50)
|
||||
$complete = $false
|
||||
while ([DateTime]::UtcNow -lt $deadline) {
|
||||
try {
|
||||
$bytes = [IO.File]::ReadAllBytes($port)
|
||||
if ($bytes.Length -ge 5) {
|
||||
$offset = [Math]::Max(0, $bytes.Length - 40)
|
||||
$complete = [Text.Encoding]::ASCII.GetString($bytes, $offset, $bytes.Length - $offset).TrimEnd().EndsWith('%%EOF')
|
||||
}
|
||||
if ($complete) {
|
||||
Move-Item -LiteralPath $port -Destination (Join-Path $output.FullName "$case.pdf")
|
||||
break
|
||||
}
|
||||
} catch [IO.IOException] { $complete = $false }
|
||||
Start-Sleep -Milliseconds 250
|
||||
}
|
||||
if (!$complete) { throw "No complete PDF arrived: $case" }
|
||||
}
|
||||
} finally { Remove-Printer -Name $queue }
|
||||
} finally { Remove-CaptureLocalPort -Name $port }
|
||||
@@ -0,0 +1,21 @@
|
||||
use std::{env, error::Error, path::PathBuf};
|
||||
use winprint::printer::{GdiPdfPrinter, PrinterDevice};
|
||||
use winprint::ticket::PrintTicket;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let queue = env::args().nth(1).ok_or("missing capture queue")?;
|
||||
let file = PathBuf::from(env::args_os().nth(2).ok_or("missing file")?).canonicalize()?;
|
||||
let device = PrinterDevice::all()?.into_iter().find(|p| p.name() == queue).ok_or("capture queue missing")?;
|
||||
let ticket = PrintTicket::default();
|
||||
let mut pages = Vec::new();
|
||||
#[cfg(provider_private_settings)]
|
||||
{
|
||||
let bytes = ticket.to_dev_mode(&device)?;
|
||||
GdiPdfPrinter::new(device).print_with_dev_mode_and_progress(&file, &bytes, |done, total| pages.push((done, total)))?;
|
||||
}
|
||||
#[cfg(not(provider_private_settings))]
|
||||
GdiPdfPrinter::new(device).print_with_progress(&file, ticket, |done, total| pages.push((done, total)))?;
|
||||
println!("GDI progress: {pages:?}");
|
||||
assert_eq!(pages.last(), Some(&(4, 4)));
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
name: Compare Windows PDF to GDI providers
|
||||
on:
|
||||
push:
|
||||
branches: [verify/print-gdi-provider-comparison-4859]
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
jobs:
|
||||
capture:
|
||||
name: GDI capture / ${{ matrix.route }}
|
||||
runs-on: windows-2025
|
||||
timeout-minutes: 45
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- route: gdi-6
|
||||
rev: 0244f03628f5ae21a304e6a9f59ab137e501e059
|
||||
- route: gdi-29
|
||||
rev: 26fb9a5ac1d3405e67a37c2299f9ab99896ed5b5
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
repository: storytold/winprint.rs
|
||||
ref: ${{ matrix.rev }}
|
||||
path: provider
|
||||
persist-credentials: false
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
repository: storytold/craft-libs
|
||||
ref: e65f21a4fcb0bbe2814847d6ccd72a982b98c4d5
|
||||
path: fallback
|
||||
sparse-checkout: crates/print/src
|
||||
persist-credentials: false
|
||||
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
|
||||
with:
|
||||
name: windows-private-settings-operator-kit
|
||||
run-id: 46998721167
|
||||
github-token: ${{ github.token }}
|
||||
path: fixture
|
||||
- name: Check contributor fallback boundaries and build the exact provider
|
||||
shell: pwsh
|
||||
env:
|
||||
ROUTE: ${{ matrix.route }}
|
||||
CARGO_PROFILE_DEV_DEBUG: '0'
|
||||
CARGO_INCREMENTAL: '0'
|
||||
run: |
|
||||
$disk = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Free -gt 0 -and $_.Root -match '^[A-Za-z]:\\$' } | Sort-Object -Descending Free | Select-Object -First 1
|
||||
$env:CARGO_TARGET_DIR = Join-Path $disk.Root "gdi-$env:GITHUB_RUN_ID"
|
||||
"CARGO_TARGET_DIR=$env:CARGO_TARGET_DIR" >> $env:GITHUB_ENV
|
||||
if ($env:ROUTE -eq 'gdi-6') {
|
||||
rustc --test --edition=2024 fallback/crates/print/src/fallback.rs -o fallback-tests.exe
|
||||
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
||||
./fallback-tests.exe
|
||||
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
||||
}
|
||||
Copy-Item .github/print-probe/compare-gdi.rs provider/examples/compare_gdi.rs
|
||||
if ($env:ROUTE -eq 'gdi-29') { $env:RUSTFLAGS = '--cfg provider_private_settings' }
|
||||
Push-Location provider
|
||||
cargo generate-lockfile
|
||||
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
||||
cargo build --locked --no-default-features --example compare_gdi
|
||||
if ($LASTEXITCODE) { exit $LASTEXITCODE }
|
||||
Pop-Location
|
||||
- name: Print the four numbered sheets through a disposable file queue
|
||||
shell: pwsh
|
||||
run: ./.github/print-probe/compare-gdi.ps1
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
|
||||
with:
|
||||
name: ${{ matrix.route }}-output
|
||||
path: |
|
||||
captured/four-sheets.pdf
|
||||
provider/Cargo.lock
|
||||
if-no-files-found: error
|
||||
inspect:
|
||||
needs: capture
|
||||
if: ${{ !cancelled() }}
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
route: [gdi-6, gdi-29]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
|
||||
with:
|
||||
repository: storytold/craft-libs
|
||||
ref: 69c17f55cf638de8539a2785a59154c815af0854
|
||||
sparse-checkout: crates/print/examples/print_acceptance
|
||||
persist-credentials: false
|
||||
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
|
||||
with:
|
||||
name: ${{ matrix.route }}-output
|
||||
path: output
|
||||
- uses: storytold/craft-common-actions/actions/install-apt-packages@58848078cd09e3ca182891a8b76ee979f1eb6e1c
|
||||
with:
|
||||
packages: poppler-utils
|
||||
- name: Independently render the sheets and check their size, marks, colours and order
|
||||
run: python3 crates/print/examples/print_acceptance/verify.py output/captured/four-sheets.pdf 1 2 3 4
|
||||
Reference in new issue
Block a user