Skip to content

openpdf-html: use ph-css CSS parser#1561

Open
andreasrosdalw wants to merge 4 commits into
LibrePDF:masterfrom
andreasrosdalw:openpdf-html-ph-css
Open

openpdf-html: use ph-css CSS parser#1561
andreasrosdalw wants to merge 4 commits into
LibrePDF:masterfrom
andreasrosdalw:openpdf-html-ph-css

Conversation

@andreasrosdalw
Copy link
Copy Markdown
Contributor

@andreasrosdalw andreasrosdalw commented May 8, 2026

#1558

Add com.helger:ph-css 8.2.0 as a dependency and lay the groundwork for replacing the hand-written JFlex CSS 2.1 parser with a modern CSS3/4-capable engine.

https://github.com/phax/ph-css

New package org.openpdf.css.phcss:

  • PhCssStylesheetFactory: static parse(String/Reader/InputStream) entry points backed by ph-css CSSReader.
  • PhCssParser: instance wrapper mirroring the legacy CSSParser surface to ease the migration for callers.
  • PhCssToOpenPdfAdapter: maps a ph-css CascadingStyleSheet onto the openpdf-html Stylesheet/Ruleset/PropertyDeclaration model, handling style rules, @media, @font-face, @page, and @import. Selector and value parsing delegates to the legacy CSSParser during the transition. Covered by 15 unit tests.

Legacy org.openpdf.css.parser, org.openpdf.css.parser.property, and CSSName marked @deprecated(since = "3.0.5"). The legacy parser remains the default; nothing is removed yet.

Also fixes misplaced Javadoc (annotations before /** block in CSSParser and Token), a duplicate /** block in BuilderUtil, dead code in the initial PhCssToOpenPdfAdapter stub, and a repeated LoggingCSSParseErrorHandler construction now replaced by a shared constant.

Note that this is a "research" and innovation time project where I have spent time trying to improve OpenPDF using AI tools such as Claude and Copilot.

Your real name

Andreas Røsdal

  Add com.helger:ph-css 8.2.0 as a dependency and lay the groundwork
  for replacing the hand-written JFlex CSS 2.1 parser with a modern
  CSS3/4-capable engine.

  New package org.openpdf.css.phcss:
  - PhCssStylesheetFactory: static parse(String/Reader/InputStream)
    entry points backed by ph-css CSSReader.
  - PhCssParser: instance wrapper mirroring the legacy CSSParser surface
    to ease the migration for callers.
  - PhCssToOpenPdfAdapter: maps a ph-css CascadingStyleSheet onto the
    openpdf-html Stylesheet/Ruleset/PropertyDeclaration model, handling
    style rules, @media, @font-face, @page, and @import. Selector and
    value parsing delegates to the legacy CSSParser during the transition.
    Covered by 15 unit tests.

  Legacy org.openpdf.css.parser, org.openpdf.css.parser.property, and
  CSSName marked @deprecated(since = "3.0.5"). The legacy parser remains
  the default; nothing is removed yet.

  Also fixes misplaced Javadoc (annotations before /** block in CSSParser
  and Token), a duplicate /** block in BuilderUtil, dead code in the
  initial PhCssToOpenPdfAdapter stub, and a repeated LoggingCSSParseErrorHandler
  construction now replaced by a shared constant.
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 61 complexity · 2 duplication

Metric Results
Complexity 61
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@andreasrosdalw andreasrosdalw changed the title introduce ph-css parser layer and implement PhCssToOpenPdfAdapter openpdf-html: introduce ph-css parser layer and implement PhCssToOpenPdfAdapter May 8, 2026
- Remove unused CSSSelector import from PhCssToOpenPdfAdapter
- Import PropertyDeclaration instead of using fully-qualified type name
- Extract duplicate string literal to STRING_READER_IO_MSG constant
- Rename unused uri parameters to ignoredUri in PhCssParser

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andreasrosdalw andreasrosdalw changed the title openpdf-html: introduce ph-css parser layer and implement PhCssToOpenPdfAdapter openpdf-html: user ph-css CSS parser May 8, 2026
@andreasrosdalw andreasrosdalw changed the title openpdf-html: user ph-css CSS parser openpdf-html: use ph-css CSS parser May 8, 2026
andreasrosdalw and others added 2 commits May 8, 2026 11:36
Checkstyle SingleLineJavadoc rule (ignoreInlineTags=false) flags /** */
comments that contain inline tags like {@link} and {@code}. Convert the
3 offending method Javadocs in PhCssParser and PhCssStylesheetFactory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant