Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Jun 6, 2022
1 parent 007a0fb commit b89c7a2
Show file tree
Hide file tree
Showing 27 changed files with 131 additions and 126 deletions.
14 changes: 2 additions & 12 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://docs.myget.org/docs/how-to/package-not-found-during-package-restore -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="sixlabors-myget" value="https://www.myget.org/F/sixlabors/api/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
5 changes: 2 additions & 3 deletions src/AED/AED.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="6.0.1" />
<PackageReference Include="MathNet.Numerics.FSharp" Version="4.12.0" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.35" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
</ItemGroup>
<ItemGroup>
<Compile Include="Util.fs" />
Expand Down
5 changes: 2 additions & 3 deletions src/Acoustics.Shared/Acoustics.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ObjectCloner" Version="2.2.2" />
<PackageReference Include="ObjectCloner.Extensions" Version="2.0.1" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.35" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.0.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/Acoustics.Shared/ImageSharp/DeltaImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void Invoke(in RowInterval rows)
{
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixelBg> background = this.sourceFrame.GetPixelRowSpan(y).Slice(0, this.width);
Span<TPixelFg> foreground = this.targetImage.GetPixelRowSpan(y).Slice(0, this.width);
Span<TPixelBg> background = this.sourceFrame.DangerousGetPixelRowMemory(y).Slice(0, this.width).Span;
Span<TPixelFg> foreground = this.targetImage.DangerousGetPixelRowMemory(y).Slice(0, this.width).Span;
this.blender.Blend(
this.configuration,
background,
Expand Down
40 changes: 20 additions & 20 deletions src/Acoustics.Shared/ImageSharp/Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ public static class Drawing
/// <summary>
/// A predefined set of graphics options that have anti-aliasing disabled.
/// </summary>
public static readonly ShapeGraphicsOptions NoAntiAlias = new ShapeGraphicsOptions()
public static readonly GraphicsOptions NoAntiAliasGraphics = new GraphicsOptions()
{
GraphicsOptions = new GraphicsOptions()
{
Antialias = false,
//BlendPercentage = 1,
//ColorBlendingMode = PixelColorBlendingMode.Normal,
//AntialiasSubpixelDepth = 0,
Antialias = false,
//BlendPercentage = 1,
//ColorBlendingMode = PixelColorBlendingMode.Normal,
//AntialiasSubpixelDepth = 0,
};

},
ShapeOptions = new ShapeOptions()
{
//IntersectionRule = SixLabors.ImageSharp.Drawing.IntersectionRule.Nonzero,
},
/// <summary>
/// A predefined set of graphics options that have anti-aliasing disabled.
/// </summary>
public static readonly DrawingOptions NoAntiAlias = new DrawingOptions()
{
GraphicsOptions = NoAntiAliasGraphics,
};

/// <summary>
/// A predefined set of options for rendering text. Currently is equivalent to the default.
/// A predefined set of drawing options for rendering text. Currently is equivalent to the default.
/// </summary>
public static readonly TextGraphicsOptions TextOptions = new TextGraphicsOptions()
public static readonly DrawingOptions TextOptions = new DrawingOptions()
{
// noop currently
};
Expand All @@ -81,7 +81,7 @@ public static class Drawing
var fonts = Directory.EnumerateFiles(fontDirectory, "*.ttf");
foreach (var font in fonts)
{
collection.Install(font);
collection.Add(font);
}

return collection;
Expand Down Expand Up @@ -139,17 +139,17 @@ public static Font GetFont(string fontFamily, float size, FontStyle style = Font
if (fontFamily == Roboto)
{
// shortcut case
return BundledFonts.CreateFont(fontFamily, size, style);
return BundledFonts.Get(fontFamily).CreateFont(size, style);
}
else if (SystemFonts.TryFind(fontFamily, out var family))
else if (SystemFonts.TryGet(fontFamily, out var family))
{
// default case
return family.CreateFont(size, style);
}
else
{
// fallback case
return BundledFonts.CreateFont(Roboto, size, style);
return BundledFonts.Get(Roboto).CreateFont(size, style);
}
}

Expand All @@ -167,9 +167,9 @@ public static Image<T> NewImage<T>(int width, int height, Color fill)
/// <summary>
/// Measures the placement of each character in a rendered string of text.
/// </summary>
public static GlyphMetric[] MeasureCharacters(string text, Font font, PointF location)
public static GlyphBounds[] MeasureCharacters(string text, Font font)
{
var rendererOptions = new RendererOptions(font, location);
var rendererOptions = new TextOptions(font);

TextMeasurer.TryMeasureCharacterBounds(text, rendererOptions, out var characterBounds);
//font.Instance.
Expand Down
21 changes: 12 additions & 9 deletions src/Acoustics.Shared/ImageSharp/ImageSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static void FillRectangle(this IImageProcessingContext context, IBrush br
public static void FillWithBlend(this IImageProcessingContext context, IBrush brush, params IPath[] paths)
{
const float Opaque = 1f;
var options = new ShapeGraphicsOptions();
var options = new DrawingOptions();

if (brush is SolidBrush s)
{
Expand All @@ -277,7 +277,7 @@ public static void FillWithBlend(this IImageProcessingContext context, IBrush br
}
else
{
context.Fill(options.GraphicsOptions, brush);
context.Fill(options, brush);
}
}

Expand Down Expand Up @@ -356,7 +356,7 @@ public static SizeF ToSizeF(this FontRectangle rectangle)

public static SizeF MeasureString(this IImageProcessingContext _, string text, Font font)
{
return TextMeasurer.MeasureBounds(text, new RendererOptions(font)).ToSizeF();
return TextMeasurer.MeasureBounds(text, new TextOptions(font)).ToSizeF();
}

public static Size ToSize(this SizeF size)
Expand Down Expand Up @@ -397,28 +397,31 @@ public static RectangleF AsRect(this FontRectangle rectangle)
/// <param name="color"></param>
/// <param name="location"></param>
/// <param name="textOptions"></param>
public static void DrawTextSafe(this IImageProcessingContext context, string text, Font font, Color color, PointF location, TextGraphicsOptions textOptions = null)
public static void DrawTextSafe(this IImageProcessingContext context, string text, Font font, Color color, PointF location, DrawingOptions drawingOptions = null, TextOptions textOptions = null)
{
if (text.IsNullOrEmpty())
{
return;
}

textOptions ??= ApDrawing.TextOptions;
drawingOptions ??= ApDrawing.TextOptions;
textOptions ??= new TextOptions(font);
textOptions.Origin = location;

// check to see if text overlaps with image
var destArea = new RectangleF(PointF.Empty, context.GetCurrentSize());
var rendererOptions = new RendererOptions(font, location);
var textArea = TextMeasurer.MeasureBounds(text, rendererOptions);

var textArea = TextMeasurer.MeasureBounds(text, textOptions);
textArea.Offset(location);
if (destArea.IntersectsWith(textArea.AsRect()))
{
context.DrawText(textOptions, text, font, color, location);
context.DrawText(drawingOptions, textOptions, text, Brushes.Solid(color), null);
}
}

public static void DrawVerticalText(this IImageProcessingContext context, string text, Font font, Color color, Point location)
{
var (width, height) = TextMeasurer.Measure(text, new RendererOptions(font)).ToSizeF();
var (width, height) = TextMeasurer.Measure(text, new TextOptions(font)).ToSizeF();
var image = new Image<Rgba32>(Configuration.Default, (int)(width + 1), (int)(height + 1), Color.Transparent);

image.Mutate(x => x
Expand Down
7 changes: 3 additions & 4 deletions src/AnalysisPrograms/AnalysisPrograms.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<StartupObject>AnalysisPrograms.MainEntry</StartupObject>
Expand Down Expand Up @@ -26,9 +26,8 @@
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="6.0.1" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.1.0" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.35" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="Spectre.Console" Version="0.43.1-preview.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
Expand Down
14 changes: 6 additions & 8 deletions src/AnalysisPrograms/Draw/RibbonPlots/RibbonPlot.Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static Image<Rgb24> CreateRibbonPlot(

// get width of text
var scaledFont = Drawing.GetFont(Drawing.Roboto, ribbonHeight * 0.8f);
int labelWidth = (int)Math.Ceiling(TextMeasurer.Measure(someRibbon.Key.ToString(AppConfigHelper.RenderedDateFormatShort), new RendererOptions(scaledFont)).Width);
int labelWidth = (int)Math.Ceiling(TextMeasurer.Measure(someRibbon.Key.ToString(AppConfigHelper.RenderedDateFormatShort), new TextOptions(scaledFont)).Width);

var finalHeight = Padding + ((Padding + ribbonHeight) * stats.Buckets);
var ribbonLeft = HorizontalPadding + labelWidth + HorizontalPadding;
Expand Down Expand Up @@ -214,14 +214,12 @@ private static Image<Rgb24> CreateRibbonPlot(
});

var bucketDate = stats.Start;
var textGraphics = new TextGraphicsOptions()
var textGraphics = new TextOptions(scaledFont)
{
TextOptions = new TextOptions()
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
},
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
};

var textColor = Color.Black;
var voidColor = Color.Gray;
for (var b = 0; b < stats.Buckets; b++)
Expand All @@ -241,7 +239,7 @@ void Operation(IImageProcessingContext context)
var y = Padding + ((Padding + ribbonHeight) * b);

// draw label
context.DrawTextSafe(dateLabel, scaledFont, textColor, new Point(HorizontalPadding, y + (ribbonHeight / 2)), textGraphics);
context.DrawTextSafe(dateLabel, scaledFont, textColor, new Point(HorizontalPadding, y + (ribbonHeight / 2)), textOptions: textGraphics);

// draw void
var @void = new RectangularPolygon(ribbonLeft, y, estimatedWidth, ribbonHeight);
Expand Down
6 changes: 3 additions & 3 deletions src/AudioAnalysisTools/AudioAnalysisTools.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>AudioAnalysisTools</AssemblyTitle>
<OutputType>Library</OutputType>
Expand All @@ -23,8 +23,8 @@
<PackageReference Include="Equ" Version="2.2.0" />
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="morelinq" Version="3.3.2" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.35" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/AudioAnalysisTools/Events/Drawing/EventDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void DrawEventLabel(this SpectralEvent @event, IImageProcessingCon
return;
}

var bounds = TextMeasurer.MeasureBounds(text, new RendererOptions(Roboto6));
var bounds = TextMeasurer.MeasureBounds(text, new TextOptions(Roboto6));
var topLeft = options.Converters.GetPoint(@event);

topLeft.Offset(0, -bounds.Height);
Expand Down
7 changes: 6 additions & 1 deletion src/AudioAnalysisTools/Events/Interfaces/IPointData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public void DrawPointsAsFillExperiment(IImageProcessingContext graphics, EventRe
.Cast<IPath>()
.ToArray();

var shapeOptions = new ShapeGraphicsOptions(options.FillOptions, new ShapeOptions());
var shapeOptions = new DrawingOptions()
{
GraphicsOptions = options.FillOptions,
ShapeOptions = new ShapeOptions(),
};

foreach (var rect in rects)
{
graphics.Fill(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ public static Image<Rgb24> DrawTitleBarOfFalseColourSpectrogram(string title, in
int x = 2;
g.DrawTextSafe(title, stringFont, Color.White, new PointF(x, 3));

var stringSize = TextMeasurer.Measure(title, new RendererOptions(stringFont));
var stringSize = TextMeasurer.Measure(title, new TextOptions(stringFont));
x += (int)stringSize.Width + 300;

var text = $"SCALE:(time x kHz) {Meta.OrganizationTag}";
Expand Down
2 changes: 1 addition & 1 deletion src/TowseyLibrary/Plot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public Image<Rgb24> DrawAnnotatedPlot(int height)

if (this.data.Length > 500)
{
var size = TextMeasurer.Measure(this.title, new RendererOptions(font));
var size = TextMeasurer.Measure(this.title, new TextOptions(font));
g.DrawTextSafe(this.title, font, Color.Red, new PointF(length - size.Width - 2, 0));
}

Expand Down
7 changes: 3 additions & 4 deletions src/TowseyLibrary/TowseyLibrary.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>TowseyLib</AssemblyTitle>
<OutputType>Library</OutputType>
Expand All @@ -16,9 +16,8 @@
<ItemGroup>
<PackageReference Include="alglib.net" Version="3.16.0" />
<PackageReference Include="MathNet.Numerics" Version="4.12.0" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.35" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions tests/Acoustics.Test/AcousticWorkbench/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void TestDefault()
{
var api = Api.Default;

Assert.AreEqual("www.ecosounds.org", api.Host);
Assert.AreEqual("api.ecosounds.org", api.Host);
Assert.AreEqual("https", api.Protocol);
Assert.AreEqual("v1", api.Version);
}
Expand All @@ -46,7 +46,7 @@ public void TestToString()
{
var api = Api.Default;

Assert.AreEqual("{Protocol=\"https\", Host=\"www.ecosounds.org\", Version=\"v1\"}", api.ToString());
Assert.AreEqual("{Protocol=\"https\", Host=\"api.ecosounds.org\", Version=\"v1\"}", api.ToString());
}

[DataTestMethod]
Expand Down
5 changes: 2 additions & 3 deletions tests/Acoustics.Test/Acoustics.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="StringTokenFormatter" Version="4.0.0" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta13.5.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.35" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AnalysisBase\AnalysisBase.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void TestLeftPaddingInLowerLayers()
new PointF(900, 256), new Point(1080, 0), new Point(1260, 256),
};
graphics.DrawLines(
new ShapeGraphicsOptions(),
new DrawingOptions(),
Brushes.Solid(Color.Red),
1,
points);
Expand Down
Loading

0 comments on commit b89c7a2

Please sign in to comment.