AuburnSounds / printed

Generate PDF/SVG/HTML with D, with a Canvas-style API. Now with a flow document emitter.
36 stars 7 forks source link

Make font embedding optional in SVG and HTML #35

Closed a-ludi closed 3 years ago

a-ludi commented 3 years ago

Hi Guillaume,

this is my appraoch to making the embedding of fonts optional in SVG (and consequently HTML). I don't really mind if you include this into the main repo, I just wanted to share it for reference and dicussion.

Maybe there is a better API for this? Since the font should probably be always embedded in PDF, I would keep this feature out of IRenderingContext2D. Another approach for a standardized API could be to define a separated interface that renderes MAY implement:

/// Describes an interface for renderers supporting system fonts. These
/// renderers may be instructed to skip font embedding and use the lcoal
/// system fonts instead.
interface SystemFontRenderer
{
    /// Enable/disable font embedding.
    void setFontEmbedding(bool enable);

    /// Get the state of font embedding.
    bool getFontEmbedding();

    /// Subclasses may support providing alternative sources for fonts
    /// that are unavailable on the current system. The `source` must be
    /// provided in the same format as CSS `@font-face` rules. Multiple values
    /// may be provided either by multiple calls to this methods or as a
    /// comma-separated string.
    /// 
    /// See_also: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src
    void addFontSource(string source);
}
p0nce commented 3 years ago

Hello, I'm a bit busy right now, I will have time to review this starting 7th July.

p0nce commented 3 years ago

Hello SVG without font embeds is implemented in printed v1.1.0

To enable:

RenderOptions options;
options.embedFonts = false;
auto svgDoc = new SVGDocument(210, 297, options);
p0nce commented 3 years ago

There is a new example for this https://github.com/AuburnSounds/printed/blob/master/examples/renderer-specific-features/source/app.d