public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); WpfDrawingContext context = renderer.Context; _drawGroup = new DrawingGroup(); string elementId = this.GetElementName(); if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId)) { _drawGroup.SetValue(FrameworkElement.NameProperty, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(_drawGroup, elementId); } } DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); }
public static void RemoveObjectNames(DrawingGroup drawingGroup) { if (drawingGroup.GetValue(FrameworkElement.NameProperty) != null) drawingGroup.SetValue(FrameworkElement.NameProperty, null); foreach (var child in drawingGroup.Children.OfType<DependencyObject>()) { if (child.GetValue(FrameworkElement.NameProperty) != null) child.SetValue(FrameworkElement.NameProperty, null); if (child is DrawingGroup) RemoveObjectNames(child as DrawingGroup); } }
public override void BeforeRender(WpfDrawingRenderer renderer) { _isTextPath = false; _isGroupAdded = false; _textWidth = 0; _isMeasuring = false; WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint == SvgRenderingHint.Clipping) { return; } // We do not directly render the contents of the clip-path, unless specifically requested... if (String.Equals(_svgElement.ParentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } string sVisibility = _textElement.GetPropertyValue("visibility"); string sDisplay = _textElement.GetPropertyValue("display"); if (String.Equals(sVisibility, "hidden") || String.Equals(sDisplay, "none")) { return; } _context = renderer.Context; SetQuality(context); SetTransform(context); SetClip(_context); SetMask(_context); _drawGroup = new DrawingGroup(); string elementId = this.GetElementName(); if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId)) { _drawGroup.SetValue(FrameworkElement.NameProperty, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(_drawGroup, elementId); } } Transform textTransform = this.Transform; if (textTransform != null && !textTransform.Value.IsIdentity) { _drawGroup.Transform = textTransform; } else { textTransform = null; // render any identity transform useless... } Geometry textClip = this.ClipGeometry; if (textClip != null && !textClip.IsEmpty()) { _drawGroup.ClipGeometry = textClip; } else { textClip = null; // render any empty geometry useless... } Brush textMask = this.Masking; if (textMask != null) { _drawGroup.OpacityMask = textMask; } if (textTransform != null || textClip != null || textMask != null) { DrawingGroup curGroup = _context.Peek(); Debug.Assert(curGroup != null); if (curGroup != null) { curGroup.Children.Add(_drawGroup); context.Push(_drawGroup); _isGroupAdded = true; } } _drawContext = _drawGroup.Open(); _horzRenderer.Initialize(_drawContext, _context); _vertRenderer.Initialize(_drawContext, _context); _pathRenderer.Initialize(_drawContext, _context); }
public override void Render(WpfDrawingRenderer renderer) { _isAggregated = false; if (_isLayer) { base.Render(renderer); return; } WpfDrawingContext context = renderer.Context; Geometry clipGeom = this.ClipGeometry; Transform transform = this.Transform; float opacityValue = -1; SvgAElement element = (SvgAElement)_svgElement; string opacity = element.GetPropertyValue("opacity"); if (opacity != null && opacity.Length > 0) { opacityValue = (float)SvgNumber.ParseNumber(opacity); opacityValue = Math.Min(opacityValue, 1); opacityValue = Math.Max(opacityValue, 0); } WpfLinkVisitor linkVisitor = context.LinkVisitor; if (linkVisitor != null || clipGeom != null || transform != null || opacityValue >= 0) { _drawGroup = new DrawingGroup(); string elementId = this.GetElementName(); if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId)) { _drawGroup.SetValue(FrameworkElement.NameProperty, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(_drawGroup, elementId); } } DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } if (linkVisitor != null && linkVisitor.Aggregates && context.Links != null) { if (!linkVisitor.Exists(elementId)) { context.Links.Children.Add(_drawGroup); } } else { currentGroup.Children.Add(_drawGroup); } context.Push(_drawGroup); if (clipGeom != null) { _drawGroup.ClipGeometry = clipGeom; } if (transform != null) { _drawGroup.Transform = transform; } if (opacityValue >= 0) { _drawGroup.Opacity = opacityValue; } if (linkVisitor != null) { linkVisitor.Visit(_drawGroup, element, context, opacityValue); _isAggregated = linkVisitor.IsAggregate; } } base.Render(renderer); }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); WpfDrawingContext context = renderer.Context; _drawGroup = new DrawingGroup(); if (context.Count == 0) { context.Push(_drawGroup); context.Root = _drawGroup; } else if (context.Count == 1) { DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } if (currentGroup == context.Root && !context.IsFragment) { _drawGroup.SetValue(FrameworkElement.NameProperty, SvgObject.DrawLayer); if (context.IncludeRuntime) { SvgLink.SetKey(_drawGroup, SvgObject.DrawLayer); } } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } else { DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } SvgSvgElement svgElm = (SvgSvgElement)_svgElement; double x = Math.Round(svgElm.X.AnimVal.Value, 4); double y = Math.Round(svgElm.Y.AnimVal.Value, 4); double width = Math.Round(svgElm.Width.AnimVal.Value, 4); double height = Math.Round(svgElm.Height.AnimVal.Value, 4); Rect elmRect = new Rect(x, y, width, height); //if (element.ParentNode is SvgElement) //{ // // TODO: should it be moved with x and y? //} XmlNode parentNode = _svgElement.ParentNode; //if (parentNode.NodeType == XmlNodeType.Document) { ISvgFitToViewBox fitToView = svgElm as ISvgFitToViewBox; if (fitToView != null) { ISvgAnimatedRect animRect = fitToView.ViewBox; if (animRect != null) { ISvgRect viewRect = animRect.AnimVal; if (viewRect != null) { Rect wpfViewRect = WpfConvert.ToRect(viewRect); if (!wpfViewRect.IsEmpty && wpfViewRect.Width > 0 && wpfViewRect.Height > 0) { elmRect = wpfViewRect; } } } } } Transform transform = null; if (parentNode.NodeType != XmlNodeType.Document) { FitToViewbox(context, elmRect); transform = this.Transform; if (transform != null) { _drawGroup.Transform = transform; } } //if (height > 0 && width > 0) //{ // ClipGeometry = new RectangleGeometry(elmRect); //} //Geometry clipGeom = this.ClipGeometry; //if (clipGeom != null) //{ // _drawGroup.ClipGeometry = clipGeom; //} if (((float)elmRect.Width != 0 && (float)elmRect.Height != 0)) { // Elements such as "pattern" are also rendered by this renderer, so we make sure we are // dealing with the root SVG element... if (parentNode != null && parentNode.NodeType == XmlNodeType.Document) { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } else { if (transform != null) { // We have already applied the transform, which will translate to the start point... if (transform is TranslateTransform) { _drawGroup.ClipGeometry = new RectangleGeometry( new Rect(0, 0, elmRect.Width, elmRect.Height)); } else { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } } else { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } } //DrawingGroup animationGroup = context.Links; //if (animationGroup != null) //{ // animationGroup.ClipGeometry = clipGeom; //} } }
/// <summary> /// Returns the thumbnail image for use outside of the control. /// </summary> /// <param name="width">Required width of the bitmap</param> /// <param name="height">Required height of the bitmap</param> /// <returns>The bitmap depicting the thumbnail.</returns> public Image GetImage(int width = THUMB_WIDTH, int height = THUMB_HEIGHT) { var drawing = new DrawingGroup(); drawing.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality); using (var context = drawing.Open()) { DrawThumb(context, width, height); } return Booster.DrawingToBitmap(drawing, width, height); }