Пример #1
0
        private static XElementBuilder BuildLinearGradientElement(LinearGradient gradient)
        {
            var startPositionPreTranslate = Coordinate.Cartesian(-50, 0).Rotate(gradient.Angle);
            var endPositionPreTranslate   = Coordinate.Cartesian(-50, 0).Rotate(gradient.Angle.Plus(Angle.FromRotations(0.5M)));

            var startPosition = startPositionPreTranslate.Translate(new Vector(50, 50));
            var endPosition   = endPositionPreTranslate.Translate(new Vector(50, 50));

            var startPercentX = startPosition.X.ToString() + "%";
            var startPercentY = 100 - startPosition.Y + "%";

            var endPercentX = endPosition.X.ToString() + "%";
            var endPercentY = 100 - endPosition.Y + "%";

            return
                (XElementBuilder.WithName("linearGradient").Add(
                     new XAttribute("x1", startPercentX),
                     new XAttribute("y1", startPercentY),
                     new XAttribute("x2", endPercentX),
                     new XAttribute("y2", endPercentY)
                     )
                 .Add(
                     new XElement("stop",
                                  new XAttribute("offset", "0%"),
                                  new XAttribute("style", $"stop-color:{SvgColor( gradient.Start )};stop-opacity:{SvgOpacity( gradient.Start )}")),
                     new XElement("stop",
                                  new XAttribute("offset", "100%"),
                                  new XAttribute("style", $"stop-color:{SvgColor( gradient.End )};stop-opacity:{SvgOpacity( gradient.End )}"))));
        }
Пример #2
0
        private static State <SvgDrawState, XElementBuilder> RenderPattern(IDiagram fillPattern, decimal fillWidthRatio, decimal fillHeightRatio) =>
        from drawState in State.Get <SvgDrawState>()
        let normalizedDiagram = NormalizeToTopLeftCorner(drawState, fillPattern)
                                from diagram in Renderer.RenderSvg(normalizedDiagram)
                                select XElementBuilder.WithName("pattern").Add(
            new XAttribute("x", 0),
            new XAttribute("y", 0),

            //calculate this based off the diagram's proportions?
            new XAttribute("width", fillWidthRatio),
            new XAttribute("height", fillHeightRatio))
                                .Add(diagram.Build());
Пример #3
0
 private static XElementBuilder BuildRadialGradient(RadialGradient gradient)
 {
     return(XElementBuilder.WithName("radialGradient").Add(
                //TODO: incorporate, fx, fy to affect the focal point( intriguing )
                new XAttribute("cx", "50%"),
                new XAttribute("cy", "50%"))
            .Add(
                new XElement("stop",
                             new XAttribute("stop-color", SvgColor(gradient.CenterColor)),
                             new XAttribute("stop-opacity", SvgOpacity(gradient.CenterColor)),
                             new XAttribute("offset", "0%")
                             ),
                new XElement("stop",
                             new XAttribute("stop-color", SvgColor(gradient.EdgeColor)),
                             new XAttribute("stop-opacity", SvgOpacity(gradient.EdgeColor)),
                             new XAttribute("offset", "100%")
                             )));
 }