//========================================================================== public virtual Geometry?GetGeometry() { var geometry = GetBaseGeometry(); if (geometry is null) { return(null); } if (Transform != null) { geometry.Transform = Transform.ToTransform(); } if (ClipPath is null) { return(geometry); } var clip_path_element = Document.Elements[ClipPath] as SvgClipPathElement; var clip_geometry = clip_path_element?.GetClipGeometry(); return(clip_geometry != null ? Geometry.Combine(geometry, clip_geometry, GeometryCombineMode.Intersect, null) : geometry); }
//========================================================================== public virtual Geometry GetGeometry() { var geometry_group = new GeometryGroup(); foreach (var element in Children) { if (element is SvgDrawableBaseElement) { geometry_group.Children.Add((element as SvgDrawableBaseElement).GetGeometry()); } else if (element is SvgDrawableContainerBaseElement) { geometry_group.Children.Add((element as SvgDrawableContainerBaseElement).GetGeometry()); } } if (Transform != null) { geometry_group.Transform = Transform.ToTransform(); } if (ClipPath != null) { var clip_path_element = Document.Elements[ClipPath.Id] as SvgClipPathElement; if (clip_path_element != null) { return(Geometry.Combine(geometry_group, clip_path_element.GetClipGeometry(), GeometryCombineMode.Exclude, null)); } } return(geometry_group); }
//========================================================================== public DrawingBrush ToBrush() { DrawingBrush brush = null; if (Reference is null) { brush = new DrawingBrush(Draw()); } else { var element = Document.Elements[Reference]; if (element is SvgPatternElement) { brush = (element as SvgPatternElement).ToBrush(); } else { throw new NotSupportedException("Other references than patterns are not supported"); } } if (brush is null) { return(null); } if ((Width != null) || (Height != null)) { var width = brush.Drawing.Bounds.Width; var height = brush.Drawing.Bounds.Height; } if (PatternUnits == SvgPatternUnits.UserSpaceOnUse) { brush.ViewportUnits = BrushMappingMode.Absolute; brush.Viewport = brush.Drawing.Bounds; } if (PatternTransform != null) { var drawing_group = new DrawingGroup(); drawing_group.Transform = PatternTransform.ToTransform(); drawing_group.Children.Add(brush.Drawing); brush.Drawing = drawing_group; } return(brush); }
//========================================================================== protected virtual GradientBrush SetBrush(GradientBrush brush) { switch (SpreadMethod) { case SvgSpreadMethod.Pad: brush.SpreadMethod = GradientSpreadMethod.Pad; break; case SvgSpreadMethod.Reflect: brush.SpreadMethod = GradientSpreadMethod.Reflect; break; case SvgSpreadMethod.Repeat: brush.SpreadMethod = GradientSpreadMethod.Repeat; break; } switch (GradientUnits) { case SvgGradientUnits.ObjectBoundingBox: brush.MappingMode = BrushMappingMode.RelativeToBoundingBox; break; case SvgGradientUnits.UserSpaceOnUse: brush.MappingMode = BrushMappingMode.Absolute; break; } if (Transform != null) { brush.Transform = Transform.ToTransform(); } foreach (var stop in Stops) { brush.GradientStops.Add(stop.ToGradientStop()); } return(brush); }