// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System;
namespace SixLabors.Fonts.Rendering {
///
/// Encapsulates logic for laying out and then rendering text to a surface.
///
public class TextRenderer
{
private readonly IGlyphRenderer renderer;
///
/// Initializes a new instance of the class.
///
/// The renderer.
public TextRenderer(IGlyphRenderer renderer) => this.renderer = renderer;
///
/// Renders the text to the .
///
/// The target renderer.
/// The text to render.
/// The text options. controls wrapping; use -1 to disable wrapping.
public static void RenderTextTo(IGlyphRenderer renderer, ReadOnlySpan text, TextOptions options)
=> new TextRenderer(renderer).RenderText(text, options);
///
/// Renders the text to the .
///
/// The target renderer.
/// The text to render.
/// The text options. controls wrapping; use -1 to disable wrapping.
public static void RenderTextTo(IGlyphRenderer renderer, string text, TextOptions options)
=> new TextRenderer(renderer).RenderText(text, options);
///
/// Renders the text to the configured renderer.
///
/// The text to render.
/// The text options. controls wrapping; use -1 to disable wrapping.
public void RenderText(string text, TextOptions options)
=> this.RenderText(text.AsSpan(), options);
///
/// Renders the text to the configured renderer.
///
/// The text to render.
/// The text options. controls wrapping; use -1 to disable wrapping.
public void RenderText(ReadOnlySpan text, TextOptions options)
{
TextBlock block = new(text, options);
block.RenderTo(this.renderer, options.WrappingLength);
}
}
}