// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System; using System.Collections.Generic; using System.Numerics; using SixLabors.Fonts.Tables.AdvancedTypographic; using SixLabors.Fonts.Unicode; namespace SixLabors.Fonts { /// /// Provides configuration options for rendering and shaping text. /// public class TextOptions { private float dpi = 72F; private float lineSpacing = 1F; private Font? font; /// /// Initializes a new instance of the class. /// /// The font. public TextOptions(Font font) => this.Font = font; /// /// Initializes a new instance of the class from properties /// copied from the given instance. /// /// The options whose properties are copied into this instance. public TextOptions(TextOptions options) { this.Font = options.Font; this.FallbackFontFamilies = new List(options.FallbackFontFamilies); this.TabWidth = options.TabWidth; this.HintingMode = options.HintingMode; this.Dpi = options.Dpi; this.LineSpacing = options.LineSpacing; this.Origin = options.Origin; this.WrappingLength = options.WrappingLength; this.MaxLines = options.MaxLines; this.WordBreaking = options.WordBreaking; this.TextEllipsis = options.TextEllipsis; this.CustomEllipsis = options.CustomEllipsis; this.TextHyphenation = options.TextHyphenation; this.CustomHyphen = options.CustomHyphen; this.TextDirection = options.TextDirection; this.TextBidiMode = options.TextBidiMode; this.TextInteractionMode = options.TextInteractionMode; this.TextAlignment = options.TextAlignment; this.TextJustification = options.TextJustification; this.HorizontalAlignment = options.HorizontalAlignment; this.VerticalAlignment = options.VerticalAlignment; this.LayoutMode = options.LayoutMode; this.KerningMode = options.KerningMode; this.Tracking = options.Tracking; this.ColorFontSupport = options.ColorFontSupport; this.FeatureTags = new List(options.FeatureTags); this.TextRuns = new List(options.TextRuns); this.DecorationPositioningMode = options.DecorationPositioningMode; } /// /// Gets or sets the font. /// public Font Font { get => this.font!; set { Guard.NotNull(value, nameof(this.Font)); this.font = value; } } /// /// Gets or sets the collection of fallback font families to use when /// a specific glyph is missing from . /// public IReadOnlyList FallbackFontFamilies { get; set; } = Array.Empty(); /// /// Gets or sets the DPI (Dots Per Inch) to render/measure the text at. /// /// Defaults to 72F. /// public float Dpi { get => this.dpi; set { Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Dpi)); this.dpi = value; } } /// /// Gets or sets the width of the tab. Measured as the distance in spaces (U+0020). /// /// /// If value is -1 then the font default tab width is used. /// public float TabWidth { get; set; } = -1F; /// /// Gets or sets a value indicating whether to apply hinting - The use of mathematical instructions /// to adjust the display of an outline font so that it lines up with a rasterized grid. /// public HintingMode HintingMode { get; set; } /// /// Gets or sets the line spacing. Applied as a multiple of the line height. /// /// Defaults to 1F. /// public float LineSpacing { get => this.lineSpacing; set { Guard.IsTrue(value != 0, nameof(this.LineSpacing), "Value must not be equal to 0."); this.lineSpacing = value; } } /// /// Gets or sets the rendering origin. /// public Vector2 Origin { get; set; } = Vector2.Zero; /// /// Gets or sets the length in pixel units (px) at which text will automatically wrap onto a new line. /// This property also affects the width or height (depending on the ) of the text box /// for alignment of text. /// /// /// If value is -1 then wrapping is disabled. /// public float WrappingLength { get; set; } = -1F; /// /// Gets or sets the maximum number of lines to lay out. /// /// /// If value is -1 then the number of lines is unlimited. /// public int MaxLines { get; set; } = -1; /// /// Gets or sets the word breaking mode to use when wrapping text. /// public WordBreaking WordBreaking { get; set; } /// /// Gets or sets the ellipsis behavior to use when laid-out text is limited to a maximum number of lines. /// public TextEllipsis TextEllipsis { get; set; } /// /// Gets or sets the ellipsis marker to use when is Custom. /// public CodePoint? CustomEllipsis { get; set; } /// /// Gets or sets the hyphenation marker behavior to use when text breaks at hyphenation opportunities. /// public TextHyphenation TextHyphenation { get; set; } /// /// Gets or sets the hyphenation marker to use when is Custom. /// public CodePoint? CustomHyphen { get; set; } /// /// Gets or sets the text direction. /// public TextDirection TextDirection { get; set; } = TextDirection.Auto; /// /// Gets or sets how bidirectional text is resolved. /// public TextBidiMode TextBidiMode { get; set; } /// /// Gets or sets how caret movement and selection model trailing breaking whitespace. /// public TextInteractionMode TextInteractionMode { get; set; } /// /// Gets or sets the text alignment of the text within the box. /// public TextAlignment TextAlignment { get; set; } /// /// Gets or sets the justification of the text within the box. /// public TextJustification TextJustification { get; set; } /// /// Gets or sets the horizontal alignment of the text box. /// public HorizontalAlignment HorizontalAlignment { get; set; } /// /// Gets or sets the vertical alignment of the text box. /// public VerticalAlignment VerticalAlignment { get; set; } /// /// Gets or sets the layout mode for the text lines. /// public LayoutMode LayoutMode { get; set; } /// /// Gets or sets the kerning mode indicating whether to apply kerning (character spacing adjustments) /// to the glyph positions from information found within the font. /// public KerningMode KerningMode { get; set; } /// /// Gets or sets the tracking (letter-spacing) value. /// Tracking adjusts the spacing between all characters uniformly and is measured in em. /// Positive values increase spacing, negative values decrease spacing, and zero applies no adjustment. /// public float Tracking { get; set; } /// /// Gets or sets the positioning mode used for rendering decorations. /// public DecorationPositioningMode DecorationPositioningMode { get; set; } /// /// Gets or sets the color font support options. /// public ColorFontSupport ColorFontSupport { get; set; } = ColorFontSupport.ColrV1 | ColorFontSupport.ColrV0 | ColorFontSupport.Svg; /// /// Gets or sets the collection of additional feature tags to apply during glyph shaping. /// public IReadOnlyList FeatureTags { get; set; } = Array.Empty(); /// /// Gets or sets an optional collection of text runs to apply to the body of text. /// public IReadOnlyList TextRuns { get; set; } = Array.Empty(); } }