Rasmus.krats.se

Reminiscing this and that, on the web since 1995

StyleScript

Published tagged , , , .

An open-source HTML / SGML printer that uses CSS2.

Update :

StyleScript is dead, viva Passepartout

I havn't touched StyleScript in quite a while. But I have taken what I learned here and gone on to Passepartout, which in its xml2ps part contains a much nicer and cleaner XML typesetting engine.

Update :

Rewritten the inline content rendering. Now I have a real model with inline boxes that can contain inline boxes (previously I faked it).

Update :

Fixed some of the todo things, modified this page accordingly.

Update :

Updated this page to include what StyleScript misses from the CSS1 spec.

Update :

Added an install target and support for finding needed files relative to a prefix (given at compile time). Reorganized some of the source into subdirectories.

Update : Development on stylescript started.

StyleScript reads a HTML / SGML file, local or from an URL, and writes a Postscript file. I use the sp library, so only files that names a dtd and conforms to it is supported. If your document passes the W3C validator without errors, it should be printable.

Rare features

So why not simply use the 'print' facility in the browser (e.g. Netscape navigator)? It lacks some things that I think are essential to print documents well. Here are some rare features of StyleScript:

  • In StyleScript, the section about page breaks in the CSS2 proposed recommendation is implemented.

  • The attribute LANG is usually ignored. I use it to set the language of auto-generated text (e.g. date) and in future versions I will use it for automatic hyphenation.

  • The entity ­ is typically rendered identical to the character '-', but it should be rendered as a hyphenation point. StyleScript (and lynx) does the right thing™.

Get the source

Actually, StyleScript is not quite open-source yet, but it soon will be. I have the source in CVS, but it is not yet possible to access it anonymously. I hope that this will change soon ... Later, when it is more functional, there will be distributions as well, but probably not before the summer.

If you are interested in taking part of the development, mail me at so I can make a source distribution (if you don't mail me, there will be a source distribution eventually, but you'll have to wait longer for it).

Required packages

netpbm

For translating bitmap images of miscellaneous formats to postscript.

ghostscript

For creating font metrics (afm files) from fonts

sp

For parsing the sgml input files.

A C++ compiler

Since it's written in C++. StyleScript requires some standard features such as dynamic_cast, exceptions, and templates. gcc 2.95.2 is ok, gcc 2.8.x or earlier is not ok.

Things left to do

This page is not complete yet, but on the other hand, StyleScript itself isn't nearly complete ... Here are a few things remaining to do in the program.

Required for CSS1 core

Ok, this is a rather long list. But I think that the fact that I actually have this list makes StyleScript better than most of the alternatives ...

2.1

Anchor pseudo-classes (link, visited, active) is not supported. They should probably be handled as identical anyway, but A:link should be different from just A.

3.1

The !important tag on rules is not supported.

3.2

Stylistic HTML elements should have lower weight than 'style'. Those I support is treated as same weight as 'style' attributes. On the other hand, support for them is optional in the first place, so I might just drop it.

4

Space should be reserved for border widths. I take half of it from the margin and half from the padding (i.e. I just draw the border, at specified width, without reserving space for it).

4.1.1

Margins should collapse in a more complicated manner than what I use. I'll check what CSS2 says before I do anything about this.

4.1.2

If both margins are 'auto', they should get half the available space each. I don't do this yet.

4.1.4 / 5.5.25 - 26

Float is not supported at all.

4.4 / 5.4.8

The 'line-height' property is not supported.

5.2.1

I don't do font matching per glyph yet.

5.2.2

Whitespace / quotes in 'font-family' is probably not handled correctly. Also, there seem to be a bug in handling a 'font-family' list with more than one generic name.

5.2.4

The 'font-variant' property is not supported yet.

5.2.5

Only 'medium' and 'bold' is supported for 'font-weight'.

5.2.7

The 'font' shorthand is not supported.

5.4.4

The 'vertical-align' property is not completely supported in all cases.

5.6.3 - 6

The 'list-style', 'list-style-type', 'list-style-image', and 'list-style-position' properties is not supported (I just use plain discs).

Advanced CSS support

2.2

:first-line, :first-letter pseudo-classes.

5.3.5

'background-attachment' not implemented. Actually, this breaks core support as well, since the rule background: url(foo.png) fixed will be completely ignored.

5.4.1

'word-spacing' not supported.

5.4.5

'text-transform' not supported.

5.5.17

'border-style' only 'none' / 'solid' supported.

Misc

Links

I use footnotes for link URIs. Make this styleable, just like the :before and :after generated content.

Making the footnotes styleable would also make it possible to do more advanced stuff (like see foo on page 17), provided there was some way of getting the page numbers, heading contents, etc from the link target ... It should also be possible to disable the footnote and use a :after (or nothing) instead.

There is a bug in local links, the filename is dropped (#foo becomes site/dir/#foo rather than site/dir/file#foo).

Images

I don't handle transparency in gifs yet, and only fake transparency for pngs (I find a background color and use that for transparent areas).

Font maps

StyleScript currently uses a hard-coded font map. It would probably be best if it could read the same Fontmap files as ghostscript.

Generated content

I do support some generated content for :before and :after, but no counters, so I handle <Q> fine (which most browsers don't) but I don't handle a <OL> different from a <UL> (which most browsers do).

Tables

Currently, <TD> is treated as inline and <TR> as block.

Other stuff
  • A lot of other minor—and not so minor—stuff needs to be fixed.

  • Sort by specificity before matching.

  • class/id selectors cannot begin with digits

  • Borders on inline elements.

  • Negative 'font-size' should be ignored.

  • Repeated bg imgs should tile in all directions

See also ...

If you want something that already works, although with limited CSS support, take a look at html2ps by Jan Kärrman.

Write a comment

Your name (or pseudonym).

Not published, except as gravatar.

Your homepage / presentation.

No formatting, except that an empty line is interpreted as a paragraph break.