Skip to content

Commit 39acb53

Browse files
Merge pull request #135 from SixLabors/js/beta-12
Update refs and tests to match latest NuGet.
2 parents d7b5c69 + 8c4c7e3 commit 39acb53

37 files changed

Lines changed: 83 additions & 12 deletions

File tree

src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.1" />
24-
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
23+
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta15" />
24+
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
2525
</ItemGroup>
2626

2727
<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />

tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class DrawTextOnImageTests
2323

2424
private const string TestText = "Sphinx of black quartz, judge my vow\n0123456789";
2525

26-
private static readonly ImageComparer TextDrawingComparer = TestEnvironment.IsFramework
27-
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework
26+
private static readonly ImageComparer TextDrawingComparer = TestEnvironment.IsFramework || TestEnvironment.NetCoreVersion.StartsWith("2")
27+
? ImageComparer.TolerantPercentage(1e-3f) // Relax comparison on .NET Framework and .NET Core 2.x
2828
: ImageComparer.TolerantPercentage(1e-5f);
2929

3030
private static readonly ImageComparer OutlinedTextDrawingComparer = ImageComparer.TolerantPercentage(5e-4f);
@@ -67,6 +67,40 @@ public void EmojiFontRendering<TPixel>(TestImageProvider<TPixel> provider, bool
6767
$"ColorFontsEnabled-{enableColorFonts}");
6868
}
6969

70+
[Theory]
71+
[WithSolidFilledImages(400, 200, "White", PixelTypes.Rgba32)]
72+
public void FallbackFontRendering<TPixel>(TestImageProvider<TPixel> provider)
73+
where TPixel : unmanaged, IPixel<TPixel>
74+
{
75+
// https://github.com/SixLabors/Fonts/issues/171
76+
var collection = new FontCollection();
77+
FontFamily whitney = collection.Install(TestFontUtilities.GetPath("whitney-book.ttf"));
78+
FontFamily malgun = collection.Install(TestFontUtilities.GetPath("malgun.ttf"));
79+
Font font = whitney.CreateFont(25);
80+
81+
Color color = Color.Black;
82+
const string text = "亞DARKSOUL亞";
83+
84+
var textGraphicOptions = new DrawingOptions
85+
{
86+
TextOptions =
87+
{
88+
HorizontalAlignment = HorizontalAlignment.Center,
89+
VerticalAlignment = VerticalAlignment.Center,
90+
FallbackFonts = { malgun },
91+
ApplyKerning = true
92+
}
93+
};
94+
95+
provider.VerifyOperation(
96+
TextDrawingComparer,
97+
img =>
98+
{
99+
var center = new PointF(img.Width / 2, img.Height / 2);
100+
img.Mutate(i => i.DrawText(textGraphicOptions, text, font, color, center));
101+
});
102+
}
103+
70104
[Theory]
71105
[WithSolidFilledImages(276, 336, "White", PixelTypes.Rgba32)]
72106
public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688<TPixel>(TestImageProvider<TPixel> provider)
@@ -249,7 +283,7 @@ public void FontShapesAreRenderedCorrectly_LargeText<TPixel>(
249283
string str = Repeat(" ", 78) + "THISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDS";
250284
sb.Append(str);
251285

252-
string newLines = Repeat(Environment.NewLine, 80);
286+
string newLines = Repeat(Environment.NewLine, 61);
253287
sb.Append(newLines);
254288

255289
for (int i = 0; i < 10; i++)

tests/ImageSharp.Drawing.Tests/ImageSharp.Drawing.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<None Update="TestFonts\*.ttf">
2424
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2525
</None>
26-
<None Update="TestFonts\SixLaborsSampleAB.woff">
26+
<None Update="TestFonts\*.woff">
2727
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2828
</None>
2929
<None Update="xunit.runner.json">
9.15 MB
Binary file not shown.
59.7 KB
Binary file not shown.

tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,32 @@ public static partial class TestEnvironment
2424

2525
private static readonly Lazy<string> SolutionDirectoryFullPathLazy = new Lazy<string>(GetSolutionDirectoryFullPathImpl);
2626

27-
private static readonly Lazy<bool> RunsOnCiLazy = new Lazy<bool>(
28-
() => bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi);
27+
private static readonly Lazy<string> NetCoreVersionLazy = new Lazy<string>(GetNetCoreVersion);
2928

3029
internal static bool IsFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");
3130

31+
/// <summary>
32+
/// Gets the .NET Core version, if running on .NET Core, otherwise returns an empty string.
33+
/// </summary>
34+
internal static string NetCoreVersion => NetCoreVersionLazy.Value;
35+
3236
/// <summary>
3337
/// Gets a value indicating whether test execution runs on CI.
3438
/// </summary>
35-
internal static bool RunsOnCI => RunsOnCiLazy.Value;
39+
#if ENV_CI
40+
internal static bool RunsOnCI => true;
41+
#else
42+
internal static bool RunsOnCI => false;
43+
#endif
44+
45+
/// <summary>
46+
/// Gets a value indicating whether test execution is running with code coverage testing enabled.
47+
/// </summary>
48+
#if ENV_CODECOV
49+
internal static bool RunsWithCodeCoverage => true;
50+
#else
51+
internal static bool RunsWithCodeCoverage => false;
52+
#endif
3653

3754
internal static string SolutionDirectoryFullPath => SolutionDirectoryFullPathLazy.Value;
3855

@@ -122,5 +139,22 @@ internal static string CreateOutputDirectory(string path, params string[] pathPa
122139

123140
return path;
124141
}
142+
143+
/// <summary>
144+
/// Solution borrowed from:
145+
/// https://github.com/dotnet/BenchmarkDotNet/issues/448#issuecomment-308424100
146+
/// </summary>
147+
private static string GetNetCoreVersion()
148+
{
149+
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
150+
string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
151+
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
152+
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
153+
{
154+
return assemblyPath[netCoreAppIndex + 1];
155+
}
156+
157+
return string.Empty;
158+
}
125159
}
126160
}

tests/ImageSharp.Drawing.Tests/TestUtilities/TestImageExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static Image DebugSave(
6060
bool appendSourceFileOrDescription = true,
6161
IImageEncoder encoder = null)
6262
{
63-
if (TestEnvironment.RunsOnCI)
63+
if (TestEnvironment.RunsWithCodeCoverage)
6464
{
6565
return image;
6666
}
@@ -99,7 +99,7 @@ public static void DebugSave(
9999
object testOutputDetails = null,
100100
bool appendPixelTypeToFileName = true)
101101
{
102-
if (TestEnvironment.RunsOnCI)
102+
if (TestEnvironment.RunsWithCodeCoverage)
103103
{
104104
return;
105105
}
@@ -120,7 +120,7 @@ public static Image<TPixel> DebugSaveMultiFrame<TPixel>(
120120
bool appendPixelTypeToFileName = true)
121121
where TPixel : unmanaged, IPixel<TPixel>
122122
{
123-
if (TestEnvironment.RunsOnCI)
123+
if (TestEnvironment.RunsWithCodeCoverage)
124124
{
125125
return image;
126126
}
Loading
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)