Pretext.Contracts makes the measurement layer pluggable. A custom backend only needs to measure text widths for a parsed font descriptor and advertise a factory to the core engine.
Pretext to another renderer or platform text APIImplement:
IPretextTextMeasurerIPretextTextMeasurerFactoryAdvertise the factory at assembly level:
[assembly: PretextTextMeasurerFactory(typeof(MyTextMeasurerFactory))]
PretextFontParser.Parse(font).PretextFontDescriptor to the host font API.IsSupported according to the current runtime.Priority that makes sense beside the first-party backends.using Pretext;
public sealed class MyTextMeasurerFactory : IPretextTextMeasurerFactory
{
public string Name => "MyBackend";
public bool IsSupported => true;
public int Priority => 50;
public IPretextTextMeasurer Create(string font)
{
var descriptor = PretextFontParser.Parse(font);
return new MyTextMeasurer(descriptor);
}
}
public sealed class MyTextMeasurer : IPretextTextMeasurer
{
public MyTextMeasurer(PretextFontDescriptor descriptor)
{
Descriptor = descriptor;
}
public PretextFontDescriptor Descriptor { get; }
public double MeasureText(string text)
{
// Call into the host text API here.
throw new NotImplementedException();
}
public void Dispose()
{
}
}
0 if your backend should beat the SkiaSharp fallback