Fixed: loading fonts from embedded resource via the FontManager.RegisterFontFromEmbeddedResource method

This commit is contained in:
MarcinZiabek
2023-01-09 11:59:06 +01:00
parent 9dbed14559
commit 641cc6dee2
6 changed files with 55 additions and 5 deletions
@@ -0,0 +1,32 @@
using System;
using System.IO;
using NUnit.Framework;
using QuestPDF.Drawing;
namespace QuestPDF.UnitTests
{
public class FontManagerTests
{
[Test]
public void LoadFontFromFile()
{
using var stream = File.OpenRead("Resources/FontContent.ttf");
FontManager.RegisterFont(stream);
}
[Test]
public void LoadFontFromEmbeddedResource()
{
FontManager.RegisterFontFromEmbeddedResource("QuestPDF.UnitTests.Resources.FontEmbeddedResource.ttf");
}
[Test]
public void LoadFontFromEmbeddedResource_ShouldThrowException_WhenResourceIsNotAvailable()
{
Assert.Throws<ArgumentException>(() =>
{
FontManager.RegisterFontFromEmbeddedResource("QuestPDF.UnitTests.WrongPath.ttf");
});
}
}
}
@@ -17,4 +17,13 @@
<ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\FontContent.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Resources\FontEmbeddedResource.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>
Binary file not shown.