|
|
@ -1,22 +1,20 @@ |
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
|
using System.Numerics; |
|
|
|
|
|
using SixLabors.Fonts; |
|
|
using SixLabors.Fonts; |
|
|
using SixLabors.ImageSharp.Drawing; |
|
|
|
|
|
using SixLabors.ImageSharp.Drawing.Brushes; |
|
|
using SixLabors.ImageSharp.Drawing.Brushes; |
|
|
using SixLabors.ImageSharp.Drawing.Pens; |
|
|
using SixLabors.ImageSharp.Drawing.Pens; |
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
using SixLabors.ImageSharp.Processing; |
|
|
using SixLabors.ImageSharp.Processing.Overlays; |
|
|
using SixLabors.Primitives; |
|
|
using SixLabors.Primitives; |
|
|
using SixLabors.Shapes; |
|
|
using SixLabors.Shapes; |
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp |
|
|
namespace SixLabors.ImageSharp.Processing.Text |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|
|
/// Adds extensions that allow the drawing of text to the <see cref="Image{TPixel}"/> type.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static partial class ImageExtensions |
|
|
public static partial class DrawTextExtensions |
|
|
{ |
|
|
{ |
|
|
private static readonly int DefaultTextDpi = 72; |
|
|
private static readonly int DefaultTextDpi = 72; |
|
|
|
|
|
|
|
|
@ -33,10 +31,8 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, color, location, TextGraphicsOptions.Default); |
|
|
return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image filled via the brush.
|
|
|
/// Draws the text onto the the image filled via the brush.
|
|
|
@ -52,10 +48,8 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, Brushes.Solid(color), null, location, options); |
|
|
return source.DrawText(text, font, Brushes.Solid(color), null, location, options); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image filled via the brush.
|
|
|
/// Draws the text onto the the image filled via the brush.
|
|
|
@ -70,10 +64,8 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); |
|
|
return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image filled via the brush.
|
|
|
/// Draws the text onto the the image filled via the brush.
|
|
|
@ -89,10 +81,8 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location, TextGraphicsOptions options) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location, TextGraphicsOptions options) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, brush, null, location, options); |
|
|
return source.DrawText(text, font, brush, null, location, options); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image outlined via the pen.
|
|
|
/// Draws the text onto the the image outlined via the pen.
|
|
|
@ -107,10 +97,8 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); |
|
|
return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image outlined via the pen.
|
|
|
/// Draws the text onto the the image outlined via the pen.
|
|
|
@ -126,10 +114,8 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location, TextGraphicsOptions options) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location, TextGraphicsOptions options) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, null, pen, location, options); |
|
|
return source.DrawText(text, font, null, pen, location, options); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image filled via the brush then outlined via the pen.
|
|
|
/// Draws the text onto the the image filled via the brush then outlined via the pen.
|
|
|
@ -145,13 +131,11 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// The <see cref="Image{TPixel}" />.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, PointF location) |
|
|
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, PointF location) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
{ |
|
|
=> source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); |
|
|
return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Draws the text onto the the image filled via the brush then outlined via the pen.
|
|
|
/// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
|
/// <param name="source">The image this method extends.</param>
|
|
|
/// <param name="source">The image this method extends.</param>
|
|
|
@ -195,4 +179,4 @@ namespace SixLabors.ImageSharp |
|
|
return source; |
|
|
return source; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |