@@ -16,7 +16,7 @@ public class SvgFileType : FileType
16
16
public SvgFileType ( ) : base ( FileTypeName ,
17
17
new FileTypeOptions
18
18
{
19
- LoadExtensions = SupportedExtensions ,
19
+ LoadExtensions = new [ ] { ".svg" , ".svgz" } ,
20
20
SupportsCancellation = true ,
21
21
SupportsLayers = true
22
22
} )
@@ -25,9 +25,9 @@ public SvgFileType() : base(FileTypeName,
25
25
26
26
private const string FileTypeName = "Scalable Vector Graphics" ;
27
27
private const string WindowTitle = "SVG Import Plug-in v1.0.1" ;
28
- private static readonly string [ ] SupportedExtensions = { ".svg" , ".svgz" } ;
29
28
30
29
// Don't change this text! It's used by a PSD import plugin to keep Photoshop's folder structure.
30
+ // https://forums.getpaint.net/topic/113742-photoshop-psd-file-plugin-with-layers-support/
31
31
public const string LayerGroupBegin = "Layer Group: {0}" ;
32
32
public const string LayerGroupEnd = "End Layer Group: {0}" ;
33
33
@@ -54,9 +54,9 @@ protected override Document OnLoad(Stream input)
54
54
using ( dialog = new SvgImportDialog ( ) )
55
55
{
56
56
dialog . Title = WindowTitle ;
57
+ dialog . SourceDpi = ppi ;
57
58
dialog . ViewportW = viewportW ;
58
59
dialog . ViewportH = viewportH ;
59
- dialog . SourceDpi = ppi ;
60
60
dialog . ViewBoxX = viewBoxX ;
61
61
dialog . ViewBoxY = viewBoxY ;
62
62
dialog . ViewBoxW = viewBoxW ;
@@ -113,7 +113,6 @@ private void Dialog_FormClosing(object sender, FormClosingEventArgs e)
113
113
114
114
private void Dialog_FormClosed ( object sender , FormClosedEventArgs e )
115
115
{
116
- cts = null ;
117
116
svg = null ;
118
117
GC . Collect ( ) ;
119
118
}
@@ -150,8 +149,6 @@ private Document DoImport()
150
149
: new SvgAspectRatio ( SvgPreserveAspectRatio . none ) ;
151
150
152
151
LayersMode layersMode = dialog . LayersMode ;
153
- int canvasW = dialog . CanvasW ;
154
- int canvasH = dialog . CanvasH ;
155
152
bool importGroupBoundariesAsLayers = dialog . ImportGroupBoundariesAsLayers ;
156
153
bool setOpacityForLayer = dialog . ImportOpacity ;
157
154
bool importHiddenLayers = dialog . ImportHiddenLayers ;
@@ -160,7 +157,7 @@ private Document DoImport()
160
157
// Render one flat image and quit.
161
158
if ( layersMode == LayersMode . Flat )
162
159
{
163
- using ( Bitmap bmp = RenderFlatImage ( svg , canvasW , canvasH ) )
160
+ using ( Bitmap bmp = RenderSvgDocument ( ) )
164
161
{
165
162
return Document . FromImage ( bmp ) ;
166
163
}
@@ -246,7 +243,8 @@ private Document DoImport()
246
243
}
247
244
}
248
245
249
- if ( ShowMemoryWarningDialog ( groupsAndElementsWithoutGroup . Count ) != DialogResult . Yes )
246
+ if ( groupsAndElementsWithoutGroup . Count > LayerCountWarningThreshold &&
247
+ ShowMemoryWarningDialog ( groupsAndElementsWithoutGroup . Count ) != DialogResult . Yes )
250
248
{
251
249
dialog . DialogResult = DialogResult . Cancel ;
252
250
return null ;
@@ -264,7 +262,7 @@ private Document DoImport()
264
262
if ( pdnDocument == null || pdnDocument . Layers . Count == 0 )
265
263
{
266
264
pdnDocument ? . Dispose ( ) ;
267
- using ( Bitmap bmp = RenderFlatImage ( svg , canvasW , canvasH ) )
265
+ using ( Bitmap bmp = RenderSvgDocument ( ) )
268
266
{
269
267
return Document . FromImage ( bmp ) ;
270
268
}
@@ -341,7 +339,7 @@ private Document RenderElements(IReadOnlyCollection<SvgVisualElement> elements,
341
339
342
340
pdnDocument = pdnDocument ?? new Document ( width , height ) ;
343
341
// Render empty group boundary and continue
344
- var pdnLayer = new BitmapLayer ( pdnDocument . Width , pdnDocument . Height )
342
+ var pdnLayer = new BitmapLayer ( width , height )
345
343
{
346
344
Name = boundaryNode . ID ,
347
345
Opacity = ( byte ) ( boundaryNode . RelatedGroup . Opacity * 255 ) ,
@@ -400,7 +398,7 @@ private Document RenderElements(IReadOnlyCollection<SvgVisualElement> elements,
400
398
private void RenderElement ( SvgElement element , bool setOpacityForLayer ,
401
399
bool importHiddenLayers )
402
400
{
403
- var opacity = element . Opacity ;
401
+ float opacity = element . Opacity ;
404
402
var visible = true ;
405
403
var visualElement = element as SvgVisualElement ;
406
404
if ( visualElement != null )
@@ -431,7 +429,7 @@ private void RenderElement(SvgElement element, bool setOpacityForLayer,
431
429
432
430
BitmapLayer pdnLayer ;
433
431
pdnDocument = pdnDocument ?? new Document ( width , height ) ;
434
- using ( Bitmap bmp = RenderFlatImage ( element . OwnerDocument , pdnDocument . Width , pdnDocument . Height ) )
432
+ using ( Bitmap bmp = RenderSvgDocument ( ) )
435
433
using ( Surface surface = Surface . CopyFromBitmap ( bmp ) )
436
434
{
437
435
pdnLayer = new BitmapLayer ( surface ) ;
@@ -464,12 +462,12 @@ private static bool IsVisibleOriginally(SvgElement element)
464
462
return true ;
465
463
}
466
464
467
- private static Bitmap RenderFlatImage ( SvgDocument doc , int canvasw , int canvash )
465
+ private Bitmap RenderSvgDocument ( )
468
466
{
469
- var bmp = new Bitmap ( canvasw , canvash ) ;
467
+ var bmp = new Bitmap ( width , height ) ;
470
468
using ( Graphics graph = Graphics . FromImage ( bmp ) )
471
469
{
472
- doc . Draw ( graph ) ;
470
+ svg . Draw ( graph ) ;
473
471
}
474
472
475
473
return bmp ;
@@ -568,13 +566,16 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
568
566
569
567
if ( toRender is SvgVisualElement visual )
570
568
{
569
+ const string hidden = "hidden" ;
570
+ const string none = "none" ;
571
+
571
572
// Fix problem that SVG visual element lib style "display:none" is not recognized as visible state.
572
573
if ( visual . Visible &&
573
- ( visual . Display ? . Trim ( ) . Equals ( " none" , StringComparison . OrdinalIgnoreCase ) == true ||
574
- visual . Display ? . Trim ( ) . Equals ( " hidden" , StringComparison . OrdinalIgnoreCase ) == true ) )
574
+ ( visual . Display ? . Trim ( ) . Equals ( none , StringComparison . OrdinalIgnoreCase ) == true ||
575
+ visual . Display ? . Trim ( ) . Equals ( hidden , StringComparison . OrdinalIgnoreCase ) == true ) )
575
576
{
576
- visual . Visibility = " hidden" ;
577
- visual . Display = " none" ;
577
+ visual . Visibility = hidden ;
578
+ visual . Display = none ;
578
579
}
579
580
580
581
// Store opacity
0 commit comments