Skip to content

Layout docs: behaviour found by probing after #542's review #552

Open

Description

@Tim81

Follow-up to #510 and PR #542. The review rounds on #542 kept finding reachable behaviour that was already in the code and that no XML doc states. From round 15 on, such findings no longer block #542; they are collected here instead, so the documentation PR can close while the list stays visible.

Each item names the member, what happens, and where the evidence comes from. Items marked lead were measured by a review lens and have not been reproduced independently yet; reproduce before writing any sentence.

Undocumented behaviour

  • LayoutImage.Height: a finite height taller than the content area makes the save throw the generic too-tall InvalidOperationException. The exception tag names zero, sub-5e-6 and non-finite heights only. PieChart.Diameter and LineSeparator.LineWidth document the equivalent for their own members. (lead, round 15 contract C)
  • Document.Language: the XMP dc:language copy differs from /Lang. C0 controls other than tab, line feed and carriage return are dropped, a lone surrogate becomes U+FFFD, and a value that becomes empty after that is written as an empty entry. Document.Info now documents the same XMP behaviour for its entries. (lead, round 15 contract A)
  • SetPdfAOutputIntent / UseCmykOutputIntent: the identifier and info bytes are written as Latin-1 (documented), but ISO 32000-2 Table 401 types both as text strings, which readers decode as PDFDocEncoding. A caller's U+00A0 reads back as €; U+0080 to U+009F read back as other characters. (lead, round 15 contract A; clause read from the local EC3 copy)
  • WinAnsi-unused codes in standard-14 faces: U+007F, U+0081, U+008D, U+008F, U+0090 and U+009D measure zero in the Helvetica and Times faces, while ISO 32000-2 Annex D note 3 says unused WinAnsi codes above 40 map to the bullet, and poppler draws a 350-unit bullet for each. Lines holding them can overrun their area, justified or not. Affects TextStyle.MeasureString, FontReference.MeasureString and the RunningBand.Template Attention paragraph. The kernel comment on Standard14Metrics.GetWidth says measured and rendered widths agree, which does not hold for these codes. (lead, round 15 contract B)
  • ParagraphRenderer(Paragraph, int startLine): a startLine near int.MinValue overflows _lines.Count - _startLine, so Layout returns Nothing and the save throws the too-tall InvalidOperationException instead of ArgumentOutOfRangeException from Draw. The Do-not paragraph already covers the input. (lead, round 15 contract C)
  • TextStyle.LinkUri: a linked run holding only white space writes no link annotation. (lead, round 12 contract B)

Internal comments found false

  • DocumentRenderer private comment (around line 665): U+007F measuring zero "in every face" is false for Courier (600 units).

New items found after #542 merges go below.

Activity

  1. Tim81 commented on Sep 19, 2026

    @Tim81
    OwnerAuthor

    Round 16 addition (contract lens A, measured on 361ac49; lead, not yet reproduced independently):

    • Document.Info (and Document.Language) → ill-formed XMP for U+FFFE / U+FFFF. XmpMetadataWriter.XmlEscape (src/VellumPdf.Kernel/Document/XmpMetadataWriter.cs:154-171) drops only C0 controls, so Title = "a�b" is written into the XMP packet as 61 EF BF BE 62 (U+FFFF likewise as EF BF BF). XML 1.0's Char production excludes both; XmlDocument.LoadXml on the packet fails with "hexadecimal value 0xFFFE, is an invalid character". /Info is written as given. Measured on Title only; the same escape serves the other Info entries and Language. veraPDF not run on it.
  2. Tim81 commented on Sep 19, 2026

    @Tim81
    OwnerAuthor

    Round 16 additions (contract lens C, measured on 361ac49 on a 300×300 page with 20pt margins; leads, not yet reproduced independently):

    • Paragraph (type remarks): a CR ending one run and an LF starting the next are two line breaks. A CRLF inside one run is one. [a\r\nb] puts b at y258; [a\r | \nb] puts it at y246, one extra empty line; [a | \r\nb] and [a\r\n | b] put it at y258. Paragraph.Text reads a\r\nb in every case. Source: WordWrap normalises CRLF per run (run.Text.Replace("\r\n","\n"), ParagraphRenderer.cs:583).
    • Mixed paragraph line height: a run holding only white space adds nothing to the line spacing. Every line, the empty ones from that run included, is spaced at the largest leading among fragments that hold other characters: ["\n\n"@50, "x"@10] and ["x"@10, "\n\n\n"@50] both take 36 (3 × 12). Source: ParagraphRenderer.cs:92-104, a max over fragments with the default only when there are none. No XML doc states the uniform per-paragraph line height.
    • List item holding only white space, where the marker fits but a default-leading line does not: the item takes only the marker's height and its empty lines are dropped rather than carried over. Size 4 (leading 4.8), 10pt left, text "\n\n": the item takes 4.8, not 28.8, and nothing carries to the next page. With 25pt left the second line does carry. Source: ListRenderer.cs:126-149 (the item proceeds unless both marker and content are Nothing; itemH = max of the two).
  3. Tim81 commented on Sep 19, 2026

    @Tim81
    OwnerAuthor

    Round 17 of #542's review, run on 215f52e, found the leads below in behaviour that already ships. Each one comes from a reviewer's probe against that head, on Windows. I have not reproduced them myself, so treat them as leads until someone measures them again. The last one is a reading of the source, with no probe behind it.

    Paths (Windows)

    • If a path's last segment holds only spaces or only dots (existingDir + @"\ " or @"\..."), LoadTrueTypeFont, LoadTrueTypeFontAsync, Save(string) and SaveAsync(string) all throw DirectoryNotFoundException naming existingDir\. Windows strips trailing spaces and dots. That makes the tag "The directory named in path does not exist" false here.
    • Save(string) and SaveAsync(string) with @"\\?\ " throw FileNotFoundException. Neither member lists that type. It is an IOException, so the IOException tag still catches it.

    Symbol and ZapfDingbats (#470 neighbours)

    • Auto-sized table column. The table measures the cell's text as zero width, so the column is only as wide as its padding. The text is still drawn at its real advances and runs over the next column. With cell 0 holding Symbol abcdefghijklmnop qrstuvwxyz, cell 1's text starts at x=89.805. The Helvetica control is x=173.012, with cell 0 wrapped to 3 lines.
    • TextStyle.LinkUri on a Symbol run. The annotation gets a zero-width rectangle, so it covers none of the text: /Rect [72 755.49 72 769.89]. The Helvetica control is [72 755.49 124.704 769.89].
    • No bullet in either face. An unordered list in either font draws no bullet. • is written as WinAnsi byte 0x95, which neither font's built-in encoding defines, so poppler extracts nothing. No TextEncodingWarning is recorded for it. More generally, layout text in these faces goes through the fonts' built-in encodings, so a comes out as α or ❁.

    Lists and cells

    • Continuation page with a suppressed marker. The layout reserves the marker's height but the draw pass does not. An item holding only "\n\n" at 30pt splits across a page. On page 2 the next paragraph then starts 21.6pt lower than the drawn content accounts for. With "\n\n\n" the gap is 7.2pt.
    • Leading spaces in a cell. A cell drops leading U+0020 spaces and keeps trailing and interior ones: " a" draws (a) and "a " draws (a ). A running band keeps the leading space: ( a).

    Kernel (read from source, not measured)

    • PdfDocument writes annotations only for its own pages (PdfDocument.cs:738-751). A DrawContext built by hand around a page from another document would therefore drop its annotations without an exception.
  4. Tim81 commented on Sep 19, 2026

    @Tim81
    OwnerAuthor

    Round 18 of #542's review, run on 846f021, found three more leads in behaviour that already ships. A reviewer's probe measured each one against that head on Windows. I have not reproduced them myself.

    A font whose head.unitsPerEm is 0 measures at an enormous width

    • FontReference.MeasureString and TextStyle.MeasureString return an enormous finite width and throw nothing: "abc" at 12pt measures 77,309,411.292.
    • TrueTypeFontEmbedder.GetAdvanceWidth computes (int)Math.Round(w * 1000.0 / 0), which saturates to int.MaxValue. Layout then runs at those widths until the save throws ArgumentException [value].
    • The save-time throw is now documented on UseTrueTypeFont. The measurement is not.

    Font size ≤ 0 in a paragraph, heading or list item

    • With font size ≤ 0 and leading ≤ 0, the text is spaced at TextStyle.Default leading.
    • The cause is ParagraphRenderer.cs:103-104, which falls back to 14.4pt whenever the largest EffectiveLeading is ≤ 0.
    • Measured: "a\nb\nc" at size 0 or -10 puts its baselines 14.4 apart, and the next paragraph lands where it would at size 12.

    Font size ≤ 0 in a table cell

    • In a cell, the row collapses instead. Row height is lines × 1.2 × size + vertical padding (TableRenderer.cs:138).
    • Measured row heights:
      • size 0: 8pt
      • size -2: 5.6pt
      • size -10 with default padding: neither the cell's text nor its border is drawn, because the draw loop breaks at TableRenderer.cs:265, and the next paragraph starts where the table began
      • size -10 with 10pt padding: 8pt
    • TextStyle.FontSize says "Below zero the glyphs are inverted". That text is on main from docs(layout): correct #503's boundary documentation across four rounds #526, and the -10 cell above contradicts it.
  5. Tim81 commented on Sep 19, 2026

    @Tim81
    OwnerAuthor

    Round 19 of #542's review, run on 3e0e6a8, found four more leads in behaviour that already ships. Each was measured by a reviewer's probe on Windows against that head, except where the item says source read only. I have not reproduced them myself.

    A non-finite DrawContext.PageBounds.Height refuses every annotation and outline entry the context registers

    • ToPdfY and ToPdfRect compute PageBounds.Height - layoutY, so a non-finite height makes the written coordinate non-finite even when the box and layoutY are finite.
    • Measured for NaN, +Infinity and -Infinity separately, with a real page: AddUriLinkAnnotation(new LayoutBox(10,10,20,20), "https://x") and AddOutlineEntry("t", 0, 10) both end in ArgumentException naming the non-finite value.
    • Reachable only from a DrawContext you construct yourself. The <exception> tags scope their condition to the caller's argument, and the PageBounds remarks say only "Stored without a check".

    A table cell past the resolved column count is never style-checked

    • Source read only, not probed. TableRenderer.cs:129 breaks on col >= _colWidths.Length before LayoutValidation.ValidateStyle at :134. It needs an earlier cell's ColSpan to consume the row.
    • TextStyle.FontSize says "A table cell or list item is checked whatever its text holds".

    The unnamed-Standard14 IndexOutOfRangeException comes from font registration during serialisation, and an empty cell reaches it where an empty paragraph does not

    • Measured with (Standard14)99 and Document.Save(MemoryStream). The stack for a paragraph, list item, cell, heading and footer band ends in PdfDocument.RegisterStandard14Fonts (PdfDocument.cs:1425), not in a SetFont call.
    • new Paragraph("", style) and new Paragraph(" ", style) do not throw, because ParagraphRenderer.Draw skips a line with no fragments and never registers the font. new Cell("") { Style = style } in a one-cell table throws. The bad style on a grandchild list item does not throw.
    • About 13 members say "and the font is selected on a page". That is a different call from the one that raises.

    A centred line that mixes Helvetica and Symbol is placed as if the Symbol run had no width, but only the Symbol run

    • Measured: "HELLO" in Helvetica followed by "HELLO" in Symbol, centred, emits Tm x = 276.298 and 318.982. 276.298 is 297.64 minus half of (39.35 + 3.336), so the line is centred on the Helvetica run plus the inter-run space, and the Symbol glyphs hang past the centre.
    • The same two runs both in Helvetica start at 256.624. TextStyle.FontRef scopes "as if it had no width" to a paragraph set wholly in Symbol or ZapfDingbats; the mixed case has no sentence.
  6. Tim81 commented on Sep 19, 2026

    @Tim81
    OwnerAuthor

    Found by probing during review round 20 of #542, on 5847721 (fixes in ade6f61). The PR documents none of these as a rule, and none of them blocks it. Measured on A4 with 72pt margins.

    1. A finite negative ListElement.Indent can write -Infinity into the text matrix, silently, when its gutter overflows and the text has no link.

    • Nested, unlinked, indent -1e308, ListElement.Margins left -1e308: saves, writing 1 0 0 1 -Infinity 743.49 Tm (Child text) Tj.
    • Flat, unlinked, one long word, indent -1e308, Document.Margins left -1e308 and right +1e308: saves, writing -Infinity 757.89 Tm.
    • With linked text the same inputs throw ArgumentException at save. The member now says so.
    • Source: ListRenderer.cs lines 338 and 350-351 (the flat override reverts the gutter to the raw indent), and 396 (the nested gutter Math.Max(indent * 2, indent + childMarkerWidth) is added to the list's left edge).

    2. DrawContext.UseEmbeddedFont: the order of its null failures is not stated.

    • A RendererContext built with a null document throws NullReferenceException. RendererContext.RegisterEmbeddedFontUsage tags that; DrawContext.UseEmbeddedFont does not.
    • With the RendererContext's page null, a null handle throws ArgumentNullException (ParamName key), not the NullReferenceException the handle tag names.
    • With both the page and the document null, NullReferenceException wins.
    • Order, from PdfDocument.RegisterEmbeddedFontUsage (PdfDocument.cs:254-261): the null document fails first, then TryGetValue(page), then handle.ResourceName.

    3. DrawContext.AddOutlineEntry on a context built with a null page: which exception surfaces depends on evaluation order in the save.

    • A null title gives NullReferenceException.
    • A NaN or infinite layoutY gives ArgumentNullException (ParamName key), not the tagged ArgumentException. It still derives from it.
    • Order, from PdfDocument.cs: FromUnicode(Title) at 1851, then pageRefMap.TryGetValue(DestPage) at 1854, then new PdfReal(DestTop) at 1859.

    4. An unnamed ListStyle value marks nested children with the top-level bullet •, not ◦.

    • Read from source, not probed. ListRenderer.cs:381-383 uses "◦" only for ListStyle.Unordered; otherwise FormatMarker, whose default arm returns "•" (ListElement.cs:255).

    5. LayoutImage.Height too tall for the page.

    • Height = 10000 or 1e308 (with Width 100, or Width null) throws the too-tall InvalidOperationException, which is tagged.
    • The remarks say only "moves to the next page". The Width remarks name their own too-tall case.

    6. LineSeparatorRenderer.Layout does not say that a separator taller than its area returns Nothing and that the save then throws the too-tall InvalidOperationException.

    • LayoutImageRenderer.Layout and PieChartRenderer.Layout both say it.
    • Measured through LineSeparator.Margins with Top = Bottom = 1e308. Source: LineSeparatorRenderer.cs:50.

    7. Follow-up to comment 1's Document.Info U+FFFE entry, which said "veraPDF not run on it". It has now been run.

    • Fixture: Conformance = PdfA2b, Info.Title set to "a", U+FFFE, "b", one Helvetica paragraph. The fixture was checked first: its XMP holds <rdf:li xml:lang="x-default">a EF BF BE b</rdf:li>.
    • Control: the same document with Title = "ab".
    • veraPDF 1.30.2, --flavour 2b:
      • Both files fail 6.2.11.4.1-1, because Helvetica is not embedded. That is the control's only failure.
      • The U+FFFE file also fails 6.6.2.1-4 and 6.6.2.1-5 (XMP content and encoding) and 6.6.4-1 (PDF/A identification). veraPDF logs XMPException: XML parsing failure.
    • Conclusion: one U+FFFE in the title makes the XMP unparseable, and with it the PDF/A identification.
  7. Tim81 commented on Sep 20, 2026

    @Tim81
    OwnerAuthor

    Round 21 (2026-09-20), non-blocking behaviour found while probing

    Measured on docs/layout-xml-complete at e84a2e8, one probe assembly per lens, exception type and
    ParamName asserted, PDFs decoded with qpdf 12.4.1.

    1. DocumentRenderer.BandTruncations returns a fresh list on every get. It allocates a new list
      per call, so two reads are never reference-equal and a caller cannot compare them to detect a
      change. No member says so. (Read from source, not probed.)

    2. Document.Save(Stream) and SaveAsync(Stream) answer a closed destination with different
      types.
      A disposed MemoryStream gives ArgumentException with ParamName stream ("Stream
      must be writable") from the synchronous save, and ObjectDisposedException from the
      asynchronous one, which documents it. A caller writing one catch for both meets two types.

    3. A RendererContext whose RegisterImageXObject threw has already consumed the resource
      name.
      After the throw the image sits in the name cache and the counter has advanced, so the
      next different image is registered as Im2 although nothing was ever registered as Im1.

    4. RegisterImageXObject stops throwing on a repeat call. With a null page the first call
      raises ArgumentNullException(key) and a second call with the same image returns the cached
      name and raises nothing. The remarks state the mechanism but not that the throw disappears.

    5. A flat list whose indent sits just below its area width hard-breaks to one glyph per line and
      splits across pages.
      At an area width of 451.28 an indent of 451.2799 draws (P)(a)(r)(e)(n)
      one glyph per line; at 451.28 the item text is discarded and only the marker is drawn. Not filed
      as a doc defect: ListElement.Indent already tells callers to stay well below half the area
      width.

    6. An internal comment in DocumentRenderer is false for Courier. It says U+0000–U+001F, U+007F
      and WinAnsi's five undefined codes measure zero "in every face". In the Courier faces U+007F and
      every C1 control measure 600 units; embedded Arial measures 750 for all 32 C0 codes. This
      belongs with the existing "internal comments found false" entry.

  8. Tim81 commented on Nov 26, 2026

    @Tim81
    OwnerAuthor

    A documentation gap found while writing a PDF/A-2u sample with the Layout API alone: nothing in the Layout docs
    says that a document with Conformance set to a PDF/A level gets the built-in sRGB output intent without any
    call. The Kernel writes it whenever Conformance is not None
    (src/VellumPdf.Kernel/Document/PdfDocument.cs:76-78, and line 2078, _outputIntentProfile ?? SrgbIccProfile.Bytes).

    Document.SetPdfAOutputIntent and UseCmykOutputIntent carry remarks about replacing or adding an intent, and
    docs/layout-guide.md lists them under "CMYK / ICC output intents", so a reader looking for how a PDF/A file gets
    its intent finds the setters and no statement of the default. The sample's first version called
    SetPdfAOutputIntent(IccProfiles.Srgb, 3, "sRGB"), which only replaced the default identifier
    ("sRGB IEC61966-2.1") with a vaguer one; veraPDF 2u and qpdf passed without it.

    Suggested wording on both setters and in the guide: "A PDF/A document gets the built-in sRGB intent by default.
    Call this only to replace it."

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions