コード例 #1
0
ファイル: Exportepub.cs プロジェクト: neilmayhew/pathway
        private static MergeCss _mc; // When mc is disposed it also deletes the merged file

        //public Exportepub(string epub3Path)
        //{
        //    //this.epub3Path = epub3Path;
        //}

        private static string MergeAndFilterCss(PreExportProcess preProcessor, string tempFolder, string cssFullPath)
        {
            var tempFolderName = Path.GetFileName(tempFolder);
            _mc = new MergeCss { OutputLocation = tempFolderName };
            var mergedCss = _mc.Make(cssFullPath, "book.css");
            preProcessor.RemoveDeclaration(mergedCss, "@top-");
            preProcessor.RemoveDeclaration(mergedCss, "@bottom-");
            preProcessor.RemoveDeclaration(mergedCss, "@footnote");
            preProcessor.RemoveDeclaration(mergedCss, "@page");
            preProcessor.RemoveStringInCss(mergedCss, "string-set:");
            preProcessor.RemoveStringInCss(mergedCss, "-moz-column-");
            preProcessor.RemoveStringInCss(mergedCss, "column-fill:");
            preProcessor.RemoveStringInCss(mergedCss, "-ps-outline-");
            preProcessor.RemoveStringInCss(mergedCss, "float:");
            preProcessor.RemoveStringInCss(mergedCss, "-ps-fixed-line-height:");
            preProcessor.RemoveStringInCss(mergedCss, "content: leader(");
            preProcessor.ReplaceStringInCss(mergedCss);
            preProcessor.SetDropCapInCSS(mergedCss);
            preProcessor.InsertCoverPageImageStyleInCSS(mergedCss);
            preProcessor.InsertSectionHeadID();
            return mergedCss;
        }
コード例 #2
0
 public void RemoveHeaderStylesTest()
 {
     const string fileName = "RemoveHeaderStyle.css";
     var input = GetFileNameWithPath(fileName);
     var output = GetFileNameWithOutputPath(fileName);
     CopyToOutput(input, output);
     preExportProcess = new PreExportProcess();
     preExportProcess.RemoveDeclaration(output, "@top-");
     var sr = new StreamReader(output);
     var data = sr.ReadToEnd();
     sr.Close();
     var index = data.IndexOf("@top-", 0, StringComparison.CurrentCultureIgnoreCase);
     Assert.AreEqual(-1, index);
 }
コード例 #3
0
ファイル: ExportPdf.cs プロジェクト: neilmayhew/pathway
        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";
                    PreExportProcess preProcessor = new PreExportProcess(projInfo);
                    if (isUnixOS)
                    {
                        projInfo.DefaultXhtmlFileWithPath =
                            Common.RemoveDTDForLinuxProcess(projInfo.DefaultXhtmlFileWithPath,"pdfconvert");
                    }
                    Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                    preProcessor.GetTempFolderPath();
                    preProcessor.ImagePreprocess(false);
                    preProcessor.ReplaceSlashToREVERSE_SOLIDUS();
                    if (projInfo.SwapHeadword)
                        preProcessor.SwapHeadWordAndReversalForm();
                    preProcessor.MovePictureAsLastChild(preProcessor.ProcessedXhtml);
                    preProcessor.SetNonBreakInVerseNumber(preProcessor.ProcessedXhtml);
                    preProcessor.ReplaceDoubleSlashToLineBreak(preProcessor.ProcessedXhtml);
                    preProcessor.MoveCallerToPrevText(preProcessor.ProcessedXhtml);
                    string tempFolder = Path.GetDirectoryName(preProcessor.ProcessedXhtml);
                    string tempFolderName = Path.GetFileName(tempFolder);
                    var mc = new MergeCss { OutputLocation = tempFolderName };
                    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");
                    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 (!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
                        string pdfFileName = 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;
                    if (Common.Testing)
                    {
                        success = true;
                    }
                }
            }
            catch (Exception)
            {
                success = false;
            }
            return success;
        }