Example #1
0
        /// <summary>
        /// Parse the given file
        /// </summary>
        GraphicVisual IFileParser.Parse(string filename)
        {
            var postscriptStarter = new PostScriptRunner();
            var visual            = postscriptStarter.RunFromFile(filename);

            var optimizedGroup = OptimizeVisual.Optimize(visual);

            CommonHelper.CleanUpTempDir();

            return(optimizedGroup);
        }
        /// <summary>
        /// Builds the selected visual.
        /// </summary>
        private GraphicVisual BuildSelectedDrawing(GraphicVisual visual)
        {
            var           selectedShapes = GetSelectedPaths();
            GraphicVisual selectedVisual = null;

            if (visual != null)
            {
                selectedVisual = BuildSelectedGeometry(visual, selectedShapes);
                selectedVisual = OptimizeVisual.Optimize(selectedVisual);
            }

            return(selectedVisual);
        }
Example #3
0
        /// <summary>
        /// Parse an SVG given as XElement root
        /// </summary>
        public GraphicVisual ParseRoot(XElement root)
        {
            var        nameSpaceAttributes       = root.Attributes().Where(a => a.IsNamespaceDeclaration);
            var        defaultNamespaceAttribute = root.Attributes().Where(a => a.IsNamespaceDeclaration && a.Name.Namespace == XNamespace.None).FirstOrDefault();
            XNamespace defaultNamespace          = defaultNamespaceAttribute.Value;

            Matrix currentTransformationMatrix = Matrix.Identity;

            cssStyleCascade = new CssStyleCascade(root);

            ReadGlobalDefinitions(root);
            GraphicVisual visual = ParseGroup(defaultNamespace, root, currentTransformationMatrix);

            visual = OptimizeVisual.Optimize(visual);

            return(visual);
        }
Example #4
0
        /// <summary>
        /// Parse the given file and convert it to a list of graphic paths
        /// </summary>
        GraphicVisual IFileParser.Parse(string filename)
        {
            var         group         = new GraphicGroup();
            PdfDocument inputDocument = PdfReader.Open(filename);

            for (int i = 0; i < inputDocument.Pages.Count; i++)
            {
                var page     = inputDocument.Pages[i];
                var geometry = Parse(page);
                group.Childreen.Add(geometry);
            }

            var visual = OptimizeVisual.Optimize(group);

            CommonHelper.CleanUpTempDir();

            return(visual);
        }
Example #5
0
        /// <summary>
        /// Parse an SVG given as XElement root
        /// </summary>
        public GraphicVisual ParseRoot(XElement root)
        {
            var        nameSpaceAttributes       = root.Attributes().Where(a => a.IsNamespaceDeclaration);
            var        defaultNamespaceAttribute = root.Attributes().Where(a => a.IsNamespaceDeclaration && a.Name.Namespace == XNamespace.None).FirstOrDefault();
            XNamespace defaultNamespace          = defaultNamespaceAttribute.Value;

            Matrix currentTransformationMatrix = Matrix.Identity;

            cssStyleCascade = new CssStyleCascade(root);

            var svgViewBox = new SvgViewBox
            {
                ViewBox = new Rect(0, 0, 100, 100),
                Align   = "none",
                Slice   = "meet"
            };

            cssStyleCascade.PushViewBox(svgViewBox);

            doubleParser = new DoubleParser(cssStyleCascade);
            ReadGlobalDefinitions(root);

            var brushParser    = new BrushParser(defaultNamespace, cssStyleCascade, globalDefinitions, doubleParser);
            var geometryParser = new GeometryParser(doubleParser);

            var geometryTextParser = new GeometryTextParser(cssStyleCascade, doubleParser);

            clipping    = new Clipping(cssStyleCascade, globalDefinitions, geometryParser, geometryTextParser);
            shapeParser = new ShapeParser(cssStyleCascade, brushParser, geometryParser, clipping);
            textParser  = new TextParser(cssStyleCascade, doubleParser, brushParser, clipping);

            GraphicVisual visual = ParseSVG(root, currentTransformationMatrix, true);

            visual = OptimizeVisual.Optimize(visual);

            return(visual);
        }