Add a real, spec-compliant CSS3/4 engine (ported from ExCSS via PeachPDF)#244
Open
jhaygood86 wants to merge 4 commits into
Open
Add a real, spec-compliant CSS3/4 engine (ported from ExCSS via PeachPDF)#244jhaygood86 wants to merge 4 commits into
jhaygood86 wants to merge 4 commits into
Conversation
Port of CSS engine from PeachPDF
The Demo app depending on 2 HTML-Renderer extensions for background gradients and border radius. This ports a minimal version of the CSS spec compliant versions from PeachPDF
Fixes <br>
jhaygood86
marked this pull request as ready for review
July 17, 2026 01:58
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.
Summary
This replaces HTML-Renderer's ad-hoc CSS parsing/matching with a real CSS3/4 spec-compliant CSS engine — a proper cascade, a real selector engine (combinators, attribute selectors, structural pseudo-classes,
:not()/:is()/:has(),::before/::after),@mediacondition parsing, andcalc()— in place of the old simple class-name-keyed block lookup.The engine is derived from ExCSS, sourced from the more up-to-date fork maintained in PeachPDF, and ported into
Source/HtmlRenderer/Core/CssEngine. Two of HTML-Renderer's own non-standard CSS extensions —corner-radiusandbackground-gradient— depended on the old parser and have been replaced with their spec-compliant equivalents (border-radius,linear-gradient()) so the demo app keeps working against the new engine.Details
corner-radiusandbackground-gradientextensions with spec-compliant versions (see below).What now works end-to-end
!importanttier and the CSS-wide keywordsinitial/inherit/unset/revert/revert-layer.>,+,~), comma-separated selector lists, attribute selectors ([attr],[attr=v],[attr~=v],[attr*=v],[attr^=v],[attr$=v],[attr|=v]),:not(),:is()/:matches(),:has()(descendant form), structural pseudo-classes:nth-child()/:nth-last-child()/:nth-of-type()/:nth-last-of-type()(including the CSS4An+B of <selector>form) and:nth-column()/:nth-last-column(),:first-child/:last-child/:first-of-type/:last-of-type,:only-child/:only-of-type,:root,:link, and::before/::aftergenerated-content pseudo-elements.@mediaconditions: parsed, indexed, and matched, including nesting andnot/type conditions.calc(): parsed and evaluated for property values.content:: supportsattr()and the open/close quote keywords.background-image: linear-gradient(...), replacing the old proprietarybackground-gradientextension.border-radius, with independent per-corner horizontal/vertical elliptical radii, replacing the old proprietarycorner-radiusextension.Known limitations (not yet wired up)
@mediaconditions are parsed and indexed, but this engine has no live "what device are we rendering for" concept, so cascading is always done against mediaall— non-allconditions (e.g.@media screen) never actually gate anything. This matches the old engine's pre-existing behavior; it's not a regression.radial-gradient()parses but isn't painted yet — onlylinear-gradient()renders.::markerwasn't ported; list markers are still painted procedurally rather than as a generated box.content:doesn't supportcounter()/counters()/string()/content().:has()only supports the default descendant relative-selector form (no leading>,+,~).Related open issues
Confirmed by reading the relevant code paths (not just title-matching):
corner-radiusvsborder-radius: fixed directly (see above).[class*="language-"]) don't match: fixed — the new engine has real attribute-selector support..token.property) don't match: fixed — the old engine's single-class-key lookup couldn't represent this; the new selector engine requires every class in a compound selector to match.url('data:...;base64,...')mis-parsed because of the semicolon inside the quoted string: fixed — the old ad-hoc parsing method is gone, replaced by a real, spec-correct tokenizer.border: 1px inset;mis-parsed: fixed — the old ad-hoc border-shorthand parser is gone, replaced by a real, order-independentbordershorthand implementation.<a>tags: likely resolved or significantly improved — the issue's own root cause (an O(rules × boxes) matching function with a hand-rolled<a>-tag special case) has been replaced by the new tag/class/id rule index. Not independently benchmarked.background:shorthand set via a descendant selector not applying: likely fixed — both prerequisites (real descendant-combinator matching, realbackgroundshorthand parsing) are now in place, though the exact reported case wasn't directly reproduced.Not addressed by this PR (layout/painting gaps, not parsing/cascade): #203 (
position: absolute), #34 (float), #42 (table border-conflict resolution), #104/#103 (<tr>display/background-color).