Exemple #1
0
        /// <summary>
        /// Convert XHTML to ODT
        /// </summary>
        public bool Export(PublicationInformation projInfo)
        {
            PreExportProcess preProcessor = new PreExportProcess(projInfo);

            preProcessor.GetTempFolderPath();
            preProcessor.InsertEmptyHeadwordForReversal(preProcessor.ProcessedXhtml);
            MergeProcessInXHTMLforMasterPage(preProcessor.ProcessedXhtml);
            preProcessor.PreserveSpace();
            preProcessor.ImagePreprocess(true);
            preProcessor.ReplaceInvalidTagtoSpan("_AllComplexFormEntryBackRefs|LexEntryRef_PrimaryLexemes", "span");
            preProcessor.InsertHiddenChapterNumber();
            preProcessor.InsertHiddenVerseNumber();
            preProcessor.GetDefinitionLanguage();
            var    exportTitle = GetExportTitle();
            string fileName    = exportTitle.ToString();

            if (exportTitle.ToString() == string.Empty)
            {
                fileName = Path.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath);
            }
            projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml;
            projInfo.DefaultCssFileWithPath   = preProcessor.ProcessedCss;
            projInfo.ProjectPath = Path.GetDirectoryName(preProcessor.ProcessedXhtml);

            Dictionary <string, Dictionary <string, string> > cssClass = new Dictionary <string, Dictionary <string, string> >();
            CssTree cssTree = new CssTree();

            cssClass = cssTree.CreateCssProperty(projInfo.DefaultCssFileWithPath, true);
            cssClass = MergeProcessInCSSforMasterPage(projInfo.DefaultCssFileWithPath, cssClass);
            preProcessor.InsertEmptyXHomographNumber(cssClass);

            //To insert the variable for macro use
            InInsertMacro insertMacro = new InInsertMacro();

            insertMacro.InsertMacroVariable(projInfo, cssClass);

            Dictionary <string, Dictionary <string, string> > idAllClass = new Dictionary <string, Dictionary <string, string> >();
            InStyles inStyles = new InStyles();

            idAllClass = inStyles.CreateIDStyles(Common.PathCombine(projInfo.TempOutputFolder, "Resources"), cssClass);

            InGraphic inGraphic = new InGraphic();

            inGraphic.CreateIDGraphic(Common.PathCombine(projInfo.TempOutputFolder, "Resources"), cssClass, cssTree.cssBorderColor);

            InStory inStory = new InStory();
            Dictionary <string, ArrayList> StyleName = inStory.CreateStory(projInfo, idAllClass, cssTree.SpecificityClass, cssTree.CssClassOrder);

            InMasterSpread inMasterSpread  = new InMasterSpread();
            ArrayList      masterPageNames = inMasterSpread.CreateIDMasterSpread(Common.PathCombine(projInfo.TempOutputFolder, "MasterSpreads"), idAllClass, StyleName["TextVariables"]);

            InSpread inSpread = new InSpread();

            inSpread.CreateIDSpread(Common.PathCombine(projInfo.TempOutputFolder, "Spreads"), idAllClass, StyleName["ColumnClass"]);

            InDesignMap inDesignMap = new InDesignMap();

            inDesignMap.CreateIDDesignMap(projInfo.TempOutputFolder, StyleName["ColumnClass"].Count, masterPageNames, StyleName["TextVariables"], StyleName["CrossRef"], projInfo.ProjectInputType);

            InMetaData inMetaData = new InMetaData();

            inMetaData.SetDateTimeinMetaDataXML(projInfo.TempOutputFolder);

            InPreferences inPreferences = new InPreferences();

            inPreferences.CreateIDPreferences(Common.PathCombine(projInfo.TempOutputFolder, "Resources"), idAllClass);

            SubProcess.AfterProcess(projInfo.ProjectFileWithPath);
            fileName = Common.ReplaceSymbolToUnderline(fileName);
            string ldmlFullName = Common.PathCombine(projInfo.DictionaryPath, fileName + ".idml");

            Compress(projInfo.TempOutputFolder, ldmlFullName);

            Common.CleanupExportFolder(ldmlFullName, ".tmp,.de", "layout.css", String.Empty);

            CreateRAMP(projInfo);

            Common.CleanupExportFolder(ldmlFullName, ".css,.xhtml,.xml", String.Empty, String.Empty);

            if (projInfo.IsOpenOutput)
            {
                Launch(ldmlFullName);
            }


            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Return the name of the preview html name in the link tag.
        /// </summary>
        /// <param name="xhtmlFile">XHTML File</param>
        /// <param name="cssFile">CSS File</param>
        /// <param name="outputFileName">Output File</param>
        /// <returns>Preview FilePath</returns>
        public static string CreatePreviewFile(string xhtmlFile, string cssFile, string outputFileName, bool excerptPreview)
        {
            PublicationInformation projInfo = new PublicationInformation();

            projInfo.DefaultXhtmlFileWithPath = xhtmlFile;
            projInfo.DefaultCssFileWithPath   = cssFile;
            if (!File.Exists(xhtmlFile))
            {
                return(string.Empty);
            }
            const int        stopAtLineNo = 100;
            PreExportProcess preProcessor = new PreExportProcess(projInfo);

            preProcessor.GetTempFolderPath();
            preProcessor.ImagePreprocess(false);
            xhtmlFile = preProcessor.ProcessedXhtml;
            string linkCss     = outputFileName + ".css";
            string previewPath = Path.GetDirectoryName(xhtmlFile);

            if (File.Exists(cssFile))
            {
                File.Copy(cssFile, Common.PathCombine(previewPath, linkCss), true);
            }
            string xhtmlPreviewFilePath = Common.PathCombine(previewPath, outputFileName + ".html");

            if (!excerptPreview)
            {
                Common.SetDefaultCSS(xhtmlPreviewFilePath, linkCss);
                return(xhtmlFile);
            }

            XmlTextReader reader;
            XmlTextWriter writer = new XmlTextWriter(xhtmlPreviewFilePath, null);

            try
            {
                reader = Common.DeclareXmlTextReader(xhtmlFile, true);
                writer.WriteStartDocument();
                int lineCount = 0;
                while (reader.Read())
                {
                    if (reader.IsEmptyElement)
                    {
                        writer.WriteStartElement(reader.Name);
                        string readName = reader.Name;
                        if (reader.HasAttributes)
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (string.Compare(readName, "link", true) == 0 && reader.Name == "href")
                                {
                                    writer.WriteAttributeString(reader.Name, linkCss);
                                }
                                else
                                {
                                    writer.WriteAttributeString(reader.Name, reader.Value);
                                }
                            }
                        }
                        writer.WriteEndElement();
                        readName = "";
                        continue;
                    }
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        writer.WriteStartElement(reader.Name);

                        if (reader.HasAttributes)
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                writer.WriteAttributeString(reader.Name, reader.Value);
                            }
                        }
                        break;

                    case XmlNodeType.EndElement:
                        writer.WriteEndElement();
                        break;

                    case XmlNodeType.Text:
                        writer.WriteString(reader.Value);
                        lineCount++;
                        break;
                    }
                    if (lineCount > stopAtLineNo)
                    {
                        break;
                    }
                }
                writer.Flush();
                writer.Close();
                reader.Close();
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
            return(xhtmlPreviewFilePath);
        }
Exemple #3
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);
        }