HTML layout caching
HTML text, Performance, Page layout
Description
HTML measurement and drawing methods automatically share bounded cached layout plans on each painter
A first request parses the source, resolves CSS, calculates line, Flexbox, Grid, table and footnote geometry, and records the resulting text, image, border, background, and link operations without writing to the page content stream
A matching draw request replays those operations at the requested position instead of parsing or measuring the HTML again
Affected methods
GetHTMLTextHeightGetHTMLTextWidthGetHTMLTextLineCountDrawHTMLTextDrawHTMLTextBoxDrawHTMLTextMatrixDrawHTMLTextBoxMatrix
Cache identity
Plans are matched by the complete HTML source, available width, optional continuation height, font set, text spacing, equivalent-tag rules, bound image identities and dimensions, and the kerning mode
The drawing position is deliberately excluded, so one measured plan can be replayed at multiple locations without changing line breaks
Changing an HTML font, image binding, or equivalent-tag rule clears plans that could retain obsolete object references
Bounds and eviction
Each painter retains at most eight recently used plans and normally limits their estimated memory to 32 MiB
A single plan larger than the memory target remains available for its immediate draw and is replaced by later activity, avoiding an unbounded document-wide cache
Measurement safety
Measurement records styled backgrounds, table borders, images, and links as deferred operations and does not append them to the selected page
Continuation results from DrawHTMLTextBox are stored with the same height-constrained plan that is replayed