Skip to content

Layout: named styles with inheritance #292

Open

Description

@Tim81

Styling is per-element. TextStyle is passed to each Paragraph, Heading or TextRun; containers
carry a default (Document.SetDefaultFont, TableElement.DefaultCellStyle, ListElement.DefaultStyle)
that applies one level down. There are no named styles, no cascade and no inheritance.

So changing a document's look means touching every element that sets a style, and there is no way to
say "all headings in this section are blue" without repeating it.

Scope

A stylesheet of named styles that elements reference by name, resolved through the containment
hierarchy L0b establishes — so a style set on a section applies to everything beneath it unless
overridden, and a named style can derive from another.

Resolution order: element's explicit style, then its named style, then inherited values from
ancestors, then the document default. Each property resolved independently, so setting a colour does
not reset a font.

Why it lands in Foundations rather than with the typography work

Three later issues assume it exists: L3's fill model wants to be settable as part of a style rather than
per-element; L26's text decoration is a style property; and the HTML→PDF epic needs something to compile
CSS into — a cascade that already exists is the natural target, and building one later means retrofitting
every element that already carries a style.

Compatibility

TextStyle is Shipped and stays. Named styles are additive: an element with an explicit TextStyle
behaves exactly as today.

Acceptance

  • A document restyled entirely by swapping its stylesheet, with no element changes.
  • Inheritance through three levels of section nesting, with per-property override.
  • A style deriving from another, overriding one property.
  • Existing documents produce byte-identical output.

Relates to

  • L0b — the hierarchy inheritance resolves through.
  • L3 — fills become style properties.
  • L26 — text decoration likewise.
  • E13 — the HTML→PDF epic's compile target.

Plan labels used above, resolved: L3 #254 · L0b #286 · L26 #305 · E13 #364.

Activity

  1. added
    area/layout
    type/feature
    on Aug 29, 2026
  2. Tim81 commented on Nov 27, 2026

    @Tim81
    OwnerAuthor

    Moved to 3.0. A cascade resolves styles by comparing them, and in 2.x TextStyle is a class without value equality: the layout merges words only when their runs share one style instance (#709 lists the places). A cascade built on that would have to be rebuilt when #709 makes TextStyle a value, so both land together. The resolution order proposed here (explicit style, named style, inherited, document default, per property) still stands as the design to start from; it also needs the containment tree of #286, or the block base of #710, to inherit through.

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/layouttype/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions