Recent

Author Topic: Lightweight HTML/CSS rendering engine written in pure Free Pascal  (Read 5935 times)

Wallaby

  • Guest
I've been building an HTML/CSS rendering engine in Free Pascal called Pixie. It has its own HTML5 parser, CSS3 tokeniser/parser, and a layout engine that handles block, inline, float, table, flexbox, and CSS grid.

I'm considering open-sourcing it and wanted to see if there's interest in the community first.

What it does

Pixie takes an HTML string and renders it into a Lazarus control (TPixieHtmlView) with full mouse interaction, scrolling, links, hover/active states, and form controls. Think of it as a way to use HTML/CSS for rich content display in native desktop apps — without embedding a browser.

Features

  • HTML5 parser (68 tokeniser states, 23 insertion modes) — handles malformed HTML the same way browsers do
  • CSS3 parser following the W3C CSS Syntax Level 3 spec
  • Layout: block, inline, float, table (colspan/rowspan), flexbox, CSS grid
  • Selectors: type, class, ID, attribute, combinators, :nth-child(), :not(), :is(), :hover, :active, ::before/::after
  • Gradients: linear-gradient(), radial-gradient(), conic-gradient() with repeating variants
  • Media queries (Level 4), custom properties (var()), border-radius, opacity, positioned elements
  • Owner-drawn form controls: text inputs, textareas, checkboxes, radio buttons, buttons — with caret, selection, and clipboard

Architecture — no dependencies

Pixie is pure Pascal with zero third-party dependencies. The rendering backend is abstracted behind a canvas interface with three implementations:

  • Direct2D / DirectWrite (Windows) — hardware-accelerated, native SVG via ID2D1DeviceContext5
  • Cairo (Linux / cross-platform)
  • Core Graphics (macOS)

~49,000 lines of Pascal across 58 units. A full demo app compiles to a 4.2 MB stripped executable (Win64, smart-linked). No DLLs, no runtime, no WebView2 redistributable.

Use cases for Lazarus apps

  • Rich "about" dialogs, changelogs, and release notes
  • In-app help systems and documentation viewers
  • HTML-formatted reports and print previews
  • Email or message display
  • Dashboard panels with styled content and tables
  • Any UI where you want the flexibility of HTML/CSS without the weight of an embedded browser

Current state

The engine is used in production in our commercial products. It handles real-world HTML well, though it's not trying to be a full browser — no JavaScript, no <video>, no CSS animations. The focus is on correct layout and rendering of static/interactive content.

Compiles with Lazarus/FPC targeting Windows (32/64), Linux (x64, ARM64), and macOS (x64, ARM64).

Would there be interest in seeing this released as open source? Curious to hear thoughts, questions, or what features would matter most to you.

440bx

  • Hero Member
  • *****
  • Posts: 6356
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #1 on: March 17, 2026, 03:24:36 am »
@Wallaby,

At first sight, it looks really, really good.

Compiles with Lazarus/FPC targeting Windows (32/64), Linux (x64, ARM64), and macOS (x64, ARM64).

Would there be interest in seeing this released as open source? Curious to hear thoughts, questions, or what features would matter most to you.
I think it would be _great_ for it to be open source.  That would give other people the chance to improve upon what looks like an already very capable and useful foundation.  It might also ensure that its continued existence and improvements is not in turn dependent on the existence of a single entity.

« Last Edit: March 17, 2026, 03:41:50 am by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

dsiders

  • Hero Member
  • *****
  • Posts: 1594
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #2 on: March 17, 2026, 03:34:31 am »
I've been building an HTML/CSS rendering engine in Free Pascal called Pixie. It has its own HTML5 parser, CSS3 tokeniser/parser, and a layout engine that handles block, inline, float, table, flexbox, and CSS grid.
I'm considering open-sourcing it and wanted to see if there's interest in the community first.

Your work to-date looks pretty impressive. I would absolutely love to see an open source version.

Pixie is pure Pascal with zero third-party dependencies. The rendering backend is abstracted behind a canvas interface with three implementations:

  • Direct2D / DirectWrite (Windows) — hardware-accelerated, native SVG via ID2D1DeviceContext5
  • Cairo (Linux / cross-platform)
  • Core Graphics (macOS)

~49,000 lines of Pascal across 58 units. A full demo app compiles to a 4.2 MB stripped executable (Win64, smart-linked). No DLLs, no runtime, no WebView2 redistributable.

Isn't Cairo GTK-specific? Asking for a QPainter/QPaintDevice friend... :)

Wallaby

  • Guest
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #3 on: March 17, 2026, 03:47:09 am »
Isn't Cairo GTK-specific? Asking for a QPainter/QPaintDevice friend... :)

I haven't researched the Qt backend yet, but architecturally shouldn't be hard at all - the canvas interface is already abstracted.

It would just need TPixieCanvasQt with the same ~15 drawing methods as the D2D/Cairo/CG backends, I'll have a look at that.

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 411
  • I use FPC [main] 💪🐯💪
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #4 on: March 17, 2026, 04:51:01 am »
Wow! This is mind-blowing!
I may seem rude - please don't take it personally

egsuh

  • Hero Member
  • *****
  • Posts: 1775
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #5 on: March 17, 2026, 06:03:45 am »
Great! Frankly speaking, Lazarus's UI is not excellent --- of course I know it's my problem. But if importing forms / designs of HTML/CSS into Lazarus then it would imporve the look of Lazarus apps by large. Am I understanding accurate?

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1875
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #6 on: March 17, 2026, 07:18:03 am »
Quote
Would there be interest in seeing this released as open source?
+1 !

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #7 on: March 17, 2026, 08:21:46 am »
Looks great, open source it !

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #8 on: March 17, 2026, 08:49:58 am »
Isn't Cairo GTK-specific? Asking for a QPainter/QPaintDevice friend... :)

I haven't researched the Qt backend yet, but architecturally shouldn't be hard at all - the canvas interface is already abstracted.

It would just need TPixieCanvasQt with the same ~15 drawing methods as the D2D/Cairo/CG backends, I'll have a look at that.

Open source it and you'll get Qt5/Qt6 backend for free on all platforms where Qt lcl works: linux, mac, win, amiga ...

paweld

  • Hero Member
  • *****
  • Posts: 1596
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #9 on: March 17, 2026, 08:59:18 am »
Looks great
Best regards / Pozdrawiam
paweld

Wallaby

  • Guest
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #10 on: March 17, 2026, 09:07:43 am »
Open source it and you'll get Qt5/Qt6 backend for free on all platforms where Qt lcl works: linux, mac, win, amiga ...

I'll get to that, the only issue is neither Qt5Pas or Qt6Pas6 have QSvgRenderer, which will be required for SVG rendering.

I might just submit a patch for Lazarus with that, otherwise maybe fallback to librsvg, which should be present in most distros.

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #11 on: March 17, 2026, 09:26:21 am »
In that case, qt6 only, I'm not willing to change bindings for Qt5 since it is EOL, but anyway, QSvgRenderer can be added into it's own unit, so won't kill current lazarus users so they must rebuild C bindings. In a few years when distros update bindings then such unit can be merged to the qt62.pas

domasz

  • Hero Member
  • *****
  • Posts: 625
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #12 on: March 17, 2026, 09:52:15 am »
Looks interesting. When you open source you might get:
- bug reports
- fixes
- new features
- fame ;)
It seems it beats THtmlViewer so billions of programmers who use THtmlViewer might want to switch to your Pixie.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1945
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #13 on: March 17, 2026, 11:35:45 am »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
Re: Lightweight HTML/CSS rendering engine written in pure Free Pascal
« Reply #14 on: March 17, 2026, 11:57:14 am »
It seems it beats THtmlViewer so billions of programmers who use THtmlViewer might want to switch to your Pixie.
Maybe not billions!  :)
Anyway, how does it compare speed-wise to THtmlViewer and TurboPowerIPro?
At least TurboPowerIPro is slow because it creates and frees a huge amount of objects.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018