// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Text;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
///
/// Adds extensions that allow the drawing of text to the type.
///
public static class DrawTextExtensions
{
///
/// Draws the text onto the the image filled via the brush.
///
/// The image this method extends.
/// The text.
/// The font.
/// The color.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
string text,
Font font,
Color color,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, color, location);
///
/// Draws the text onto the the image filled via the brush.
///
/// The image this method extends.
/// The options.
/// The text.
/// The font.
/// The color.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextGraphicsOptions options,
string text,
Font font,
Color color,
PointF location) =>
source.DrawText(options, text, font, Brushes.Solid(color), null, location);
///
/// Draws the text onto the the image filled via the brush.
///
/// The image this method extends.
/// The text.
/// The font.
/// The brush.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
string text,
Font font,
IBrush brush,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, location);
///
/// Draws the text onto the the image filled via the brush.
///
/// The image this method extends.
/// The options.
/// The text.
/// The font.
/// The brush.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextGraphicsOptions options,
string text,
Font font,
IBrush brush,
PointF location) =>
source.DrawText(options, text, font, brush, null, location);
///
/// Draws the text onto the the image outlined via the pen.
///
/// The image this method extends.
/// The text.
/// The font.
/// The pen.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
string text,
Font font,
IPen pen,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, pen, location);
///
/// Draws the text onto the the image outlined via the pen.
///
/// The image this method extends.
/// The options.
/// The text.
/// The font.
/// The pen.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextGraphicsOptions options,
string text,
Font font,
IPen pen,
PointF location) =>
source.DrawText(options, text, font, null, pen, location);
///
/// Draws the text onto the the image filled via the brush then outlined via the pen.
///
/// The image this method extends.
/// The text.
/// The font.
/// The brush.
/// The pen.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
string text,
Font font,
IBrush brush,
IPen pen,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location);
///
/// Draws the text using the default resolution of 72dpi onto the the image filled via the brush then outlined via the pen.
///
/// The image this method extends.
/// The options.
/// The text.
/// The font.
/// The brush.
/// The pen.
/// The location.
///
/// The .
///
public static IImageProcessingContext DrawText(
this IImageProcessingContext source,
TextGraphicsOptions options,
string text,
Font font,
IBrush brush,
IPen pen,
PointF location) =>
source.ApplyProcessor(new DrawTextProcessor(options, text, font, brush, pen, location));
}
}