mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
7.7 KiB
218 lines
7.7 KiB
// <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 : BaseImageOperationsExtensionTest
|
|
{
|
|
Rgba32 color = Rgba32.HotPink;
|
|
|
|
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
|
|
|
|
IPath path = new SixLabors.Shapes.Path(
|
|
new LinearLineSegment(
|
|
new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), }));
|
|
|
|
private readonly FontCollection FontCollection;
|
|
|
|
private readonly Font Font;
|
|
|
|
public DrawText()
|
|
{
|
|
this.FontCollection = new FontCollection();
|
|
this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillsForEachACharachterWhenBrushSetAndNotPen()
|
|
{
|
|
this.operations.DrawText(
|
|
"123",
|
|
this.Font,
|
|
Brushes.Solid(Rgba32.Red),
|
|
null,
|
|
Vector2.Zero,
|
|
new TextGraphicsOptions(true));
|
|
|
|
this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero);
|
|
|
|
this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillsForEachACharachterWhenBrushSet()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true));
|
|
|
|
this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillsForEachACharachterWhenBrushSetDefaultOptions()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero);
|
|
|
|
this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillsForEachACharachterWhenColorSet()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true));
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
|
|
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
|
|
Assert.Equal(Rgba32.Red, brush.Color);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillsForEachACharachterWhenColorSetDefaultOptions()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero);
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
|
|
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
|
|
Assert.Equal(Rgba32.Red, brush.Color);
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawForEachACharachterWhenPenSetAndNotBrush()
|
|
{
|
|
this.operations.DrawText(
|
|
"123",
|
|
this.Font,
|
|
null,
|
|
Pens.Dash(Rgba32.Red, 1),
|
|
Vector2.Zero,
|
|
new TextGraphicsOptions(true));
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions()
|
|
{
|
|
this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawForEachACharachterWhenPenSet()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true));
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawForEachACharachterWhenPenSetDefaultOptions()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet()
|
|
{
|
|
this.operations.DrawText(
|
|
"123",
|
|
this.Font,
|
|
Brushes.Solid(Rgba32.Red),
|
|
Pens.Dash(Rgba32.Red, 1),
|
|
Vector2.Zero,
|
|
new TextGraphicsOptions(true));
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
|
|
this.Verify<FillRegionProcessor<Rgba32>>(3);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(4);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(5);
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions()
|
|
{
|
|
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(2);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(3);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(4);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(5);
|
|
}
|
|
|
|
[Fact]
|
|
public void BrushAppliesBeforPen()
|
|
{
|
|
this.operations.DrawText(
|
|
"1",
|
|
this.Font,
|
|
Brushes.Solid(Rgba32.Red),
|
|
Pens.Dash(Rgba32.Red, 1),
|
|
Vector2.Zero,
|
|
new TextGraphicsOptions(true));
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
}
|
|
|
|
[Fact]
|
|
public void BrushAppliesBeforPenDefaultOptions()
|
|
{
|
|
this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
|
|
|
|
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
|
|
this.Verify<FillRegionProcessor<Rgba32>>(1);
|
|
}
|
|
}
|
|
}
|
|
|