Repository navigation
fix(kernel,layout): report glyph 0 and unembedded fonts under a claim - #657
Merged
Merged
Conversation
An embedded font drew a missing character as glyph 0 and the save said nothing. PdfCanvas.NotdefGlyphs and PdfDocument.NotdefGlyphs now list each glyph 0 the canvas writes, one entry per character and font resource, capped at 1,000 with the rest counted in NotdefGlyphsDropped. The ToUnicode map no longer lists a code point against glyph 0; it carries one entry, <0000> <FFFD>, which ISO 14289-1 7.21.7 accepts. The content stream is unchanged.
…#593) The layout now reports through Document.Diagnostics what a PDF/A or PDF/UA file fails on without saying so. NotdefGlyph (102) lists each character an embedded font has no glyph for, per font, with its count. UnembeddedFont (601) lists each element that selects a Standard 14 font while a conformance claim is set, which is what a list, table, heading or running band without its own style does because SetDefaultFont reaches only Document.Add(string). Both cite the clause of the claim, save by default and are refused by StrictDiagnostics. Paragraphs, table cells and running bands now select the font and show text through one TextEmitter, so one report covers every built-in element. The bytes written do not change.
…ault-font # Conflicts: # src/VellumPdf.Layout/Elements/Heading.cs # src/VellumPdf.Layout/Elements/ListItem.cs # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
…ault-font # Conflicts: # CHANGELOG.md # tests/VellumPdf.Kernel.Tests/VellumPdf.Kernel.Tests.csproj
…ded-font reports (#592, #593) State where each list and report stops, name the validator-versus-clause difference for a font selected with no glyph shown, say why the single U+FFFD entry exists and when it is written, and name the cases the reports do not see (one-dimensional barcode text, control characters in Standard 14 text). Build the 601 message only for a new subject, make the tally copy self-consistent, resolve pdffonts through the same identity probe as the other poppler tools, and pin the grouping and counting rules, the measured-only and raw-id ToUnicode cases and the refused SaveAsync and PrepareForSigning cases with tests. Re-pin the byte-identity hashes that the font bounding box change moved.
…ounding box change moved
…ault-font # Conflicts: # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #592
Closes #593
A character that an embedded font has no glyph for is written as glyph 0, and a PDF/A or PDF/UA document that falls back to an unembedded Helvetica for a list, table or running band is written as it always was. Both files fail veraPDF, and the save said nothing about either. This PR makes the save say so. It changes no content stream.
What changed
Kernel (first commit).
PdfCanvas.NotdefGlyphs,PdfCanvas.NotdefGlyphsDropped,PdfDocument.NotdefGlyphs,PdfDocument.NotdefGlyphsDroppedand the newNotdefGlyphWarninglist every glyph 0 the canvas writes: one entry per character and font resource, in order of first occurrence, with a count. At most 1,000 entries per canvas and per document; the rest are counted in...Dropped. The type has an internal constructor and getters only, so it takes no input and nothing throws.TextEncodingWarningsis untouched and does not list glyph 0.ShowGlyphssees ids, not text, so its entries have no character. The library's own text drawing names the character and the font.Finishstores a snapshot of the canvas's entries on the page beside its content bytes. SettingPdfPage.ContentBytesdirectly clears them.PdfDocument.NotdefGlyphsis built on each read from the pages, andSave,SaveAsyncandPrepareForSigningleave it as it was.<0000> <FFFD>, when any character was mapped to glyph 0. Before, a font whose subset used glyph 0 wrote one<0000> <...>line per missing character. The entry exists because glyph 0 is itself what ISO 19005-2, 6.2.11.8, and ISO 14289-1, 7.21.8, refuse, and U+FFFD satisfies the value rule of 7.21.7. A document in which no character was mapped to glyph 0, drawn or only measured, is unchanged. One in which a character was (a character that was only measured, such as a running band's cut tail, counts) differs only in that stream, which tests pin, including the measured-only case. Glyph ids passed straight toShowGlyphsadd no entry, which a test pins too.Layout (second commit).
LayoutDiagnosticCode.NotdefGlyph(102) reports each character and font written as glyph 0, with the count. The clause is ISO 19005-2:2011, 6.2.11.8 under a PDF/A claim, ISO 14289-1:2014, 7.21.8 under PDF/UA-1, and null with no claim.LayoutDiagnosticCode.UnembeddedFont(601) reports each element that writes a font operator for a named Standard 14 font whileConformanceis notNone, once per element and font, with the number of font operators. The clause is ISO 19005-2:2011, 6.2.11.4.1 or ISO 14289-1:2014, 7.21.4.1.SetDefaultFontstill applies only toDocument.Add(string); making it reach every element is not part of this PR.StrictDiagnosticsrefuses them.TextEmitter, so one report covers every built-in element. Each site keeps its own text object, colour and matrix, and their order.Document.SetDefaultFont,Document.Add(string, TextStyle),SetHeader,SetFooter,Document.Conformance,Paragraph,Heading,ListElement.DefaultStyle,ListItem.Style,TableElement.DefaultCellStyle,Cell.Style,RunningBand,TextStyle.FontRef,TextStyle.Default,Cell.Content), names the report, the strict switch and the exception.Compatibility
StrictDiagnostics"A ⚹ B \U0001F31F C", PDF/A-2u<0000> <26B9>and<0000> <D83CDF1F><0000> <FFFD>once, twoNotdefGlyphitemsInvalidOperationException, stream emptyLiberationMono (TT1)?and oneUnencodableCharacteritemNotdefGlyphShowGlyphs([0, 36])Add(string)only; a list and a table, PDF/A-2uUnembeddedFontfor the List (count 2) and the Table (count 1)UnembeddedFontitemTextStyle { Font = (Standard14)99 }, PDF/A-2uIndexOutOfRangeExceptionfrom the writeNo document that saved before is refused by default. Strict mode is opt-in. A Kernel save is not refused for glyph 0, because that would tighten
ShowGlyphs, which has shipped.Two existing tests whose pinned decision this changes, both rewritten on purpose:
ToUnicodeStandInTests.CodePointsThatAreNotStandIns_keepTheirEntries_glyphZeroGetsOneReplacementEntry(renamed) pinned that missing characters keep their own glyph-0 entries. It now expects one entry,(0, 0xFFFD).NoBreakSpaceBundledFontTests.LiberationMono_toUnicode_missingCharactersThatAreNotSpacesShareOneReplacementEntryForGlyphZero(renamed) pinned the same for two CJK code points. It now asserts the(0, 0xFFFD)entry is present and neither code point is listed.Byte-identity:
PlacementLoopGoldenTestsand every other existing golden pass unchanged.FontReportByteIdentityTestspins six hashes over five documents: a PDF/A-2u document with a default font and an unstyled list, table, paragraph, heading and footer; the empty unstyled cell; a document whose two runs in one font differ in size (still written as oneTf, which this PR does not change); a no-claim document mixing Standard 14 and embedded text in every kind of element and both bands; and, for the sixth hash, the missing-character document with its ToUnicode stream removed. They were first taken on the branch point before any change.Re-pins after merging main. The font bounding box change (#656) moves every embedded-font digest, so these moved, and nothing in this PR moves them: I computed the same values on main without this PR's source for the six hashes of
FontReportByteIdentityTests(DefaultFontWithUnstyledListAndTable_pinsBytes,UnstyledElementsAndFooterUnderAClaim_pinsBytes,EmptyUnstyledCell_pinsBytes,TwoSizesOfOneFont_pinsBytes_andWritesOneFontOperator,MixedNoClaimDocument_pinsBytes,AMissingCharacterDocument_differsOnlyInItsToUnicodeStream) and for the two goldens that merged with #654,RunsHeadingListItemGoldenTests.EmbeddedHeadings_pinTheBytesandEmbeddedLists_pinTheBytes, which fail on main itself after #656 and are re-pinned here.Tests
All in Release with veraPDF 1.30.4, qpdf 12.4.2 and poppler as the oracles required. Kernel, Conformance and TestSupport counts are from the head before the last merge of main (#655, layout only); Layout was re-run after it.
dotnet build VellumPdf.slnx -c Releasehas 0 warnings,dotnet format --verify-no-changes,eng/clean-room-check.ps1andpython eng/generate-roadmap.py --checkexit 0.Oracle checks on the PDF/A-2u missing-character file, each asserting the fixture holds the change first (
<0000> <FFFD>present, no<0000> <26B9>):6.2.11.8-1, so the new ToUnicode entry does not trip 6.2.11.7.2. veraPDF ua1 on the PDF/UA-1 variant:7.21.8-1fails,7.21.7-1does not.pdftotext -enc UTF-8: exactly two U+FFFD, no U+26B9 or U+1F31F.qpdf --checkreports "No syntax or stream encoding errors found" on it and on the default-font file.ISO19005-2:6.2.11.8-notdefand notISO19005-2:6.2.11.7.2-tounicode.pdffontslists Helvetica as not embedded and veraPDF 2u fails exactly6.2.11.4.1-1. The file with the empty unstyled cell fails exactly that rule too. The file whose styles are all embedded has no unembedded row inpdffontsand veraPDF 2u reports no failed rule.tests/VellumPdf.TestSupport/ExternalTool.csnow resolvespdffontsthroughPOPPLER_HOMEand checks its identity (pdffonts version) like the other poppler tools, so a missing tool skips instead of failing and a wrongPOPPLER_HOMEis reported. It is inExternalToolResolutionTests.Tools.Mutation proof
Each mutant was built in a detached worktree and killed by the named tests, then restored.
NotdefGlyphTests,ToUnicodeStandInTests(1), 6 inNotdefGlyphReportTests, the byte-identity projection testShowEmbeddedTextrecords nothingNotdefGlyphTests, 15 inNotdefGlyphReportTestsShowGlyphsrecords nothingNotdefGlyphTests, 2 inNotdefGlyphReportTests(custom renderer, sink drop count)GetGlyphIdsandShowGlyphsNotdefGlyphReportTestsATableCell_isReportedAHeaderBand_isReported,AFooterBand_isReportedreport: falsefor glyph 0TheSink_reportsGlyphZeroWhateverReportSays_asAListMarkerNeedsTf)Sizes_pinsBytes_andWritesOneFontOperator,TwoRunsInOneFontAtTwoSizes_countOneFontOperatorWithNoClaim_nothingIsReported,AHelveticaParagraph_reportsTheUnencodableCharacters_andNoGlyphZeroUnembeddedFontwhen text is shown, not atTfAnEmptyCell_isReported_becauseTheFontOperatorIsWrittenAStandard14ValueTheEnumerationDoesNotName_isNotReported_andTheSaveThrowsAsBeforeUnembeddedFontReportTestsUnembeddedFontReportTestsFinishstores the live tallyDrawingAfterFinish_isNotCountedUntilFinishRunsAgainContentBytessetter does not clearSettingContentBytesDirectly_clearsThePagesEntries>instead of>=TheCanvasListHoldsAThousandEntries_andCountsTheRestAsDropped,TheDocumentList_isCappedAtAThousandEntries_andAddsEveryDropCountTheDocumentList_addsTheCountsOfEveryFinishedPage,TheDocumentList_isCappedAtAThousandEntries_andAddsEveryDropCountTheSink_countsWhatTheCanvasDropped_andReadsItOnceNotdefGlyphTestsTheSameCharacter_isOneItemPerFont_countedAcrossElements,TheSink_countsWhatTheCanvasDropped_andReadsItOnceNotdefGlyphper elementTheSameCharacter_isOneItemPerFont_countedAcrossElementsTheSameCharacter_isOneItemPerFont_countedAcrossElementsUnembeddedFontsubject is constantAnExplicitStandard14Style_underPdfUa_isReportedUnderThePdfUaClause,TwoStandard14FontsInOneParagraph_areTwoItemsMutants 1 to 20 were run against the first two commits' tests; 21 to 25 against the head after the review round, with the new grouping and counting tests (the same-character, two-fonts, two-Standard-14-fonts and three-item-list cases).
The mutant that drops the sink's per-sync shortcut (reading every entry on every sync) changes no output, so no test can fail on it; its cost is in the bound table.
Bounds
GC.GetAllocatedBytesForCurrentThread()aroundSave, PDF/A-2u, one paragraph of n U+26B9 characters separated by spaces, before and after (net10.0 Release):The public list: 100,000 further
ShowGlyphs([0])calls on a stored entry allocate 2,096,928 B, the same as 100,000 calls with glyph 36 (theTjbytes), and the entry's count grows. The same calls past the 1,000-entry cap allocate 2,031,736 B, add 100,001 toNotdefGlyphsDroppedand store nothing. One read ofPdfDocument.NotdefGlyphson a 1,000-page document with one entry per page allocates 235,904 B, and 0 B when no page wrote glyph 0. A page without glyph 0 costs the sink one comparison per sync.Not done
SetDefaultFontis not applied to lists, tables, headings or bands, and nothing is refused by default.Barcode1D.TextFontand in theUnembeddedFontremarks).NotdefGlyph; theNotdefGlyphremarks name it.UnembeddedFonttrigger is the font operator, as veraPDF's rule is: an empty cell in Helvetica is reported, while ISO 14289-1, 7.21.4.1, counts a font as used only when a glyph is referenced. The remarks and the CHANGELOG say so.Differential against 2.3.3
A harness that runs 28,631 inputs against the 2.3.3 libraries and against the build reported 0 violations on the branch point, on the first commit and on the second. Comparing the verdict rows of the branch point with those of each commit, after masking output paths and file hashes, no row changed except
cancel-scanon the first commit (a cancellation race; the second commit's run does not repeat it). One row's hash moves on every run: it saves an encrypted document, which is never reproducible. Each build's assembly informational version is printed by the harness:2.3.3+3bfb8cf,2.3.3+cdd49f3and2.3.3+111e4ef.