Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-03

Is there a CSS parser in FPC?

11 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

As the subject says, I would like to know if there is a CSS parser included with FPC (2.6.4 or Trunk)? No issue if there isn't, as I might not initially need one for the project I want to start - but looking around in the mean time wouldn't hurt.

I'm thinking of writing a couple of articles documenting a pet project I have been meaning to do for some time. Writing a "toy" web browser engine. I don't think many people actually know what is involved in a browser engine, or the rendering pipeline. So documenting the process from scratch should be a good learning experience for many (myself included). I want to initially limit as much dependencies as possible, and obviously simplify it for the articles, but at the same time make it so various rasterizers (AggPas, OpenGL, fpGUI Canvas, LCL Canvas, Image file output etc) can be plugged in for the final output.

What's your thoughts? Who knows, this project might even grow to become something useful for fpGUI or LCL based apps. But that is far down the road for now.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 6 lines
Hi, As the subject says, I would like to know if there is a CSS parser included with FPC (2.6.4 or Trunk)? No issue if there isn't, as I might not initially need one for the project I want to start - but looking around in the mean time wouldn't hurt.

FPC doesn't contain one, but I would be glad to put one in the source tree.

Show quoted text 13 lines
I'm thinking of writing a couple of articles documenting a pet project I have been meaning to do for some time. Writing a "toy" web browser engine. I don't think many people actually know what is involved in a browser engine, or the rendering pipeline. So documenting the process from scratch should be a good learning experience for many (myself included). I want to initially limit as much dependencies as possible, and obviously simplify it for the articles, but at the same time make it so various rasterizers (AggPas, OpenGL, fpGUI Canvas, LCL Canvas, Image file output etc) can be plugged in for the final output. What's your thoughts? Who knows, this project might even grow to become something useful for fpGUI or LCL based apps. But that is far down the road for now.

Presumably the HTML browser of TurboPower IP included in lazarus has a CSS parser. Maybe you can have a .

Graeme Geldenhuys
to Michael Van Canneyt: FPC doesn't contain one, but I would be glad to put one in the source tree. Presumably…
Michael Van Canneyt wrote
FPC doesn't contain one, but I would be glad to put one in the source tree.

Thanks for the info. Closer to the time I'll let you know so you can decide if the code is worthy of finding a home in FCL. ;-)

Presumably the HTML browser of TurboPower IP included in lazarus has a CSS parser. Maybe you can have a (1 & 2 at least) actually seem a lot easier to parse that

HTML. I'll take a look, but probably just roll my own.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Graeme Geldenhuys
to Unknown author: you might also want to take a look at https://code.google.com/p/thtmlviewer It's still…
you might also want to take a look at https://code.google.com/p/thtmlviewer

Thanks for the info. I see it is a descendant of PBear.com code. I remember using that back in 1998. :)

It's still actively developed, so the CSS parser should be more advanced than the one of TurboPower IP.

I took a quick look at the code in general and was truly disappointed. Quick examples:

===========[HtmlImages.pas]====================
uses
{$ifdef LCL}
LclIntf, IntfGraphics, FpImage, LclType, LResources, LMessages, HtmlMisc, {$else}
Windows, Jpeg,
{$endif}
SysUtils, Classes, Graphics, Forms,
Controls,
===============================

...or...

===========[HTMLSubs.pas]====================
uses
{$ifdef UseInline}
HtmlCaches,
{$endif}
{$ifdef VCL}
Windows,

  {$ifndef Compiler28_Plus}
  EncdDecd,
  {$endif}

{$endif}
Messages, Graphics, Controls, ExtCtrls, Classes, SysUtils, Variants, Forms, Math, Contnrs, ComCtrls,
{$ifdef LCL}
LclIntf, LclType, HtmlMisc, types,
{$endif}
HtmlGlobals,
===============================

...or...

===========[ReadHTML.pas]====================
uses
{$ifdef LCL}
LclIntf, LclType, HtmlMisc,
{$else}
Windows,
{$endif}
SysUtils, Math, Variants, Classes, Graphics, Controls, Contnrs, HtmlGlobals,
===============================

Those dependencies are crazy! LCLIntf, Forms, Graphics, Controls, Windows (???) all in a unit that just reads and parses HTML. Wow.

Sadly TurboPower IP doesn't look any better - at least the version included with Lazarus.

My plan is to develop a 100% non-GUI-toolkit-dependent browser engine, which is 100% doable. The only (optional) GUI toolkit dependency would be the rasterizer integration for LCL or fpGUI - the last step in the engine pipeline. But if you render to an image file for example (via FPImage or AggPas), their would be no GUI toolkit dependency.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Dmitry Boyarintsev
to Graeme Geldenhuys

On Tue, Mar 3, 2015 at 12:55 PM, Graeme Geldenhuys <

Show quoted text 7 lines
wrote: My plan is to develop a 100% non-GUI-toolkit-dependent browser engine, which is 100% doable. The only (optional) GUI toolkit dependency would be the rasterizer integration for LCL or fpGUI - the last step in the engine pipeline.

Can it be the last step? You need to get font information somehow for text measurements, which should come from the "underlying" GUI toolkit only. I can understand that you'd create some sort of wrapper class (that would be implemented by a gui toolkit), but I doubt it could be done as the actual last step.

thanks,
Dmitry

Graeme Geldenhuys
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote
Can it be the last step? You need to get font information somehow for text measurements, which should come from the "underlying" GUI toolkit only.

Yes, and no problem either. FreeType (library or Object Pascal implementation) doesn't require a GUI toolkit. Well, the library for sure, I'll have to double check the Object Pascal implementation. eg: I use AggPas with the FreeType text renderer to generate images of graphs with text via a CGI or console app. 100% non GUI.

For example:
http://fpgui.sourceforge.net/images/full/fpgui_agg-powered.png

Other than displaying that image (one image the full size of the window) via fpGUI - the actual content of the image can be done 100% via a console app using AggPas.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Dmitry Boyarintsev
to Graeme Geldenhuys

On Tue, Mar 3, 2015 at 1:09 PM, Graeme Geldenhuys <

Show quoted text 5 lines
wrote: Yes, and no problem either. FreeType (library or Object Pascal implementation) doesn't require a GUI toolkit.

Hmm. I didn't consider that as an option.
Ok, can it handle complex scripts languages such as Arabic or Hindi?

thanks,
Dmitry

Graeme Geldenhuys
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote
Ok, can it handle complex scripts languages such as Arabic or Hindi?

FreeText is the primary text renderer for X11. So if Linux can display such text, then I guess it answers your question. ;-)

The primary goal of this project is to document how a browser engine works. During the writing of the articles I'll implement basic block layout and text rendering. CSS rules will be the primary method of sizing, positioning. I'll also implement some CSS rules to manipulate DIV and text attributes (font and color (including alpha support). I'll probably use AggPas as the reference implementation of a rasterizer. This should conclude what I want to accomplish.

What happens then... I don't know yet. :) Maybe tackle the http://css3test.com/ test suite. :-P

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/
Andrew Haines
to Graeme Geldenhuys: As the subject says, I would like to know if there is a CSS parser included with FPC…
Graeme Geldenhuys wrote 24 lines
Hi, As the subject says, I would like to know if there is a CSS parser included with FPC (2.6.4 or Trunk)? No issue if there isn't, as I might not initially need one for the project I want to start - but looking around in the mean time wouldn't hurt. I'm thinking of writing a couple of articles documenting a pet project I have been meaning to do for some time. Writing a "toy" web browser engine. I don't think many people actually know what is involved in a browser engine, or the rendering pipeline. So documenting the process from scratch should be a good learning experience for many (myself included). I want to initially limit as much dependencies as possible, and obviously simplify it for the articles, but at the same time make it so various rasterizers (AggPas, OpenGL, fpGUI Canvas, LCL Canvas, Image file output etc) can be plugged in for the final output. What's your thoughts? Who knows, this project might even grow to become something useful for fpGUI or LCL based apps. But that is far down the road for now. Regards, - Graeme -

As Michael said the turbopower ipro component has a css parser. It was added for lazarus/lhelp and wasn't part of the original ipro component so it's mostly separated from ipro.
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/turbopower_ipro/ipcss.inc?view=markup&revision=44873&root=lazarus

Regards,

Andrew Haines

Graeme Geldenhuys
to Andrew Haines
Andrew Haines wrote
It was added for lazarus/lhelp and wasn't part of the original ipro component so it's mostly separated from ipro.

Thank you Andrew. I'll take a second look.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/