Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Images are traced to SVG even when LibreOffice is installed

KnifeLemondf2eb7735dc6
diff --git a/src/Filee.Core/Conversion/IConverter.cs b/src/Filee.Core/Conversion/IConverter.cs
index cad7fbb4..23735d44 100644
--- a/src/Filee.Core/Conversion/IConverter.cs
+++ b/src/Filee.Core/Conversion/IConverter.cs
@@ -18,7 +18,12 @@ namespace Filee.Core.Conversion;
/// The edge is used only in routes that start from a raster image (<see cref="Formats.FormatCategory.Image"/>): image
/// tracing may follow ICNS → PNG, but must never redraw a PDF, a vector drawing or a video frame that became a PNG.
/// </param>
-public readonly record struct ConversionEdge(string From, string To, int Cost = 10, bool ImageSourcesOnly = false);
+/// <param name="NotForImageSources">
+/// The opposite: never used in routes that start from a raster image. PDF → SVG through LibreOffice keeps a PDF's
+/// vectors, but a photo that became a PDF would only come back as a picture inside an SVG, so images are traced.
+/// </param>
+public readonly record struct ConversionEdge(
+ string From, string To, int Cost = 10, bool ImageSourcesOnly = false, bool NotForImageSources = false);
/// <summary>Whether an engine can currently be used.</summary>
/// <param name="IsAvailable">True if conversions can run.</param>
diff --git a/src/Filee.Core/Conversion/RoutePlanner.cs b/src/Filee.Core/Conversion/RoutePlanner.cs
index 684ec201..e7d49cb7 100644
--- a/src/Filee.Core/Conversion/RoutePlanner.cs
+++ b/src/Filee.Core/Conversion/RoutePlanner.cs
@@ -77,7 +77,7 @@ public sealed class RoutePlanner
foreach (var (converter, edge, edgeCost) in EdgesFrom(node))
{
- if (edge.To == edge.From || (edge.ImageSourcesOnly && !imageSource))
+ if (edge.To == edge.From || (edge.ImageSourcesOnly && !imageSource) || (edge.NotForImageSources && imageSource))
continue;
var next = cost + edgeCost;
if (dist.TryGetValue(edge.To, out var known) && known <= next)
diff --git a/src/Filee.Engines/Office/LibreOfficeConverter.cs b/src/Filee.Engines/Office/LibreOfficeConverter.cs
index 57005fa8..5c036f0e 100644
--- a/src/Filee.Engines/Office/LibreOfficeConverter.cs
+++ b/src/Filee.Engines/Office/LibreOfficeConverter.cs
@@ -297,7 +297,9 @@ public sealed class LibreOfficeConverter : IConverter
foreach (var s in sources)
foreach (var t in targets)
if (s != t)
- edges.Add(new ConversionEdge(s, t, cost));
+ // An image that reached a drawing or a PDF would come back as a picture inside the SVG:
+ // images are traced instead.
+ edges.Add(new ConversionEdge(s, t, cost, NotForImageSources: t == "svg"));
}
// LibreOffice is the fallback: its costs make the built-in engines win wherever they can do the job
diff --git a/tests/Filee.Core.Tests/RoutePlannerTests.cs b/tests/Filee.Core.Tests/RoutePlannerTests.cs
index 5c7a9483..973f56b5 100644
--- a/tests/Filee.Core.Tests/RoutePlannerTests.cs
+++ b/tests/Filee.Core.Tests/RoutePlannerTests.cs
@@ -39,6 +39,18 @@ public class RoutePlannerTests
Assert.Null(planner.Plan("pdf", "svg")); // a document rendered to PNG is never traced
}
+ [Fact]
+ public void Edges_not_for_image_sources_leave_images_to_tracing()
+ {
+ // LibreOffice's PDF → SVG keeps a PDF's vectors, but a photo through PDF would only be a picture in the SVG.
+ var tracer = new FakeConverter("trace", new ConversionEdge("png", "svg", 40, ImageSourcesOnly: true));
+ var pdf = new FakeConverter("pdf", new ConversionEdge("png", "pdf"), new ConversionEdge("pdf", "svg", 25, NotForImageSources: true));
+ var planner = new RoutePlanner([tracer, pdf]);
+
+ Assert.Equal(["png→svg"], planner.Plan("png", "svg")!.Steps.Select(s => $"{s.From}→{s.To}"));
+ Assert.Equal(["pdf→svg"], planner.Plan("pdf", "svg")!.Steps.Select(s => $"{s.From}→{s.To}"));
+ }
+
[Fact]
public void Cheaper_route_wins()
{