vidstige / NRasterizer

OpenType parser in pure c#
Apache License 2.0
39 stars 11 forks source link

Expose font name & provided variants/features on the Typeface class #41

Open tocsoft opened 7 years ago

tocsoft commented 7 years ago

Typeface doesn't expose any information about whats inside the font.

Typeface should be extended to expose the font name, and any/all capabilities the font provides.

I'm thinking an API a bit like this could work nicely.

var typeface = reader.Read(stream);
var raterizer = new GlyphRasterizer(target);

if(typeface.KerningAvalible)
{
    var options = new RendererOptions(){
        Size = 30,
        Resolution = 72  // possibly should just be a sensible default inside the renderer???
        ApplyKerning = true // should this be opt-in or out?
    };
    var renderer = new Renderer(typeface, raterizer, options)
    renderer.Render(10, 20, "Hello\nWorld"); // render across 2 lines with kerning applied
}

if(typeface.Weights.Contains(FontWeights.Bold))
{
    var options = new RendererOptions(){
        Size = 30,
        Resolution = 72  // possibly should just be a sensible default inside the renderer???
        Weight = FontWeights.Bold
    };
    var renderer = new Renderer(typeface, raterizer, options)
    renderer.Render(10, 20, "Hello World"); //will render in Bold if availible otherwise Regular
}
vidstige commented 7 years ago

Great idea :+1: