@@ -250,8 +250,18 @@ private static void RenderElements( List<SvgVisualElement> elements, Document ou
250
250
{
251
251
// Render empty group boundary and continue
252
252
var pdnLayer = new BitmapLayer ( outputDocument . Width , outputDocument . Height ) ;
253
- pdnLayer . Name = ( ( PaintGroupBoundaries ) element ) . ID ;
253
+ var boundaryNode = ( ( PaintGroupBoundaries ) element ) ;
254
+ pdnLayer . Name = boundaryNode . ID ;
255
+
256
+ // Store related group opacity and visibility.
257
+ if ( boundaryNode . RelatedGroup != null )
258
+ {
259
+ pdnLayer . Opacity = ( byte ) ( boundaryNode . RelatedGroup . Opacity * 255 ) ;
260
+ pdnLayer . Visible = boundaryNode . RelatedGroup . Visible ;
261
+ }
262
+
254
263
outputDocument . Layers . Add ( pdnLayer ) ;
264
+
255
265
continue ;
256
266
}
257
267
@@ -319,7 +329,8 @@ private static void RenderElement(SvgElement element, Document outputDocument, b
319
329
// Store opacity as layer options.
320
330
if ( setOpacityForLayer )
321
331
{
322
- // Set full opacity when enabled to render 100%. We will use this opacity as layer property.
332
+ // Set full opacity when enabled to render 100%.
333
+ // Anyway opacity will be set as paint layer options.
323
334
if ( element . Opacity > 0.01 )
324
335
{
325
336
element . Opacity = 1 ;
@@ -457,15 +468,6 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
457
468
continue ;
458
469
}
459
470
460
- var isGroup = toRender is SvgGroup ;
461
- if ( isGroup )
462
- {
463
- groupName = GetLayerTitle ( ( SvgGroup ) toRender ) ;
464
-
465
- // Return fake node to indicate group end.
466
- yield return new PaintGroupBoundaries ( ) { ID = string . Format ( LayerGroupEnd , groupName ) } ;
467
- }
468
-
469
471
var visual = toRender as SvgVisualElement ;
470
472
471
473
if ( visual != null )
@@ -487,6 +489,19 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
487
489
toRender . CustomAttributes . Add ( groupAttribute , groupName ) ;
488
490
}
489
491
}
492
+
493
+ var group = toRender as SvgGroup ;
494
+ if ( group != null )
495
+ {
496
+ groupName = GetLayerTitle ( group ) ;
497
+
498
+ // Return fake node to indicate group end. (order is reversed)
499
+ yield return new PaintGroupBoundaries ( )
500
+ {
501
+ RelatedGroup = group ,
502
+ ID = string . Format ( LayerGroupEnd , groupName )
503
+ } ;
504
+ }
490
505
491
506
var returned = PrepareFlatElements ( toRender . Children , groupName ) ;
492
507
if ( returned != null )
@@ -497,12 +512,15 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
497
512
}
498
513
}
499
514
500
- if ( isGroup )
515
+ if ( group != null )
501
516
{
502
- groupName = GetLayerTitle ( ( SvgGroup ) toRender ) ;
503
-
504
517
// Return fake node to indicate group start.
505
- yield return new PaintGroupBoundaries ( ) { ID = string . Format ( LayerGroupBegin , groupName ) , IsStart = true } ;
518
+ yield return new PaintGroupBoundaries ( )
519
+ {
520
+ ID = string . Format ( LayerGroupBegin , groupName ) ,
521
+ IsStart = true ,
522
+ RelatedGroup = group
523
+ } ;
506
524
}
507
525
508
526
// Skip text with empty content. But keep all children nodes.
@@ -552,6 +570,7 @@ public void Dispose()
552
570
// Used to determine boundaries of a group.
553
571
public class PaintGroupBoundaries : SvgVisualElement
554
572
{
573
+ public SvgGroup RelatedGroup { get ; set ; }
555
574
public bool IsStart { get ; set ; }
556
575
public override RectangleF Bounds => throw new NotImplementedException ( ) ;
557
576
0 commit comments