Skip to content

Commit 56a5cb0

Browse files
committed
Group boundaries properties like opacity and visibility now also stored as paint layer properties.
1 parent c70ab35 commit 56a5cb0

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

SvgFileType/SvgFileType.cs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,18 @@ private static void RenderElements( List<SvgVisualElement> elements, Document ou
250250
{
251251
// Render empty group boundary and continue
252252
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+
254263
outputDocument.Layers.Add(pdnLayer);
264+
255265
continue;
256266
}
257267

@@ -319,7 +329,8 @@ private static void RenderElement(SvgElement element, Document outputDocument, b
319329
// Store opacity as layer options.
320330
if (setOpacityForLayer)
321331
{
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.
323334
if (element.Opacity > 0.01)
324335
{
325336
element.Opacity = 1;
@@ -457,15 +468,6 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
457468
continue;
458469
}
459470

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-
469471
var visual = toRender as SvgVisualElement;
470472

471473
if (visual != null)
@@ -487,6 +489,19 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
487489
toRender.CustomAttributes.Add(groupAttribute, groupName);
488490
}
489491
}
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+
}
490505

491506
var returned = PrepareFlatElements(toRender.Children, groupName);
492507
if (returned != null)
@@ -497,12 +512,15 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
497512
}
498513
}
499514

500-
if (isGroup)
515+
if (group != null)
501516
{
502-
groupName = GetLayerTitle((SvgGroup)toRender);
503-
504517
// 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+
};
506524
}
507525

508526
// Skip text with empty content. But keep all children nodes.
@@ -552,6 +570,7 @@ public void Dispose()
552570
// Used to determine boundaries of a group.
553571
public class PaintGroupBoundaries : SvgVisualElement
554572
{
573+
public SvgGroup RelatedGroup { get; set; }
555574
public bool IsStart { get; set; }
556575
public override RectangleF Bounds => throw new NotImplementedException();
557576

0 commit comments

Comments
 (0)