private Drawing GetImage(WpfDrawingContext context) { WpfDrawingRenderer renderer = new WpfDrawingRenderer(); renderer.Window = _patternElement.OwnerDocument.Window as SvgWindow; WpfDrawingSettings settings = context.Settings.Clone(); settings.TextAsGeometry = true; WpfDrawingContext patternContext = new WpfDrawingContext(true, settings); patternContext.Initialize(null, context.FontFamilyVisitor, null); SvgSvgElement elm = MoveIntoSvgElement(); renderer.Render(elm, patternContext); DrawingGroup rootGroup = renderer.Drawing; MoveOutOfSvgElement(elm); if (rootGroup.Children.Count == 1) { return(rootGroup.Children[0]); } return(rootGroup); }
public void Render(ISvgDocument node) { //SvgRectF updatedRect; //if (invalidRect != SvgRectF.Empty) // updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y, // invalidRect.Width, invalidRect.Height); //else // updatedRect = SvgRectF.Empty; //RendererBeforeRender(); //_renderingContext = new WpfDrawingContext(new DrawingGroup()); if (_svgRenderer == null) { _svgRenderer = new WpfRenderingHelper(this); } _context = new WpfDrawingContext(_isEmbedded, _settings); _context.Initialize(_linkVisitor, _fontFamilyVisitor, _imageVisitor); _context.BeginDrawing(_drawingDocument); _svgRenderer.Render(node); _context.EndDrawing(); //RendererAfterRender(); //if (onRender != null) // OnRender(updatedRect); }
public void Render(ISvgElement node) { //throw new NotImplementedException(); //SvgRectF updatedRect; //if (invalidRect != SvgRectF.Empty) // updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y, // invalidRect.Width, invalidRect.Height); //else // updatedRect = SvgRectF.Empty; //RendererBeforeRender(); //if (graphics != null && graphics.Graphics != null) //{ // _svgRenderer.Render(node); //} //RendererAfterRender(); //if (onRender != null) // OnRender(updatedRect); _renderingContext = new WpfDrawingContext(true, _renderingSettings); _renderingContext.Initialize(null, _fontFamilyVisitor, _imageVisitor); _renderingContext.BeginDrawing(); _svgRenderer.Render(node); _renderingContext.EndDrawing(); }
private GeometryCollection GetTextClippingRegion(SvgStyleableElement element, WpfDrawingContext context) { GeometryCollection geomColl = new GeometryCollection(); WpfDrawingRenderer renderer = new WpfDrawingRenderer(); renderer.Window = _svgElement.OwnerDocument.Window as SvgWindow; WpfDrawingSettings settings = context.Settings.Clone(); settings.TextAsGeometry = true; WpfDrawingContext clipContext = new WpfDrawingContext(true, settings); clipContext.RenderingClipRegion = true; clipContext.Initialize(null, context.FontFamilyVisitor, null); renderer.Render(element, clipContext); DrawingGroup rootGroup = renderer.Drawing as DrawingGroup; if (rootGroup != null && rootGroup.Children.Count == 1) { DrawingGroup textGroup = rootGroup.Children[0] as DrawingGroup; if (textGroup != null) { ExtractGeometry(textGroup, geomColl); } } return(geomColl); }
public void Render(ISvgDocument node) { //SvgRectF updatedRect; //if (invalidRect != SvgRectF.Empty) // updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y, // invalidRect.Width, invalidRect.Height); //else // updatedRect = SvgRectF.Empty; //RendererBeforeRender(); //_renderingContext = new WpfDrawingContext(new DrawingGroup()); if (_svgRenderer == null) { _svgRenderer = new WpfRenderingHelper(this); } var isStatic = node.Static; node.Static = true; _context = new WpfDrawingContext(_isEmbedded, _settings); _context.Initialize(_linkVisitor, _fontFamilyVisitor, _imageVisitor); if (!_isEmbedded) { if (_svgWindow != null && _svgWindow.BaseUrls == null) { _svgWindow.BaseUrls = _context.BaseUrls; } } _context.BeginDrawing(_drawingDocument); _svgRenderer.Render(node); _context.EndDrawing(); if (!_isEmbedded) { if (_svgWindow != null && _svgWindow.BaseUrls != null && _svgWindow.BaseUrls.Count != 0) { _svgWindow.BaseUrls.Clear(); } node.Static = isStatic; } //RendererAfterRender(); //if (onRender != null) // OnRender(updatedRect); }
public void RenderMask(ISvgElement node, WpfDrawingContext context) { if (context == null) { _context = new WpfDrawingContext(true, _settings); _context.Initialize(null, _fontFamilyVisitor, _imageVisitor); } else { _context = context; } _context.BeginDrawing(_drawingDocument); _svgRenderer.RenderMask(node); _context.EndDrawing(); }
protected void SetMask(WpfDrawingContext context) { _maskUnits = SvgUnitType.UserSpaceOnUse; _maskContentUnits = SvgUnitType.UserSpaceOnUse; CssPrimitiveValue maskPath = _svgElement.GetComputedCssValue("mask", string.Empty) as CssPrimitiveValue; SvgMaskElement maskElement = null; if (maskPath != null && maskPath.PrimitiveType == CssPrimitiveType.Uri) { string absoluteUri = _svgElement.ResolveUri(maskPath.GetStringValue()); maskElement = _svgElement.OwnerDocument.GetNodeByUri(absoluteUri) as SvgMaskElement; } else if (string.Equals(_svgElement.ParentNode.LocalName, "use")) { var parentElement = _svgElement.ParentNode as SvgElement; maskPath = parentElement.GetComputedCssValue("mask", string.Empty) as CssPrimitiveValue; if (maskPath != null && maskPath.PrimitiveType == CssPrimitiveType.Uri) { string absoluteUri = _svgElement.ResolveUri(maskPath.GetStringValue()); maskElement = _svgElement.OwnerDocument.GetNodeByUri(absoluteUri) as SvgMaskElement; } } if (maskElement != null) { WpfDrawingRenderer renderer = new WpfDrawingRenderer(); renderer.Window = _svgElement.OwnerDocument.Window as SvgWindow; WpfDrawingSettings settings = context.Settings.Clone(); settings.TextAsGeometry = true; WpfDrawingContext maskContext = new WpfDrawingContext(true, settings); //maskContext.Initialize(null, context.FontFamilyVisitor, null); maskContext.Initialize(context.LinkVisitor, context.FontFamilyVisitor, context.ImageVisitor); renderer.RenderMask(maskElement, maskContext); DrawingGroup maskDrawing = renderer.Drawing; Rect bounds = new Rect(0, 0, 1, 1); //Rect destRect = GetMaskDestRect(maskElement, bounds); //destRect = bounds; //DrawingImage drawImage = new DrawingImage(image); //DrawingVisual drawingVisual = new DrawingVisual(); //DrawingContext drawingContext = drawingVisual.RenderOpen(); //drawingContext.DrawDrawing(image); //drawingContext.Close(); //RenderTargetBitmap drawImage = new RenderTargetBitmap((int)200, // (int)200, 96, 96, PixelFormats.Pbgra32); //drawImage.Render(drawingVisual); //ImageBrush imageBrush = new ImageBrush(drawImage); //imageBrush.Viewbox = image.Bounds; //imageBrush.Viewport = image.Bounds; //imageBrush.ViewboxUnits = BrushMappingMode.Absolute; //imageBrush.ViewportUnits = BrushMappingMode.Absolute; //imageBrush.TileMode = TileMode.None; //imageBrush.Stretch = Stretch.None; //this.Masking = imageBrush; DrawingBrush maskBrush = new DrawingBrush(maskDrawing); //tb.Viewbox = new Rect(0, 0, destRect.Width, destRect.Height); //tb.Viewport = new Rect(0, 0, destRect.Width, destRect.Height); maskBrush.Viewbox = maskDrawing.Bounds; maskBrush.Viewport = maskDrawing.Bounds; maskBrush.ViewboxUnits = BrushMappingMode.Absolute; maskBrush.ViewportUnits = BrushMappingMode.Absolute; maskBrush.TileMode = TileMode.None; maskBrush.Stretch = Stretch.Uniform; ////maskBrush.AlignmentX = AlignmentX.Center; ////maskBrush.AlignmentY = AlignmentY.Center; this.Masking = maskBrush; _maskUnits = (SvgUnitType)maskElement.MaskUnits.AnimVal; _maskContentUnits = (SvgUnitType)maskElement.MaskContentUnits.AnimVal; } }
private DrawingGroup GetImage(WpfDrawingContext context, Rect bounds) { PrepareTargetPattern(); _renderedElement.PatternBounds = new SvgRect(bounds.X, bounds.Y, bounds.Width, bounds.Height); WpfDrawingRenderer renderer = new WpfDrawingRenderer(); renderer.Window = _renderedElement.OwnerDocument.Window as SvgWindow; // WpfDrawingSettings settings = context.Settings.Clone(); WpfDrawingSettings settings = context.Settings; bool isTextAsGeometry = settings.TextAsGeometry; settings.TextAsGeometry = true; WpfDrawingContext patternContext = new WpfDrawingContext(true, settings); patternContext.Name = "Pattern"; patternContext.Initialize(null, context.FontFamilyVisitor, null); if (_renderedElement.PatternContentUnits.AnimVal.Equals((ushort)SvgUnitType.ObjectBoundingBox)) { // svgElm.SetAttribute("viewBox", "0 0 1 1"); } else { _isUserSpace = true; } //SvgSvgElement elm = MoveIntoSvgElement(); //renderer.Render(elm, patternContext); //SvgPatternElement patternElement = _patternElement.ReferencedElement; //if (patternElement != null) //{ // if (patternElement.ReferencedElement != null) // { // _renderedElement = patternElement.ReferencedElement; // renderer.RenderAs(patternElement.ReferencedElement, patternContext); // } // else // { // _renderedElement = patternElement; // renderer.RenderAs(patternElement, patternContext); // } //} //else //{ // _renderedElement = _patternElement; // renderer.RenderAs(_patternElement, patternContext); //} renderer.RenderAs(_renderedElement, patternContext); DrawingGroup rootGroup = renderer.Drawing; //MoveOutOfSvgElement(elm); if (_renderedElement != null && _renderedElement != _patternElement) { _patternElement.RemoveChild(_renderedElement); } settings.TextAsGeometry = isTextAsGeometry; if (rootGroup.Children.Count == 1) { var childGroup = rootGroup.Children[0] as DrawingGroup; if (childGroup != null) { return(childGroup); } } return(rootGroup); }