@@ -16,7 +16,7 @@ public class SvgFileType : FileType
1616 public SvgFileType ( ) : base ( FileTypeName ,
1717 new FileTypeOptions
1818 {
19- LoadExtensions = SupportedExtensions ,
19+ LoadExtensions = new [ ] { ".svg" , ".svgz" } ,
2020 SupportsCancellation = true ,
2121 SupportsLayers = true
2222 } )
@@ -25,9 +25,9 @@ public SvgFileType() : base(FileTypeName,
2525
2626 private const string FileTypeName = "Scalable Vector Graphics" ;
2727 private const string WindowTitle = "SVG Import Plug-in v1.0.1" ;
28- private static readonly string [ ] SupportedExtensions = { ".svg" , ".svgz" } ;
2928
3029 // 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/
3131 public const string LayerGroupBegin = "Layer Group: {0}" ;
3232 public const string LayerGroupEnd = "End Layer Group: {0}" ;
3333
@@ -54,9 +54,9 @@ protected override Document OnLoad(Stream input)
5454 using ( dialog = new SvgImportDialog ( ) )
5555 {
5656 dialog . Title = WindowTitle ;
57+ dialog . SourceDpi = ppi ;
5758 dialog . ViewportW = viewportW ;
5859 dialog . ViewportH = viewportH ;
59- dialog . SourceDpi = ppi ;
6060 dialog . ViewBoxX = viewBoxX ;
6161 dialog . ViewBoxY = viewBoxY ;
6262 dialog . ViewBoxW = viewBoxW ;
@@ -113,7 +113,6 @@ private void Dialog_FormClosing(object sender, FormClosingEventArgs e)
113113
114114 private void Dialog_FormClosed ( object sender , FormClosedEventArgs e )
115115 {
116- cts = null ;
117116 svg = null ;
118117 GC . Collect ( ) ;
119118 }
@@ -150,8 +149,6 @@ private Document DoImport()
150149 : new SvgAspectRatio ( SvgPreserveAspectRatio . none ) ;
151150
152151 LayersMode layersMode = dialog . LayersMode ;
153- int canvasW = dialog . CanvasW ;
154- int canvasH = dialog . CanvasH ;
155152 bool importGroupBoundariesAsLayers = dialog . ImportGroupBoundariesAsLayers ;
156153 bool setOpacityForLayer = dialog . ImportOpacity ;
157154 bool importHiddenLayers = dialog . ImportHiddenLayers ;
@@ -160,7 +157,7 @@ private Document DoImport()
160157 // Render one flat image and quit.
161158 if ( layersMode == LayersMode . Flat )
162159 {
163- using ( Bitmap bmp = RenderFlatImage ( svg , canvasW , canvasH ) )
160+ using ( Bitmap bmp = RenderSvgDocument ( ) )
164161 {
165162 return Document . FromImage ( bmp ) ;
166163 }
@@ -246,7 +243,8 @@ private Document DoImport()
246243 }
247244 }
248245
249- if ( ShowMemoryWarningDialog ( groupsAndElementsWithoutGroup . Count ) != DialogResult . Yes )
246+ if ( groupsAndElementsWithoutGroup . Count > LayerCountWarningThreshold &&
247+ ShowMemoryWarningDialog ( groupsAndElementsWithoutGroup . Count ) != DialogResult . Yes )
250248 {
251249 dialog . DialogResult = DialogResult . Cancel ;
252250 return null ;
@@ -264,7 +262,7 @@ private Document DoImport()
264262 if ( pdnDocument == null || pdnDocument . Layers . Count == 0 )
265263 {
266264 pdnDocument ? . Dispose ( ) ;
267- using ( Bitmap bmp = RenderFlatImage ( svg , canvasW , canvasH ) )
265+ using ( Bitmap bmp = RenderSvgDocument ( ) )
268266 {
269267 return Document . FromImage ( bmp ) ;
270268 }
@@ -341,7 +339,7 @@ private Document RenderElements(IReadOnlyCollection<SvgVisualElement> elements,
341339
342340 pdnDocument = pdnDocument ?? new Document ( width , height ) ;
343341 // Render empty group boundary and continue
344- var pdnLayer = new BitmapLayer ( pdnDocument . Width , pdnDocument . Height )
342+ var pdnLayer = new BitmapLayer ( width , height )
345343 {
346344 Name = boundaryNode . ID ,
347345 Opacity = ( byte ) ( boundaryNode . RelatedGroup . Opacity * 255 ) ,
@@ -400,7 +398,7 @@ private Document RenderElements(IReadOnlyCollection<SvgVisualElement> elements,
400398 private void RenderElement ( SvgElement element , bool setOpacityForLayer ,
401399 bool importHiddenLayers )
402400 {
403- var opacity = element . Opacity ;
401+ float opacity = element . Opacity ;
404402 var visible = true ;
405403 var visualElement = element as SvgVisualElement ;
406404 if ( visualElement != null )
@@ -431,7 +429,7 @@ private void RenderElement(SvgElement element, bool setOpacityForLayer,
431429
432430 BitmapLayer pdnLayer ;
433431 pdnDocument = pdnDocument ?? new Document ( width , height ) ;
434- using ( Bitmap bmp = RenderFlatImage ( element . OwnerDocument , pdnDocument . Width , pdnDocument . Height ) )
432+ using ( Bitmap bmp = RenderSvgDocument ( ) )
435433 using ( Surface surface = Surface . CopyFromBitmap ( bmp ) )
436434 {
437435 pdnLayer = new BitmapLayer ( surface ) ;
@@ -464,12 +462,12 @@ private static bool IsVisibleOriginally(SvgElement element)
464462 return true ;
465463 }
466464
467- private static Bitmap RenderFlatImage ( SvgDocument doc , int canvasw , int canvash )
465+ private Bitmap RenderSvgDocument ( )
468466 {
469- var bmp = new Bitmap ( canvasw , canvash ) ;
467+ var bmp = new Bitmap ( width , height ) ;
470468 using ( Graphics graph = Graphics . FromImage ( bmp ) )
471469 {
472- doc . Draw ( graph ) ;
470+ svg . Draw ( graph ) ;
473471 }
474472
475473 return bmp ;
@@ -568,13 +566,16 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
568566
569567 if ( toRender is SvgVisualElement visual )
570568 {
569+ const string hidden = "hidden" ;
570+ const string none = "none" ;
571+
571572 // Fix problem that SVG visual element lib style "display:none" is not recognized as visible state.
572573 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 ) )
575576 {
576- visual . Visibility = " hidden" ;
577- visual . Display = " none" ;
577+ visual . Visibility = hidden ;
578+ visual . Display = none ;
578579 }
579580
580581 // Store opacity
0 commit comments