// ----------------------------------------------------------------------- // // Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Media { using System; using System.Collections.Generic; using Perspex.Platform; using Splat; /// /// Represents a piece of text with formatting. /// public class FormattedText : IDisposable { /// /// Initializes a new instance of the class. /// /// The text. /// The font family. /// The font size. /// The font style. /// The text alignment. /// The font weight. public FormattedText( string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { this.Text = text; this.FontFamilyName = fontFamilyName; this.FontSize = fontSize; this.FontStyle = fontStyle; this.FontWeight = fontWeight; this.TextAlignment = textAlignment; var platform = Locator.Current.GetService(); this.PlatformImpl = platform.CreateFormattedText( text, fontFamilyName, fontSize, fontStyle, textAlignment, fontWeight); } /// /// Gets or sets the constraint of the text. /// public Size Constraint { get { return this.PlatformImpl.Constraint; } set { this.PlatformImpl.Constraint = value; } } /// /// Gets the font family. /// public string FontFamilyName { get; private set; } /// /// Gets the font size. /// public double FontSize { get; private set; } /// /// Gets the font style. /// public FontStyle FontStyle { get; private set; } /// /// Gets the font weight. /// public FontWeight FontWeight { get; private set; } /// /// Gets the text. /// public string Text { get; private set; } /// /// Gets platform-specific platform implementation. /// public IFormattedTextImpl PlatformImpl { get; private set; } /// /// Gets the text alignment. /// public TextAlignment TextAlignment { get; private set; } /// /// Disposes of unmanaged resources associated with the formatted text. /// public void Dispose() { this.PlatformImpl.Dispose(); } /// /// Gets the lines in the text. /// /// /// A collection of objects. /// public IEnumerable GetLines() { return this.PlatformImpl.GetLines(); } /// /// Hit tests a point in the text. /// /// The point. /// /// A describing the result of the hit test. /// public TextHitTestResult HitTestPoint(Point point) { return this.PlatformImpl.HitTestPoint(point); } /// /// Gets the bounds rectangle that the specified character occupies. /// /// The index of the character. /// The character bounds. public Rect HitTestTextPosition(int index) { return this.PlatformImpl.HitTestTextPosition(index); } /// /// Gets the bounds rectangles that the specified text range occupies. /// /// The index of the first character. /// The number of characters in the text range. /// The character bounds. public IEnumerable HitTestTextRange(int index, int length) { return this.PlatformImpl.HitTestTextRange(index, length); } /// /// Gets the size of the text, taking into account. /// /// The bounds box of the text. public Size Measure() { return this.PlatformImpl.Measure(); } /// /// Sets the foreground brush for the specified text range. /// /// The brush. /// The start of the text range. /// The length of the text range. public void SetForegroundBrush(Brush brush, int startIndex, int length) { this.PlatformImpl.SetForegroundBrush(brush, startIndex, length); } } }