コード例 #1
0
ファイル: RenderPath.cs プロジェクト: ywscr/circuitdiagram
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            var commands = new List <IPathCommand>(Commands.Count);
            var flipType = layout.GetFlipType();

            foreach (IPathCommand command in Commands)
            {
                var flippedCommand = command;
                if ((flipType & FlipType.Horizontal) == FlipType.Horizontal)
                {
                    flippedCommand = flippedCommand.Flip(true);
                }
                if ((flipType & FlipType.Vertical) == FlipType.Vertical)
                {
                    flippedCommand = flippedCommand.Flip(false);
                }
                commands.Add(flippedCommand);
            }

            Point start = Start.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawPath(Point.Add(start, layout.Location), commands, Thickness, Fill);
            }
            else
            {
                drawingContext.DrawPath(start, commands, Thickness, Fill);
            }
        }
コード例 #2
0
        public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false)
        {
            Expand(new Rect(start, new Size(1, 1)));

            foreach (var command in commands)
            {
                Expand(new Rect(start.Add(new Vector(command.End.X, command.End.Y)), new Size(1, 1)));
            }

            underlying?.DrawPath(start, commands, thickness, fill);
        }
コード例 #3
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            IList <IPathCommand> commands = Commands;

            if (layout.IsFlipped)
            {
                commands = new List <IPathCommand>(Commands.Count);
                foreach (IPathCommand command in Commands)
                {
                    commands.Add(command.Flip(layout.Orientation == Orientation.Horizontal));
                }
            }

            Point start = Start.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawPath(Point.Add(start, layout.Location), commands, Thickness, Fill);
            }
            else
            {
                drawingContext.DrawPath(start, commands, Thickness, Fill);
            }
        }
コード例 #4
0
 public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false)
 {
     // Not supported
     underlying?.DrawPath(start, commands, thickness, fill);
 }
コード例 #5
0
 public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false)
 {
     underlying.DrawPath(start.Add(offset), commands, thickness, fill);
 }
コード例 #6
0
 protected override void OnRender(IDrawingContext drawingContext, Measurement measurement)
 {
     drawingContext.DrawPath(Path, Fill, new Pen(Stroke, StrokeWidth));
 }
コード例 #7
0
        public static bool RenderFromXml(Stream xmlStream, IDrawingContext drawingContext, out Size imageSize)
        {
            var doc = XDocument.Load(xmlStream);

            var previewNode = doc.Elements().First(x => x.Name == PreviewNamespace + "preview");

            imageSize = new Size(double.Parse(previewNode.Attribute("width").Value),
                                 double.Parse(previewNode.Attribute("height").Value));

            var renderElements = previewNode.Elements();

            foreach (var renderElement in renderElements)
            {
                if (renderElement.Name == "line")
                {
                    Point  start     = Point.Parse(renderElement.Attribute("start").Value);
                    Point  end       = Point.Parse(renderElement.Attribute("end").Value);
                    double thickness = double.Parse(renderElement.Attribute("thickness").Value);
                    drawingContext.DrawLine(start, end, thickness);
                }
                else if (renderElement.Name == "rect")
                {
                    Point  start     = Point.Parse(renderElement.Attribute("start").Value);
                    Size   size      = Size.Parse(renderElement.Attribute("size").Value);
                    double thickness = double.Parse(renderElement.Attribute("thickness").Value);
                    bool   fill      = bool.Parse(renderElement.Attribute("fill").Value);
                    drawingContext.DrawRectangle(start, size, thickness, fill);
                }
                else if (renderElement.Name == "ellipse")
                {
                    Point  centre    = Point.Parse(renderElement.Attribute("centre").Value);
                    double radiusx   = double.Parse(renderElement.Attribute("rx").Value);
                    double radiusy   = double.Parse(renderElement.Attribute("ry").Value);
                    double thickness = double.Parse(renderElement.Attribute("thickness").Value);
                    bool   fill      = bool.Parse(renderElement.Attribute("fill").Value);
                    drawingContext.DrawEllipse(centre, radiusx, radiusy, thickness, fill);
                }
                else if (renderElement.Name == "path")
                {
                    Point  start     = Point.Parse(renderElement.Attribute("start").Value);
                    double thickness = double.Parse(renderElement.Attribute("thickness").Value);
                    bool   fill      = bool.Parse(renderElement.Attribute("fill").Value);
                    string data      = renderElement.Value;
                    List <IPathCommand> pathCommands = new List <IPathCommand>();
                    using (MemoryStream dataStream = new MemoryStream(Convert.FromBase64String(data)))
                    {
                        BinaryReader reader = new BinaryReader(dataStream);

                        int numCommands = reader.ReadInt32();

                        for (int l = 0; l < numCommands; l++)
                        {
                            CommandType  pType      = (CommandType)reader.ReadInt32();
                            IPathCommand theCommand = null;
                            switch (pType)
                            {
                            case CommandType.MoveTo:
                                theCommand = new MoveTo();
                                break;

                            case CommandType.LineTo:
                                theCommand = new LineTo();
                                break;

                            case CommandType.CurveTo:
                                theCommand = new CurveTo();
                                break;

                            case CommandType.EllipticalArcTo:
                                theCommand = new EllipticalArcTo();
                                break;

                            case CommandType.QuadraticBeizerCurveTo:
                                theCommand = new QuadraticBeizerCurveTo();
                                break;

                            case CommandType.SmoothCurveTo:
                                theCommand = new SmoothCurveTo();
                                break;

                            case CommandType.SmoothQuadraticBeizerCurveTo:
                                theCommand = new SmoothQuadraticBeizerCurveTo();
                                break;

                            default:
                                theCommand = new ClosePath();
                                break;
                            }
                            theCommand.Read(reader);
                            pathCommands.Add(theCommand);
                        }
                    }
                    drawingContext.DrawPath(start, pathCommands, thickness, fill);
                }
                else if (renderElement.Name == "text")
                {
                    Point          anchor    = Point.Parse(renderElement.Attribute("anchor").Value);
                    TextAlignment  alignment = (TextAlignment)Enum.Parse(typeof(TextAlignment), renderElement.Attribute("alignment").Value);
                    List <TextRun> runs      = new List <TextRun>();
                    foreach (var runNode in renderElement.Elements())
                    {
                        if (runNode.Name != "run")
                        {
                            continue;
                        }

                        double size = double.Parse(runNode.Attribute("size").Value);
                        TextRunFormattingType formattingType = (TextRunFormattingType)Enum.Parse(typeof(TextRunFormattingType), runNode.Attribute("formatting").Value);
                        string text = runNode.Value;
                        runs.Add(new TextRun(text, new TextRunFormatting(formattingType, size)));
                    }
                    drawingContext.DrawText(anchor, alignment, runs);
                }
            }

            return(true);
        }