/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathElementType.CubicBezier)); }
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathElementType.MoveTo)); }
/// <summary> /// Gets the Brush Element Attributes from the Match /// </summary> /// <param name="match">Match object</param> protected override void GetAttributes(Match match) { // Start Point float.TryParse(match.Groups["StartX"].Value, out var startX); float.TryParse(match.Groups["StartY"].Value, out var startY); _startPoint = new Vector2(startX, startY); // End Point float.TryParse(match.Groups["EndX"].Value, out var endX); float.TryParse(match.Groups["EndY"].Value, out var endY); _endPoint = new Vector2(endX, endY); // Opacity (optional) var group = match.Groups["Opacity"]; if (group.Success) { float.TryParse(group.Value, out _opacity); } // Alpha Mode (optional) group = match.Groups["AlphaMode"]; if (group.Success) { Enum.TryParse(group.Value, out _alphaMode); } // Buffer Precision (optional) group = match.Groups["BufferPrecision"]; if (group.Success) { Enum.TryParse(group.Value, out _bufferPrecision); } // Edge Behavior (optional) group = match.Groups["EdgeBehavior"]; if (group.Success) { Enum.TryParse(group.Value, out _edgeBehavior); } // Pre Interpolation ColorSpace (optional) group = match.Groups["PreColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _preInterpolationColorSpace); } // Post Interpolation ColorSpace (optional) group = match.Groups["PostColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _postInterpolationColorSpace); } // GradientStops group = match.Groups["GradientStops"]; if (group.Success) { _gradientStops.Clear(); foreach (Capture capture in group.Captures) { var gradientMatch = RegexFactory.GradientStopRegex.Match(capture.Value); if (!gradientMatch.Success) { continue; } float position; Color color; // Main Attributes var main = gradientMatch.Groups["Main"]; if (main.Success) { var mainMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Main).Match(main.Value); float.TryParse(mainMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(mainMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } // Additional Attributes var additional = gradientMatch.Groups["Additional"]; if (!additional.Success) { continue; } foreach (Capture addCapture in additional.Captures) { var addMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Additional).Match(addCapture.Value); float.TryParse(addMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(addMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } } // Sort the stops based on their position if (_gradientStops.Any()) { _gradientStops = _gradientStops.OrderBy(g => g.Position).ToList(); } } }
/// <summary> /// Gets the Regex for extracting Brush Element Attributes /// </summary> /// <returns>Regex</returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(BrushType.LinearGradient)); }
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathFigureType.RoundedRectangleFigure)); }
/// <summary> /// Gets the Brush Element Attributes from the Match /// </summary> /// <param name="match">Match object</param> protected override void GetAttributes(Match match) { float centerX, centerY; // RadiusX Single.TryParse(match.Groups["RadiusX"].Value, out _radiusX); // Sanitize by taking the absolute value _radiusX = Math.Abs(_radiusX); // RadiusY Single.TryParse(match.Groups["RadiusY"].Value, out _radiusY); // Sanitize by taking the absolute value _radiusY = Math.Abs(_radiusY); // CenterX Single.TryParse(match.Groups["CenterX"].Value, out centerX); // CenterY Single.TryParse(match.Groups["CenterY"].Value, out centerY); _center = new Vector2(centerX, centerY); // Opacity (optional) var group = match.Groups["Opacity"]; if (group.Success) { Single.TryParse(group.Value, out _opacity); } // Origin Offset (optional) group = match.Groups["OriginOffset"]; if (group.Success) { float offsetX, offsetY; Single.TryParse(match.Groups["OffsetX"].Value, out offsetX); Single.TryParse(match.Groups["OffsetY"].Value, out offsetY); _originOffset = new Vector2(offsetX, offsetY); } // Alpha Mode (optional) group = match.Groups["AlphaMode"]; if (group.Success) { Enum.TryParse(group.Value, out _alphaMode); } // Buffer Precision (optional) group = match.Groups["BufferPrecision"]; if (group.Success) { Enum.TryParse(group.Value, out _bufferPrecision); } // Edge Behavior (optional) group = match.Groups["EdgeBehavior"]; if (group.Success) { Enum.TryParse(group.Value, out _edgeBehavior); } // Pre Interpolation ColorSpace (optional) group = match.Groups["PreColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _preInterpolationColorSpace); } // Post Interpolation ColorSpace (optional) group = match.Groups["PostColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _postInterpolationColorSpace); } // Gradient Stops group = match.Groups["GradientStops"]; if (group.Success) { _gradientStops.Clear(); foreach (Capture capture in group.Captures) { var gradientMatch = RegexFactory.GradientStopRegex.Match(capture.Value); if (!gradientMatch.Success) { continue; } float position; Color color; // Main Attributes var main = gradientMatch.Groups["Main"]; if (main.Success) { var mainMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Main).Match(main.Value); Single.TryParse(mainMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(mainMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } // Additional Attributes var additional = gradientMatch.Groups["Additional"]; if (!additional.Success) { continue; } foreach (Capture addCapture in additional.Captures) { var addMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Additional).Match(addCapture.Value); Single.TryParse(addMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(addMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } } // Sort the stops based on their position if (_gradientStops.Any()) { _gradientStops = _gradientStops.OrderBy(g => g.Position).ToList(); } } }
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathFigureType.PolygonFigure)); }