As I've posted before, I'm using libCSS in an ebook/ePub rendering project
('libEucalyptus'). I've recently come across the need to parse @font-face
rules.
Attached is a patch that does this, following (or attempting to :-) the CSS 3 spec. It
extends the parser to parse font-face rules (which use a slightly different grammar to the
regular CSS, of course...), and adds support to the selection engine to query font-faces
by family name. The support is limited - at the moment it supports 'src:',
'font-family:', 'font-style', and 'font-weight:' rules. It should
be fairly easily extensible to the other font-face directives in the future (unicode-range
etc.).
When parsing, it 'correctly' handles other unsupported directives by ignoring
them. I've tried to keep the font-face handling well compartmentalised into its own
files, although I have extended a couple of the parsing util routines where I thought that
made sense.
On the selection side, for the client, the new css_select_font_faces function will take a
font family name and media and provide a list of font-face results that specify the
font-faces that match. I've deliberately not tried to filter this list further than
by family name and doing some sorting by specificity, so that the user agent can apply its
own logic to the font selection and fallback This logic is - mostly - specified in the
CSS spec, of course, but it's rather vague places, but more importantly also depends
so much on installed fonts and OS capabilities in rendering that I thought it best to
leave it to the client.
I hope the patch meets with approval. Criticism and changes are appreciated, and I'm
very happy to receive constructive feedback (or bug fixes :-). While I am using this in
its current state in a product now, I would very much like to keep my libCSS unforked -
and I hope this will also be useful to others in the future.
Thanks,
Jamie.