Add support for .kra and .cdr previews #1662

This commit is contained in:
ema
2025-07-05 04:58:24 +08:00
parent 63f516b504
commit 22e8838ce3
2 changed files with 69 additions and 0 deletions

View File

@@ -20,7 +20,9 @@ using PureSharpCompress.Common;
using PureSharpCompress.Readers; using PureSharpCompress.Readers;
using QuickLook.Common.Plugin; using QuickLook.Common.Plugin;
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Resources; using System.Windows.Resources;
@@ -73,6 +75,34 @@ internal static class Handler
context.PreferredSize = new Size { Width = 1200, Height = 900 }; context.PreferredSize = new Size { Width = 1200, Height = 900 };
} }
} }
else if (path.EndsWith(".kra", StringComparison.OrdinalIgnoreCase))
{
try
{
using Stream imageData = ViewImage(path);
BitmapImage bitmap = imageData.ReadAsBitmapImage();
context.SetPreferredSizeFit(new Size(bitmap.PixelWidth, bitmap.PixelHeight), 0.8d);
}
catch (Exception e)
{
_ = e;
context.PreferredSize = new Size { Width = 800, Height = 600 };
}
}
else if (path.EndsWith(".cdr", StringComparison.OrdinalIgnoreCase))
{
try
{
using Stream imageData = ViewImage(path);
BitmapImage bitmap = imageData.ReadAsBitmapImage();
context.SetPreferredSizeFit(new Size(bitmap.PixelWidth, bitmap.PixelHeight), 0.8d);
}
catch (Exception e)
{
_ = e;
context.PreferredSize = new Size { Width = 800, Height = 600 };
}
}
} }
public static Stream ViewImage(string path) public static Stream ViewImage(string path)
@@ -142,6 +172,40 @@ internal static class Handler
} }
} }
} }
else if (path.EndsWith(".kra", StringComparison.OrdinalIgnoreCase))
{
using ZipArchive archive = ZipArchive.Open(path, new());
using IReader reader = archive.ExtractAllEntries();
while (reader.MoveToNextEntry())
{
Debug.WriteLine(reader.Entry.Key);
if (reader.Entry.Key!.Contains("mergedimage"))
{
MemoryStream ms = new();
using EntryStream stream = reader.OpenEntryStream();
stream.CopyTo(ms);
return ms;
}
}
}
else if (path.EndsWith(".cdr", StringComparison.OrdinalIgnoreCase))
{
using ZipArchive archive = ZipArchive.Open(path, new());
using IReader reader = archive.ExtractAllEntries();
while (reader.MoveToNextEntry())
{
if (reader.Entry.Key!.Equals("previews/thumbnail.png", StringComparison.OrdinalIgnoreCase))
{
MemoryStream ms = new();
using EntryStream stream = reader.OpenEntryStream();
stream.CopyTo(ms);
return ms;
}
}
}
return null; return null;
} }

View File

@@ -30,7 +30,9 @@ public class Plugin : IViewer
{ {
private static readonly HashSet<string> WellKnownImageExtensions = new( private static readonly HashSet<string> WellKnownImageExtensions = new(
[ [
".cdr", // CorelDraw
".fig", // Figma ".fig", // Figma
".kra", // Krita
".xd", // AdobeXD ".xd", // AdobeXD
".xmind", // XMind ".xmind", // XMind
]); ]);
@@ -65,6 +67,9 @@ public class Plugin : IViewer
_ = Task.Run(() => _ = Task.Run(() =>
{ {
using Stream imageData = Handler.ViewImage(path); using Stream imageData = Handler.ViewImage(path);
if (imageData is null) return;
BitmapImage bitmap = imageData.ReadAsBitmapImage(); BitmapImage bitmap = imageData.ReadAsBitmapImage();
if (_ip is null) return; if (_ip is null) return;