// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors.Text
{
///
/// Defines a processor to draw text on an .
///
public class DrawTextProcessor : IImageProcessor
{
///
/// Initializes a new instance of the class.
///
/// The options
/// The text we want to render
/// The font we want to render with
/// The brush to source pixel colors from.
/// The pen to outline text with.
/// The location on the image to start drawing the text from.
public DrawTextProcessor(TextGraphicsOptions options, string text, Font font, IBrush brush, IPen pen, PointF location)
{
Guard.NotNull(text, nameof(text));
Guard.NotNull(font, nameof(font));
if (brush is null && pen is null)
{
throw new ArgumentNullException($"Expected a {nameof(brush)} or {nameof(pen)}. Both were null");
}
this.Options = options;
this.Text = text;
this.Font = font;
this.Location = location;
this.Brush = brush;
this.Pen = pen;
}
///
/// Gets the brush used to fill the glyphs.
///
public IBrush Brush { get; }
///
/// Gets the defining blending modes and text-specific drawing settings.
///
public TextGraphicsOptions Options { get; }
///
/// Gets the text to draw.
///
public string Text { get; }
///
/// Gets the pen used for outlining the text, if Null then we will not outline
///
public IPen Pen { get; }
///
/// Gets the font used to render the text.
///
public Font Font { get; }
///
/// Gets the location to draw the text at.
///
public PointF Location { get; }
///
public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle)
where TPixel : struct, IPixel
=> new DrawTextProcessor(configuration, this, source, sourceRectangle);
}
}