[repo] Workspace: CLAUDE.md, DEPENDENCIES.md, deps check, pinned pdfium fetch
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
# Pictor Domi — core (public)
|
||||
|
||||
Pictor (Latin: painter) is the Domi snipping tool, PDF workbench and image toolbox.
|
||||
This repository is the **public, MPL-2.0 core** (`https://gitea.marek-novak.cz/mnovak/Pictor-public`; the brief
|
||||
calls it `pictor-core`): pure Rust, no network, no UI. The Windows app lives in the private `Pictor` repo
|
||||
(`https://gitea.marek-novak.cz/mnovak/Pictor`, the brief's `pictor`) and depends on this one **by git tag**,
|
||||
never by a local path. The brief and roadmap are in the app repo, `docs/roadmap.md`; the day pages are there too
|
||||
(`docs/01_v1.md`).
|
||||
|
||||
## Layout
|
||||
```
|
||||
crates/raster decode (with pixel and size caps), encode, convert, crop, rotate, resize, batch presets,
|
||||
compress to a target size; HEIC/HEIF through the Windows Imaging Component (OS codec, Windows only)
|
||||
crates/pdf pdfium (render, text, search, outline, forms, page ops, merge/split, image <-> pdf, flatten,
|
||||
unlock) + lopdf (annotations, stamps, redaction rebuild, encryption, metadata); docs/FORMATS.md
|
||||
crates/meta read and strip EXIF / GPS / XMP / IPTC from images, document info and XMP from PDFs
|
||||
crates/qr QR payloads (text, URL, Wi-Fi, contact), PNG and SVG, centre logo (level forced to H)
|
||||
crates/save atomic save: temp file + flush + rename, the .bak, the <name>-edited.pdf naming
|
||||
crates/worker pictor-worker.exe: the only process that parses outside files (JSON lines on stdin/stdout,
|
||||
docs/FORMATS.md); the app spawns it in a Job Object with a memory cap and kills it on a time cap
|
||||
scripts/ fetch-pdfium.ps1 (pinned release + sha256 -> third_party/pdfium/), deps.mjs (DEPENDENCIES.md table)
|
||||
fixtures-fetch/ fetch.ps1: sha256-pinned hostile corpora -> fixtures/fetched/ (never in git)
|
||||
docs/ FORMATS.md (formats, the worker protocol), DEPENDENCIES.md (every crate and its licence)
|
||||
```
|
||||
Direction: `worker → pdf, raster, meta, qr, save`; `pdf → meta, raster`. The library crates never spawn processes,
|
||||
open sockets or touch the registry.
|
||||
|
||||
## Commands
|
||||
```
|
||||
powershell -File scripts/fetch-pdfium.ps1 # pdfium.dll -> third_party/pdfium/bin (tests need it)
|
||||
powershell -File fixtures-fetch/fetch.ps1 # optional extra hostile corpora; the generated ones need nothing
|
||||
cargo test --workspace # all mandatory tests (PDFIUM_DYNAMIC_LIB_PATH overrides the dll folder)
|
||||
node scripts/deps.mjs # regenerate the crate table in docs/DEPENDENCIES.md; exits 1 on a
|
||||
# licence outside the allowed set
|
||||
```
|
||||
On the dev machine `CARGO_HOME=F:\C-Drive-Migration\future-caches\cargo` (C: is off limits) — already set.
|
||||
|
||||
## Rules
|
||||
- Commits: `[<crate>] <Feature>: <description>`, e.g. `[pdf] Redaction: drop the struct tree`.
|
||||
- **No AI attribution in commits or PRs, ever**: no `Co-Authored-By`, no session links, no "Generated with".
|
||||
- **No binaries in git**: pdfium and corpora are fetched by sha256-pinned scripts.
|
||||
- **Licence rule**: a new crate is recorded in `docs/DEPENDENCIES.md` (with its licence) before it is used.
|
||||
Allowed: MIT, Apache-2.0, BSD, Zlib, MPL-2.0 (and their no-deal equivalents listed there), or an OS codec.
|
||||
Anything else: stop and report. `node scripts/deps.mjs` must exit 0.
|
||||
- **Hostile input**: every outside file is parsed only inside `pictor-worker`, with caps (pixels, bytes, time,
|
||||
memory). Library functions take explicit `Limits`; no unbounded allocation from a size read out of a file.
|
||||
- Tests first where the risk is (redaction, hostile PDFs and images, metadata, save safety, QR round trip).
|
||||
- Branch → PR on Gitea (token in `$GITEA_TOKEN`, never echoed; pushed through git's environment config) →
|
||||
self-review in the PR body → merge `--no-ff` → push → `git rev-parse HEAD origin/main` twice the same →
|
||||
tag `vX.Y.Z` (the app pins tags).
|
||||
|
||||
## Known traps
|
||||
- pdfium is not thread-safe: pdfium-render's `thread_safe` feature serialises calls; one `Pdfium` per process.
|
||||
- pdfium's own save copies unreferenced objects of the original file: anything that must *disappear* (redaction)
|
||||
is written by lopdf after `prune_objects`, never by pdfium.
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["crates/raster", "crates/pdf", "crates/meta", "crates/qr", "crates/save", "crates/worker"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = "MPL-2.0"
|
||||
repository = "https://gitea.marek-novak.cz/mnovak/Pictor-public"
|
||||
rust-version = "1.88"
|
||||
|
||||
# Every dependency here is listed with its licence in docs/DEPENDENCIES.md before it is used.
|
||||
[workspace.dependencies]
|
||||
pictor-raster = { path = "crates/raster" }
|
||||
pictor-pdf = { path = "crates/pdf" }
|
||||
pictor-meta = { path = "crates/meta" }
|
||||
pictor-qr = { path = "crates/qr" }
|
||||
pictor-save = { path = "crates/save" }
|
||||
|
||||
thiserror = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
base64 = "0.22"
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "bmp", "gif", "tiff", "ico"] }
|
||||
kamadak-exif = "0.6"
|
||||
img-parts = "0.4"
|
||||
qrcode = { version = "0.14", default-features = false, features = ["svg"] }
|
||||
lopdf = { version = "0.47", default-features = false }
|
||||
pdfium-render = { version = "0.9.5", default-features = false, features = ["thread_safe", "image_latest", "pdfium_latest"] }
|
||||
tempfile = "3"
|
||||
sha2 = "0.11"
|
||||
windows = "0.62"
|
||||
|
||||
# dev-only
|
||||
rqrr = "0.11"
|
||||
proptest = "1"
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 2
|
||||
@@ -0,0 +1,86 @@
|
||||
# Dependencies and their licences
|
||||
|
||||
Every crate and binary Pictor's core uses, with its licence, recorded **before** it is used.
|
||||
The brief's rule: only components that need no licence deal — MIT, Apache-2.0, BSD, Zlib, MPL-2.0, or a codec the
|
||||
OS already provides. Nothing paid, copyleft-to-bundle, patent-encumbered or non-commercial.
|
||||
|
||||
## The allowed set, as checked by `scripts/deps.mjs`
|
||||
|
||||
| Licence (SPDX) | Why it is allowed |
|
||||
| :-- | :-- |
|
||||
| MIT, MIT-0 | named in the brief |
|
||||
| Apache-2.0, Apache-2.0 WITH LLVM-exception | named in the brief |
|
||||
| BSD-2-Clause, BSD-3-Clause, 0BSD | named in the brief ("BSD") |
|
||||
| Zlib | named in the brief |
|
||||
| MPL-2.0 | named in the brief (file-level copyleft: our own changes to such files stay MPL, which suits this repo) |
|
||||
| ISC | **interpretation, Mark to confirm**: the BSD-style licence of the ISC; OSI calls it functionally the simplified BSD licence |
|
||||
| Unicode-3.0, Unicode-DFS-2016 | **interpretation, Mark to confirm**: the MIT-style licence of Unicode's data tables; every Rust program that parses identifiers or text pulls it in (`unicode-ident`) |
|
||||
| BSL-1.0, CC0-1.0 | **interpretation, Mark to confirm**: Boost (MIT-like, no attribution in binaries) and public domain |
|
||||
|
||||
An SPDX expression with `OR` passes when one branch passes; `AND` needs every part to pass. Anything else makes the
|
||||
script exit 1, and the feature that needs it waits (the brief: "it never gets a fallback").
|
||||
|
||||
## Direct dependencies
|
||||
|
||||
| Crate | Version | Licence | Used by | For |
|
||||
| :-- | :-- | :-- | :-- | :-- |
|
||||
| thiserror | 2 | MIT OR Apache-2.0 | all | error types |
|
||||
| serde, serde_json | 1 | MIT OR Apache-2.0 | worker, pdf, meta, qr | the worker protocol, reports |
|
||||
| base64 | 0.22 | MIT OR Apache-2.0 | worker | binary payloads in the protocol |
|
||||
| image | 0.25 | MIT OR Apache-2.0 | raster, pdf, qr | PNG, JPG, WebP, BMP, GIF, TIFF, ICO decode/encode (no default features: only these codecs) |
|
||||
| kamadak-exif | 0.6 | BSD-2-Clause | meta | reading EXIF (and writing EXIF fixtures in tests) |
|
||||
| img-parts | 0.4 | MIT OR Apache-2.0 | meta | JPEG segments, PNG and WebP chunks, without re-encoding |
|
||||
| qrcode | 0.14 | MIT OR Apache-2.0 | qr | QR matrix and SVG |
|
||||
| lopdf | 0.47 | MIT | pdf, meta | PDF structure: annotations, stamps, the redaction rebuild, encryption, metadata |
|
||||
| pdfium-render | 0.9.5 | MIT OR Apache-2.0 | pdf | bindings to pdfium (render, text, forms, pages) |
|
||||
| tempfile | 3 | MIT OR Apache-2.0 | save (and tests) | temporary files next to the target |
|
||||
| sha2 | 0.11 | MIT OR Apache-2.0 | worker, tests | hashes for fixtures and the fetch scripts' self-check |
|
||||
| windows | 0.62 | MIT OR Apache-2.0 | raster (Windows only), worker | WIC (HEIC), Job Objects |
|
||||
| rqrr | 0.11 (dev) | (MIT OR Apache-2.0) AND ISC | qr tests | decoding generated codes back (ISC: see above) |
|
||||
| proptest | 1 (dev) | MIT OR Apache-2.0 | tests | property tests |
|
||||
|
||||
## Binaries (fetched, never in git)
|
||||
|
||||
| Binary | Licence | Fetched by |
|
||||
| :-- | :-- | :-- |
|
||||
| pdfium (bblanchon/pdfium-binaries, Windows x64) | see "pdfium" below | `scripts/fetch-pdfium.ps1`, sha256-pinned |
|
||||
|
||||
### pdfium
|
||||
|
||||
Release `chromium/8125` (PDFium 158.0.8125.0), `pdfium-win-x64.tgz`, sha256
|
||||
`9a964261760cff52570aabf038ab346d3a5034dd8b30d0d5fe8861235d356b8b`, built without V8 and XFA (`args.gn`). It matches
|
||||
pdfium-render 0.9.5's `pdfium_latest` (= `pdfium_8125`). The archive's `LICENSE` and `licenses/` folder ship beside
|
||||
the dll (the app's installer copies them). Read from those files on 2026-11-16:
|
||||
|
||||
| Component inside pdfium.dll | Licence | In the allowed set? |
|
||||
| :-- | :-- | :-- |
|
||||
| the binary build (bblanchon/pdfium-binaries) | MIT | yes |
|
||||
| PDFium | BSD-3-Clause (+ Apache-2.0 parts) | yes |
|
||||
| abseil, highway | Apache-2.0 | yes |
|
||||
| llvm-libc, dragonbox | Apache-2.0 WITH LLVM-exception (dragonbox also BSL-1.0) | yes |
|
||||
| fast_float, simdutf | MIT | yes |
|
||||
| lcms2, agg 2.3 | MIT-style permission notice | yes (MIT family) |
|
||||
| OpenJPEG | BSD-2-Clause | yes |
|
||||
| zlib | Zlib | yes |
|
||||
| HarfBuzz | "Old MIT" | yes (MIT family) |
|
||||
| ICU | Unicode-3.0 | **interpretation** (see above) |
|
||||
| libpng | PNG Reference Library License v2 (Libpng-2.0, zlib-style) | **interpretation**: zlib-style permissive |
|
||||
| libjpeg-turbo | IJG + BSD-3-Clause | **interpretation**: IJG is BSD-style (credit in documentation) |
|
||||
| FreeType | The FreeType Project License (FTL; dual with GPL-2.0, we take FTL) | **interpretation**: BSD-style with a credit clause — the app's About box says "Portions of this software are copyright © The FreeType Project (www.freetype.org). All rights reserved." |
|
||||
|
||||
None of these needs a licence deal, is paid, copyleft-to-bundle, patent-encumbered or non-commercial. The four marked
|
||||
"interpretation" are not named in the brief's list; they are BSD/zlib-style, and **Mark should confirm** them (PDF
|
||||
support depends on pdfium, which the brief chose).
|
||||
|
||||
## OS codecs (not bundled)
|
||||
|
||||
| Codec | Provided by | Used for |
|
||||
| :-- | :-- | :-- |
|
||||
| HEIF/HEIC through WIC | Windows (HEIF Image Extensions + an HEVC decoder from the Microsoft Store) | decoding iPhone photos; never bundled |
|
||||
|
||||
## Every crate in Cargo.lock
|
||||
|
||||
Generated by `node scripts/deps.mjs` from `cargo metadata`; do not edit by hand.
|
||||
|
||||
<!-- deps:begin -->
|
||||
<!-- deps:end -->
|
||||
@@ -0,0 +1,2 @@
|
||||
max_width = 120
|
||||
use_small_heuristics = "Max"
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
// Regenerates the "Every crate in Cargo.lock" table in docs/DEPENDENCIES.md from `cargo metadata`
|
||||
// and exits 1 when a crate's licence is outside the allowed set (or missing).
|
||||
// Usage: node scripts/deps.mjs [--check] (--check: do not rewrite the file, only verify it is current)
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const docPath = join(root, 'docs', 'DEPENDENCIES.md');
|
||||
|
||||
export const ALLOWED = new Set([
|
||||
'MIT', 'MIT-0', 'Apache-2.0', 'Apache-2.0 WITH LLVM-exception', 'BSD-2-Clause', 'BSD-3-Clause', '0BSD',
|
||||
'Zlib', 'MPL-2.0', 'ISC', 'Unicode-3.0', 'Unicode-DFS-2016', 'BSL-1.0', 'CC0-1.0',
|
||||
]);
|
||||
|
||||
// Minimal SPDX evaluator: OR / AND / WITH and parentheses. Old crates write "MIT/Apache-2.0" for OR.
|
||||
export function allowed(expr) {
|
||||
if (!expr) return false;
|
||||
const tokens = expr.replace(/\//g, ' OR ').replace(/\(/g, ' ( ').replace(/\)/g, ' ) ').split(/\s+/).filter(Boolean);
|
||||
let i = 0;
|
||||
function primary() {
|
||||
if (tokens[i] === '(') { i++; const v = orExpr(); i++; return v; }
|
||||
let id = tokens[i++];
|
||||
if (tokens[i] === 'WITH') { id += ` WITH ${tokens[i + 1]}`; i += 2; }
|
||||
return ALLOWED.has(id);
|
||||
}
|
||||
function andExpr() { let v = primary(); while (tokens[i] === 'AND') { i++; v = primary() && v; } return v; }
|
||||
function orExpr() { let v = andExpr(); while (tokens[i] === 'OR') { i++; v = andExpr() || v; } return v; }
|
||||
return orExpr();
|
||||
}
|
||||
|
||||
function main() {
|
||||
const meta = JSON.parse(execFileSync('cargo', ['metadata', '--format-version', '1', '--locked', '--filter-platform', 'x86_64-pc-windows-msvc'], {
|
||||
cwd: root, maxBuffer: 1 << 28, encoding: 'utf8',
|
||||
}));
|
||||
// Only crates reachable on Windows x64 (the one target of V1), not every lockfile entry of every platform:
|
||||
// with --filter-platform, resolve.nodes lists what the workspace really depends on there.
|
||||
const used = new Set(meta.resolve.nodes.map((n) => n.id));
|
||||
const workspace = new Set(meta.workspace_members);
|
||||
const rows = meta.packages
|
||||
.filter((p) => used.has(p.id) && !workspace.has(p.id))
|
||||
.map((p) => ({ name: p.name, version: p.version, licence: p.license ?? (p.license_file ? `file: ${p.license_file}` : '') }))
|
||||
.sort((a, b) => a.name.localeCompare(b.name) || a.version.localeCompare(b.version));
|
||||
const bad = rows.filter((r) => !allowed(r.licence));
|
||||
const table = [
|
||||
`${rows.length} crates; ${bad.length} outside the allowed set.`,
|
||||
'',
|
||||
'| Crate | Version | Licence | Allowed |',
|
||||
'| :-- | :-- | :-- | :-- |',
|
||||
...rows.map((r) => `| ${r.name} | ${r.version} | ${r.licence || '(none)'} | ${allowed(r.licence) ? 'yes' : '**NO**'} |`),
|
||||
].join('\n');
|
||||
const doc = readFileSync(docPath, 'utf8');
|
||||
const next = doc.replace(/<!-- deps:begin -->[\s\S]*<!-- deps:end -->/, `<!-- deps:begin -->\n${table}\n<!-- deps:end -->`);
|
||||
if (process.argv.includes('--check')) {
|
||||
if (next !== doc) { console.error('docs/DEPENDENCIES.md is out of date: run node scripts/deps.mjs'); process.exit(1); }
|
||||
} else if (next !== doc) {
|
||||
writeFileSync(docPath, next);
|
||||
}
|
||||
for (const r of bad) console.error(`not allowed: ${r.name} ${r.version} (${r.licence || 'no licence field'})`);
|
||||
console.log(`${rows.length} crates, ${bad.length} not allowed`);
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) main();
|
||||
@@ -0,0 +1,42 @@
|
||||
# Fetches the pinned pdfium build (bblanchon/pdfium-binaries, Windows x64) into third_party/pdfium/.
|
||||
# The archive's sha256 is pinned: a different file is refused and nothing is extracted.
|
||||
# pdfium-render's `pdfium_latest` feature (0.9.5) targets chromium/8125: keep the two in step.
|
||||
# Usage: powershell -File scripts/fetch-pdfium.ps1 [-Dest <folder>]
|
||||
param([string]$Dest = (Join-Path $PSScriptRoot '..\third_party\pdfium'))
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$Release = 'chromium/8125'
|
||||
$Url = 'https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F8125/pdfium-win-x64.tgz'
|
||||
$Sha256 = '9a964261760cff52570aabf038ab346d3a5034dd8b30d0d5fe8861235d356b8b'
|
||||
|
||||
$Dest = [IO.Path]::GetFullPath($Dest)
|
||||
$marker = Join-Path $Dest 'RELEASE'
|
||||
if ((Test-Path (Join-Path $Dest 'bin\pdfium.dll')) -and (Test-Path $marker) -and ((Get-Content $marker -Raw).Trim() -eq "$Release $Sha256")) {
|
||||
Write-Host "pdfium $Release already in $Dest"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$tmp = Join-Path ([IO.Path]::GetTempPath()) ("pdfium-" + [Guid]::NewGuid())
|
||||
New-Item -ItemType Directory -Force $tmp | Out-Null
|
||||
try {
|
||||
$archive = Join-Path $tmp 'pdfium-win-x64.tgz'
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $archive
|
||||
$got = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
|
||||
if ($got -ne $Sha256) { throw "pdfium archive sha256 mismatch: expected $Sha256, got $got. Nothing was extracted." }
|
||||
$x = Join-Path $tmp 'x'
|
||||
New-Item -ItemType Directory -Force $x | Out-Null
|
||||
# Windows' own bsdtar: Git's GNU tar on PATH reads "F:\..." as a remote host.
|
||||
& (Join-Path $env:SystemRoot 'System32\tar.exe') -xzf $archive -C $x
|
||||
if ($LASTEXITCODE -ne 0) { throw "tar failed ($LASTEXITCODE)" }
|
||||
if (Test-Path $Dest) { Remove-Item -Recurse -Force $Dest }
|
||||
New-Item -ItemType Directory -Force (Join-Path $Dest 'bin') | Out-Null
|
||||
Copy-Item (Join-Path $x 'bin\pdfium.dll') (Join-Path $Dest 'bin\pdfium.dll')
|
||||
Copy-Item (Join-Path $x 'LICENSE') (Join-Path $Dest 'LICENSE')
|
||||
Copy-Item -Recurse (Join-Path $x 'licenses') (Join-Path $Dest 'licenses')
|
||||
Copy-Item (Join-Path $x 'VERSION') (Join-Path $Dest 'VERSION')
|
||||
Set-Content -Encoding ascii $marker "$Release $Sha256"
|
||||
Write-Host "pdfium $Release -> $Dest"
|
||||
} finally {
|
||||
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
|
||||
}
|
||||
Reference in New Issue
Block a user