mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 09:49:07 +00:00
Add support for .kra and .cdr previews #1662
This commit is contained in:
@@ -20,7 +20,9 @@ using PureSharpCompress.Common;
|
||||
using PureSharpCompress.Readers;
|
||||
using QuickLook.Common.Plugin;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Resources;
|
||||
@@ -73,6 +75,34 @@ internal static class Handler
|
||||
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)
|
||||
@@ -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;
|
||||
}
|
||||
|
@@ -30,7 +30,9 @@ public class Plugin : IViewer
|
||||
{
|
||||
private static readonly HashSet<string> WellKnownImageExtensions = new(
|
||||
[
|
||||
".cdr", // CorelDraw
|
||||
".fig", // Figma
|
||||
".kra", // Krita
|
||||
".xd", // AdobeXD
|
||||
".xmind", // XMind
|
||||
]);
|
||||
@@ -65,6 +67,9 @@ public class Plugin : IViewer
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
using Stream imageData = Handler.ViewImage(path);
|
||||
|
||||
if (imageData is null) return;
|
||||
|
||||
BitmapImage bitmap = imageData.ReadAsBitmapImage();
|
||||
|
||||
if (_ip is null) return;
|
||||
|
Reference in New Issue
Block a user