Hi,
I think it would be nice if font declarations in the html were automatically handled by flying saucer when creating a PDF instead of having to add fonts explicitly to the renderer.
I looked for a way to hook in such handling, similar to how we can add a ReplacedElementFactory e.g. to deal with e.g. SVG content but did not find a way so i ended up pre-parsing the html and add the fonts specified in all @font-face declarations.
It would be nice if this was supported out of the box though.
Do you think it would be a good idea to add the ability to add style sheet rule actions e.g:
renderer.addStyleSheetRuleListener("@font-face", ruleListener)
where a ruleListener would be something like:
public interface StyleSheetRuleListener {
void onRule(Properties ruleProperties);
}
This would enable a user to do any type of action (such as adding a font) based on the style rules.
Given an html with the following font declaration:
```html
<style>
@font-face {
font-family: "Jersey 25";
src: url(file:///usr/local/fonts/Jersey25-Regular.ttf);
}
```
The rule action would be called once with the Properties object containing two properties (one for the font-family and one for the src)
This would have to happen before layout() though (e.g. in . setDocumentFromString) When i tried to add handling code in the ReplacedElementFactory it was too late (the font was not rendered properly).
An alternative to this approach would be to add a configuration option e.g:
var cfg = new Configuration(Configuration.VERSION_2_3_32);
cfg.setAddCssDeclaredFonts(true);
... and handle the font additions without the user having to to anything else.
What do you think?
Regards,
Per