csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
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.
39 lines
1.2 KiB
39 lines
1.2 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="TextService.cs" company="Steven Kirk">
|
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Direct2D1
|
|
{
|
|
using Perspex.Media;
|
|
using Perspex.Platform;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|