public bool LoadXaml() { if (_mainWindow == null || string.IsNullOrWhiteSpace(_svgFilePath) || !File.Exists(_svgFilePath) || _drawing == null) { return(false); } this.UnloadDocument(); var optionSettings = _mainWindow.OptionSettings; var wpfSettings = optionSettings.ConversionSettings; var fileReader = new FileSvgReader(wpfSettings); fileReader.SaveXaml = false; fileReader.SaveZaml = false; fileReader.Drawing = _drawing; MemoryStream xamlStream = new MemoryStream(); if (fileReader.Save(xamlStream)) { _mainWindow.XamlPage.LoadDocument(xamlStream); return(true); } return(false); }
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(); } } } }
public bool SaveDocument(string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { return(false); } if (_fileReader == null || _fileReader.Drawing == null) { return(false); } return(_fileReader.Save(fileName, true, false)); }
public bool LoadTests(string svgFilePath, string pngFilePath) { if (string.IsNullOrWhiteSpace(svgFilePath) || !File.Exists(svgFilePath)) { return(false); } if (_mainWindow == null) { return(false); } this.UnloadDocument(); var optionSettings = _mainWindow.OptionSettings; Size imageSize = new Size(0, 0); if (!LoadImage(pngFilePath, optionSettings, ref imageSize)) { return(false); } try { if (webView != null) { webView.Url = svgFilePath; if (imageSize.Width >= ImageWidth || imageSize.Height >= ImageHeight) { webView.Width = ImageWidth; webView.Height = ImageHeight; } else { webView.Width = imageSize.Width + 10; webView.Height = imageSize.Height + 10; } if (webView.IsCreated) { webView.InvalidateVisual(); } } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } var wpfSettings = optionSettings.ConversionSettings; var fileReader = new FileSvgReader(wpfSettings); fileReader.SaveXaml = false; fileReader.SaveZaml = false; _svgFilePath = svgFilePath; string fileExt = Path.GetExtension(svgFilePath); if (string.Equals(fileExt, SvgConverter.SvgExt, StringComparison.OrdinalIgnoreCase) || string.Equals(fileExt, SvgConverter.CompressedSvgExt, StringComparison.OrdinalIgnoreCase)) { if (fileReader != null) { _drawing = fileReader.Read(svgFilePath); if (_drawing != null) { if (LoadDrawing(imageSize, _drawing)) { if (optionSettings.ShowOutputFile && _mainWindow.XamlPage != null) { MemoryStream xamlStream = new MemoryStream(); if (fileReader.Save(xamlStream)) { _mainWindow.XamlPage.LoadDocument(xamlStream); } } return(true); } } } } _drawing = null; _svgFilePath = null; return(false); }