public static WpfFill CreateFill(SvgDocument document, string absoluteUri) { XmlNode node = document.GetNodeByUri(absoluteUri); SvgGradientElement gradientNode = node as SvgGradientElement; if (gradientNode != null) { return(new WpfGradientFill(gradientNode)); } SvgPatternElement patternNode = node as SvgPatternElement; if (patternNode != null) { return(new WpfPatternFill(patternNode)); } SvgSolidColorElement solidColorNode = node as SvgSolidColorElement; if (solidColorNode != null) { return(new WpfSolidColorFill(solidColorNode)); } return(null); }
public static GdiFill CreateFill(SvgDocument document, string absoluteUri) { XmlNode node = document.GetNodeByUri(absoluteUri); var linearGradient = node as SvgLinearGradientElement; if (linearGradient != null) { return(new GdiLinearGradientFill(linearGradient)); } var radialGradient = node as SvgRadialGradientElement; if (radialGradient != null) { return(new GdiRadialGradientFill(radialGradient)); } SvgPatternElement patternNode = node as SvgPatternElement; if (patternNode != null) { return(new GdiPatternFill(patternNode)); } return(null); }
public void TestHref() { SvgPatternElement elm = Util.GetXmlElement("<pattern xlink:href='kalle.svg#someOtherPattern' />", "", "pattern") as SvgPatternElement; Assert.AreEqual("kalle.svg#someOtherPattern", elm.Href.AnimVal); elm = Util.GetXmlElement("<pattern />", "", "pattern") as SvgPatternElement; Assert.AreEqual("", elm.Href.AnimVal); }
public void TestSize() { SvgPatternElement elm = Util.GetXmlElement("<pattern x='1' y='2' width='3' height='4' />", "", "pattern") as SvgPatternElement; Assert.AreEqual(1, elm.X.AnimVal.Value, "x"); Assert.AreEqual(2, elm.Y.AnimVal.Value, "y"); Assert.AreEqual(3, elm.Width.AnimVal.Value, "width"); Assert.AreEqual(4, elm.Height.AnimVal.Value, "height"); }
public void TestPatternContentUnits() { SvgPatternElement elm = Util.GetXmlElement("<pattern patternContentUnits='userSpaceOnUse' />", "", "pattern") as SvgPatternElement; Assert.AreEqual((ushort)SvgUnitType.UserSpaceOnUse, elm.PatternContentUnits.AnimVal); elm = Util.GetXmlElement("<pattern patternContentUnits='objectBoundingBox' />", "", "pattern") as SvgPatternElement; Assert.AreEqual((ushort)SvgUnitType.ObjectBoundingBox, elm.PatternContentUnits.AnimVal); elm = Util.GetXmlElement("<pattern />", "", "pattern") as SvgPatternElement; Assert.AreEqual((ushort)SvgUnitType.UserSpaceOnUse, elm.PatternContentUnits.AnimVal); }
public void TestPreserveAspectRatio() { SvgPatternElement elm = Util.GetXmlElement("<pattern preserveAspectRatio='xMidYMin slice' />", "", "pattern") as SvgPatternElement; Assert.AreEqual(SvgPreserveAspectRatioType.XMidYMin, elm.PreserveAspectRatio.AnimVal.Align); Assert.AreEqual(SvgMeetOrSlice.Slice, elm.PreserveAspectRatio.AnimVal.MeetOrSlice); elm = Util.GetXmlElement("<pattern />", "", "pattern") as SvgPatternElement; Assert.AreEqual(SvgPreserveAspectRatioType.XMidYMid, elm.PreserveAspectRatio.AnimVal.Align); Assert.AreEqual(SvgMeetOrSlice.Meet, elm.PreserveAspectRatio.AnimVal.MeetOrSlice); }
// private SvgSvgElement MoveIntoSvgElement() // { // SvgDocument doc = _patternElement.OwnerDocument; // SvgSvgElement svgElm = doc.CreateElement("", "svg", SvgDocument.SvgNamespace) as SvgSvgElement; // XmlNodeList children = _patternElement.Children; // if (children.Count > 0) // { // oldParent = children[0].ParentNode as XmlElement; // } // for (int i = 0; i < children.Count; i++) // { // svgElm.AppendChild(children[i]); // } // if (_patternElement.HasAttribute("viewBox")) // { // svgElm.SetAttribute("viewBox", _patternElement.GetAttribute("viewBox")); // } // //svgElm.SetAttribute("x", "0"); // //svgElm.SetAttribute("y", "0"); // svgElm.SetAttribute("x", _patternElement.GetAttribute("x")); // svgElm.SetAttribute("y", _patternElement.GetAttribute("y")); // svgElm.SetAttribute("width", _patternElement.GetAttribute("width")); // svgElm.SetAttribute("height", _patternElement.GetAttribute("height")); // if (_patternElement.PatternContentUnits.AnimVal.Equals((ushort)SvgUnitType.ObjectBoundingBox)) // { //// svgElm.SetAttribute("viewBox", "0 0 1 1"); // } // else // { // _isUserSpace = true; // } // _patternElement.AppendChild(svgElm); // return svgElm; // } //private void MoveOutOfSvgElement(SvgSvgElement svgElm) //{ // while (svgElm.ChildNodes.Count > 0) // { // oldParent.AppendChild(svgElm.ChildNodes[0]); // } // _patternElement.RemoveChild(svgElm); //} private void PrepareTargetPattern() { var renderedElement = _patternElement; if (renderedElement.ReferencedElement != null) { SvgPatternElement svgElm = _patternElement.CloneNode(true) as SvgPatternElement; renderedElement = _patternElement.ReferencedElement; if (svgElm.IsEmpty) { XmlNodeList children = renderedElement.Children; if (children.Count > 0) { foreach (SvgElement element in children) { svgElm.AppendChild(element.Clone()); } } } var inheritedAttributes = renderedElement.Attributes; foreach (XmlAttribute attr in inheritedAttributes) { if (!svgElm.HasAttribute(attr.Name)) { svgElm.SetAttribute(attr.Name, attr.Value); } } _patternElement.AppendChild(svgElm); // renderedElement = svgElm; while (renderedElement.ReferencedElement != null) { renderedElement = renderedElement.ReferencedElement; inheritedAttributes = renderedElement.Attributes; foreach (XmlAttribute attr in inheritedAttributes) { if (!svgElm.HasAttribute(attr.Name)) { svgElm.SetAttribute(attr.Name, attr.Value); } } } svgElm.Id = ""; renderedElement = svgElm; } _renderedElement = renderedElement; }
public void TestPatternTransform() { SvgPatternElement elm = Util.GetXmlElement("<pattern patternTransform='translate(1,1) rotate(34)' />", "", "pattern") as SvgPatternElement; ISvgAnimatedTransformList satl = elm.PatternTransform as ISvgAnimatedTransformList; Assert.IsNotNull(satl); Assert.AreEqual(2, elm.PatternTransform.AnimVal.NumberOfItems); elm = Util.GetXmlElement("<pattern />", "", "pattern") as SvgPatternElement; satl = elm.PatternTransform as ISvgAnimatedTransformList; Assert.IsNotNull(satl); Assert.AreEqual(0, elm.PatternTransform.AnimVal.NumberOfItems); }
public void TestViewBox() { SvgPatternElement elm = Util.GetXmlElement("<pattern viewBox='1 2 3 4' />", "", "pattern") as SvgPatternElement; Assert.AreEqual(1, elm.ViewBox.AnimVal.X); Assert.AreEqual(2, elm.ViewBox.AnimVal.Y); Assert.AreEqual(3, elm.ViewBox.AnimVal.Width); Assert.AreEqual(4, elm.ViewBox.AnimVal.Height); elm = Util.GetXmlElement("<pattern />", "", "pattern") as SvgPatternElement; Assert.AreEqual(0, elm.ViewBox.AnimVal.X); Assert.AreEqual(0, elm.ViewBox.AnimVal.Y); Assert.AreEqual(0, elm.ViewBox.AnimVal.Width); Assert.AreEqual(0, elm.ViewBox.AnimVal.Height); }
public static GdiFill CreateFill(SvgDocument document, string absoluteUri) { XmlNode node = document.GetNodeByUri(absoluteUri); SvgGradientElement gradientNode = node as SvgGradientElement; if (gradientNode != null) { return(new GdiGradientFill(gradientNode)); } SvgPatternElement patternNode = node as SvgPatternElement; if (patternNode != null) { return(new GdiPatternFill(patternNode)); } return(null); }
public PatternPaintServer(SvgPatternElement patternElement) { _patternElement = patternElement; }
public virtual void VisitPatternElement(SvgPatternElement element) => DefaultVisit(element);
public WpfPatternFill(SvgPatternElement patternElement) { _isUserSpace = false; _patternElement = patternElement; }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); _idElement = string.Empty; WpfDrawingContext context = renderer.Context; DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } if (currentGroup == context.Root) { if (context.IsFragment) { // Do not add extra layer to fragments... _drawGroup = currentGroup; } else { _drawGroup = new DrawingGroup(); SvgObject.SetName(_drawGroup, SvgObject.DrawLayer); if (context.IncludeRuntime) { SvgLink.SetKey(_drawGroup, SvgObject.DrawLayer); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } else { _drawGroup = new DrawingGroup(); currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } SvgPatternElement svgElm = (SvgPatternElement)_svgElement; _idElement = svgElm.Id; if (!string.IsNullOrWhiteSpace(_idElement)) { context.AddUrl(_idElement); } 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); if (width < 0 || height < 0) { // For invalid dimension, prevent the drawing of the children... _isRecursive = true; return; } Rect elmRect = new Rect(x, y, width, height); // XmlNode parentNode = _svgElement.ParentNode; ISvgFitToViewBox fitToView = svgElm as ISvgFitToViewBox; ISvgAnimatedPreserveAspectRatio preserveAspectRatio = null; if (fitToView != null && fitToView.PreserveAspectRatio != null) { preserveAspectRatio = fitToView.PreserveAspectRatio; 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; var aspectRatio = (preserveAspectRatio != null) ? preserveAspectRatio.AnimVal : null; if (aspectRatio != null /* && aspectRatio.Align == SvgPreserveAspectRatioType.None*/) { FitToViewbox(context, elmRect); transform = this.Transform; if (transform != null) { _drawGroup.Transform = transform; } } }
public static ImageBrush ConstructBrush(SvgPatternElement linearGradient, Rect bounds, Matrix transform) { return(null); }
public WpfPatternFill(SvgPatternElement patternElement) { _patternElement = patternElement; }
public GdiPatternFill(SvgPatternElement patternElement) { _patternElement = patternElement; }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); WpfDrawingContext context = renderer.Context; //if (context.Count == 0) //{ // _drawGroup = new DrawingGroup(); // 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) { if (context.IsFragment) { // Do not add extra layer to fragments... _drawGroup = currentGroup; } else { _drawGroup = new DrawingGroup(); SvgObject.SetName(_drawGroup, SvgObject.DrawLayer); if (context.IncludeRuntime) { SvgLink.SetKey(_drawGroup, SvgObject.DrawLayer); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } else { _drawGroup = new DrawingGroup(); currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } //else //{ // _drawGroup = new DrawingGroup(); // DrawingGroup currentGroup = context.Peek(); // if (currentGroup == null) // { // throw new InvalidOperationException("An existing group is expected."); // } // currentGroup.Children.Add(_drawGroup); // context.Push(_drawGroup); //} SvgPatternElement svgElm = (SvgPatternElement)_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); if (width < 0 || height < 0) { // For invalid dimension, prevent the drawing of the children... _isRecursive = true; return; } Rect elmRect = new Rect(x, y, width, height); // XmlNode parentNode = _svgElement.ParentNode; ISvgFitToViewBox fitToView = svgElm as ISvgFitToViewBox; ISvgAnimatedPreserveAspectRatio preserveAspectRatio = null; if (fitToView != null && fitToView.PreserveAspectRatio != null) { preserveAspectRatio = fitToView.PreserveAspectRatio; 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; var aspectRatio = (preserveAspectRatio != null) ? preserveAspectRatio.AnimVal : null; if (aspectRatio != null /* && aspectRatio.Align == SvgPreserveAspectRatioType.None*/) { FitToViewbox(context, elmRect); transform = this.Transform; if (transform != null) { _drawGroup.Transform = transform; } } //if (!elmRect.IsEmpty && !elmRect.Width.Equals(0) && !elmRect.Height.Equals(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); // } // } //} }