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 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); }
/// <summary> /// Background task work method. /// </summary> private void DoPrepareSvg(object sender, DoWorkEventArgs e) { // Lock to allow only one of these operations at a time. lock (_updateLock) { KanjiDao dao = new KanjiDao(); // Get the kanji strokes. KanjiStrokes strokes = dao.GetKanjiStrokes(_kanjiEntity.DbKanji.ID); if (strokes != null && strokes.FramesSvg.Length > 0) { // If the strokes was successfuly retrieved, we have to read the compressed SVG contained inside. SharpVectors.Renderers.Wpf.WpfDrawingSettings settings = new SharpVectors.Renderers.Wpf.WpfDrawingSettings(); using (FileSvgReader r = new FileSvgReader(settings)) { // Unzip the stream and remove instances of "px" that are problematic for SharpVectors. string svgString = StringCompressionHelper.Unzip(strokes.FramesSvg); svgString = svgString.Replace("px", string.Empty); StrokesCount = Regex.Matches(svgString, "<circle").Count; using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(svgString))) { // Then read the stream to a DrawingGroup. // We are forced to do this operation on the UI thread because DrawingGroups must // be always manipulated by the same thread. DispatcherHelper.Invoke(() => { StrokesDrawingGroup = r.Read(stream); SetCurrentStroke(1); }); } } } } }
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; } }
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); }
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); }
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; }
/// <inheritdoc /> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || value == DependencyProperty.UnsetValue) { return(null); } var path = value as string; if (string.IsNullOrEmpty(path)) { return(null); } if (!File.Exists(path)) { return(null); } try { if (path.EndsWith(".svg")) { var svgDrawing = new FileSvgReader(new WpfDrawingSettings()).Read(path); svgDrawing.Freeze(); return(new DrawingImage(svgDrawing)); } return(new BitmapImage(new Uri(path))); } catch { return(null); } }
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); }
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); }
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); } }
public void Handwheel1() //pure svg# without any modifications { var fileReader = new FileSvgReader(null); DrawingGroup drawing = fileReader.Read("TestFiles\\Handwheel.svg"); XmlXamlWriter writer = new XmlXamlWriter(null); var xaml = writer.Save(drawing); CheckXamlOutput(xaml); }
/// <see cref="IDiagramRenderer.Render(Stream)"/> public ImageSource Render(Stream imageData) { using (var reader = new StreamReader(imageData)) using (var converter = new FileSvgReader(settings)) { var drawingGroup = converter.Read(reader); return(CreateFrozenDrawing(drawingGroup)); } }
public MainWindow() { InitializeComponent(); var wpfSettings = new WpfDrawingSettings(); wpfSettings.CultureInfo = wpfSettings.NeutralCultureInfo; _fileSvgReader = new FileSvgReader(wpfSettings); }
public void Handwheel1() //pure svg# without any modifications { var fileReader = new FileSvgReader(null); DrawingGroup drawing = fileReader.Read("TestFiles\\Handwheel.svg"); XmlXamlWriter writer = new XmlXamlWriter(null); var xaml = writer.Save(drawing); Console.WriteLine(xaml); Clipboard.SetText(xaml); }
private void UpdateDrawing(string svgFilePath) { var wpfSettings = new WpfDrawingSettings(); wpfSettings.CultureInfo = wpfSettings.NeutralCultureInfo; using (var textReader = new StreamReader(svgFilePath)) { using (var fileReader = new FileSvgReader(wpfSettings)) { _imageCount++; try { if (_isVerbose) { this.AppendLine("Start Converting: " + svgFilePath); } else { _columnCount++; AppendText("*"); if (_columnCount >= NumberOfColumns) { _columnCount = 0; if (_imageCount < NumberOfImages) { AppendLine(string.Empty); } } } fileReader.SaveXaml = false; fileReader.SaveZaml = false; var drawing = fileReader.Read(textReader); drawing.Freeze(); AppendImage(drawing, Path.GetFileNameWithoutExtension(svgFilePath)); if (_isVerbose) { this.AppendLine("Completed Converting: " + svgFilePath); } } catch (Exception ex) { if (_isVerbose) { AppendClear(); } this.AppendLine("File: " + svgFilePath); AppendError(ex.ToString()); } } } }
public static DrawingGroup SvgToDrawingGroup(Stream stream) { FileSvgReader reader = new FileSvgReader(new WpfDrawingSettings { CultureInfo = CultureInfo.InvariantCulture, IncludeRuntime = true, }); reader.Read(stream); return(reader.Drawing); }
public SVGExplorer(string svgFile) { FileSvgReader fr = new FileSvgReader(false, false, new DirectoryInfo(Environment.CurrentDirectory), null); fr.DrawingSettings.InteractiveMode = SvgInteractiveModes.Standard; //PAUL: Updates! var dg = fr.Read(svgFile); constructFromDrawing(dg, fr.DrawingDocument); }
public DrawingPage() { InitializeComponent(); _wpfSettings = new WpfDrawingSettings(); _fileReader = new FileSvgReader(_wpfSettings); _fileReader.SaveXaml = false; _fileReader.SaveZaml = false; this.Loaded += new RoutedEventHandler(OnPageLoaded); }
public DrawingPage() { InitializeComponent(); _saveXaml = true; _wpfSettings = new WpfDrawingSettings(); _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo; _fileReader = new FileSvgReader(_wpfSettings); _fileReader.SaveXaml = _saveXaml; _fileReader.SaveZaml = false; _mouseHandlingMode = ZoomPanMouseHandlingMode.SelectPoint; //string workDir = Path.Combine(Path.GetDirectoryName( // System.Reflection.Assembly.GetExecutingAssembly().Location), TemporalDirName); string workDir = Path.Combine(Path.GetFullPath("..\\"), TemporalDirName); _workingDir = new DirectoryInfo(workDir); _embeddedImages = new List <EmbeddedImageSerializerArgs>(); _embeddedImageVisitor = new EmbeddedImageSerializerVisitor(true); _wpfSettings.Visitors.ImageVisitor = _embeddedImageVisitor; _embeddedImageVisitor.ImageCreated += OnEmbeddedImageCreated; textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML"); TextEditorOptions options = textEditor.Options; if (options != null) { //options.AllowScrollBelowDocument = true; options.EnableHyperlinks = true; options.EnableEmailHyperlinks = true; options.EnableVirtualSpace = false; options.HighlightCurrentLine = true; options.ShowSpaces = true; options.ShowTabs = true; options.ShowEndOfLine = true; } textEditor.ShowLineNumbers = true; textEditor.WordWrap = true; _foldingManager = FoldingManager.Install(textEditor.TextArea); _foldingStrategy = new XmlFoldingStrategy(); this.Loaded += OnPageLoaded; this.Unloaded += OnPageUnloaded; this.SizeChanged += OnPageSizeChanged; }
/// <see cref="IDiagramRenderer.Render(Diagram)"/> public ImageSource Render(Diagram diagram) { if (diagram.ImageFile == null || !diagram.ImageFile.Exists) { return(null); } using (var converter = new FileSvgReader(settings)) { var drawingGroup = converter.Read(diagram.ImageFile.FullName); return(CreateFrozenDrawing(drawingGroup)); } }
public static ImageSource LoadTurtleImage() { var settings = new WpfDrawingSettings { IncludeRuntime = true, TextAsGeometry = false }; var converter = new FileSvgReader(settings); var drawing = converter.Read(Path.Combine(GetProjectDir(), "assets", "Turtle1.svg")); return(new DrawingImage(drawing)); }
private void Part8Button_Click(object sender, RoutedEventArgs e) { if (!_part8Complete) { //var layersList = _segmentLayers.Select(p => p.Value).ToList(); //_image.Layers = layersList; //_svgImage = ToSvgString(_image, _segmentLayers, _options.SvgRendering); _svgImage = new TracedImage(_segmentLayers, _loadedImage.Width, _loadedImage.Height).ToSvgString(_options.SvgRendering); File.WriteAllText(_outputFilename, _svgImage); //http://stackoverflow.com/questions/1879395/how-to-generate-a-stream-from-a-string using (MemoryStream stream = new MemoryStream()) using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(_svgImage); writer.Flush(); stream.Position = 0; var wpfSettings = new WpfDrawingSettings(); wpfSettings.CultureInfo = wpfSettings.NeutralCultureInfo; var reader = new FileSvgReader(wpfSettings); _renderedSvg = reader.Read(stream); //ZoomPanControl.ScaleToFit(); //CanvasScroller.Visibility = Visibility.Visible; } //SvgViewer.UnloadDiagrams(); CanvasScroller.Visibility = Visibility.Hidden; SvgViewer.RenderDiagrams(_renderedSvg); Rect bounds = SvgViewer.Bounds; if (bounds.IsEmpty) { bounds = new Rect(0, 0, CanvasScroller.ActualWidth, CanvasScroller.ActualHeight); } ZoomPanControl.AnimatedZoomTo(bounds); _part8Complete = true; //Part8Button.IsEnabled = false; } else { CanvasScroller.Visibility = Visibility.Visible; } ImageDisplay.Source = BitmapToImageSource(CreateTransparentBitmap(_loadedImage.Width + 1, _loadedImage.Height + 1)); }
public static DrawingGroup SvgToDrawingGroup(string svgStr) { WpfDrawingSettings settings = new WpfDrawingSettings { CultureInfo = CultureInfo.InvariantCulture, IncludeRuntime = true, }; using (FileSvgReader reader = new FileSvgReader(settings)) { reader.Read(svgStr); return(reader.Drawing); } }
public MainWindow() { InitializeComponent(); _titleBase = this.Title; this.Loaded += new RoutedEventHandler(OnWindowLoaded); //this.Unloaded += new RoutedEventHandler(OnWindowUnloaded); this.Closing += new CancelEventHandler(OnWindowClosing); _fileReader = new FileSvgReader(); _fileReader.SaveXaml = false; _fileReader.SaveZaml = false; }
public BrowserPage() { InitializeComponent(); _viewBoxWidth = 0; _viewBoxHeight = 0; _wpfSettings = new WpfDrawingSettings(); _fileReader = new FileSvgReader(_wpfSettings); _fileReader.SaveXaml = false; _fileReader.SaveZaml = false; this.Loaded += OnPageLoaded; this.SizeChanged += OnPageSizeChanged; }
public SvgPage() { InitializeComponent(); // string workingDir = PathUtils.Combine(Assembly.GetExecutingAssembly()); string workingDir = IoPath.GetFullPath("..\\"); _svgFilePath = IoPath.Combine(workingDir, SvgFileName); _xamlFilePath = IoPath.Combine(workingDir, XamlFileName); _backFilePath = IoPath.Combine(workingDir, BackFileName); _directoryInfo = new DirectoryInfo(workingDir); _wpfSettings = new WpfDrawingSettings(); _fileReader = new FileSvgReader(_wpfSettings); _fileReader.SaveXaml = true; _fileReader.SaveZaml = false; textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML"); TextEditorOptions options = textEditor.Options; if (options != null) { //options.AllowScrollBelowDocument = true; options.EnableHyperlinks = true; options.EnableEmailHyperlinks = true; options.EnableVirtualSpace = false; options.HighlightCurrentLine = true; //options.ShowSpaces = true; //options.ShowTabs = true; //options.ShowEndOfLine = true; } textEditor.ShowLineNumbers = true; _foldingManager = FoldingManager.Install(textEditor.TextArea); _foldingStrategy = new XmlFoldingStrategy(); _searchPanel = SearchPanel.Install(textEditor); textEditor.TextArea.IndentationStrategy = new DefaultIndentationStrategy(); this.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display); this.Loaded += OnPageLoaded; this.SizeChanged += OnPageSizeChanged; }
public static DrawingGroup ConvertToDrawingGroup(string svgContent) { var settings = new WpfDrawingSettings { IncludeRuntime = false, TextAsGeometry = false, OptimizePath = true }; var converter = new FileSvgReader(settings); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(svgContent))) { return(converter.Read(stream)); } }
public InfiniteZoomPanPage() { InitializeComponent(); _wpfSettings = new WpfDrawingSettings(); _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo; _fileReader = new FileSvgReader(_wpfSettings); _fileReader.SaveXaml = false; _fileReader.SaveZaml = false; _mouseHandlingMode = ZoomPanMouseHandlingMode.None; this.Loaded += OnPageLoaded; this.Unloaded += OnPageUnloaded; this.SizeChanged += OnPageSizeChanged; }
public MainWindow() { InitializeComponent(); _titleBase = this.Title; this.Loaded += new RoutedEventHandler(OnWindowLoaded); //this.Unloaded += new RoutedEventHandler(OnWindowUnloaded); this.Closing += new CancelEventHandler(OnWindowClosing); _wpfSettings = new WpfDrawingSettings(); _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo; _fileReader = new FileSvgReader(_wpfSettings); _fileReader.SaveXaml = false; _fileReader.SaveZaml = false; }