Skip to content

Commit 221267f

Browse files
Add tests for #46
1 parent 5a74c69 commit 221267f

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Globalization;
5+
using SixLabors.Fonts;
6+
using SixLabors.ImageSharp.Drawing.Processing;
7+
using SixLabors.ImageSharp.PixelFormats;
8+
using SixLabors.ImageSharp.Processing;
9+
using Xunit;
10+
11+
namespace SixLabors.ImageSharp.Drawing.Tests.Issues
12+
{
13+
public class Issue_46
14+
{
15+
[Fact]
16+
public void CanRenderCustomFont()
17+
{
18+
Font font = CreateFont("icomoon-events.ttf", 175);
19+
20+
var options = new RendererOptions(font)
21+
{
22+
VerticalAlignment = VerticalAlignment.Center
23+
};
24+
25+
const int ImageSize = 300;
26+
27+
var image = new Image<Rgba32>(ImageSize, ImageSize);
28+
29+
string iconText = char.ConvertFromUtf32(int.Parse("e926", NumberStyles.HexNumber));
30+
31+
FontRectangle rect = TextMeasurer.Measure(iconText, options);
32+
33+
float textX = ((ImageSize - rect.Width) * 0.5F) + rect.Left;
34+
float textY = ((ImageSize - rect.Height) * 0.5F) + (rect.Top * 0.25F);
35+
36+
image.Mutate(x => x.DrawText(iconText, font, Color.Black, new PointF(textX, textY)));
37+
image.Save(TestFontUtilities.GetPath("e96.png"));
38+
}
39+
40+
private static Font CreateFont(string fontName, int size)
41+
{
42+
var fontCollection = new FontCollection();
43+
string fontPath = TestFontUtilities.GetPath(fontName);
44+
return fontCollection.Install(fontPath).CreateFont(size);
45+
}
46+
}
47+
}
22.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)