Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Svg.Tests.Win/DeepZoom/TileGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,42 @@ public async Task GenerateTilesFromSvgAsync_ProducesExpectedZoomLevels()
var dims = System.Text.Json.JsonDocument.Parse(dimsJson).RootElement;
Assert.AreEqual(pyramidW, dims.GetProperty("width").GetInt32(), "dimensions.json width mismatch.");
Assert.AreEqual(pyramidH, dims.GetProperty("height").GetInt32(), "dimensions.json height mismatch.");
Assert.IsTrue(dims.TryGetProperty("scaleX", out _), "dimensions.json missing scaleX.");
Assert.IsTrue(dims.TryGetProperty("scaleY", out _), "dimensions.json missing scaleY.");
#endif
}

#if !NETFRAMEWORK
[Test]
public async Task GenerateTilesFromSvgAsync_WritesScaleFactorsToDimensionsJson()
{
// Arrange — render the SVG into a pyramid 10× wider than the document so scaleX ≈ 10.
// Consumers (RenderOnPlanOptionsProvider) use these to re-map plan-item coordinates
// from the original SVG coordinate system into pyramid space and back.
var file = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Assets\\plan_iss.svg");
var doc = SvgDocument.Open(file);
var docSize = doc.GetDimensions();
int targetWidth = (int)Math.Ceiling(docSize.Width * 10);
int pyramidH = (int)Math.Ceiling(targetWidth * docSize.Height / docSize.Width);
float expectedScaleX = targetWidth / docSize.Width;
float expectedScaleY = pyramidH / docSize.Height;

var tiles = new ConcurrentDictionary<string, MemoryStream>();

// Act
await new TileGenerator().GenerateTilesAsync(doc, targetWidth, CreateMemoryStreamProvider(tiles));

// Assert
Assert.IsTrue(tiles.ContainsKey("/dimensions.json"), "dimensions.json missing.");
var dimsJson = System.Text.Encoding.UTF8.GetString(tiles["/dimensions.json"].ToArray());
var dims = System.Text.Json.JsonDocument.Parse(dimsJson).RootElement;
Assert.AreEqual(expectedScaleX, (float)dims.GetProperty("scaleX").GetDouble(), 0.0001f,
"dimensions.json scaleX mismatch.");
Assert.AreEqual(expectedScaleY, (float)dims.GetProperty("scaleY").GetDouble(), 0.0001f,
"dimensions.json scaleY mismatch.");
}
#endif

[Test]
public async Task GenerateTilesFromSvgAsync_TilesMatchCurrentPipeline_WithinTolerance()
{
Expand Down
12 changes: 8 additions & 4 deletions Svg/DeepZoom/TileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Svg.Platform;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -102,7 +103,7 @@ await GenerateZ0TilesScanlineAsync(codec, originalWidth, originalHeight,
kvp.Value.Dispose();
}
pending.Clear();
await WriteMetadataAsync(originalWidth, originalHeight, tileOutputStreamProvider);
await WriteMetadataAsync(originalWidth, originalHeight, 1.0, 1.0, tileOutputStreamProvider);
}

private async Task GenerateZ0TilesSubsetAsync(
Expand Down Expand Up @@ -431,7 +432,7 @@ await TryCascadeAsync(0, tx, ty, pending, pendingLock, levelTilesX, levelTilesY,
kvp.Value.Dispose();
}
pending.Clear();
await WriteMetadataAsync(pyramidW, pyramidH, tileOutputStreamProvider);
await WriteMetadataAsync(pyramidW, pyramidH, scaleX, scaleY, tileOutputStreamProvider);
}

private async Task WriteTileAndStorePendingAsync(
Expand Down Expand Up @@ -566,10 +567,13 @@ private static async Task WriteEncodedTileAsync(
}

private static async Task WriteMetadataAsync(
int width, int height,
int width, int height, double scaleX, double scaleY,
Func<string, string, Task<Stream>> streamProvider)
{
var json = System.Text.Encoding.UTF8.GetBytes($"{{\"width\":{width},\"height\":{height}}}");
var sx = scaleX.ToString("R", CultureInfo.InvariantCulture);
var sy = scaleY.ToString("R", CultureInfo.InvariantCulture);
var json = System.Text.Encoding.UTF8.GetBytes(
$"{{\"width\":{width},\"height\":{height},\"scaleX\":{sx},\"scaleY\":{sy}}}");
using var outStream = await streamProvider("", "dimensions.json");
await outStream.WriteAsync(json, 0, json.Length);
}
Expand Down
4 changes: 3 additions & 1 deletion Svg/Svg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net48;net10.0</TargetFrameworks>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<Version>3.2.0-optiq01</Version>
<Version>3.2.0-optiq02</Version>
<Authors>gentledpp,zepr</Authors>
<Company>Opti-Q GmbH</Company>
<PackageReleaseNotes>
#3.2.0-optiq02
TileGenerator stores scale factor in dimensions.json (relative to svg dimensions)
#3.2.0-optiq01
Moved to avalonia 12
#3.1.4-optiq01
Expand Down
Loading