Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
0
        private void OnOpenRsvgDirectory(object sender, RoutedEventArgs e)
        {
            var filePath = txtRsvgDirectory.Text;

            if (string.IsNullOrWhiteSpace(filePath) || Directory.Exists(filePath) == false)
            {
                return;
            }

            OptionSettings.OpenFolderAndSelectItem(filePath, null);
        }
Пример #4
0
        public OptionSettings Clone()
        {
            OptionSettings optSettings = new OptionSettings(this);

            if (_wpfSettings != null)
            {
                optSettings._wpfSettings = _wpfSettings.Clone();
            }
            if (_svgDirectory != null)
            {
                optSettings._svgDirectory = new string(_svgDirectory.ToCharArray());
            }
            if (_pngDirectory != null)
            {
                optSettings._pngDirectory = new string(_pngDirectory.ToCharArray());
            }

            return(optSettings);
        }
Пример #5
0
        public Task <bool> LoadDocumentAsync(OptionSettings optionSettings, string svgFilePath)
        {
            if (_isLoadingImages || string.IsNullOrWhiteSpace(svgFilePath) || !File.Exists(svgFilePath))
            {
#if DOTNET40
                return(TaskEx.FromResult <bool>(false));
#else
                return(Task.FromResult <bool>(false));
#endif
            }

            string fileExt = Path.GetExtension(svgFilePath);

            if (!(string.Equals(fileExt, SvgConverter.SvgExt, StringComparison.OrdinalIgnoreCase) ||
                  string.Equals(fileExt, SvgConverter.CompressedSvgExt, StringComparison.OrdinalIgnoreCase)))
            {
#if DOTNET40
                return(TaskEx.FromResult <bool>(false));
#else
                return(Task.FromResult <bool>(false));
#endif
            }

            _optionSettings  = optionSettings;
            _isLoadingImages = true;
            _svgFilePath     = svgFilePath;

            _testImages.Clear();

            List <TestImage> testImages = new List <TestImage>();

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

            return(Task <bool> .Factory.StartNew((Func <bool>)(() =>
            {
                string svgFileName = Path.GetFileName(svgFilePath);

                string imageFile;
                imageFile = ProcessSvgnet(svgFileName);
                if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                {
                    testImages.Add((TestImage) new TestImage("SVG-NET", GetPng(imageFile)));
                }
                imageFile = ProcessBatik(svgFileName);
                if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                {
                    testImages.Add((TestImage) new TestImage("Apache Batik", GetPng(imageFile)));
                }
                imageFile = ProcessResvg(svgFileName);
                if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                {
                    testImages.Add((TestImage) new TestImage("Resvg", GetPng(imageFile)));
                }
                imageFile = ProcessFirefox(svgFileName);
                if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                {
                    testImages.Add((TestImage) new TestImage("Firefox", GetPng(imageFile)));
                }
                imageFile = ProcessInkscape(svgFileName);
                if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                {
                    testImages.Add((TestImage) new TestImage("Inkscape", GetPng(imageFile)));
                }
                imageFile = ProcessMagick(svgFileName);
                if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                {
                    testImages.Add((TestImage) new TestImage("Image Magick", GetPng(imageFile)));
                }
                else
                {
                    imageFile = ProcessRsvg(svgFileName);
                    if (!string.IsNullOrWhiteSpace(imageFile) && File.Exists(imageFile))
                    {
                        testImages.Add((TestImage) new TestImage("Librsvg", GetPng(imageFile)));
                    }
                }

                return testImages.Count != 0;
            })).ContinueWith((t) => {
                try
                {
                    if (!t.Result)
                    {
                        _isLoadingImages = false;
                        _svgFilePath = null;
                        return false;
                    }

                    foreach (var testImage in testImages)
                    {
                        _testImages.Add(testImage);
                    }

                    _isLoadingImages = false;

                    return true;
                }
                catch
                {
                    _isLoadingImages = false;
                    throw;
                }
            }, context));
        }
Пример #6
0
        private bool LoadImage(string pngFilePath, OptionSettings options, ref Size imageSize)
        {
            if (string.IsNullOrWhiteSpace(pngFilePath) || !File.Exists(pngFilePath))
            {
                return(false);
            }

            FileInfo pathInfo = new FileInfo(pngFilePath);

            if (pathInfo.Attributes.HasFlag(FileAttributes.ReparsePoint))
            {
                pngFilePath = options.EmptyImageFile;
            }

            if (!IsPng(pngFilePath))
            {
                var pngDir    = Path.GetDirectoryName(pngFilePath);
                var textLines = File.ReadAllLines(pngFilePath);
                if (textLines == null || textLines.Length == 0)
                {
                    return(false);
                }
                var linkedFileName = string.Empty;
                foreach (var textLine in textLines)
                {
                    if (!string.IsNullOrWhiteSpace(textLine))
                    {
                        linkedFileName = textLine;
                        break;
                    }
                }
                if (string.IsNullOrWhiteSpace(linkedFileName))
                {
                    return(false);
                }

                var currentDir = Environment.CurrentDirectory;
                Environment.CurrentDirectory = pngDir;
                var linkedPngFilePath = Path.GetFullPath(linkedFileName.Replace("/", "\\"));
                Environment.CurrentDirectory = currentDir;

                if (!File.Exists(linkedPngFilePath))
                {
                    return(false);
                }
                pngFilePath = linkedPngFilePath;
            }

            _pngFilePath = pngFilePath;

            BitmapSource bitmap = null;

            try
            {
                bitmap = new BitmapImage(new Uri(pngFilePath));
                if ((int)bitmap.DpiY != 96) // Some of the images were not created in right DPI
                {
                    double dpi    = 96;
                    int    width  = bitmap.PixelWidth;
                    int    height = bitmap.PixelHeight;

                    int    bitsPerPixel = (int)((bitmap.Format.BitsPerPixel + 7) / 8);
                    int    stride       = width * bitsPerPixel;
                    int    dataLength   = stride * height;
                    byte[] pixelData    = new byte[dataLength];
                    bitmap.CopyPixels(pixelData, stride, 0);

                    if (bitsPerPixel == 4)
                    {
                        bitmap = BitmapSource.Create(width, height, dpi, dpi, PixelFormats.Bgra32, null, pixelData, stride);
                    }
                    else
                    {
                        bitmap = BitmapSource.Create(width, height, dpi, dpi, bitmap.Format, bitmap.Palette, pixelData, stride);
                    }
                }

                pngImage.Source     = bitmap;
                pngImage.RenderSize = new Size(ImageWidth, ImageHeight);

                if (bitmap.Width >= ImageWidth || bitmap.Height >= ImageHeight)
                {
                    pngImage.Width  = ImageWidth;
                    pngImage.Height = ImageHeight;

                    pngCanvas.Width  = ImageWidth + 10;
                    pngCanvas.Height = ImageHeight + 10;

                    imageSize = new Size(ImageWidth, ImageHeight);
                }
                else
                {
                    pngCanvas.Width  = bitmap.Width + 10;
                    pngCanvas.Height = bitmap.Height + 10;

                    imageSize = new Size(bitmap.Width, bitmap.Height);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("Png: " + pngFilePath);
                Trace.TraceError(ex.ToString());
            }

            return(true);
        }