예제 #1
0
        public static string SvgDirToXaml(string folder, ResKeyInfo resKeyInfo, WpfDrawingSettings wpfDrawingSettings)
        {
            //firstChar Upper
            var firstChar = Char.ToUpper(resKeyInfo.XamlName[0]);
            resKeyInfo.XamlName = firstChar + resKeyInfo.XamlName.Remove(0, 1);


            var files = SvgFilesFromFolder(folder);
            var dict = ConvertFilesToResourceDictionary(files, wpfDrawingSettings, resKeyInfo);
            var xamlUntidy = WpfObjToXaml(dict, wpfDrawingSettings != null ? wpfDrawingSettings.IncludeRuntime : false);

            var doc = XDocument.Parse(xamlUntidy);
            RemoveResDictEntries(doc.Root);
            var drawingGroupElements = doc.Root.XPathSelectElements("defns:DrawingGroup", NsManager).ToList();
            foreach (var drawingGroupElement in drawingGroupElements)
            {
                BeautifyDrawingElement(drawingGroupElement, null);

                if (resKeyInfo.ExtractChildElements)
                {
                    ExtractGeometries(drawingGroupElement, resKeyInfo);
                }
            }

            AddNameSpaceDef(doc.Root, resKeyInfo);
            if (resKeyInfo.UseSvgConvertedImageSourceBehavior)
            {
                ReplaceBrushesInDrawingGroups(doc.Root, resKeyInfo);
            }
            AddDrawingImagesToDrawingGroups(doc.Root, resKeyInfo);
            return doc.ToString();
        }
예제 #2
0
        internal static DrawingGroup SvgFileToWpfObject(string filepath, WpfDrawingSettings wpfDrawingSettings)
        {
            if (wpfDrawingSettings == null) //use defaults if null
                wpfDrawingSettings = new WpfDrawingSettings { IncludeRuntime = false, TextAsGeometry = false, OptimizePath = true };
            var reader = new FileSvgReader(wpfDrawingSettings);

            //this is straight forward, but in this version of the dlls there is an error when name starts with a digit
            //var uri = new Uri(Path.GetFullPath(filepath));
            //reader.Read(uri); //accessing using the filename results is problems with the uri (if the dlls are packed in ressources)
            //return reader.Drawing;

            //this should be faster, but using CreateReader will loose text items like "JOG" ?!
            //using (var stream = File.OpenRead(Path.GetFullPath(filepath)))
            //{
            //    //workaround: error when Id starts with a number
            //    var doc = XDocument.Load(stream);
            //    ReplaceIdsWithNumbers(doc.Root); //id="3d-view-icon" -> id="_3d-view-icon"
            //    using (var xmlReader = doc.CreateReader())
            //    {
            //        reader.Read(xmlReader);
            //        return reader.Drawing;
            //    }
            //}

            //workaround: error when Id starts with a number
            var doc = XDocument.Load(Path.GetFullPath(filepath));
            FixIds(doc.Root); //id="3d-view-icon" -> id="_3d-view-icon"
            using (var ms = new MemoryStream())
            {
                doc.Save(ms);
                ms.Position = 0;
                reader.Read(ms);
                return reader.Drawing;
            }
        }
예제 #3
0
 private static DrawingGroup ConvertFileToDrawingGroup(string filepath, WpfDrawingSettings wpfDrawingSettings)
 {
     var dg = SvgFileToWpfObject(filepath, wpfDrawingSettings);
     SetSizeToGeometries(dg);
     RemoveObjectNames(dg);
     return dg;
 }
예제 #4
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            // 1. Create conversion options
            WpfDrawingSettings settings = new WpfDrawingSettings();

            settings.IncludeRuntime = true;
            settings.TextAsGeometry = false;

            // 2. Select a file to be converted
            string svgTestFile = "Test.svg";

            // 3. Create a file reader
            StreamSvgConverter converter = new StreamSvgConverter(settings);
            // 4. convert the SVG file
            MemoryStream memStream = new MemoryStream();

            if (converter.Convert(svgTestFile, memStream))
            {
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = memStream;
                bitmap.EndInit();
                // Set the image source.
                svgImage.Source = bitmap;
            }

            memStream.Close();
        }
예제 #5
0
        public static ImageSource GetSVGImageSource(string svgXml, out Exception svgException)
        {
            ImageSource imageSource = null;

            try
            {
                WpfDrawingSettings settings = new WpfDrawingSettings();
                settings.IncludeRuntime = true;
                settings.TextAsGeometry = true;
                settings.OptimizePath   = true;
                //settings.CultureInfo = ;

                using (var stringReader = new StringReader(svgXml))
                {
                    using (FileSvgReader reader = new FileSvgReader(settings))
                    {
                        DrawingGroup drawGroup = reader.Read(stringReader);

                        if (drawGroup != null)
                        {
                            svgException = null;
                            return(new DrawingImage(drawGroup));
                        }
                    }
                }
            }
            catch (Exception e1)
            {
                svgException = e1;
                return(null);
            }

            svgException = null;
            return(imageSource);
        }
 public OptionSettings(OptionSettings source)
 {
     _hidePathsRoot  = source._hidePathsRoot;
     _webSuitePath   = source._webSuitePath;
     _localSuitePath = source._localSuitePath;
     _wpfSettings    = source._wpfSettings;
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSvgConverter"/> class
 /// with the specified drawing or rendering settings and the saving options.
 /// </summary>
 /// <param name="saveXaml">
 /// This specifies whether to save result object tree in XAML file.
 /// </param>
 /// <param name="saveZaml">
 /// This specifies whether to save result object tree in ZAML file. The
 /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ.
 /// </param>
 /// <param name="settings">
 /// This specifies the settings used by the rendering or drawing engine.
 /// If this is <see langword="null"/>, the default settings is used.
 /// </param>
 public FileSvgConverter(bool saveXaml, bool saveZaml,
                         WpfDrawingSettings settings)
     : base(saveXaml, saveZaml, settings)
 {
     _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings);
     _wpfWindow   = new WpfSvgWindow(640, 480, _wpfRenderer);
 }
예제 #8
0
        public OptionSettings(WpfDrawingSettings wpfSettings, string testPath)
        {
            _wpfSettings = wpfSettings;

            _localSuitePath = testPath;
            _testSuites     = SvgTestSuite.Create();

            if (wpfSettings == null)
            {
                _wpfSettings = new WpfDrawingSettings();
            }

            // For the start the default is selected
            var selectedSuite = SvgTestSuite.GetDefault(_testSuites);

            if (selectedSuite != null)
            {
                if (string.IsNullOrWhiteSpace(testPath))
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                }
                _webSuitePath = selectedSuite.WebSuitePath;
            }

            if (!Directory.Exists(_localSuitePath))
            {
                Directory.CreateDirectory(_localSuitePath);
            }
        }
예제 #9
0
        public SVGWidgetViewModel(IWidget widget)
        {
            _model = new SVGModel(widget);

            _bSupportBorder       = false;
            _bSupportBackground   = false;
            _bSupportText         = false;
            _bSupportTextVerAlign = false;
            _bSupportTextHorAlign = false;
            widgetGID             = widget.Guid;
            Type = ObjectType.SVG;
            _bSupportGradientBackground = false;
            _bSupportGradientBorderline = false;
            _bSupportRotate             = true;
            _bSupportTextRotate         = false;

            _BackgroundColor = new StyleColor(ColorFillType.Solid, 0);
            _StrokeColor     = new StyleColor(ColorFillType.Solid, 0);

            // Create conversion options and a file reader
            WpfDrawingSettings settings = new WpfDrawingSettings();

            settings.IncludeRuntime = true;
            settings.TextAsGeometry = false;
            _converter = new FileSvgReader(settings);
            SVGSource  = LoadSvg((_model as SVGModel).SVGStream);
        }
예제 #10
0
        public static bool TryConvert(byte[] bytes, out DrawingGroup drawing)
        {
            drawing = null;
            if (bytes == null || bytes.Length == 0)
            {
                return(false);
            }

            using (var stream = new MemoryStream(bytes))
            {
                try
                {
                    var settings = new WpfDrawingSettings
                    {
                        IncludeRuntime = true,
                        TextAsGeometry = false
                    };

                    var converter = new FileSvgReader(settings);
                    drawing = converter.Read(stream);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #11
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            // 1. Create conversion options
            WpfDrawingSettings settings = new WpfDrawingSettings();

            settings.IncludeRuntime = true;
            settings.TextAsGeometry = false;

            // 2. Select a file to be converted
            string svgTestFile = "Test.svg";

            // 3. Create a file reader
            FileSvgReader converter = new FileSvgReader(settings);
            // 4. Read the SVG file
            DrawingGroup drawing = converter.Read(svgTestFile);

            if (drawing != null)
            {
                svgImage.Source = new DrawingImage(drawing);

                using (StringWriter textWriter = new StringWriter())
                {
                    if (converter.Save(textWriter))
                    {
                        svgBox.Text = textWriter.ToString();
                    }
                }
            }
        }
예제 #12
0
        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            if (_svgPage == null)
            {
                return;
            }
            var wpfSettings = _svgPage.ConversionSettings;

            if (wpfSettings != null)
            {
                _wpfSettings = wpfSettings.Clone();
            }
            if (_wpfSettings == null)
            {
                return;
            }

            _isInitialising = true;

            chkTextAsGeometry.IsChecked = _wpfSettings.TextAsGeometry;
            chkIncludeRuntime.IsChecked = _wpfSettings.IncludeRuntime;

            chkIgnoreRootViewbox.IsChecked     = _wpfSettings.IgnoreRootViewbox;
            chkEnsureViewboxSize.IsChecked     = _wpfSettings.EnsureViewboxSize;
            chkEnsureViewboxPosition.IsChecked = _wpfSettings.EnsureViewboxPosition;

            _isModified = false;

            _isInitialising = false;
        }
예제 #13
0
        private void LoadSvg(string svg)
        {
            // 1. Create conversion options
            var settings = new WpfDrawingSettings
            {
                IncludeRuntime = true,
                TextAsGeometry = false
            };

            // 2. Select a file to be converted
            byte[] stringBytes = Encoding.UTF8.GetBytes(svg);
            using (var sourceStream = new MemoryStream(stringBytes))
                // 3. Create a file reader
                using (var converter = new StreamSvgConverter(settings))
                    // 4. convert the SVG file
                    using (var resultStream = new MemoryStream())
                    {
                        if (converter.Convert(sourceStream, resultStream))
                        {
                            BitmapImage bitmap = new BitmapImage();
                            bitmap.BeginInit();
                            bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                            bitmap.StreamSource = resultStream;
                            bitmap.EndInit();
                            // Set the image source.
                            BitmapIcon = bitmap;
                        }
                    }
        }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WpfDrawingSettings"/>
 /// class with the specified drawing or rendering settings.
 /// </summary>
 /// <param name="settings">
 /// This specifies the settings used by the rendering or drawing engine.
 /// If this is <see langword="null"/>, the default settings is used.
 /// </param>
 public DirectorySvgConverter(WpfDrawingSettings settings)
     : base(settings)
 {
     _isOverwrite = true;
     _isRecursive = true;
     _encoderType = ImageEncoderType.PngBitmap;
 }
예제 #15
0
        public DrawingPage()
        {
            InitializeComponent();

            _saveXaml                = true;
            _wpfSettings             = new WpfDrawingSettings();
            _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo;

            _fileReader          = new FileSvgReader(_wpfSettings);
            _fileReader.SaveXaml = _saveXaml;
            _fileReader.SaveZaml = false;

            _mouseHandlingMode = ZoomPanMouseHandlingMode.None;

            string workDir = Path.Combine(Path.GetDirectoryName(
                                              System.Reflection.Assembly.GetExecutingAssembly().Location), TemporalDirName);

            _workingDir = new DirectoryInfo(workDir);

            _embeddedImages = new List <EmbeddedImageSerializerArgs>();

            _embeddedImageVisitor = new EmbeddedImageSerializerVisitor(true);
            _wpfSettings.Visitors.ImageVisitor = _embeddedImageVisitor;

            _embeddedImageVisitor.ImageCreated += OnEmbeddedImageCreated;

            this.Loaded      += OnPageLoaded;
            this.Unloaded    += OnPageUnloaded;
            this.SizeChanged += OnPageSizeChanged;
        }
예제 #16
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var settings = new WpfDrawingSettings
            {
                IncludeRuntime = IncludeRuntime,
                TextAsGeometry = TextAsGeometry,
                OptimizePath   = OptimizePath
            };

            if (Culture != null)
            {
                settings.CultureInfo = Culture;
            }
            using (FileSvgReader fileSvgReader = new FileSvgReader(settings))
            {
                using (var svgStream = new MemoryStream(Source))
                {
                    var drawingGroup = fileSvgReader.Read(svgStream);

                    if (Size.HasValue)
                    {
                        var rect = drawingGroup.Bounds;
                        drawingGroup.Transform = new ScaleTransform(Size.Value.Width / rect.Width, Size.Value.Height / rect.Height);
                    }
                    if (drawingGroup != null)
                    {
                        return(new DrawingImage(drawingGroup));
                    }
                }
            }
            return(null);
        }
예제 #17
0
        public static string SvgFileToXaml(string filepath, ResultMode resultMode, ResKeyInfo resKeyInfo,
                                           bool filterPixelsPerDip, WpfDrawingSettings wpfDrawingSettings = null)
        {
            var obj = ConvertSvgToObject(filepath, resultMode, wpfDrawingSettings, out var name, resKeyInfo);

            return(SvgObjectToXaml(obj, wpfDrawingSettings != null && wpfDrawingSettings.IncludeRuntime, name, filterPixelsPerDip));
        }
예제 #18
0
        public static FrameworkElement LoadSvg(string filename)
        {
            var settings = new WpfDrawingSettings();

            settings.IncludeRuntime = true;
            var renderer = new WpfDrawingRenderer(settings);

            renderer.LinkVisitor       = new LinkVisitor();
            renderer.ImageVisitor      = new EmbeddedImageVisitor();
            renderer.FontFamilyVisitor = new FontFamilyVisitor();
            var svgWindow = new WpfSvgWindow(4096, 4096, renderer);

            svgWindow.LoadDocument(filename);
            svgWindow.Resize((int)svgWindow.Document.RootElement.Width.BaseVal.Value, (int)svgWindow.Document.RootElement.Height.BaseVal.Value);
            renderer.InvalidRect = SvgRectF.Empty;
            renderer.Render(svgWindow.Document as SvgDocument);
            var drawing = new System.Windows.Media.DrawingImage();

            drawing.Drawing = renderer.Drawing;
            var image = new System.Windows.Controls.Image();

            image.Source = drawing;
            image.Width  = renderer.Window.InnerWidth;
            image.Height = renderer.Window.InnerHeight;
            return(image);
        }
예제 #19
0
        static void Main(string[] args)
        {
            // 1. Create conversion options
            WpfDrawingSettings settings = new WpfDrawingSettings();

            settings.IncludeRuntime = true;
            settings.TextAsGeometry = false;

            // 2. Select a file to be converted
            string svgTestFile = "Test.svg";

            // 3. Create a file converter
            ImageSvgConverter converter = new ImageSvgConverter(settings);

            // 4. Perform the conversion to image
            converter.EncoderType = ImageEncoderType.BmpBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.GifBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.JpegBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.PngBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.TiffBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.WmpBitmap;
            converter.Convert(svgTestFile);
        }
예제 #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSvgConverter"/> class
        /// with the specified drawing or rendering settings, the saving options
        /// and the working directory.
        /// </summary>
        /// <param name="saveXaml">
        /// This specifies whether to save result object tree in XAML file.
        /// </param>
        /// <param name="saveZaml">
        /// This specifies whether to save result object tree in ZAML file. The
        /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ.
        /// </param>
        /// <param name="workingDir">
        /// The working directory, where converted outputs are saved.
        /// </param>
        /// <param name="settings">
        /// This specifies the settings used by the rendering or drawing engine.
        /// If this is <see langword="null"/>, the default settings is used.
        /// </param>
        public FileSvgReader(bool saveXaml, bool saveZaml,
                             DirectoryInfo workingDir, WpfDrawingSettings settings)
            : base(saveXaml, saveZaml, settings)
        {
            long pixelWidth  = 0;
            long pixelHeight = 0;

            if (settings != null && settings.HasPixelSize)
            {
                pixelWidth  = settings.PixelWidth;
                pixelHeight = settings.PixelHeight;
            }

            _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings);
            _wpfWindow   = new WpfSvgWindow(pixelWidth, pixelHeight, _wpfRenderer);

            _workingDir = workingDir;

            if (_workingDir != null)
            {
                if (!_workingDir.Exists)
                {
                    _workingDir.Create();
                }
            }
        }
예제 #21
0
        public static string SvgDirToXaml(string folder, ResKeyInfo resKeyInfo, WpfDrawingSettings wpfDrawingSettings,
                                          bool filterPixelsPerDip, bool handleSubFolders = false)
        {
            //firstChar Upper
            var firstChar = char.ToUpperInvariant(resKeyInfo.XamlName[0]);

            resKeyInfo.XamlName = firstChar + resKeyInfo.XamlName.Remove(0, 1);


            var files      = SvgFilesFromFolder(folder, handleSubFolders);
            var dict       = ConvertFilesToResourceDictionary(files, wpfDrawingSettings, resKeyInfo);
            var xamlUntidy = WpfObjToXaml(dict, wpfDrawingSettings?.IncludeRuntime ?? false);

            var doc = XDocument.Parse(xamlUntidy);

            RemoveResDictEntries(doc.Root);
            var drawingGroupElements = doc.Root.XPathSelectElements("defns:DrawingGroup", NsManager).ToList();

            foreach (var drawingGroupElement in drawingGroupElements)
            {
                BeautifyDrawingElement(drawingGroupElement, null);
                if (filterPixelsPerDip)
                {
                    FilterPixelsPerDip(drawingGroupElement);
                }

                ExtractGeometries(drawingGroupElement, resKeyInfo);
            }

            AddNameSpaceDef(doc.Root, resKeyInfo);
            //ReplaceBrushesInDrawingGroups(doc.Root, resKeyInfo);
            AddDrawingImagesToDrawingGroups(doc.Root);
            return(doc.ToString());
        }
예제 #22
0
        public virtual void SetupStyleSheets(WpfDrawingSettings drawingSettings)
        {
            if (drawingSettings == null)
            {
                return;
            }

            CssXmlDocument cssDocument = this.Document as CssXmlDocument;

            if (cssDocument == null)
            {
                return;
            }

            string userCssFilePath = drawingSettings.UserCssFilePath;

            if (!string.IsNullOrWhiteSpace(userCssFilePath) && File.Exists(userCssFilePath))
            {
                cssDocument.SetUserStyleSheet(userCssFilePath);
            }

            string userAgentCssFilePath = drawingSettings.UserAgentCssFilePath;

            if (!string.IsNullOrWhiteSpace(userAgentCssFilePath) && File.Exists(userAgentCssFilePath))
            {
                cssDocument.SetUserAgentStyleSheet(userAgentCssFilePath);
            }
        }
예제 #23
0
        public void LoadDocument(XmlReader xmlReader, WpfDrawingSettings drawingSettings)
        {
            if (xmlReader == null)
            {
                return;
            }

            SvgDocument document = new SvgDocument(this);

            if (_settings != null)
            {
                document.CustomSettings = _settings;
            }
            if (drawingSettings != null && drawingSettings.DpiScale != null)
            {
                var dpiScale = drawingSettings.DpiScale;
                document.Dpi = dpiScale.PixelsPerInchY;
            }

            document.Load(xmlReader);

            this.Document = document;

            this.SetupStyleSheets(drawingSettings);
        }
예제 #24
0
        public OptionSettings(OptionSettings source)
        {
            if (source == null)
            {
                return;
            }
            _hidePathsRoot     = source._hidePathsRoot;
            _isMagickInstalled = source._isMagickInstalled;
            _svgDirectory      = source._svgDirectory;
            _pngDirectory      = source._pngDirectory;
            _fontsDirectory    = source._fontsDirectory;
            _imagesDirectory   = source._imagesDirectory;

            _rsvgDirectory   = source._rsvgDirectory;
            _magickDirectory = source._magickDirectory;

            _showInputFile   = source._showInputFile;
            _showOutputFile  = source._showOutputFile;
            _recursiveSearch = source._recursiveSearch;
            _testCssFile     = source._testCssFile;
            _testRunnerFile  = source._testRunnerFile;
            _emptyImageFile  = source._emptyImageFile;
            _crashImageFile  = source._crashImageFile;
            _wpfSettings     = source._wpfSettings;
        }
예제 #25
0
        /// <summary>
        /// This sets the source SVG for a <see cref="SvgCanvas"/> by using the supplied Uniform Resource Identifier (URI)
        /// and processing the result asynchronously.
        /// </summary>
        /// <param name="uriSource">A reference to the SVG source file.</param>
        /// <returns>
        /// A value that indicates whether the operation was successful. This is <see langword="true"/>
        /// if successful, otherwise, it is <see langword="false"/>.
        /// </returns>
        public Task <bool> LoadAsync(Uri uriSource)
        {
            TaskCompletionSource <bool> result = new TaskCompletionSource <bool>();

            if (uriSource == null)
            {
                result.SetResult(false);
                return(result.Task);
            }
            WpfDrawingSettings settings = new WpfDrawingSettings();

            settings.IncludeRuntime = _includeRuntime;
            settings.TextAsGeometry = _textAsGeometry;
            settings.OptimizePath   = _optimizePath;
            if (_culture != null)
            {
                settings.CultureInfo = _culture;
            }

            try
            {
                MemoryStream drawingStream = new MemoryStream();

                // Get the UI thread's context
                var context = TaskScheduler.FromCurrentSynchronizationContext();

                return(Task.Factory.StartNew <bool>(() =>
                {
                    DrawingGroup drawing = this.CreateDrawing(uriSource, settings);
                    if (drawing != null)
                    {
                        _sourceUri = uriSource;
                        _sourceStream = null;

                        XamlWriter.Save(drawing, drawingStream);
                        drawingStream.Seek(0, SeekOrigin.Begin);

                        return true;
                    }
                    return false;
                }).ContinueWith((t) => {
                    if (t.Result && drawingStream.Length != 0)
                    {
                        DrawingGroup drawing = (DrawingGroup)XamlReader.Load(drawingStream);

                        this.OnLoadDrawing(drawing);

                        return true;
                    }
                    return false;
                }, context));
            }
            catch (Exception ex)
            {
                result.SetResult(false);
                result.SetException(ex);

                return(result.Task);
            }
        }
예제 #26
0
        public MainWindow()
        {
            InitializeComponent();

            leftExpander.Expanded  += OnLeftExpanderExpanded;
            leftExpander.Collapsed += OnLeftExpanderCollapsed;
            leftSplitter.MouseMove += OnLeftSplitterMove;

            bottomExpander.Expanded  += OnBottomExpanderExpanded;
            bottomExpander.Collapsed += OnBottomExpanderCollapsed;
            bottomSplitter.MouseMove += OnBottomSplitterMove;

            this.Loaded  += OnWindowLoaded;
            this.Closing += OnWindowClosing;

            _drawingDir = IoPath.Combine(IoPath.GetDirectoryName(
                                             System.Reflection.Assembly.GetExecutingAssembly().Location), "XamlDrawings");

            if (!Directory.Exists(_drawingDir))
            {
                Directory.CreateDirectory(_drawingDir);
            }

            _directoryInfo = new DirectoryInfo(_drawingDir);

            _wpfSettings = new WpfDrawingSettings();

            _fileReader          = new FileSvgReader(_wpfSettings);
            _fileReader.SaveXaml = false;
            _fileReader.SaveZaml = false;

            try
            {
                //                _folderClose = new BitmapImage();
                //var folderClose = new BitmapImage();
                //folderClose.BeginInit();
                //folderClose.UriSource = new Uri("Images/FolderClose.png", UriKind.Relative);
                //folderClose.EndInit();
                //_folderClose = folderClose;

                _folderClose = this.GetImage(new Uri("Images/FolderClose.svg", UriKind.Relative));

                //var folderOpen = new BitmapImage();
                //folderOpen.BeginInit();
                //folderOpen.UriSource = new Uri("Images/FolderOpen.png", UriKind.Relative);
                //folderOpen.EndInit();
                //_folderOpen = folderOpen;

                _folderOpen = this.GetImage(new Uri("Images/FolderOpen.svg", UriKind.Relative));
            }
            catch (Exception ex)
            {
                _folderClose = null;
                _folderOpen  = null;

                MessageBox.Show(ex.ToString(), "Svg Test Suite - Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageSvgConverter"/> class
        /// with the specified drawing or rendering settings and the saving options.
        /// </summary>
        /// <param name="saveXaml">
        /// This specifies whether to save result object tree in image file.
        /// </param>
        /// <param name="saveZaml">
        /// This specifies whether to save result object tree in ZAML file. The
        /// ZAML is simply a G-Zip compressed image format, similar to the SVGZ.
        /// </param>
        /// <param name="settings">
        /// This specifies the settings used by the rendering or drawing engine.
        /// If this is <see langword="null"/>, the default settings is used.
        /// </param>
        public ImageSvgConverter(bool saveXaml, bool saveZaml,
                                 WpfDrawingSettings settings) : base(saveXaml, saveZaml, settings)
        {
            _encoderType = ImageEncoderType.PngBitmap;

            _wpfRenderer = new WpfDrawingRenderer(this.DrawingSettings);
            _wpfWindow   = new WpfSvgWindow(640, 480, _wpfRenderer);
        }
예제 #28
0
        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            if (_mainWindow == null || _mainWindow.OptionSettings == null)
            {
                return;
            }
            _optionSettings = _mainWindow.OptionSettings;

            var wpfSettings = _optionSettings.ConversionSettings;

            if (wpfSettings != null)
            {
                _wpfSettings = wpfSettings.Clone();
            }
            if (_wpfSettings == null)
            {
                return;
            }

            _isInitialising = true;

            txtPngDirectory.Text = _optionSettings.GetPath(_optionSettings.PngDirectory);
            txtSvgDirectory.Text = _optionSettings.GetPath(_optionSettings.SvgDirectory);

            txtPngDirectory.IsReadOnly = _optionSettings.HidePathsRoot;

            txtFontDirectory.Text  = _optionSettings.FontsDirectory;
            txtImageDirectory.Text = _optionSettings.ImagesDirectory;

            chkHidePathsRoot.IsChecked   = _optionSettings.HidePathsRoot;
            chkRecursiveSearch.IsChecked = _optionSettings.RecursiveSearch;
            chkShowInputFile.IsChecked   = _optionSettings.ShowInputFile;
            chkShowOutputFile.IsChecked  = _optionSettings.ShowOutputFile;

            chkTextAsGeometry.IsChecked = _wpfSettings.TextAsGeometry;
            chkIncludeRuntime.IsChecked = _wpfSettings.IncludeRuntime;

            chkIgnoreRootViewbox.IsChecked     = _wpfSettings.IgnoreRootViewbox;
            chkEnsureViewboxSize.IsChecked     = _wpfSettings.EnsureViewboxSize;
            chkEnsureViewboxPosition.IsChecked = _wpfSettings.EnsureViewboxPosition;

            txtMagickDirectory.Text = _optionSettings.MagickDirectory;
            txtRsvgDirectory.Text   = _optionSettings.RsvgDirectory;
            if (_optionSettings.IsMagickInstalled)
            {
                txtMagickDirectory.IsEnabled = false;
                btnMagickBrowse.IsEnabled    = false;
                btnMagickOpen.IsEnabled      = false;

                txtRsvgDirectory.IsEnabled = false;
                btnRsvgBrowse.IsEnabled    = false;
                btnRsvgOpen.IsEnabled      = false;
            }

            _isConversionModified = false;

            _isInitialising = false;
        }
예제 #29
0
        public static void ConvertSvg(string filename, string destfile)
        {
            var settings = new WpfDrawingSettings();

            settings.IncludeRuntime = false;
            var converter = new FileSvgConverter(settings);

            converter.Convert(filename, destfile);
        }
        public MainWindow()
        {
            InitializeComponent();

            var wpfSettings = new WpfDrawingSettings();

            wpfSettings.CultureInfo = wpfSettings.NeutralCultureInfo;
            _fileSvgReader          = new FileSvgReader(wpfSettings);
        }