Esempio n. 1
0
        /// <summary>
        /// Convert XHTML to ODT
        /// </summary>
        public bool Export(PublicationInformation projInfo)
        {
            string xeLatexFullFile;
            StreamWriter xeLatexFile;
            XeLaTexStyles xeLaTexStyles;
            _xhtmlXelatexXslProcess.Load(XmlReader.Create(Common.UsersXsl("AddBidi.xsl")));
            _isUnixOs = Common.IsUnixOS();
            _langFontDictionary = new Dictionary<string, string>();
            _langFontCodeandName = new Dictionary<string, string>();
            string mainXhtmlFileWithPath = projInfo.DefaultXhtmlFileWithPath;
            projInfo.OutputExtension = "pdf";

            var preProcessor = new PreExportProcess(projInfo);
            ExportPreprocessForXelatex(projInfo, preProcessor);
            var organization = SettingFrontmatter();
            BuildLanguagesList(projInfo.DefaultXhtmlFileWithPath);

            string fileName = Path.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath);

            AssignExportFile(projInfo, preProcessor);
            ModifyXeLaTexStyles modifyXeLaTexStyles = new ModifyXeLaTexStyles();
            modifyXeLaTexStyles.LangFontDictionary = _langFontCodeandName;

            Dictionary<string, Dictionary<string, string>> newProperty;
            var cssClass = WrittingTexFile(projInfo, fileName, out xeLatexFullFile, out xeLatexFile, out xeLaTexStyles, out newProperty);
            string include = xeLaTexStyles.PageStyle.ToString();

            InitilizeXelatexStyle(modifyXeLaTexStyles);

            if (ExportCopyright(projInfo, mainXhtmlFileWithPath))
            {
                _copyrightTexCreated = true;
                modifyXeLaTexStyles.CopyrightTexCreated = true;
                modifyXeLaTexStyles.CopyrightTexFilename = Path.GetFileName(_copyrightTexFileName);
            }

            ExportReversalProcess(projInfo, modifyXeLaTexStyles);
            ProcessWrittingStyles(projInfo, modifyXeLaTexStyles, newProperty, xeLatexFile, cssClass, xeLatexFullFile, include);
            Dictionary<string, string> imgPath = new Dictionary<string, string>();
            if (newProperty.ContainsKey("ImagePath"))
            {
                imgPath = newProperty["ImagePath"];
            }
            UpdateXeLaTexFontCacheIfNecessary();
            CallXeLaTex(projInfo, xeLatexFullFile, true, imgPath);
            ProcessRampFile(projInfo, xeLatexFullFile, organization);
            return true;
        }
Esempio n. 2
0
        private void ExportProcess(string file)
        {
            string input = FileInput(file + ".xhtml");
            _projInfo.DefaultXhtmlFileWithPath = input;
            _langFontCodeandName = new Dictionary<string, string>();
            GetXhtmlFileFontCodeandFontName(_projInfo.DefaultXhtmlFileWithPath);
            input = FileInput(file + ".css");
            _projInfo.DefaultCssFileWithPath = input;

            _projInfo.TempOutputFolder = _outputPath;
            _projInfo.OutputExtension = ".tex";

            Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>();
            CssTree cssTree = new CssTree();
            cssTree.OutputType = Common.OutputType.XELATEX;
            cssClass = cssTree.CreateCssProperty(input, true);
            int pageWidth = Common.GetPictureWidth(cssClass, _projInfo.ProjectInputType);

            string xetexFullFile = Common.PathCombine(_outputPath, file + ".tex");
            StreamWriter xetexFile = new StreamWriter(xetexFullFile);

            XeLaTexStyles styles = new XeLaTexStyles();
            _classInlineStyle = styles.CreateXeTexStyles(_projInfo, xetexFile, cssClass);

            XeLaTexContent content = new XeLaTexContent();
            Dictionary<string, List<string>> classInlineText = styles._classInlineText;
            Dictionary<string, Dictionary<string, string>> newProperty = content.CreateContent(_projInfo, cssClass, xetexFile, _classInlineStyle, cssTree.SpecificityClass, cssTree.CssClassOrder, classInlineText, pageWidth);

            CloseFile(xetexFile);

            ModifyXeLaTexStyles modifyXeTexStyles = new ModifyXeLaTexStyles();
            modifyXeTexStyles.ModifyStylesXML(_projInfo.ProjectPath, xetexFile, newProperty, cssClass, xetexFullFile, string.Empty, _langFontCodeandName,true);

        }
Esempio n. 3
0
        public bool ExportReversalIndex(PublicationInformation projInfo)
        {

            if (projInfo.IsReversalExist)
            {
                var revFile = Common.PathCombine(projInfo.ProjectPath, "FlexRev.xhtml");
                if (!File.Exists(revFile))
                {
                    return false;
                }

                if (File.Exists(revFile))
                {
                    if (Common.UnixVersionCheck())
                    {
                        Common.RemoveDTDForLinuxProcess(revFile, "xelatex");
                    }
                }

                projInfo.DefaultXhtmlFileWithPath = revFile;
                PreExportProcess preProcessor = new PreExportProcess(projInfo);
                preProcessor.SetLangforLetter(projInfo.DefaultXhtmlFileWithPath);

                CheckFontFamilyAvailable(projInfo.DefaultRevCssFileWithPath);

                Dictionary<string, Dictionary<string, string>> cssClass =
                    new Dictionary<string, Dictionary<string, string>>();
                CssTree cssTree = new CssTree();
                cssTree.OutputType = Common.OutputType.XELATEX;
                cssClass = cssTree.CreateCssProperty(projInfo.DefaultRevCssFileWithPath, true);
                string fileNameXhtml = Path.GetFileNameWithoutExtension(revFile);
                string xeLatexRevesalIndexFile = Common.PathCombine(projInfo.ProjectPath, fileNameXhtml + ".tex");
                _reversalIndexTexFileName = xeLatexRevesalIndexFile;
                StreamWriter xeLatexFile = new StreamWriter(xeLatexRevesalIndexFile);
                Dictionary<string, List<string>> classInlineStyle = new Dictionary<string, List<string>>();
                XeLaTexStyles xeLaTexStyles = new XeLaTexStyles();
                xeLaTexStyles.LangFontDictionary = _langFontCodeandName;
                classInlineStyle = xeLaTexStyles.CreateXeTexStyles(projInfo, xeLatexFile, cssClass);
                int pageWidth = Common.GetPictureWidth(cssClass, projInfo.ProjectInputType);

                XeLaTexContent xeLaTexContent = new XeLaTexContent();
                xeLaTexContent.IsUnix = _isUnixOs;
                Dictionary<string, List<string>> classInlineText = xeLaTexStyles._classInlineText;
                Dictionary<string, Dictionary<string, string>> newProperty = xeLaTexContent.CreateContent(projInfo,
                                                                                                          cssClass,
                                                                                                          xeLatexFile,
                                                                                                          classInlineStyle,
                                                                                                          cssTree
                                                                                                              .SpecificityClass,
                                                                                                          cssTree
                                                                                                              .CssClassOrder,
                                                                                                          classInlineText,
                                                                                                          pageWidth);

                _xelatexDocumentOpenClosedRequired = true; //Don't change the place.
                CloseDocument(xeLatexFile, false, string.Empty);
                string include = xeLaTexStyles.PageStyle.ToString();
                ModifyXeLaTexStyles modifyXeLaTexStyles = new ModifyXeLaTexStyles();
                modifyXeLaTexStyles.XelatexDocumentOpenClosedRequired = true;
                modifyXeLaTexStyles.ProjectType = projInfo.ProjectInputType;
	            bool createPageNumber = false;
	            if (projInfo.DefaultXhtmlFileWithPath.IndexOf("PreserveFlexRev.xhtml") > 0)
		            createPageNumber = true;

                modifyXeLaTexStyles.ModifyStylesXML(projInfo.ProjectPath, xeLatexFile, newProperty, cssClass,
													xeLatexRevesalIndexFile, include, _langFontCodeandName, createPageNumber);
                _xeLaTexPropertyFullFontStyleList = modifyXeLaTexStyles.XeLaTexPropertyFontStyleList;

                if (newProperty.ContainsKey("TableofContent") && newProperty["TableofContent"].Count > 0)
                {
                    foreach (var tocSection in newProperty["TableofContent"])
                    {
                        if (tocSection.Key.Contains("PageStock"))
                        {
                            _tocPropertyList.Add(tocSection.Key, tocSection.Value);
                        }
                    }
                }
                return true;
            }
            return false;
        }
Esempio n. 4
0
        public bool ExportCopyright(PublicationInformation projInfo, string mainXhtmlFileWithPath)
        {
            if (_copyrightInformation)
            {
                var preProcess = new PreExportProcess(projInfo);
                var processFolder = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                preProcess.CopyCopyrightPage(processFolder);
                string copyRightFilePath = Common.PathCombine(processFolder, "File2Cpy.xhtml");

                if (copyRightFilePath.Trim().Length <= 0 && !File.Exists(copyRightFilePath))
                {
                    return false;
                }
                if (File.Exists(copyRightFilePath))
                {
                    if (Common.UnixVersionCheck())
                    {
                        string draftTempFileName = Path.GetFileName(copyRightFilePath);
                        draftTempFileName = Common.PathCombine(Path.GetTempPath(), draftTempFileName);
                        if (!File.Exists(draftTempFileName))
                        {
                            File.Copy(copyRightFilePath, draftTempFileName, true);
                            Common.RemoveDTDForLinuxProcess(draftTempFileName, "xelatex");
                        }
                        projInfo.DefaultXhtmlFileWithPath = draftTempFileName;
                        copyRightFilePath = draftTempFileName;
                    }
                    else
                    {
                        projInfo.DefaultXhtmlFileWithPath = copyRightFilePath;
                    }
                }
                else
                {
                    return false;
                }

                string filepath = Path.GetFullPath(copyRightFilePath);

                Dictionary<string, Dictionary<string, string>> cssClass =
                    new Dictionary<string, Dictionary<string, string>>();
                CssTree cssTree = new CssTree();
                cssTree.OutputType = Common.OutputType.XELATEX;
                cssClass = cssTree.CreateCssProperty(Common.PathCombine(filepath, "copy.css"), true);
                string fileNameXhtml = Path.GetFileNameWithoutExtension(copyRightFilePath);
                string xeLatexCopyrightFile = Common.PathCombine(projInfo.ProjectPath, fileNameXhtml + ".tex");
                _copyrightTexFileName = xeLatexCopyrightFile;
                int pageWidth = Common.GetPictureWidth(cssClass, projInfo.ProjectInputType);

                StreamWriter xeLatexFile = new StreamWriter(xeLatexCopyrightFile);
                Dictionary<string, List<string>> classInlineStyle = new Dictionary<string, List<string>>();
                XeLaTexStyles xeLaTexStyles = new XeLaTexStyles();
                xeLaTexStyles.LangFontDictionary = _langFontCodeandName;
                classInlineStyle = xeLaTexStyles.CreateXeTexStyles(projInfo, xeLatexFile, cssClass);

                XeLaTexContent xeLaTexContent = new XeLaTexContent();
                xeLaTexContent.IsUnix = _isUnixOs;
                Dictionary<string, List<string>> classInlineText = xeLaTexStyles._classInlineText;
                xeLaTexContent.CreateContent(projInfo, cssClass, xeLatexFile, classInlineStyle, cssTree.SpecificityClass, cssTree.CssClassOrder, classInlineText, pageWidth);

                _xelatexDocumentOpenClosedRequired = true; //Don't change the place.
                CloseDocument(xeLatexFile, false, string.Empty);
                ModifyXeLaTexStyles modifyXeLaTexStyles = new ModifyXeLaTexStyles();
                modifyXeLaTexStyles.XelatexDocumentOpenClosedRequired = true;
                modifyXeLaTexStyles.ProjectType = projInfo.ProjectInputType;

                string copyright = GetLanguageInfo(mainXhtmlFileWithPath, projInfo);
                InsertInFile(xeLatexCopyrightFile, "copyright information", copyright);

                return true;
            }
            return false;
        }
Esempio n. 5
0
        private void ExportReversalProcess(PublicationInformation projInfo, ModifyXeLaTexStyles modifyXeLaTexStyles)
        {
            if (projInfo.IsReversalExist)
            {
                if (_inputType.ToLower() == "dictionary")
                {
                    Common.ApplyXslt(projInfo.DefaultXhtmlFileWithPath, _xhtmlXelatexXslProcess);
                }
                if (ExportReversalIndex(projInfo))
                {
                    _reversalIndexTexCreated = true;
                    var revFile = Common.PathCombine(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath),
                                                     "FlexRev.xhtml");
                    string fileNameXhtml = Path.GetFileNameWithoutExtension(revFile);
                    string xeLatexReversalFile = Common.PathCombine(projInfo.ProjectPath, fileNameXhtml + ".tex");

                    modifyXeLaTexStyles.ReversalIndexExist = true;
                    modifyXeLaTexStyles.ReversalIndexTexFilename = Path.GetFileName(xeLatexReversalFile);
                }
            }
        }
Esempio n. 6
0
        private void InitilizeXelatexStyle(ModifyXeLaTexStyles modifyXeLaTexStyles)
        {
            modifyXeLaTexStyles.ProjectType = _inputType;
            modifyXeLaTexStyles.TocChecked = _tableOfContent.ToString();

            modifyXeLaTexStyles.CoverImage = _coverImage.ToString();
            modifyXeLaTexStyles.TitleInCoverPage = _titleInCoverPage.ToString();
            modifyXeLaTexStyles.CopyrightInformation = _copyrightInformation.ToString();
            modifyXeLaTexStyles.IncludeBookTitleintheImage = _includeBookTitleintheImage.ToString();
            modifyXeLaTexStyles.CopyrightInformationPagePath = _copyrightInformationPagePath;
            modifyXeLaTexStyles.CoverPageImagePath = _coverPageImagePath;
        }
Esempio n. 7
0
        private void ProcessWrittingStyles(PublicationInformation projInfo, ModifyXeLaTexStyles modifyXeLaTexStyles, Dictionary<string, Dictionary<string, string>> newProperty,
                              StreamWriter xeLatexFile, Dictionary<string, Dictionary<string, string>> cssClass, string xeLatexFullFile, string include)
        {
            modifyXeLaTexStyles.XelatexDocumentOpenClosedRequired = false;
            _xelatexDocumentOpenClosedRequired = false;
            modifyXeLaTexStyles.ProjectType = projInfo.ProjectInputType;

            if (newProperty.ContainsKey("TableofContent") && newProperty["TableofContent"].Count > 0)
            {
                foreach (var tocSection in _tocPropertyList)
                {
                    if (tocSection.Key.Contains("PageStock"))
                    {
                        newProperty["TableofContent"].Add(tocSection.Key, tocSection.Value);
                    }
                }
            }

            modifyXeLaTexStyles.XeLaTexPropertyFontStyleList = _xeLaTexPropertyFullFontStyleList;
            modifyXeLaTexStyles.ModifyStylesXML(projInfo.ProjectPath, xeLatexFile, newProperty, cssClass, xeLatexFullFile,
                                                include, _langFontCodeandName, true);
        }