Fixed SvgContainer support for the .greenshot file

This commit is contained in:
Robin Krom 2023-03-27 22:43:03 +02:00
commit f862e79485
4 changed files with 116 additions and 95 deletions

View file

@ -21,6 +21,7 @@
using System;
using System.Drawing;
using System.IO;
using Dapplo.Windows.Common.Structs;
using Greenshot.Base.Core;
using Greenshot.Base.Interfaces;
@ -34,12 +35,30 @@ namespace Greenshot.Editor.Drawing
[Serializable]
public class SvgContainer : VectorGraphicsContainer
{
private readonly SvgDocument _svgDocument;
private MemoryStream _svgContent;
public SvgContainer(SvgDocument svgDocument, ISurface parent) : base(parent)
[NonSerialized]
private SvgDocument _svgDocument;
public SvgContainer(Stream stream, ISurface parent) : base(parent)
{
_svgDocument = svgDocument;
Size = new Size((int)svgDocument.Width, (int)svgDocument.Height);
_svgContent = new MemoryStream();
stream.CopyTo(_svgContent);
Init();
Size = new Size((int)_svgDocument.Width, (int)_svgDocument.Height);
}
protected override void Init()
{
base.Init();
// Do nothing when there is no content
if (_svgContent == null)
{
return;
}
_svgContent.Position = 0;
_svgDocument = SvgDocument.Open<SvgDocument>(_svgContent);
}
protected override Image ComputeBitmap()

View file

@ -47,7 +47,8 @@ namespace Greenshot.Editor.Drawing
/// This is the cached version of the bitmap, pre-rendered to save performance
/// Do not serialized, it can be rebuild with other information.
/// </summary>
[NonSerialized] private Image _cachedImage;
[NonSerialized]
private Image _cachedImage;
/// <summary>
/// Constructor takes care of calling Init

View file

@ -71,18 +71,18 @@ namespace Greenshot.Editor.FileFormatHandlers
public override IEnumerable<IDrawableContainer> LoadDrawablesFromStream(Stream stream, string extension, ISurface parent = null)
{
SvgDocument svgDocument = null;
SvgContainer svgContainer = null;
try
{
svgDocument = SvgDocument.Open<SvgDocument>(stream);
svgContainer = new SvgContainer(stream, parent);
}
catch (Exception ex)
{
Log.Error("Can't load SVG", ex);
}
if (svgDocument != null)
if (svgContainer != null)
{
yield return new SvgContainer(svgDocument, parent);
yield return svgContainer;
}
}
}

View file

@ -48,6 +48,7 @@ namespace Greenshot.Editor.Helpers
{"System.Drawing.Bitmap",typeof(System.Drawing.Bitmap) },
{"System.Drawing.Icon",typeof(System.Drawing.Icon) },
{"System.Drawing.Size",typeof(System.Drawing.Size) },
{"System.IO.MemoryStream",typeof(System.IO.MemoryStream) },
{"System.Drawing.StringAlignment",typeof(System.Drawing.StringAlignment) },
{"System.Collections.Generic.List`1[[Greenshot.Base.Interfaces.Drawing.IFieldHolder", typeof(List<IFieldHolder>)},
{"System.Collections.Generic.List`1[[Greenshot.Base.Interfaces.Drawing.IField", typeof(List<IField>)},