Skip to content

Colour: a page converts DeviceCMYK through its own output intent (#186) - #227

Merged
timzifer merged 4 commits into
mainfrom
claude/issue-186
Oct 14, 2026
Merged

timzifer merged 4 commits into
mainfrom
claude/issue-186

Conversation

@timzifer

Copy link
Copy Markdown
Owner

Fixes #186. Stacked on #226 (on #225); merge those first.

Change

  • A page with /OutputIntents of its own (PDF 2.0, 14.11.5) is drawn with a view of the document (Page.cmykDoc, used where the interpreter starts on a page in render.go) whose DeviceCMYK converts through the profile of the page's intent. The intent is read as the catalogue's (Document.intentCMYK, factored out of deviceCMYK): the first of kind GTS_PDFX, GTS_PDFA1 or ISO_PDFE1 with a CMYK profile.
  • Document is split by embedding: *docShared (reader, fonts, form, outline…, ICC profiles and their budget, transfer functions — shared by all views) and cmykView (DeviceCMYK and what is cached on it: colour spaces, shadings and patterns by reference, decoded images under an id of the view's own). No field was renamed; the two struct literals became newDocument.
  • Pages with the same profile share a view (docShared.views, pageViews); forms and patterns drawn on a page take its view. NaiveCMYK, CMYKProfile and IgnoreOutputIntent decide for pages as for the document. A page intent with the document's own profile draws with the document itself.
  • A page profile counts against maxCMYKProfiles; one cera cannot read is counted as icc-lut on that page, which then converts as the document does.
  • Document.Trim drops the images of the views too; a shared Cache drops them when a view is collected.

Tests

TestPageOutputIntent: three pages that share an image, a form, an Indexed space on DeviceCMYK and a shading (one object each), rendered in the order 0 1 2 1 0 so that a page drawn with what another made would show — pages with and without an intent, a page intent over the document's, equal to the document's, of another kind, ignored, naive, the caller's profile, unreadable (counted), with a shared cache; views counted and Trim checked. Fails without the change (3 cases).

go test ./... green. Corpus API run and accuracy against PDFium: identical to main.

The /BBox of an annotation's appearance stream is mapped onto its /Rect,
and the border of a field lies on the edge of that box. With the box off
the pixels, the exact clip and the border's edge, both antialiased,
lightened the edge pixels twice: a field Editor.SetFields wrote was drawn
with other edges than the same value shown from a FormState, which is not
clipped. The clip of an annotation's appearance is now rounded outward to
whole device pixels when it stays on the axes, as PDFium, MuPDF, Poppler
and Ghostscript clip rectangles. The accuracy report against PDFium is
unchanged.

overlayFile puts its fields off the pixels, which the test held them to.

Fixes #222.
The first fix of #222 rounded the clip of every annotation's appearance
outward to whole pixels. That made the render of an appearance stream
differ from the page it is flattened to, whose content clips exactly: the
corpus API run reported 41 files of pdf.js whose flattened first page
differed, by up to 4.9 % of its pixels.

The other way round: the appearance cera generates for a widget is
clipped to the widget's box exactly, as the stream Editor.SetFields
writes for it and the form Editor.Flatten draws are. The render with a
FormState, the saved file and the flattened page are drawn alike at any
scale; the border of a field off the pixels is lighter on its outer edge
in all three, as the appearance streams of documents are.

The corpus API report and the accuracy report against PDFium are the same
as on main.
ImportOptions.Structure brings the elements of the source's structure
tree whose content is on imported pages, with the elements above them;
an element left without content is dropped. Where the result has a tree,
the elements follow its own in a Part under its Document element (or its
root): the source's Document becomes the Part, or one is made around its
elements, with the source's /Lang where it differs. A result without a
tree takes the first one brought as its own.

The keys of the parent tree are numbered anew after the result's: pages
(/StructParents), their annotations (/StructParent) and the form XObjects
they draw. A page imported twice is tagged once, its first copy; a form
only pages that did not come draw as tagged content loses its keys. Marked
content and object references are mapped to the copies. Role maps are
merged, a type the result maps otherwise written as what the source means
by it; a class the result defines otherwise is renamed Cls_2, an
identifier the result has id_2; namespaces are joined. /MarkInfo says
/Marked.

The corpus API run gets a step: the pages looked at, imported with their
structure into the document itself, keep their marked content in the
tree. Over the pdf.js corpus it finds no difference.

Fixes #183.
PDF 2.0 lets a page carry /OutputIntents of its own (14.11.5), which
take precedence over the document's on it. Such a page is now drawn with
a view of the document (Page.cmykDoc) whose DeviceCMYK converts through
the profile of the page's intent, read as the catalogue's is: the first
intent of kind GTS_PDFX, GTS_PDFA1 or ISO_PDFE1 with a CMYK profile.

Document is split into what all views share (docShared: the reader,
fonts, the form, the profiles and their budget, transfer functions) and
what stands on DeviceCMYK (cmykView: colour spaces, shadings and
patterns by reference, decoded images under an id of their own). Pages
with one profile share a view; forms and patterns drawn on a page take
its view. NaiveCMYK, CMYKProfile and IgnoreOutputIntent decide for the
pages as for the document. A page profile counts against
maxCMYKProfiles, and one cera cannot read is counted as icc-lut, the page
then converting as the document does.

The corpus API report and the accuracy report against PDFium are the
same as before.

Fixes #186.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Colour: output intents of single pages (PDF 2.0)

1 participant