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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Merge origin/main into feature/rotate-flip
KnifeLemon458de1e03568
diff --cc src/Filee.Core/Presets/BuiltInData.csindex 77da1bf2,bb11ebab..c47d818d--- a/src/Filee.Core/Presets/BuiltInData.cs+++ b/src/Filee.Core/Presets/BuiltInData.cs@@@ -166,47 -220,20 +221,61 @@@ public static class BuiltInDatnew() { Id = "to-eot", Name = "EOT", TargetFormat = "eot" },];+ /// <summary>- /// Rotate and flip presets, and the two groups that fan them out on the donut (added in settings schema 11). On no++ /// Rotate and flip presets, and the two groups that fan them out on the donut (added in settings schema 17). On no+ /// default donut: users add "Rotate" / "Flip" (or single presets) in Settings → Toolbar.+ /// </summary>+ public static List<Preset> ImageToolPresets() =>+ [+ Tool("rotate-left", "preset.rotate_left", "{name}_left", i => i.Rotation = ImageRotation.Left90),+ Tool("rotate-right", "preset.rotate_right", "{name}_right", i => i.Rotation = ImageRotation.Right90),+ Tool("rotate-180", "preset.rotate_180", "{name}_180", i => i.Rotation = ImageRotation.Rotate180),+ Tool("flip-horizontal", "preset.flip_horizontal", "{name}_mirrored", i => i.Flip = ImageFlip.Horizontal),+ Tool("flip-vertical", "preset.flip_vertical", "{name}_flipped", i => i.Flip = ImageFlip.Vertical),+ new()+ {+ Id = "rotate", NameKey = "preset.group_rotate", TargetFormat = Preset.GroupTarget, Kind = PresetKind.Group,+ SubPresetIds = ["rotate-left", "rotate-right", "rotate-180"],+ },+ new()+ {+ Id = "flip", NameKey = "preset.group_flip", TargetFormat = Preset.GroupTarget, Kind = PresetKind.Group,+ SubPresetIds = ["flip-horizontal", "flip-vertical"],+ },+ ];++ /// <summary>+ /// A rotate / flip preset. A JPG (or WEBP, AVIF) is encoded again when it turns: at 95 rather than the usual 90, so+ /// turning a good photo doesn't visibly cost it quality.+ /// </summary>+ private static Preset Tool(string id, string nameKey, string pattern, Action<ImageOptions> set)+ {+ var preset = new Preset+ {+ Id = id,+ NameKey = nameKey,+ TargetFormat = SameAsSource,+ Image = { Quality = 95 },+ Output = { FileNamePattern = pattern },+ };+ set(preset.Image);+ return preset;+ }++ /// <summary>+ /// Structured data and contacts targets (added in settings schema 14, see SettingsMigrations). EML is for Outlook+ /// MSG files, vCard for contact lists in CSV; neither is on a donut.+ /// </summary>+ public static List<Preset> DataPresets() =>+ [+ new() { Id = "to-json", Name = "JSON", TargetFormat = "json" },+ new() { Id = "to-yaml", Name = "YAML", TargetFormat = "yaml" },+ new() { Id = "to-toml", Name = "TOML", TargetFormat = "toml" },+ new() { Id = "to-xml", Name = "XML", TargetFormat = "xml" },+ new() { Id = "to-eml", Name = "EML", TargetFormat = "eml" },+ new() { Id = "to-vcf", Name = "vCard", TargetFormat = "vcf" },+ ];+/// <summary>Creates the default toolbar profiles.</summary>public static List<ToolbarProfile> CreateProfiles() =>[diff --cc src/Filee.Core/Settings/AppSettings.csindex 4df29b84,89e3ccfa..1701b12f--- a/src/Filee.Core/Settings/AppSettings.cs+++ b/src/Filee.Core/Settings/AppSettings.cs@@@ -50,7 -50,7 +50,7 @@@ public sealed class DonutSettingpublic sealed class AppSettings{/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>- public const int CurrentSchemaVersion = 11;- public const int CurrentSchemaVersion = 16;++ public const int CurrentSchemaVersion = 17;public int SchemaVersion { get; set; } = CurrentSchemaVersion;diff --cc src/Filee.Core/Settings/UserDataStore.csindex fcbec663,e64eb47e..9b0f3880--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@@ -372,38 -401,82 +401,114 @@@ internal static class SettingsMigrationchanged = true;}- // v11: rotate / flip presets and the "Rotate" / "Flip" groups that fan them out, on no donut, after "Remove- // background" as in a new library. Present already but saved since by a Filee before 11 (it reads and writes- // schema 10, so back and forth between versions comes here again): that one dropped what it didn't know, the- // rotation and the group, and left a preset that re-encodes unturned. Those parts are put back, the user's- // own changes (name, quality, file names) stay.+ // v11: more document formats (Org, AsciiDoc, Typst, ... through Pandoc; flat OpenDocument, templates,+ // ClarisWorks, ... through LibreOffice; KEPUB built in). Built-in donuts learn the new extensions unless+ // another donut already has them, and the e-books donut gets KEPUB after MOBI.if (from < 11)+ {+ if (presets.All(p => p.Id != "to-kepub"))+ {+ presets.Add(BuiltInData.CreatePresets().Single(p => p.Id == "to-kepub"));+ changed = true;+ changed |= Offer(presets, profiles, "ebooks", "to-kepub", "to-mobi");+ }+ changed |= LearnExtensions(profiles, out _);+ }++ // v12: HEVC / AV1 video, ALAC and the new audio formats (WavPack, TTA, APE, DSD, ...), and a subtitles donut+ // after the audio donut. The video donut offers "MP4 HEVC" and "Extract subtitles".+ if (from < 12)+ changed |= AddCodecsAndSubtitles(presets, profiles);++ // v13: more image formats (APNG, MNG, QOI, DDS, DICOM, OpenEXR, …, Fujifilm's .hif): the images donut learns+ // their extensions unless another donut already has them.+ if (from < 13)+ changed |= LearnExtensions(profiles, out _);++ // v14: structured data (JSON, YAML, TOML, XML, vCard) gets its own donut after "fonts", Outlook MSG joins+ // the documents donut next to EML, and the spreadsheets donut gets JSON after CSV.+ if (from < 14)+ changed |= AddData(presets, profiles);++ // v15: 3D models (GLB, glTF, STL, OBJ, 3MF, PLY) get presets and their own donut after "data" (else after+ // "fonts", else before the mixed-files one), with the extensions no donut of the user takes yet.+ if (from < 15)+ changed |= AddModels(presets, profiles);++ // v16: raster → SVG tracing ("Trace to SVG" in colour, "Line art to SVG" in black), on the images donut after+ // PDF.+ if (from < 16)+ {+ foreach (var preset in BuiltInData.TracePresets().Where(p => presets.All(existing => existing.Id != p.Id)))+ {+ presets.Add(preset);+ changed = true;+ }+ changed |= Offer(presets, profiles, "images", "trace-svg", "to-pdf");+ changed |= Offer(presets, profiles, "images", "trace-line-art", "trace-svg");+ }++++ // v17: rotate / flip presets and the "Rotate" / "Flip" groups that fan them out, on no donut, after "Remove++ // background" as in a new library. Present already but saved since by a Filee before 17 (it reads and writes++ // an older schema, so back and forth between versions comes here again): that one dropped what it didn't++ // know, the rotation and the group, and left a preset that re-encodes unturned. Those parts are put back, the++ // user's own changes (name, quality, file names) stay.++ if (from < 17)+ {+ var at = presets.FindIndex(p => p.Id == "remove-background");+ at = at < 0 ? presets.Count : at + 1;+ foreach (var tool in BuiltInData.ImageToolPresets())+ {+ if (presets.FirstOrDefault(p => p.Id == tool.Id) is not { } existing)+ {+ presets.Insert(Math.Min(at++, presets.Count), tool);+ changed = true;+ }+ else if (tool.IsGroup && !existing.IsGroup)+ {+ existing.Kind = PresetKind.Group;+ existing.SubPresetIds = [.. tool.SubPresetIds];+ existing.TargetFormat = tool.TargetFormat;+ changed = true;+ }+ else if (!tool.IsGroup && !existing.Image.TurnsOrMirrors)+ {+ existing.Image.Rotation = tool.Image.Rotation;+ existing.Image.Flip = tool.Image.Flip;+ changed = true;+ }+ }+ }+ return changed;+ }++ private static bool AddData(List<Preset> presets, List<ToolbarProfile> profiles)+ {+ var changed = false;+ foreach (var preset in BuiltInData.DataPresets().Where(p => presets.All(existing => existing.Id != p.Id)))+ {+ presets.Add(preset);+ changed = true;+ }+ changed |= LearnExtensions(profiles, out var claimed);++ if (profiles.All(p => p.Id != "data"))+ {+ var data = BuiltInData.DataProfile();+ // Only the extensions no donut of the user takes yet.+ data.Extensions = data.Extensions.Where(claimed.Add).ToList();+ if (data.Extensions.Count > 0)+ {+ var presetIds = presets.Select(p => p.Id).ToHashSet();+ data.PresetIds = data.PresetIds.Where(presetIds.Contains).ToList();+ var fonts = profiles.FindIndex(p => p.Id == "fonts");+ var insertAt = fonts >= 0 ? fonts + 1 : profiles.FindIndex(p => p.IsFallback);+ profiles.Insert(insertAt < 0 ? profiles.Count : insertAt, data);+ changed = true;+ }+ }+ changed |= Offer(presets, profiles, "spreadsheets", "to-json", "to-csv");return changed;}diff --cc src/Filee.Engines/Magick/MagickImageConverter.csindex a16a2a6f,b15b607e..7085d339--- a/src/Filee.Engines/Magick/MagickImageConverter.cs+++ b/src/Filee.Engines/Magick/MagickImageConverter.cs@@@ -7,10 -7,11 +7,11 @@@ using ImageMagicknamespace Filee.Engines.Magick;/// <summary>- /// Converts between PNG, JPG, WEBP, TIFF, BMP, GIF, ICO, AVIF, JPEG XL, JPEG 2000, PSD/PSB, TGA and PPM, and reads- /// HEIC, XCF, camera RAW and (on Windows) EMF/WMF.+ /// Converts between PNG, JPG, WEBP, TIFF, BMP, GIF, ICO, AVIF, JPEG XL, JPEG 2000, PSD/PSB, TGA, PPM, APNG, MNG, QOI,+ /// DDS, PCX, CUR, XPM, XBM, WBMP, PAM, PFM, SGI, Sun Raster and MIFF, and reads HEIC, XCF, camera RAW, DICOM,+ /// Photo CD, OpenEXR, Radiance HDR and (on Windows) EMF/WMF./// </summary>-public sealed class MagickImageConverter : IConverter, ITiffMerger+public sealed class MagickImageConverter : IConverter, ITiffMerger, IImageTransformer{public string Id => "magick";public string DisplayName => "ImageMagick";diff --cc src/Filee.Engines/Pdf/PdfiumConverter.csindex d964c896,a83d5653..336fd371--- a/src/Filee.Engines/Pdf/PdfiumConverter.cs+++ b/src/Filee.Engines/Pdf/PdfiumConverter.cs@@@ -16,9 -16,9 +16,9 @@@ using SkiaSharpnamespace Filee.Engines.Pdf;/// <summary>PDF → every raster format ImageMagick writes (PNG, JPG, WEBP, TIFF, …, PSD, TGA, PPM).</summary>-public sealed class PdfiumConverter : IConverter+public sealed class PdfiumConverter : IConverter, IImageTransformer{- private static readonly HashSet<string> MultiPageTargets = ["tiff", "gif"];+ private static readonly HashSet<string> MultiPageTargets = ["tiff", "gif", "apng", "mng"];/// <summary>A tall image beyond this many pixels is scaled down (a 300-page PDF at 300 dpi would need gigabytes).</summary>internal const long MaxStackedPixels = 200_000_000;diff --cc src/Filee.Engines/Vector/VectorConverter.csindex 79d04d26,b601b3d6..d23f0fdb--- a/src/Filee.Engines/Vector/VectorConverter.cs+++ b/src/Filee.Engines/Vector/VectorConverter.cs@@@ -10,9 -12,17 +12,17 @@@ using Filee.Engines.Vector.Tracingnamespace Filee.Engines.Vector;- /// <summary>SVG, SVGZ and AI conversions that need no external program.</summary>+ /// <summary>SVG, SVGZ and AI conversions and raster image tracing that need no external program.</summary>-public sealed class VectorConverter : IConverter+public sealed class VectorConverter : IConverter, IImageTransformer{+ /// <summary>+ /// Cost of tracing a raster image into SVG. Tracing redraws the picture, so it must never be a step on the way to+ /// another format (PNG → SVG → PDF instead of PNG → PDF): its cost is higher than any route from an image to a+ /// format SVG leads to, and the planner only takes it when SVG (or DXF, DWG through SVG) is the target. Its edges+ /// are for raster sources only: a PDF, EPS or other vector file that can be rendered to PNG is never traced.+ /// </summary>+ public const int TraceCost = 40;+public string Id => "vector";public string DisplayName => "Vector graphics (built-in)";public int MaxParallelism => 0;diff --cc tests/Filee.Core.Tests/UserDataStoreTests.csindex a0962593,7d676d7c..36e7c4bc--- a/tests/Filee.Core.Tests/UserDataStoreTests.cs+++ b/tests/Filee.Core.Tests/UserDataStoreTests.cs@@@ -281,63 -420,90 +420,156 @@@ public class UserDataStoreTestAssert.True(SettingsMigrations.ApplyToLibrary(10, presets, profiles));+ Assert.Equal("kepub", presets.Single(p => p.Id == "to-kepub").TargetFormat);+ var ebooks = profiles.Single(p => p.Id == "ebooks");+ Assert.Equal(ebooks.PresetIds.IndexOf("to-mobi") + 1, ebooks.PresetIds.IndexOf("to-kepub"));+ Assert.Contains("kepub.epub", ebooks.Extensions);+ Assert.Contains("typ", profiles.Single(p => p.Id == "text").Extensions);+ Assert.DoesNotContain("org", profiles.Single(p => p.Id == "text").Extensions);+ Assert.Contains("fodt", profiles.Single(p => p.Id == "office").Extensions);+ Assert.Contains("fods", profiles.Single(p => p.Id == "spreadsheets").Extensions);+ Assert.Contains("otp", profiles.Single(p => p.Id == "presentations").Extensions);+ Assert.Contains("fodg", profiles.Single(p => p.Id == "vector").Extensions);+ foreach (var expected in BuiltInData.CreateProfiles())+ Assert.Equal(expected.PresetIds, profiles.Single(p => p.Id == expected.Id).PresetIds);+ Assert.False(SettingsMigrations.ApplyToLibrary(10, presets, profiles)); // once only+ }++ [Fact]+ public void Version_14_libraries_get_3d_model_presets_and_their_donut_after_data()+ {+ // As written with schema 14: no 3D formats.+ var modelIds = BuiltInData.ModelPresets().Select(p => p.Id).ToHashSet();+ var presets = BuiltInData.CreatePresets().Where(p => !modelIds.Contains(p.Id)).ToList();+ var profiles = BuiltInData.CreateProfiles().Where(p => p.Id != "models").ToList();++ Assert.True(SettingsMigrations.ApplyToLibrary(14, presets, profiles));++ Assert.Equal(["to-glb", "to-stl", "to-obj", "to-3mf", "to-ply", "to-gltf"], presets.Where(p => modelIds.Contains(p.Id)).Select(p => p.Id));+ var ids = profiles.Select(p => p.Id).ToList();+ Assert.Equal(ids.IndexOf("data") + 1, ids.IndexOf("models"));+ Assert.Equal(ids.IndexOf("mixed") - 1, ids.IndexOf("models"));+ var models = profiles.Single(p => p.Id == "models");+ Assert.Equal(["glb", "gltf", "stl", "obj", "3mf", "ply"], models.Extensions);+ Assert.Equal(BuiltInData.ModelProfile().PresetIds, models.PresetIds);+ Assert.False(SettingsMigrations.ApplyToLibrary(14, presets, profiles)); // once only+ }++ [Fact]+ public void The_3d_donut_leaves_out_extensions_a_profile_of_the_user_takes()+ {+ var presets = BuiltInData.CreatePresets();+ var profiles = BuiltInData.CreateProfiles().Where(p => p.Id != "models").ToList();+ profiles.Insert(0, new ToolbarProfile { Id = "printing", Name = "Printing", Extensions = ["stl", "3mf"] });++ Assert.True(SettingsMigrations.ApplyToLibrary(14, presets, profiles));++ Assert.Equal(["glb", "gltf", "obj", "ply"], profiles.Single(p => p.Id == "models").Extensions);+ }++ [Fact]+ public void Version_15_libraries_get_the_tracing_presets_on_the_images_donut_after_pdf()+ {+ // As written before tracing: no trace presets, and the images donut without them.+ var presets = BuiltInData.CreatePresets();+ presets.RemoveAll(p => p.Id is "trace-svg" or "trace-line-art");+ var profiles = BuiltInData.CreateProfiles();+ var images = profiles.Single(p => p.Id == "images");+ images.PresetIds.RemoveAll(id => id is "trace-svg" or "trace-line-art");++ Assert.True(SettingsMigrations.ApplyToLibrary(15, presets, profiles));++ Assert.Equal(TracingMode.Color, presets.Single(p => p.Id == "trace-svg").Trace.Mode);+ Assert.Equal(TracingMode.BlackAndWhite, presets.Single(p => p.Id == "trace-line-art").Trace.Mode);+ Assert.All(presets.Where(p => p.Id.StartsWith("trace-", StringComparison.Ordinal)), p => Assert.Equal("svg", p.TargetFormat));+ Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "images").PresetIds, images.PresetIds);+ Assert.False(SettingsMigrations.ApplyToLibrary(15, presets, profiles)); // once only+ }++ [Fact]+ public void Trace_options_survive_a_save_and_load()+ {+ using var dir = new TempDir();+ var store = new UserDataStore(dir.Path);+ store.Load();+ var preset = store.Presets.Single(p => p.Id == "trace-svg");+ preset.Trace.Colors = 6;+ preset.Trace.Detail = 80;+ store.SaveLibrary();++ var reloaded = new UserDataStore(dir.Path);+ reloaded.Load();+ var trace = reloaded.Presets.Single(p => p.Id == "trace-svg").Trace;+ Assert.Equal((TracingMode.Color, 6, 80), (trace.Mode, trace.Colors, trace.Detail));+ Assert.Equal(TracingMode.BlackAndWhite, reloaded.Presets.Single(p => p.Id == "trace-line-art").Trace.Mode);+ }+++ [Fact]++ public void Version_16_libraries_get_rotate_and_flip_presets_and_groups_on_no_donut()++ {++ var presets = BuiltInData.CreatePresets();++ presets.RemoveAll(p => p.Id is "rotate-left" or "rotate-right" or "rotate-180" or "flip-horizontal" or "flip-vertical" or "rotate" or "flip");++ var profiles = BuiltInData.CreateProfiles();++++ Assert.True(SettingsMigrations.ApplyToLibrary(16, presets, profiles));+++ var rotate = presets.Single(p => p.Id == "rotate");+ Assert.True(rotate.IsGroup);+ Assert.Equal(["rotate-left", "rotate-right", "rotate-180"], rotate.SubPresetIds);+ Assert.Equal(ImageRotation.Left90, presets.Single(p => p.Id == "rotate-left").Image.Rotation);+ Assert.Equal(ImageFlip.Horizontal, presets.Single(p => p.Id == "flip-horizontal").Image.Flip);+ Assert.DoesNotContain(profiles, p => p.PresetIds.Any(id => id.StartsWith("rotate") || id.StartsWith("flip")));- Assert.False(SettingsMigrations.ApplyToLibrary(10, presets, profiles)); // once only++ Assert.False(SettingsMigrations.ApplyToLibrary(16, presets, profiles)); // once only+ // Where a new library has them: after "Remove background".+ var background = presets.FindIndex(p => p.Id == "remove-background");+ Assert.Equal("rotate-left", presets[background + 1].Id);+ }++ [Fact]+ public void A_rotation_from_a_newer_Filee_reads_as_none_and_the_other_presets_still_load()+ {+ using var dir = new TempDir();+ var store = new UserDataStore(dir.Path);+ store.Load();+ store.SaveLibrary();+ var path = Path.Combine(dir.Path, "presets.json");+ var json = File.ReadAllText(path);+ Assert.Contains("\"rotation\": \"Left90\"", json);+ File.WriteAllText(path, json.Replace("\"rotation\": \"Left90\"", "\"rotation\": \"Transpose\"")+ .Replace("\"flip\": \"Vertical\"", "\"flip\": 7"));++ var reloaded = new UserDataStore(dir.Path);+ reloaded.Load();++ Assert.Equal(ImageRotation.None, reloaded.FindPreset("rotate-left")!.Image.Rotation);+ Assert.Equal(ImageFlip.None, reloaded.FindPreset("flip-vertical")!.Image.Flip);+ Assert.Equal(ImageRotation.Right90, reloaded.FindPreset("rotate-right")!.Image.Rotation); // the rest as saved+ Assert.False(File.Exists(path + ".broken"));+ }++ [Fact]+ public void Back_from_an_older_Filee_rotate_and_flip_work_again_and_keep_the_users_changes()+ {- // What a Filee before 11 leaves after saving: kind, members and rotation dropped, the rest as it was.++ // What a Filee before 17 leaves after saving: kind, members and rotation dropped, the rest as it was.+ var presets = BuiltInData.CreatePresets();+ var left = presets.Single(p => p.Id == "rotate-left");+ left.Image.Rotation = ImageRotation.None;+ left.Name = "Turn left";+ var rotate = presets.Single(p => p.Id == "rotate");+ rotate.Kind = PresetKind.Convert;+ rotate.SubPresetIds = [];+ var profiles = BuiltInData.CreateProfiles();+- Assert.True(SettingsMigrations.ApplyToLibrary(10, presets, profiles));++ Assert.True(SettingsMigrations.ApplyToLibrary(16, presets, profiles));++ Assert.Equal(ImageRotation.Left90, left.Image.Rotation);+ Assert.Equal("Turn left", left.Name);+ Assert.True(rotate.IsGroup);+ Assert.Equal(["rotate-left", "rotate-right", "rotate-180"], rotate.SubPresetIds);+ Assert.Equal(Preset.GroupTarget, rotate.TargetFormat);+ Assert.Single(presets, p => p.Id == "rotate-left"); // repaired, not added twice+ }+[Fact]public void Catalog_migration_ignores_extensions_checked_on_mixed_profiles(){