public void Test_CanvasGeometry_3()
        {
            CanvasDevice device = new CanvasDevice();

            Assert.IsNotNull(device, "Could not create CanvasDevice instance.");

            const string sample = "F1 M 331.341,81.975 L 398.766,218.593 L 549.533,240.500 L 440.437,346.842 L 466.191,497.000 L 331.341,426.105 L 196.491,497.000 L 222.245,346.842 L 113.150,240.500 L 263.916,218.593 L 331.341,81.975 Z S A M P L E E R R O R";

            var geometry = CanvasPathGeometry.CreateGeometry(device, sample);
        }
Ejemplo n.º 2
0
        private void OnCanvasDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (string.IsNullOrWhiteSpace(_data))
            {
                CommandsList.Text = string.Empty;
                return;
            }

            this._errorGeometry ??= CanvasPathGeometry.CreateGeometry(sender, ErrorString);

            _logger?.Clear();
            CommandsList.Text = string.Empty;

            try
            {
                _logger?.AppendLine("// The following commands represent the CanvasPathBuilder command(s) needed");
                _logger?.AppendLine("// to create the CanvasGeometry from the specified Win2d Path Mini Language.");
                var geometry = CanvasPathGeometry.CreateGeometry(sender, _data);
                _reader.StartLogging();
                geometry.SendPathTo(_reader);
                _logger?.AppendLine(_reader.EndLogging());
                CommandsList.Text = _logger?.ToString() ?? string.Empty;

                args.DrawingSession.FillGeometry(geometry, _fillColor);
                args.DrawingSession.DrawGeometry(geometry, _strokeColor, _strokeThickness);
                RootPivot.SelectedIndex = 0;
                CommandsList.Foreground = _commandBrush;
            }
            catch (ArgumentException argEx)
            {
                var message    = argEx.Message;
                var errorCode  = message.Substring(0, 11);
                var parseError = string.Empty;
                if (message.StartsWith(ParseError1))
                {
                    parseError = "Parse Error: No matching data!";
                }
                else if (message.StartsWith(ParseError2))
                {
                    parseError = "Parse Error: Multiple FillRule elements present in Path Data!";
                }
                else if (message.StartsWith(ParseError3))
                {
                    var tokens = message.Split('\n', StringSplitOptions.RemoveEmptyEntries);
                    if (tokens.Length == 3)
                    {
                        parseError = $"Parse Error at {tokens[1]}. Cannot parse '{tokens[2]}'.";
                    }
                }
                else
                {
                    parseError = "Parsing error! Invalid input data!";
                }

                args.DrawingSession.FillGeometry(_errorGeometry, Colors.Black);
                CommandsList.Text       = parseError;
                RootPivot.SelectedIndex = 1;
                CommandsList.Foreground = _commandErrorBrush;
            }
            catch (Exception)
            {
                args.DrawingSession.FillGeometry(_errorGeometry, Colors.Black);
                CommandsList.Text       = "Parsing error! Invalid input data!";
                RootPivot.SelectedIndex = 1;
                CommandsList.Foreground = _commandErrorBrush;
            }
        }