예제 #1
0
        int ProcessDotFile(string inputFile)
        {
            Graph graph;
            int   i = CreateGraphFromDotFile(inputFile, out graph);

            graph.Attr.LayerDirection = GetLayerDirection();

            if (i != 0)
            {
                return(i);
            }
            if (argsParser.OptionIsUsed("-nolayout") && GeometryIsPresent(graph))
            {
                double nodeScale;
                bool   scaling = argsParser.GetDoubleOptionValue("-scaleNodesBy", out nodeScale);
                if (scaling)
                {
                    foreach (var node in graph.GeometryGraph.Nodes)
                    {
                        node.BoundaryCurve = node.BoundaryCurve.Transform(PlaneTransformation.ScaleAroundCenterTransformation(nodeScale,
                                                                                                                              node.Center));
                    }
                    graph.GeometryGraph.UpdateBoundingBox();
                }
                double nodeLineWidth;
                if (argsParser.GetDoubleOptionValue("-nblw", out nodeLineWidth))
                {
                    foreach (var node in graph.Nodes)
                    {
                        node.Attr.LineWidth = nodeLineWidth;
                    }
                    graph.GeometryGraph.UpdateBoundingBox();
                }
            }
            else
            {
                PrepareForOutput(graph);
            }

            var    outputFile = Path.ChangeExtension(inputFile, ".svg");
            string outputDir  = argsParser.GetStringOptionValue(OutputDirOption);

            if (outputDir != null)
            {
                var name = Path.GetFileName(outputFile);
                if (name != null)
                {
                    outputFile = Path.Combine(outputDir, name);
                }
            }


            SetConsolasFontAndSize(graph, 11);
            if (argsParser.OptionIsUsed(NoLabelsOption))
            {
                RemoveLabelsFromGraph(graph);
            }
            using (var stream = File.Create(outputFile)) {
                var svgWriter = new SvgGraphWriter(stream, graph)
                {
                    BlackAndWhite     = argsParser.OptionIsUsed("-bw"),
                    NodeSanitizer     = AntiXss.HtmlAttributeEncode,
                    AttrSanitizer     = AntiXss.HtmlAttributeEncode,
                    Precision         = precision,
                    AllowedToWriteUri = !argsParser.OptionIsUsed(NoUrls),
                    IgnoreEdges       = argsParser.OptionIsUsed("-noedges")
                };
                svgWriter.Write();
                DumpFileToConsole(outputFile);
            }

            if (msaglOutput)
            {
                outputFile = SetMsaglOutputFileName(inputFile);
                var geomGraph = graph.GeometryGraph;
                WriteGeomGraph(outputFile, geomGraph);
            }
            return(0);
        }