当前位置: 首页>>代码示例>>C#>>正文


C# IRenderContext.DrawPath方法代码示例

本文整理汇总了C#中IRenderContext.DrawPath方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderContext.DrawPath方法的具体用法?C# IRenderContext.DrawPath怎么用?C# IRenderContext.DrawPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRenderContext的用法示例。


在下文中一共展示了IRenderContext.DrawPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderFromXml

        public static bool RenderFromXml(Stream xmlStream, IRenderContext renderContext, out Size imageSize)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlStream);

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);
            namespaceManager.AddNamespace("p", PreviewNamespace);

            XmlNode previewNode = doc.SelectSingleNode("/p:preview", namespaceManager);
            imageSize = new Size(double.Parse(previewNode.Attributes["width"].InnerText), double.Parse(previewNode.Attributes["height"].InnerText));

            XmlNodeList renderNodes = previewNode.ChildNodes;
            foreach (XmlNode renderNode in renderNodes)
            {
                XmlElement renderElement = renderNode as XmlElement;

                if (renderElement == null)
                    continue;

                if (renderElement.Name == "line")
                {
                    Point start = Point.Parse(renderElement.Attributes["start"].InnerText);
                    Point end = Point.Parse(renderElement.Attributes["end"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    renderContext.DrawLine(start, end, thickness);
                }
                else if (renderElement.Name == "rect")
                {
                    Point start = Point.Parse(renderElement.Attributes["start"].InnerText);
                    Size size = Size.Parse(renderElement.Attributes["size"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    bool fill = bool.Parse(renderElement.Attributes["fill"].InnerText);
                    renderContext.DrawRectangle(start, size, thickness, fill);
                }
                else if (renderElement.Name == "ellipse")
                {
                    Point centre = Point.Parse(renderElement.Attributes["centre"].InnerText);
                    double radiusx = double.Parse(renderElement.Attributes["rx"].InnerText);
                    double radiusy = double.Parse(renderElement.Attributes["ry"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    bool fill = bool.Parse(renderElement.Attributes["fill"].InnerText);
                    renderContext.DrawEllipse(centre, radiusx, radiusy, thickness, fill);
                }
                else if (renderElement.Name == "path")
                {
                    Point start = Point.Parse(renderElement.Attributes["start"].InnerText);
                    double thickness = double.Parse(renderElement.Attributes["thickness"].InnerText);
                    bool fill = bool.Parse(renderElement.Attributes["fill"].InnerText);
                    string data = renderElement.InnerText;
                    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);
                        }
                    }
                    renderContext.DrawPath(start, pathCommands, thickness, fill);
                }
                else if (renderElement.Name == "text")
                {
                    Point anchor = Point.Parse(renderElement.Attributes["anchor"].InnerText);
                    TextAlignment alignment = (TextAlignment)Enum.Parse(typeof(TextAlignment), renderElement.Attributes["alignment"].InnerText);
                    List<TextRun> runs = new List<TextRun>();
                    foreach (XmlNode runNode in renderElement.ChildNodes)
                    {
//.........这里部分代码省略.........
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:101,代码来源:XmlRenderer.cs


注:本文中的IRenderContext.DrawPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。