diff --git a/GraphLayout/Drawing/SvgGraphWriter.cs b/GraphLayout/Drawing/SvgGraphWriter.cs index d8a34de1..a5a8c2c7 100644 --- a/GraphLayout/Drawing/SvgGraphWriter.cs +++ b/GraphLayout/Drawing/SvgGraphWriter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -156,12 +156,12 @@ protected virtual void WriteLabel(Label label) { if (!LabelIsValid(label)) return; - //need to remove these hecks. TODO + //need to remove the hack. TODO const double yScaleAdjustment = 1.5; var x = label.Center.X - label.Width / 2; var y = label.Center.Y + label.Height / (2 * yScaleAdjustment); - var fontSize = 16; + var fontSize = label.fontsize; WriteStartElement("text"); WriteAttribute("x", x); WriteAttribute("y", y); @@ -955,4 +955,4 @@ public void WriteLine(Point a, Point b) { WriteEndElement(); } } -} \ No newline at end of file +} diff --git a/GraphLayout/Test/TestWpfViewer/App.cs b/GraphLayout/Test/TestWpfViewer/App.cs index 2442608c..e8c8e42f 100644 --- a/GraphLayout/Test/TestWpfViewer/App.cs +++ b/GraphLayout/Test/TestWpfViewer/App.cs @@ -92,6 +92,7 @@ internal class App : Application { public static readonly RoutedUICommand OpenFileCommand = new RoutedUICommand("Open File...", "OpenFileCommand", typeof (App)); + public static readonly RoutedUICommand SaveSvgCommand = new RoutedUICommand("Save SVG", "SaveSvgCommand", typeof(App)); public static readonly RoutedUICommand CancelLayoutCommand = new RoutedUICommand("Cancel Layout...", "CancelLayoutCommand", @@ -605,6 +606,8 @@ void UpdateThumbOnDrag(Slider slider, double del, Thumb draggedThumb) { void SetCommands() { + appWindow.CommandBindings.Add(new CommandBinding(SaveSvgCommand, SaveSvg)); + appWindow.CommandBindings.Add(new CommandBinding(SaveImageCommand, SaveImage)); appWindow.CommandBindings.Add(new CommandBinding(SaveMsaglCommand, SaveMsagl)); appWindow.CommandBindings.Add(new CommandBinding(ExitCommand, ExitHandler)); @@ -629,6 +632,29 @@ void SetCommands() { } + private void SaveSvg(object sender, ExecutedRoutedEventArgs e) { + if (graphViewer.Graph==null) { + MessageBox.Show("Graph is not loaded", "No Graph", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); + dlg.FileName = lastFileName + ".svg"; // Default file name + dlg.DefaultExt = ".svg "; // Default file extension + dlg.Filter = "svg files (.svg )|*.svg "; // Filter files by extension + + Nullable result = dlg.ShowDialog(); + + if (result != true) { + return; + } + + using (StreamWriter writer = new StreamWriter(dlg.FileName)) { + var svgWriter = new SvgGraphWriter(writer.BaseStream, graphViewer.Graph); + svgWriter.Write(); + } + + } + void SaveImage(object sender, ExecutedRoutedEventArgs e) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); @@ -641,6 +667,7 @@ void SaveImage(object sender, ExecutedRoutedEventArgs e) if (result == true) { graphViewer.DrawImage(dlg.FileName); + } } @@ -693,7 +720,9 @@ void SetViewMenu(Menu mainMenu) { void SetFileMenu(Menu mainMenu) { var fileMenu = new MenuItem {Header = "_File"}; var openFileMenuItem = new MenuItem {Header = "_Open", Command = OpenFileCommand}; - fileMenu.Items.Add(openFileMenuItem); + fileMenu.Items.Add(openFileMenuItem); + fileMenu.Items.Add(new MenuItem { Header = "Save _SVG", Command = SaveSvgCommand }); + var reloadFileMenuItem = new MenuItem {Header = "_Reload", Command = ReloadCommand}; fileMenu.Items.Add(reloadFileMenuItem); @@ -702,7 +731,7 @@ void SetFileMenu(Menu mainMenu) { mainMenu.Items.Add(fileMenu); toolBar.Items.Add(mainMenu); - var saveImageMenuItem = new MenuItem { Header = "_Save Image", Command = SaveImageCommand }; + var saveImageMenuItem = new MenuItem { Header = "Save _Image", Command = SaveImageCommand }; fileMenu.Items.Add(saveImageMenuItem); var saveMsaglMenuItem = new MenuItem { Header = "_Save MSAGL", Command = SaveMsaglCommand }; diff --git a/GraphLayout/tools/WpfGraphControl/GraphViewer.cs b/GraphLayout/tools/WpfGraphControl/GraphViewer.cs index 80ab850f..31b8aaf0 100644 --- a/GraphLayout/tools/WpfGraphControl/GraphViewer.cs +++ b/GraphLayout/tools/WpfGraphControl/GraphViewer.cs @@ -1439,6 +1439,11 @@ static TextBlock CreateTextBlock(Label drawingLabel) { textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); textBlock.Width = textBlock.DesiredSize.Width; textBlock.Height = textBlock.DesiredSize.Height; + if (drawingLabel.GeometryLabel == null) { + drawingLabel.GeometryLabel = new Core.Layout.Label(); + } + drawingLabel.GeometryLabel.Width = textBlock.Width; + drawingLabel.GeometryLabel.Height = textBlock.Height; return textBlock; } @@ -1729,4 +1734,4 @@ void MakeRoomForNewNode(Drawing.Node drawingNode) { public bool IncrementalDraggingModeAlways { get; set; } public bool CreateToolTipForNodes { get => createToolTipForNodes; private set => createToolTipForNodes = value; } } -} \ No newline at end of file +}