mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 454 additions and 182 deletions
@ -0,0 +1,200 @@ |
|||
// <copyright file="DrawText.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
using Drawing; |
|||
using Drawing.Brushes; |
|||
using Drawing.Pens; |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Fonts; |
|||
using SixLabors.Shapes; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Draws the text onto the the image filled via the brush.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, IPath path) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image filled via the brush.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="color">The color.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <param name="options">The options.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, Brushes.Solid(color), null, path, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image filled via the brush.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="path">The location.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPath path) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image filled via the brush.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <param name="options">The options.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPath path, TextGraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, brush, null, path, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image outlined via the pen.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="pen">The pen.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IPen<TPixel> pen, IPath path) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image outlined via the pen.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="pen">The pen.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <param name="options">The options.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IPen<TPixel> pen, IPath path, TextGraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, null, pen, path, options); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image filled via the brush then outlined via the pen.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="pen">The pen.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, IPath path) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the text onto the the image filled via the brush then outlined via the pen.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
/// <param name="font">The font.</param>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="pen">The pen.</param>
|
|||
/// <param name="path">The path.</param>
|
|||
/// <param name="options">The options.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Image{TPixel}" />.
|
|||
/// </returns>
|
|||
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, IPath path, TextGraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
Vector2 dpi = DefaultTextDpi; |
|||
if (options.UseImageResolution) |
|||
{ |
|||
dpi = new Vector2((float)source.MetaData.HorizontalResolution, (float)source.MetaData.VerticalResolution); |
|||
} |
|||
|
|||
var style = new FontSpan(font, dpi) |
|||
{ |
|||
ApplyKerning = options.ApplyKerning, |
|||
TabWidth = options.TabWidth, |
|||
WrappingWidth = options.WrapTextWidth, |
|||
HorizontalAlignment = options.HorizontalAlignment, |
|||
VerticalAlignment = options.VerticalAlignment |
|||
}; |
|||
|
|||
IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, path, style); |
|||
|
|||
var pathOptions = (GraphicsOptions)options; |
|||
if (brush != null) |
|||
{ |
|||
source.Fill(brush, glyphs, pathOptions); |
|||
} |
|||
|
|||
if (pen != null) |
|||
{ |
|||
source.Draw(pen, glyphs, pathOptions); |
|||
} |
|||
|
|||
return source; |
|||
} |
|||
} |
|||
} |
|||
@ -1,179 +0,0 @@ |
|||
|
|||
namespace ImageSharp.Tests.Drawing.Paths |
|||
{ |
|||
using System; |
|||
|
|||
using ImageSharp.Drawing.Brushes; |
|||
|
|||
using Xunit; |
|||
using ImageSharp.Drawing; |
|||
using System.Numerics; |
|||
using SixLabors.Shapes; |
|||
using ImageSharp.Drawing.Processors; |
|||
using ImageSharp.Drawing.Pens; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
public class DrawPathCollection : IDisposable |
|||
{ |
|||
float thickness = 7.2f; |
|||
GraphicsOptions noneDefault = new GraphicsOptions(); |
|||
Rgba32 color = Rgba32.HotPink; |
|||
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink); |
|||
Pen<Rgba32> pen = new Pen<Rgba32>(Rgba32.Gray, 99.9f); |
|||
IPath path1 = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { |
|||
new Vector2(10,10), |
|||
new Vector2(20,10), |
|||
new Vector2(20,10), |
|||
new Vector2(30,10), |
|||
})); |
|||
|
|||
IPath path2 = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { |
|||
new Vector2(10,10), |
|||
new Vector2(20,10), |
|||
new Vector2(20,10), |
|||
new Vector2(30,10), |
|||
})); |
|||
|
|||
IPathCollection pathCollection; |
|||
private ProcessorWatchingImage img; |
|||
|
|||
public DrawPathCollection() |
|||
{ |
|||
this.pathCollection = new PathCollection(this.path1, this.path2); |
|||
this.img = new Paths.ProcessorWatchingImage(10, 10); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
img.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CorrectlySetsBrushThicknessAndPath() |
|||
{ |
|||
img.Draw(brush, thickness, pathCollection); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
|
|||
for (var i = 0; i < 2; i++) |
|||
{ |
|||
DrawPathProcessor<Rgba32> processor = Assert.IsType<DrawPathProcessor<Rgba32>>(img.ProcessorApplications[i].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.Contains(shapepath.Path, this.pathCollection); |
|||
|
|||
Pen<Rgba32> pen = Assert.IsType<Pen<Rgba32>>(processor.Pen); |
|||
Assert.Equal(brush, pen.Brush); |
|||
Assert.Equal(thickness, pen.Width); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void CorrectlySetsBrushThicknessPathAndOptions() |
|||
{ |
|||
img.Draw(brush, thickness, pathCollection, noneDefault); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
|
|||
for (var i = 0; i < 2; i++) |
|||
{ |
|||
DrawPathProcessor<Rgba32> processor = Assert.IsType<DrawPathProcessor<Rgba32>>(img.ProcessorApplications[i].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.Contains(shapepath.Path, pathCollection); |
|||
|
|||
Pen<Rgba32> pen = Assert.IsType<Pen<Rgba32>>(processor.Pen); |
|||
Assert.Equal(brush, pen.Brush); |
|||
Assert.Equal(thickness, pen.Width); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void CorrectlySetsColorThicknessAndPath() |
|||
{ |
|||
img.Draw(color, thickness, pathCollection); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
for (var i = 0; i < 2; i++) |
|||
{ |
|||
DrawPathProcessor<Rgba32> processor = Assert.IsType<DrawPathProcessor<Rgba32>>(img.ProcessorApplications[i].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.Contains(shapepath.Path, pathCollection); |
|||
|
|||
Pen<Rgba32> pen = Assert.IsType<Pen<Rgba32>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void CorrectlySetsColorThicknessPathAndOptions() |
|||
{ |
|||
img.Draw(color, thickness, pathCollection, noneDefault); |
|||
|
|||
Assert.Equal(2, img.ProcessorApplications.Count); |
|||
for (var i = 0; i < 2; i++) |
|||
{ |
|||
DrawPathProcessor<Rgba32> processor = Assert.IsType<DrawPathProcessor<Rgba32>>(img.ProcessorApplications[i].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.Contains(shapepath.Path, pathCollection); |
|||
|
|||
Pen<Rgba32> pen = Assert.IsType<Pen<Rgba32>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void CorrectlySetsPenAndPath() |
|||
{ |
|||
img.Draw(pen, pathCollection); |
|||
|
|||
Assert.Equal(2, img.ProcessorApplications.Count); |
|||
for (var i = 0; i < 2; i++) |
|||
{ |
|||
DrawPathProcessor<Rgba32> processor = Assert.IsType<DrawPathProcessor<Rgba32>>(img.ProcessorApplications[i].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.Contains(shapepath.Path, pathCollection); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void CorrectlySetsPenPathAndOptions() |
|||
{ |
|||
img.Draw(pen, pathCollection, noneDefault); |
|||
|
|||
Assert.Equal(2, img.ProcessorApplications.Count); |
|||
for (var i = 0; i < 2; i++) |
|||
{ |
|||
DrawPathProcessor<Rgba32> processor = Assert.IsType<DrawPathProcessor<Rgba32>>(img.ProcessorApplications[i].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.Contains(shapepath.Path, pathCollection); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,251 @@ |
|||
// <copyright file="DrawText.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests.Drawing.Text |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
|
|||
using ImageSharp.Drawing; |
|||
using ImageSharp.Drawing.Brushes; |
|||
using ImageSharp.Drawing.Pens; |
|||
using ImageSharp.Drawing.Processors; |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Tests.Drawing.Paths; |
|||
|
|||
using SixLabors.Fonts; |
|||
using SixLabors.Shapes; |
|||
|
|||
using Xunit; |
|||
|
|||
public class DrawText_Path : IDisposable |
|||
{ |
|||
Rgba32 color = Rgba32.HotPink; |
|||
|
|||
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink); |
|||
|
|||
IPath path = new SixLabors.Shapes.Path( |
|||
new LinearLineSegment( |
|||
new Vector2[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), })); |
|||
|
|||
private ProcessorWatchingImage img; |
|||
|
|||
private readonly FontCollection FontCollection; |
|||
|
|||
private readonly Font Font; |
|||
|
|||
public DrawText_Path() |
|||
{ |
|||
this.FontCollection = new FontCollection(); |
|||
this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")); |
|||
this.img = new ProcessorWatchingImage(10, 10); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
this.img.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void FillsForEachACharachterWhenBrushSetAndNotPen() |
|||
{ |
|||
this.img.DrawText( |
|||
"123", |
|||
this.Font, |
|||
Brushes.Solid(Rgba32.Red), |
|||
null, |
|||
path, |
|||
new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void FillsForEachACharachterWhenBrushSet() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void FillsForEachACharachterWhenBrushSetDefaultOptions() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void FillsForEachACharachterWhenColorSet() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); |
|||
FillRegionProcessor<Rgba32> processor = |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
|
|||
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush); |
|||
Assert.Equal(Rgba32.Red, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void FillsForEachACharachterWhenColorSetDefaultOptions() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Rgba32.Red, path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
FillRegionProcessor<Rgba32> processor = |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
|
|||
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush); |
|||
Assert.Equal(Rgba32.Red, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DrawForEachACharachterWhenPenSetAndNotBrush() |
|||
{ |
|||
this.img.DrawText( |
|||
"123", |
|||
this.Font, |
|||
null, |
|||
Pens.Dash(Rgba32.Red, 1), |
|||
path, |
|||
new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() |
|||
{ |
|||
this.img.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DrawForEachACharachterWhenPenSet() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DrawForEachACharachterWhenPenSetDefaultOptions() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
|
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() |
|||
{ |
|||
this.img.DrawText( |
|||
"123", |
|||
this.Font, |
|||
Brushes.Solid(Rgba32.Red), |
|||
Pens.Dash(Rgba32.Red, 1), |
|||
path, |
|||
new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(6, this.img.ProcessorApplications.Count); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() |
|||
{ |
|||
this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(6, this.img.ProcessorApplications.Count); |
|||
} |
|||
|
|||
[Fact] |
|||
public void BrushAppliesBeforPen() |
|||
{ |
|||
this.img.DrawText( |
|||
"1", |
|||
this.Font, |
|||
Brushes.Solid(Rgba32.Red), |
|||
Pens.Dash(Rgba32.Red, 1), |
|||
path, |
|||
new TextGraphicsOptions(true)); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(2, this.img.ProcessorApplications.Count); |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void BrushAppliesBeforPenDefaultOptions() |
|||
{ |
|||
this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(2, this.img.ProcessorApplications.Count); |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor); |
|||
} |
|||
|
|||
[Fact] |
|||
public void GlyphHeightChangesBasedOnuseImageResolutionFlag() |
|||
{ |
|||
this.img.MetaData.VerticalResolution = 1; |
|||
this.img.MetaData.HorizontalResolution = 1; |
|||
this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true) { |
|||
UseImageResolution = false |
|||
}); |
|||
|
|||
this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true) |
|||
{ |
|||
UseImageResolution = true |
|||
}); |
|||
|
|||
Assert.NotEmpty(this.img.ProcessorApplications); |
|||
Assert.Equal(2, this.img.ProcessorApplications.Count); |
|||
FillRegionProcessor<Rgba32> ownResolution = Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor); |
|||
FillRegionProcessor<Rgba32> imgResolution = Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor); |
|||
|
|||
ShapeRegion ownRegion = Assert.IsType<ShapeRegion>(ownResolution.Region); |
|||
ShapeRegion imgRegion = Assert.IsType<ShapeRegion>(imgResolution.Region); |
|||
|
|||
// magic numbers based on the font used at well known resolutions
|
|||
Assert.Equal(7.44, ownRegion.Shape.Bounds.Height, 2); |
|||
Assert.Equal(0.1, imgRegion.Shape.Bounds.Height, 2); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue