Exemple #1
0
        private bool ConvertDocument()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(_svgFilePath) || File.Exists(_svgFilePath) == false)
                {
                    return(false);
                }
                DrawingGroup drawing = _fileReader.Read(_svgFilePath, _directoryInfo);
                if (drawing == null)
                {
                    return(false);
                }

                if (_xamlPage != null && !string.IsNullOrWhiteSpace(_xamlFilePath))
                {
                    if (File.Exists(_xamlFilePath))
                    {
                        _xamlPage.LoadDocument(_xamlFilePath);

                        // Delete the file after loading it...
                        File.Delete(_xamlFilePath);
                    }
                }
                _currentDrawing = drawing;

                Rect drawingBounds = drawing.Bounds;

                svgDrawing.UnloadDiagrams();

                svgDrawing.RenderDiagrams(drawing);

                zoomPanControl.InvalidateMeasure();

                Rect bounds = drawing.Bounds;

                //zoomPanControl.AnimatedScaleToFit();
                //Rect rect = new Rect(0, 0,
                //    mainFrame.RenderSize.Width, mainFrame.RenderSize.Height);
                //Rect rect = new Rect(0, 0,
                //    bounds.Width, bounds.Height);
                if (bounds.IsEmpty)
                {
                    bounds = new Rect(0, 0, viewerFrame.ActualWidth, viewerFrame.ActualHeight);
                }
                zoomPanControl.AnimatedZoomTo(bounds);

                return(true);
            }
            catch (Exception ex)
            {
                //svgDrawing.Source = null;
                svgDrawing.UnloadDiagrams();

                this.ReportError(ex);

                return(false);
            }
        }
        private bool ConvertDocument(string filePath = null)
        {
            if (string.IsNullOrWhiteSpace(filePath) || File.Exists(filePath) == false)
            {
                filePath = _svgFilePath;
            }
            try
            {
                if (string.IsNullOrWhiteSpace(filePath) || File.Exists(filePath) == false)
                {
                    return(false);
                }
                DrawingGroup drawing = _fileReader.Read(filePath, _directoryInfo);
                if (drawing == null)
                {
                    return(false);
                }

                if (_renderCount != 0)
                {
                    Trace.WriteLine(string.Empty);
                }

                Trace.TraceInformation("ConvertDocument: Started");

                if (_xamlPage != null && !string.IsNullOrWhiteSpace(_xamlFilePath))
                {
                    if (File.Exists(_xamlFilePath))
                    {
                        _xamlPage.LoadDocument(_xamlFilePath);

                        // Delete the file after loading it...
                        File.Delete(_xamlFilePath);
                    }
                    else
                    {
                        string xamlFilePath = IoPath.Combine(_directoryInfo.FullName,
                                                             IoPath.GetFileNameWithoutExtension(filePath) + ".xaml");
                        if (File.Exists(xamlFilePath))
                        {
                            _xamlPage.LoadDocument(xamlFilePath);

                            // Delete the file after loading it...
                            File.Delete(xamlFilePath);
                        }
                    }
                }
                _currentDrawing = drawing;

                Rect drawingBounds = drawing.Bounds;

                svgDrawing.UnloadDiagrams();

                svgDrawing.RenderDiagrams(drawing);

                zoomPanControl.InvalidateMeasure();

                Rect bounds = drawing.Bounds;

                //zoomPanControl.AnimatedScaleToFit();
                //Rect rect = new Rect(0, 0,
                //    mainFrame.RenderSize.Width, mainFrame.RenderSize.Height);
                //Rect rect = new Rect(0, 0,
                //    bounds.Width, bounds.Height);
                if (bounds.IsEmpty)
                {
                    bounds = new Rect(0, 0, viewerFrame.ActualWidth, viewerFrame.ActualHeight);
                }
                zoomPanControl.AnimatedZoomTo(bounds);

                Trace.TraceInformation("ConvertDocument: Completed");

                _renderCount++;

                return(true);
            }
            catch (Exception ex)
            {
                //svgDrawing.Source = null;
                svgDrawing.UnloadDiagrams();

                this.ReportError(ex);

                return(false);
            }
        }