A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
888 B

namespace Perspex.Windows.Media
{
using Perspex.Media;
using SharpDX.DirectWrite;
public class TextService : ITextService
{
private Factory factory;
public TextService(Factory factory)
{
this.factory = factory;
}
public static TextFormat Convert(Factory factory, FormattedText text)
{
return new TextFormat(
factory,
text.FontFamilyName,
(float)text.FontSize);
}
public Size Measure(FormattedText text)
{
TextFormat f = Convert(this.factory, text);
TextLayout layout = new TextLayout(this.factory, text.Text, f, float.MaxValue, float.MaxValue);
return new Size(
layout.Metrics.WidthIncludingTrailingWhitespace,
layout.Metrics.Height);
}
}
}