Skip to content

Layout: a Heading bookmark cannot be collapsed, because DrawContext.AddOutlineEntry never sets IsExpanded #609

Closed

Description

@Tim81

Problem

The Kernel outline entry has an IsExpanded property, and the Layout path never sets it, so every Layout bookmark
is open. (origin/main 1c61fa6.)

  • src/VellumPdf.Kernel/Annotations/PdfOutlineEntry.cs:43: public bool IsExpanded { get; init; } = true;. Its
    documentation (:36-41): false shows the item collapsed with a negative /Count.
  • The writer honours it: PdfDocument.cs:1887 (var countValue = entry.IsExpanded ? visibleCount : -visibleCount;)
    and :1938.
  • src/VellumPdf.Layout/Core/DrawContext.cs:244-255:
247:         _document.AddOutlineEntry(new PdfOutlineEntry
248:         {
249:             Title = title,
250:             DestPage = _page,
251:             DestLeft = 0,
252:             DestTop = pdfY,
253:             Level = level,
254:         });
  • HeadingRenderer.Draw calls it with title, level and Y only (HeadingRenderer.cs:76).
  • A search of src for IsExpanded finds it only in PdfOutlineEntry.cs, PdfDocument.cs and the Kernel
    PublicAPI.Shipped.txt (lines 488-489), none under src/VellumPdf.Layout.
  • Heading has BookmarkTitle (Heading.cs:85) and Level (:79) and nothing for expansion.

Why it matters

A 200-page handbook with several hundred bookmarks opens with every one expanded. Readers show chapters collapsed
by convention.

Scope

  • Heading.BookmarkExpanded (bool, default true, so today's output is unchanged).
  • A DrawContext.AddOutlineEntry overload that takes it. The existing three-argument method is a shipped member
    and stays as it is.
  • The split heading of Layout: a heading that splits across pages gets its bookmark at the page top #464 uses the same value on its single entry.
  • XML documentation: a collapsed entry with no children has a visible-descendant count of zero, so its sign is
    not observable. The brief checks what PdfDocument writes for that case and documents it.

Acceptance

  • A level-0 heading with BookmarkExpanded = false followed by two level-1 headings writes the parent's /Count
    as -2 (read back with the Reader).
  • The default heading writes a positive count, byte-identical to today (golden test).
  • A custom renderer calling the old three-argument method is unaffected (test).
  • The test fails on origin/main 1c61fa6 (no such property), proven by mutation.

Relates to

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

    area/layoutenhancementtype/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions