Skip to content

Read a comment's rich text over the reader's defaults - #113

Merged
bobsingor merged 1 commit into
embedpdf/mainfrom
embedpdf/fix/comment-reads-over-reader-defaults
Nov 4, 2026
Merged

bobsingor merged 1 commit into
embedpdf/mainfrom
embedpdf/fix/comment-reads-over-reader-defaults

Conversation

@bobsingor

Copy link
Copy Markdown
Contributor

A markup annotation's /RC is its comment (ISO 32000-2 §12.5.6.2). A comment draws nothing on the page, so it states its style over the reader's defaults: Acrobat writes a note's /RC with no body style at all. The parser read every annotation's /RC over its /DA and /DS, the base style a free text draws its text in.

Among the comment kinds, only a redact has a /DA, and it styles the overlay text ("CONFIDENTIAL"). So with a Courier 10pt red overlay:

  • a redact comment that stated no font read as Courier 10pt red;
  • a comment written in the default style read back as Courier 10pt red. The writer (Write a markup annotation's comment as rich text #110) leaves out what matches the reader's defaults, and the read then filled in the overlay's.

Now CPDF_RichTextParser::DefaultsFromAnnotation takes /DA, /DS, /Q and /TextColor only for a free text and a widget, whose rich text is the text they draw. Any other annotation's rich text reads over CPDF_RichTextStyle{}, the same defaults the comment writer compares against. EPDFAnnot_GetRichTextJSON, EPDFAnnot_SetRichTextJSON and EPDFAnnot_SetRichTextXHTML all go through it. Free text and form fields are unchanged, and a redact's overlay still reads from its /DA through EPDFAnnot_GetDefaultAppearance.

Pin this after embedpdf/embed-pdf-viewer#978. Main's engine still reads a redact's overlay font through EPDFAnnot_GetRichTextJSON; #978 reads it from /DA directly (EPDFAnnot_GetDefaultAppearanceFontFace). With this change and without #978, a redact whose overlay uses a registered font would read back as a standard font.

Tests

  • RedactCommentReadsOverTheReadersDefaults, on a redact whose overlay is Courier 10pt red:

    • a comment written as JSON stores no body style and reads in the reader's defaults (no family, 12pt, black);
    • so does one imported from XHTML;
    • the overlay keeps its /DA.

    It fails without the change, on both the JSON and the XHTML write. It is recorded as a layer-mode writer (6 objects).

  • On macOS: every *EPDFAnnot*, *RichText* and *Redact* embedder test passes (305, 2 skipped), and the 19 rich text unit tests pass. In layer mode, the 47 rich text and comment tests pass with no unknown writers. Linux CI hasn't run yet.

A markup annotation's /RC is its comment, which draws nothing, so it
states its style over the reader's defaults, as Acrobat writes one with
no body style. The parser read every annotation's /RC over its /DA and
/DS. Among the comment kinds only a redact has a /DA, and it styles the
overlay text: a redact's comment that stated no font read in the
overlay's font, size and color, and one written with the default body
read back in the overlay's style. DefaultsFromAnnotation now takes /DA,
/DS, /Q and /TextColor only for a free text and a widget, whose rich text
is the text they draw. EPDFAnnot_GetRichTextJSON, SetRichTextJSON and
SetRichTextXHTML all go through it.
@bobsingor
bobsingor merged commit eeac787 into embedpdf/main Nov 4, 2026
1 check passed
@bobsingor
bobsingor deleted the embedpdf/fix/comment-reads-over-reader-defaults branch November 4, 2026 12:16
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.

1 participant