예제 #1
0
        public void MakeTest2()
        {
            MergeCss target   = new MergeCss();                                              // TODO: Initialize to an appropriate value
            string   css      = Common.PathCombine(_inputBasePath, "MergeFile5.css");        // TODO: Initialize to an appropriate value
            string   actual   = target.Make(css, "Temp1.css");
            string   expected = Common.PathCombine(_expectBasePath, "MergeMissingFile.css"); // TODO: Initialize to an appropriate value

            TextFileAssert.AreEqual(expected, actual, "Make Funtion missing file test failed");
        }
예제 #2
0
        public void OutputLocationTest()
        {
            MergeCss target   = new MergeCss(); // TODO: Initialize to an appropriate value
            string   expected = string.Empty;   // TODO: Initialize to an appropriate value
            string   actual;

            target.OutputLocation = expected;
            actual = target.OutputLocation;
            Assert.AreEqual(expected, actual, "OutputLocationTest failed");
        }
예제 #3
0
        /// <summary>
        /// Write the Pdf file
        /// </summary>
        /// <param name="outName">Name to use for Pdf file</param>
        public void Create(string outName)
        {
            Debug.Assert(!string.IsNullOrEmpty(Xhtml), "xhtml not set");

            if (Common.UnixVersionCheck())
            {
                if (!File.Exists("/usr/bin/Prince"))
                {
                    throw new MISSINGPRINCE();
                }
                Common.RunCommand("Prince ", Xhtml + " " + Css + " -o " + outName, 1);
                return;
            }
            RegistryKey regPrinceKey;

            try
            {
                regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                }
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                }
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                }
            }
            catch (Exception)
            {
                regPrinceKey = null;
            }
            if (regPrinceKey != null)
            {
                object princePath     = regPrinceKey.GetValue("InstallLocation");
                string princeFullName = Common.PathCombine(princePath as string, "Engine/Bin/Prince.exe");
                var    myPrince       = new Prince(princeFullName);
                var    mc             = new MergeCss();
                if (File.Exists(Css))
                {
                    myPrince.AddStyleSheet(mc.Make(Css, "Temp1.css"));
                }
                myPrince.Convert(Xhtml, outName);
            }
            else
            {
                throw new MISSINGPRINCE();
            }
        }
예제 #4
0
        public void MakeTest3()
        {
            MergeCss target = new MergeCss {
                OutputLocation = "Preprocess"
            };
            var workDir = Common.PathCombine(Path.GetTempPath(), "Preprocess");

            Common.CleanDirectory(new DirectoryInfo(workDir));
            string css      = Common.PathCombine(_inputBasePath, "MergeFile4.css"); // TODO: Initialize to an appropriate value
            string actual   = target.Make(css, "Temp1.css");
            string expected = Common.PathCombine(_expectBasePath, "MergeFile.css"); // TODO: Initialize to an appropriate value

            TextFileAssert.AreEqual(expected, actual, "Make Funtion test failed");
        }
예제 #5
0
파일: Preview.cs 프로젝트: sillsdev/pathway
        public string CreatePreview()
        {
            Debug.Assert(ParentForm != null);
            if (inProcess)
            {
                return(string.Empty);
            }
            inProcess = true;
            var cr = ParentForm.Cursor;

            ParentForm.Cursor = Cursors.WaitCursor;
            Debug.Assert(!string.IsNullOrEmpty(Param.Value[Param.CurrentInput]), "The given key was not present in the dictionary.");
            var xhtml = Param.Value[Param.CurrentInput];

            if (string.IsNullOrEmpty(xhtml) || !File.Exists(xhtml))
            {
                return(string.Empty);
            }
            string PreviewCSSPath = Param.StylePath(Sheet);
            var    mergedCss      = new MergeCss();
            string cssCombine     = mergedCss.Make(PreviewCSSPath, "Temp1.css");

            var returnXhtml = CreatePreviewFile(xhtml, cssCombine, "preview", true);
            var pdf         = new Pdf(returnXhtml, cssCombine);
            var outName     = Common.PathCombine(Param.Value[Param.OutputPath], Path.GetFileNameWithoutExtension(xhtml) + ".pdf");

            try
            {
                pdf.Create(outName);
            }
            catch (Pdf.MISSINGPRINCE)
            {
                LocDB.Message("errInstallPrinceXML", "PrinceXML must be downloaded and installed from www.PrinceXML.com", null, LocDB.MessageTypes.Error,
                              LocDB.MessageDefault.First);
                ParentForm.Cursor = cr;
                inProcess         = false;
                return(string.Empty);
            }
            ParentForm.Cursor = cr;
            inProcess         = false;
            return(outName);
        }
예제 #6
0
        public void MakeTest4()
        {
            MergeCss target = new MergeCss {
                OutputLocation = "Preprocess"
            };
            var workDir = Common.PathCombine(Path.GetTempPath(), "Preprocess");

            Common.CleanDirectory(new DirectoryInfo(workDir));
            string css      = Common.PathCombine(_inputBasePath, "MergeFile7.css");
            string actual   = target.Make(css, "Temp1.css");
            var    fileName = "MergeBottomImportFile.css";

            if (Common.UsingMonoVM)
            {
                fileName = fileName.Replace(".css", "_Linux.css");
            }
            string expected = Common.PathCombine(_expectBasePath, fileName);

            TextFileAssert.AreEqual(expected, actual, "Make Funtion test failed");
        }
예제 #7
0
        /// <summary>
        /// Combines all css files into one and adds expected css to beginning
        /// </summary>
        /// <param name="outputFullName">Name used to calculate default css name</param>
        /// <param name="outDir">where results will be stored</param>
        /// <param name="cssFullName">name and path of css file</param>
        /// <returns></returns>
        public string GetFluffedCssFullName(string outputFullName, string outDir, string cssFullName)
        {
            var    mc = new MergeCss();
            string fluffedCssFullName;

            try
            {
                if (!File.Exists(cssFullName))
                {
                    var layout = Param.Value[Param.LayoutSelected];
                    cssFullName = Param.StylePath(Param.StyleFile[layout]);
                }
                string myCss = Common.PathCombine(outDir, Path.GetFileName(cssFullName));
                if (cssFullName != myCss)
                {
                    File.Copy(cssFullName, myCss, true);
                }

                SetPageCenterTitle(myCss);

                var    expCss     = Path.GetFileNameWithoutExtension(outputFullName) + ".css";
                string expCssLine = "@import \"" + expCss + "\";";
                Common.FileInsertText(myCss, expCssLine);
                string outputCSSFileName = "merged" + expCss;
                var    tmpCss            = mc.Make(myCss, outputCSSFileName);
                fluffedCssFullName = Common.PathCombine(outDir, Path.GetFileName(tmpCss));
                File.Copy(tmpCss, fluffedCssFullName, true);
                File.Delete(tmpCss);
                Common.StreamReplaceInFile(fluffedCssFullName, "string(verse) ' = '", "string(verse) ' '"); //TD-1945
            }
            catch (Exception)
            {
                fluffedCssFullName = string.Empty;
            }
            return(fluffedCssFullName);
        }
예제 #8
0
        public bool Export(PublicationInformation projInfo)
        {
            bool success;
            bool isUnixOS = Common.UnixVersionCheck();
            //try
            //{
            var regPrinceKey = RegPrinceKey;

            if (regPrinceKey != null || isUnixOS)
            {
                var curdir = Environment.CurrentDirectory;
                projInfo.OutputExtension = "pdf";
                _pdfSymbols.Load(XmlReader.Create(Common.UsersXsl("PdfSymbols.xsl")));
                PreExportProcess preProcessor = new PreExportProcess(projInfo);
                if (isUnixOS)
                {
                    projInfo.DefaultXhtmlFileWithPath =
                        Common.RemoveDTDForLinuxProcess(projInfo.DefaultXhtmlFileWithPath, "pdfconvert");
                }
                Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);

                preProcessor.IncludeHyphenWordsOnXhtml(preProcessor.ProcessedXhtml);
                preProcessor.GetTempFolderPath();
                preProcessor.ImagePreprocess(false, delegate(string s, string to) { ImageMods.ResizeImage(s, to, 1, 1); });
                preProcessor.ReplaceSlashToREVERSE_SOLIDUS();
                if (projInfo.SwapHeadword)
                {
                    preProcessor.SwapHeadWordAndReversalForm();
                }
                preProcessor.MovePictureAsLastChild(preProcessor.ProcessedXhtml);
                preProcessor.SetNonBreakInVerseNumber(preProcessor.ProcessedXhtml);
                preProcessor.ReplaceProcessForPrinceOutput(preProcessor.ProcessedXhtml);
                Common.ApplyXsltArgs = new XsltArgumentList();
                Common.ApplyXsltArgs.AddParam("avPath", string.Empty, new Uri(projInfo.ProjectPath).AbsoluteUri);
                Common.ApplyXslt(preProcessor.ProcessedXhtml, _pdfSymbols);
                Common.ApplyXsltArgs = null;
                RenameAudioVisual(projInfo.ProjectPath, Path.GetDirectoryName(preProcessor.ProcessedXhtml));

                preProcessor.MoveCallerToPrevText(preProcessor.ProcessedXhtml);
                string tempFolder = Path.GetDirectoryName(preProcessor.ProcessedXhtml);
                var    mc         = new MergeCss {
                    OutputLocation = tempFolder
                };

                if (projInfo.IsReversalExist && File.Exists(projInfo.DefaultRevCssFileWithPath))
                {
                    Common.CopyContent(projInfo.DefaultCssFileWithPath, projInfo.DefaultRevCssFileWithPath);
                }

                string mergedCSS = mc.Make(projInfo.DefaultCssFileWithPath, "Temp1.css");
                preProcessor.ReplaceStringInCss(mergedCSS);
                preProcessor.InsertPropertyInCSS(mergedCSS);
                preProcessor.RemoveDeclaration(mergedCSS, ".pictureRight > .picture");
                preProcessor.RemoveDeclaration(mergedCSS, "div.pictureLeft > img.picture");
                preProcessor.HandleNewFieldworksChangeInCss(mergedCSS);
                mergedCSS = preProcessor.RemoveTextIndent(mergedCSS);

                if (isUnixOS)
                {
                    Common.StreamReplaceInFile(mergedCSS, "Scheherazade Graphite Alpha", "Scheherazade");
                }

                Dictionary <string, Dictionary <string, string> > cssClass = new Dictionary <string, Dictionary <string, string> >();
                CssTree cssTree = new CssTree();
                cssTree.OutputType = Common.OutputType.PDF;
                cssClass           = cssTree.CreateCssProperty(mergedCSS, true);
                if (cssClass.ContainsKey("@page") && cssClass["@page"].ContainsKey("-ps-hide-versenumber-one"))
                {
                    string value = cssClass["@page"]["-ps-hide-versenumber-one"];
                    if (value.ToLower() == "true")
                    {
                        preProcessor.RemoveVerseNumberOne(preProcessor.ProcessedXhtml, mergedCSS);
                    }
                }
                if (cssClass.ContainsKey("@page:left-top-left") && cssClass["@page:left-top-left"].ContainsKey("-ps-referenceformat"))
                {
                    string value = cssClass["@page:left-top-left"]["-ps-referenceformat"];
                    if (value.ToLower().Contains("gen 1"))
                    {
                        ReplaceBookNametoBookCode(preProcessor.ProcessedXhtml);
                    }
                }

                string xhtmlFileName = Path.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath);
                string defaultCSS    = Path.GetFileName(mergedCSS);
                Common.SetDefaultCSS(preProcessor.ProcessedXhtml, defaultCSS);

                _processedXhtml = preProcessor.ProcessedXhtml;
                if (projInfo.IsReversalExist && projInfo.IsLexiconSectionExist)
                {
                    var reversalFile = Path.GetDirectoryName(_processedXhtml);
                    reversalFile = Common.PathCombine(reversalFile, "FlexRev.xhtml");
                    Common.SetDefaultCSS(reversalFile, defaultCSS);
                }

                if (!ExportPrince(projInfo, xhtmlFileName, isUnixOS, regPrinceKey, defaultCSS))
                {
                    return(false);
                }

                Environment.CurrentDirectory = curdir;
                if (!projInfo.DefaultXhtmlFileWithPath.ToLower().Contains("local"))
                {
                    //Copyright information added in PDF files
                        #pragma warning disable 168
                    Common.InsertCopyrightInPdf(Common.PathCombine(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath), xhtmlFileName + ".pdf"), "Prince XML", projInfo.ProjectInputType);
                        #pragma warning restore 168
                }
                else
                {
                    string pdfFileName = xhtmlFileName + ".pdf";
                    pdfFileName = Common.PathCombine(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath), pdfFileName);

                    if (!Common.Testing && File.Exists(pdfFileName))
                    {
                        // ReSharper disable RedundantAssignment
                        success = true;
                        // ReSharper restore RedundantAssignment
                        Process.Start(pdfFileName);
                    }
                }
                success = true;
            }
            else
            {
                success = false || Common.Testing;
            }
            //}
            //catch (Exception)
            //{
            //    success = false;
            //}
            return(success);
        }