/// <summary> /// Entry point for epub 3 converter /// </summary> /// <param name="projInfo">values passed including epub2 exported files and changed to epub3 support</param> /// <returns>true if succeeds</returns> public bool Export(PublicationInformation projInfo) { bool epub3Export = false; string oebpsPath = Common.PathCombine(Epub3Directory, "OEBPS"); string cssFile = Common.PathCombine(oebpsPath, "book.css"); var preProcessor = new PreExportProcess(); preProcessor.ReplaceStringInFile(cssFile, "{direction:ltr}", "{direction:ltr;}"); preProcessor.ReplaceStringInFile(cssFile, "direction:", "dir:"); //preProcessor.RemoveStringInCss(cssFile, "direction:"); var xhmltohtml5Space = Loadxhmltohtml5Xslt(projInfo.ProjectInputType.ToLower()); Convertxhtmltohtml5(oebpsPath, xhmltohtml5Space); ModifyContainerXML(); ModifyContentOPF(projInfo, oebpsPath); ModifyTocContent(oebpsPath); ModifyCoverpage(oebpsPath); epub3Export = true; return epub3Export; }
public void GoBibleRearrangeVerseAlphaNumericTest() { string filename = "GoBibleRearrangeVerseAlphaNumeric.xhtml"; string input = GetFileNameWithPath(filename); PublicationInformation projInfo = new PublicationInformation(); projInfo.DefaultXhtmlFileWithPath = input; preExportProcess = new PreExportProcess(projInfo); string expected = GetFileNameWithExpectedPath(filename); string output = preExportProcess.GoBibleRearrangeVerseNumbers(projInfo.DefaultXhtmlFileWithPath); XmlAssert.AreEqual(expected, output, ""); }
public void ImagePreprocessTest() { string filename = "ImagePreProcess.xhtml"; string input = GetFileNameWithPath(filename); PublicationInformation projInfo = new PublicationInformation(); string expected = GetFileNameWithExpectedPath(filename); string output = GetFileNameWithOutputPath(filename); CopyToOutput(input, output); projInfo.DefaultXhtmlFileWithPath = output; projInfo.ProjectInputType = "Scripture"; preExportProcess = new PreExportProcess(projInfo); output = preExportProcess.ImagePreprocess(false); XmlAssert.AreEqual(expected, output, ""); }
public void WriteEpubInsertCoverCSSStyle() { const string cssFileName = "EpubInsertCoverCSSStyle.css"; string sourceCssFile = GetFileNameWithPath(cssFileName); string output = GetFileNameWithOutputPath(cssFileName); string expected = GetFileNameWithExpectedPath(cssFileName); CopyToOutput(sourceCssFile, output); PreExportProcess preExport = new PreExportProcess(); preExport.InsertCoverPageImageStyleInCSS(output); TextFileAssert.AreEqual(expected, output); }
private string GetStyleOutput(string file) { LOContent contentXML = new LOContent(); LOStyles stylesXML = new LOStyles(); string fileOutput = _index > 0 ? file + _index + ".css" : file + ".css"; //string input = FileInput(file + ".css"); string input = FileInput(fileOutput); _projInfo.DefaultCssFileWithPath = input; _projInfo.TempOutputFolder = _outputPath; Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>(); CssTree cssTree = new CssTree(); cssClass = cssTree.CreateCssProperty(input, true); //StyleXML string styleOutput = FileOutput(file + _styleFile); Dictionary<string, Dictionary<string, string>> idAllClass = stylesXML.CreateStyles(_projInfo, cssClass, styleOutput); // ContentXML var pageSize = new Dictionary<string, string>(); pageSize["height"] = cssClass["@page"]["page-height"]; pageSize["width"] = cssClass["@page"]["page-width"]; _projInfo.DefaultXhtmlFileWithPath = FileInput(file + ".xhtml"); _projInfo.TempOutputFolder = FileOutput(file); _projInfo.HideSpaceVerseNumber = stylesXML.HideSpaceVerseNumber; PreExportProcess preProcessor = new PreExportProcess(_projInfo); preProcessor.GetTempFolderPath(); _projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml; if (Param.HyphenEnable) preProcessor.IncludeHyphenWordsOnXhtml(_projInfo.DefaultXhtmlFileWithPath); AfterBeforeProcess afterBeforeProcess = new AfterBeforeProcess(); afterBeforeProcess.RemoveAfterBefore(_projInfo, cssClass, cssTree.SpecificityClass, cssTree.CssClassOrder); contentXML.CreateStory(_projInfo, idAllClass, cssTree.SpecificityClass, cssTree.CssClassOrder, 325, pageSize); _projInfo.TempOutputFolder = _projInfo.TempOutputFolder + _contentFile; return styleOutput; }
public void XelatexXhtmlFileDivLetterAddingLangAttributeTest() { string filename = "XelatexXhtmlFileDivLetterAddingLangAttribute.xhtml"; string input = GetFileNameWithPath(filename); PublicationInformation projInfo = new PublicationInformation(); projInfo.DefaultXhtmlFileWithPath = input; preExportProcess = new PreExportProcess(projInfo); string expected = GetFileNameWithExpectedPath(filename); string outputFile = GetFileNameWithOutputPath(filename); File.Copy(projInfo.DefaultXhtmlFileWithPath, outputFile, true); string output = preExportProcess.SetLangforLetter(outputFile); XmlAssert.AreEqual(expected, output, ""); }
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); }
public void MultiLangHeader3() { _inputXHTML = Common.DirectoryPathReplace(_testFolderPath + "/input/MultiLangHeader3.xhtml"); _inputCSS = Common.DirectoryPathReplace(_testFolderPath + "/input/MultiLangHeader3.css"); PublicationInformation projInfo = new PublicationInformation(); projInfo.ProjectPath = Path.GetDirectoryName(_inputXHTML); projInfo.DefaultXhtmlFileWithPath = _inputXHTML; projInfo.DefaultCssFileWithPath = _inputCSS; PreExportProcess preProcessor = new PreExportProcess(projInfo); preProcessor.GetTempFolderPath(); preProcessor.ImagePreprocess(false); preProcessor.ReplaceInvalidTagtoSpan("_AllComplexFormEntryBackRefs|LexEntryRef_PrimaryLexemes", "span"); preProcessor.InsertHiddenChapterNumber(); preProcessor.InsertHiddenVerseNumber(); preProcessor.GetDefinitionLanguage(); projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml; projInfo.DefaultCssFileWithPath = preProcessor.ProcessedCss; Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>(); CssTree cssTree = new CssTree(); cssClass = cssTree.CreateCssProperty(projInfo.DefaultCssFileWithPath, true); preProcessor.InsertEmptyXHomographNumber(cssClass); Dictionary<string, Dictionary<string, string>> idAllClass = new Dictionary<string, Dictionary<string, string>>(); InStyles inStyles = new InStyles(); projInfo.TempOutputFolder = _outputPath; idAllClass = inStyles.CreateIDStyles(Common.PathCombine(_outputPath, "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"], string.Empty); InPreferences inPreferences = new InPreferences(); inPreferences.CreateIDPreferences(Common.PathCombine(projInfo.TempOutputFolder, "Resources"), idAllClass); string classname = "dTextVariablenFirst1"; string output = Common.PathCombine(projInfo.TempOutputFolder, "designmap.xml"); string xPath = "//TextVariable[@Self = \"" + classname + "\"]"; XmlNode node = Common.GetXmlNodeInDesignNamespace(output, xPath); string result = node.InnerXml; string expected = "<MatchCharacterStylePreference TextBefore=\"\" TextAfter=\"\" AppliedCharacterStyle=\"CharacterStyle/headword\" SearchStrategy=\"FirstOnPage\" ChangeCase=\"None\" DeleteEndPunctuation=\"false\" />"; Assert.AreEqual(expected, result, "MultiLangHeader1 test failed"); classname = "dTextVariablenLast1"; output = Common.PathCombine(projInfo.TempOutputFolder, "designmap.xml"); xPath = "//TextVariable[@Self = \"" + classname + "\"]"; node = Common.GetXmlNodeInDesignNamespace(output, xPath); result = node.InnerXml; expected = "<MatchCharacterStylePreference TextBefore=\"\" TextAfter=\"\" AppliedCharacterStyle=\"CharacterStyle/headword\" SearchStrategy=\"LastOnPage\" ChangeCase=\"None\" DeleteEndPunctuation=\"false\" />"; Assert.AreEqual(expected, result, "MultiLangHeader1 test failed"); }
private static void XhtmlNamespaceHack(PublicationInformation projInfo, PreExportProcess preProcessor, string[] langArray) { // EDB 10/22/2010 // HACK: we need the preprocessed image file names (preprocessor.imageprocess()), but // it's missing the xml namespace that makes it a valid xhtml file. We'll add it here. // (The unprocessed html works fine, but doesn't have the updated links to the image files in it, // so we can't use it.) // TODO: remove this line when TE provides valid XHTML output. if (langArray.Length > 0) { Common.StreamReplaceInFile(preProcessor.ProcessedXhtml, "<html>", string.Format( "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='{0}' dir='{1}'>", langArray[0], Common.GetTextDirection(langArray[0]))); // The TE export outputs both xml:lang and lang parameters if (projInfo.ProjectInputType.ToLower() == "scripture") Common.StreamReplaceInFile(preProcessor.ProcessedXhtml, "xml:lang=\"utf-8\" lang=\"utf-8\"", "xml:lang=\"utf-8\""); Common.StreamReplaceInFile(preProcessor.ProcessedXhtml, " lang=\"", " xml:lang=\""); } }
private static void ModifyTocContent(string oebpsPath) { var epub3Toc = LoadEpub3Toc(); string ncxTempFile = Common.PathCombine(oebpsPath, "toctemp.ncx"); string ncxfile = Common.PathCombine(oebpsPath, "toc.ncx"); File.Copy(ncxfile, ncxTempFile, true); string epub3TocFile = Common.PathCombine(oebpsPath, "toc.xhtml"); if (File.Exists(ncxfile)) { Common.ApplyXslt(ncxfile, epub3Toc); File.Copy(ncxfile, epub3TocFile, true); if (File.Exists(ncxTempFile)) { File.Copy(ncxTempFile, ncxfile, true); var preProcessor = new PreExportProcess(); preProcessor.ReplaceStringInFile(ncxfile, ".xhtml", ".html"); File.Delete(ncxTempFile); } } }
/// <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; }
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; }
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; }
private void ExportPreprocessForXelatex(PublicationInformation projInfo, PreExportProcess preProcessor) { if (_isUnixOs) { Common.RemoveDTDForLinuxProcess(projInfo.DefaultXhtmlFileWithPath, "xelatex"); } preProcessor.SetLangforLetter(projInfo.DefaultXhtmlFileWithPath); preProcessor.XelatexImagePreprocess(); if (_inputType.ToLower() == "dictionary" && projInfo.ProjectInputType.ToLower() == "dictionary") { Common.ApplyXslt(projInfo.DefaultXhtmlFileWithPath, _xhtmlXelatexXslProcess); } }
private static void AssignExportFile(PublicationInformation projInfo, PreExportProcess preProcessor) { if (projInfo.DefaultXhtmlFileWithPath.Contains("FlexRev.xhtml")) { projInfo.IsReversalExist = false; } projInfo.DefaultCssFileWithPath = preProcessor.ProcessedCss; projInfo.ProjectPath = Path.GetDirectoryName(preProcessor.ProcessedXhtml); projInfo.DefaultXhtmlFileWithPath = preProcessor.PreserveSpace(); preProcessor.InsertPropertyForXelatexCss(projInfo.DefaultCssFileWithPath); projInfo.DefaultCssFileWithPath = preProcessor.RemoveTextIndent(projInfo.DefaultCssFileWithPath); }
private void FixRelativeHyperlinks(string contentFolder) { string[] files = Directory.GetFiles(contentFolder, "PartFile*.xhtml"); string[] revFiles = Directory.GetFiles(contentFolder, "RevIndex*.xhtml"); //inProcess.AddToMaximum(files.Length); var preExport = new PreExportProcess(); var dictHyperlinks = new Dictionary<string, string>(); var sourceList = new List<string>(); var targetList = new List<string>(); var targettempList = new List<string>(); var fileDict = new Dictionary<string, string>(); foreach (string targetFile in files) { preExport.GetReferenceList(targetFile, sourceList, targettempList); targetList.AddRange(targettempList); foreach (string target in targettempList) { fileDict[target] = Path.GetFileName(targetFile); } targettempList.Clear(); } foreach (string target in targetList) { if (sourceList.Contains(target) && !dictHyperlinks.ContainsKey(target)) { dictHyperlinks.Add(target, fileDict[target] + "#" + target); } } if (dictHyperlinks.Count > 0) { foreach (string targetFile in files) { RemoveSpanVerseNumberNodeInXhtmlFile(targetFile); ReplaceAllBrokenHrefs(targetFile, dictHyperlinks); } foreach (string targetFile in revFiles) { RemoveSpanVerseNumberNodeInXhtmlFile(targetFile); ReplaceAllBrokenHrefs(targetFile, dictHyperlinks); } } else { if (files.Length > 0) { foreach (string targetFile in files) { RemoveSpanVerseNumberNodeInXhtmlFile(targetFile); } } if (revFiles.Length > 0) { foreach (string targetFile in revFiles) { RemoveSpanVerseNumberNodeInXhtmlFile(targetFile); } } } }
private void SplittingFrontMatter(PublicationInformation projInfo, PreExportProcess preProcessor, string defaultCss, List<string> splitFiles) { foreach (var file in splitFiles) { Common.SetDefaultCSS(file, defaultCss); } if ((InputType.ToLower().Equals("dictionary") && projInfo.IsLexiconSectionExist) || (InputType.ToLower().Equals("scripture"))) { if (projInfo.FileToProduce.ToLower() != "one") { splitFiles.AddRange(SplitFile(preProcessor.ProcessedXhtml, projInfo)); } else { splitFiles.Add(preProcessor.ProcessedXhtml); } } if (_isIncludeImage == false) { foreach (string file in splitFiles) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); if (fileNameWithoutExtension != null && fileNameWithoutExtension.IndexOf(@"PartFile", StringComparison.CurrentCulture) == 0) { RemoveNodeInXhtmlFile(file); } } } }
public void CSSStyleForHeaderShowInPrincePdfTest() { _projInfo.ProjectInputType = "Scripture"; const string file = "CSSStyleForHeaderShowInPrincePdf"; ExportProcess(file); string outputCSSFile = Common.PathCombine(_outputPath, file + ".css"); File.Copy(_projInfo.DefaultCssFileWithPath, outputCSSFile, true); PreExportProcess pdfObj = new PreExportProcess(); pdfObj.InsertPropertyInCSS(outputCSSFile); FileCompare(file, ".css"); }
public void FileComparisionTest(string fileName, string fileNo) { PublicationInformation projInfo = new PublicationInformation(); projInfo.ProjectPath = Path.GetDirectoryName(_inputXHTML); projInfo.DefaultXhtmlFileWithPath = _inputXHTML; projInfo.DefaultCssFileWithPath = _inputCSS; projInfo.ProjectInputType = "Scripture"; PreExportProcess preProcessor = new PreExportProcess(projInfo); preProcessor.GetTempFolderPath(); preProcessor.ImagePreprocess(false); preProcessor.InsertHiddenChapterNumber(); preProcessor.InsertHiddenVerseNumber(); projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml; projInfo.DefaultCssFileWithPath = preProcessor.ProcessedCss; Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>(); CssTree cssTree = new CssTree(); cssClass = cssTree.CreateCssProperty(projInfo.DefaultCssFileWithPath, true); preProcessor.InsertEmptyXHomographNumber(cssClass); Dictionary<string, Dictionary<string, string>> idAllClass = new Dictionary<string, Dictionary<string, string>>(); InStyles inStyles = new InStyles(); projInfo.TempOutputFolder = _outputPath; idAllClass = inStyles.CreateIDStyles(Common.PathCombine(_outputPath, "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, headwordStyles); 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"], string.Empty); InPreferences inPreferences = new InPreferences(); inPreferences.CreateIDPreferences(Common.PathCombine(projInfo.TempOutputFolder, "Resources"), idAllClass); // Compare files string expectedFolder = Common.PathCombine(_testFolderPath, "Expected\\" + fileName); string output = Common.PathCombine(projInfo.TempOutputFolder, "Stories\\Story_" + fileNo + ".xml"); string expected = Common.PathCombine(expectedFolder, "Stories\\Story_" + fileNo + ".xml"); XmlAssert.AreEqual(output, expected, " Story_"+ fileNo + ".xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "Resources\\styles.xml"); expected = Common.PathCombine(expectedFolder, "Resources\\styles.xml"); XmlAssert.AreEqual(output, expected, " styles.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "Resources\\Graphic.xml"); expected = Common.PathCombine(expectedFolder, "Resources\\Graphic.xml"); XmlAssert.AreEqual(output, expected, " Graphic.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "Resources\\Preferences.xml"); expected = Common.PathCombine(expectedFolder, "Resources\\Preferences.xml"); XmlAssert.AreEqual(output, expected, " Preferences.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "Spreads\\Spread_1.xml"); expected = Common.PathCombine(expectedFolder, "Spreads\\Spread_1.xml"); XmlAssert.AreEqual(output, expected, " Spread_1.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "Spreads\\Spread_2.xml"); expected = Common.PathCombine(expectedFolder, "Spreads\\Spread_2.xml"); XmlAssert.AreEqual(output, expected, " Spread_2.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "Spreads\\Spread_3.xml"); expected = Common.PathCombine(expectedFolder, "Spreads\\Spread_3.xml"); XmlAssert.AreEqual(output, expected, " Spread_3.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "MasterSpreads\\MasterSpread_All.xml"); expected = Common.PathCombine(expectedFolder, "MasterSpreads\\MasterSpread_All.xml"); XmlAssert.AreEqual(output, expected, " MasterSpread_All.xml is not matching"); output = Common.PathCombine(projInfo.TempOutputFolder, "MasterSpreads\\MasterSpread_First.xml"); expected = Common.PathCombine(expectedFolder, "MasterSpreads\\MasterSpread_First.xml"); XmlAssert.AreEqual(output, expected, " MasterSpread_First.xml is not matching"); }
/// <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; }
public void ParagraphVerserSetUpTest() { XmlDocument xmldoc = Common.DeclareXMLDocument(false); string fileName = "ParaChapBorder.xhtml"; string input = GetFileNameWithPath(fileName); string output = GetFileNameWithOutputPath(fileName); CopyToOutput(input, output); string expected = GetFileNameWithExpectedPath(fileName); xmldoc.Load(output); preExportProcess = new PreExportProcess(); preExportProcess.ParagraphVerserSetUp(xmldoc); xmldoc.Save(output); TextFileAssert.AreEqual(expected, output); }
private void InsertFrontMatter(PublicationInformation projInfo) { if (_isFromExe && _isFirstODT) { PreExportProcess preProcessor = new PreExportProcess(projInfo); //Preprocess XHTML & CSS for FrontMatter preProcessor.InsertLoFrontMatterContent(projInfo.DefaultXhtmlFileWithPath, projInfo.IsODM); _isFirstODT = false; } }
public void InsertHyphenationWords() { const string fileName = "InsertHyphenationWords.xhtml"; var input = GetFileNameWithPath(fileName); var output = GetFileNameWithOutputPath(fileName); var projInfo = new PublicationInformation { ProjectInputType = "Scripture" }; Param.HyphenEnable = true; CopyToOutput(input, output); preExportProcess = new PreExportProcess(); preExportProcess.IncludeHyphenWordsOnXhtml(output); string expected = GetFileNameWithExpectedPath(fileName); TextFileAssert.AreEqual(expected, output, fileName + " in xhtml "); }
/// <summary> /// Convert XHTML to ODT and ODM /// </summary> public bool ExportODT(PublicationInformation projInfo) { string defaultXhtml = projInfo.DefaultXhtmlFileWithPath; projInfo.OutputExtension = "odt"; Common.OdType = Common.OdtType.OdtChild; bool returnValue = false; string strFromOfficeFolder = Common.PathCombine(Common.GetPSApplicationPath(), "OfficeFiles" + Path.DirectorySeparatorChar + projInfo.ProjectInputType); projInfo.TempOutputFolder = Common.PathCombine(Path.GetTempPath(), "OfficeFiles" + Path.DirectorySeparatorChar + projInfo.ProjectInputType); Common.DeleteDirectory(projInfo.TempOutputFolder); string strStylePath = Common.PathCombine(projInfo.TempOutputFolder, "styles.xml"); string strContentPath = Common.PathCombine(projInfo.TempOutputFolder, "content.xml"); CopyOfficeFolder(strFromOfficeFolder, projInfo.TempOutputFolder); string strMacroPath = Common.PathCombine(projInfo.TempOutputFolder, "Basic/Standard/Module1.xml"); string outputFileName; string outputPath = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath); VerboseClass verboseClass = VerboseClass.GetInstance(); if (projInfo.FileSequence != null && projInfo.FileSequence.Count > 1) { projInfo.OutputExtension = "odm"; // Master Document Common.OdType = Common.OdtType.OdtMaster; if (projInfo.DictionaryOutputName == null) projInfo.DictionaryOutputName = projInfo.DefaultXhtmlFileWithPath.Replace(Path.GetExtension(projInfo.DefaultXhtmlFileWithPath), ""); outputFileName = Common.PathCombine(outputPath, projInfo.DictionaryOutputName); // OdtMaster is created in Dictionary Name } else { // All other OdtChild files are created in the name of Xhtml or xml file Names. if (projInfo.DictionaryOutputName == null) { outputFileName = projInfo.DefaultXhtmlFileWithPath.Replace(Path.GetExtension(projInfo.DefaultXhtmlFileWithPath), ""); } else { string inputFileName = Path.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath); outputFileName = Common.PathCombine(outputPath, inputFileName); Common.OdType = Common.OdtType.OdtNoMaster; // to all the Page property process } } string cssFile = projInfo.DefaultCssFileWithPath; SetBookReferenceDivInCss(cssFile); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(defaultXhtml); if (projInfo.DefaultRevCssFileWithPath != null && projInfo.DefaultRevCssFileWithPath.Trim().Length > 0) { if (fileNameWithoutExtension != null && fileNameWithoutExtension.ToLower() == "flexrev") { cssFile = projInfo.DefaultRevCssFileWithPath; } } PreExportProcess preProcessor = new PreExportProcess(projInfo); if (fileNameWithoutExtension != null && fileNameWithoutExtension.ToLower() == "flexrev") { preProcessor.InsertEmptyDiv(preProcessor.ProcessedXhtml); preProcessor.InsertSpanAfterLetter(preProcessor.ProcessedXhtml); } preProcessor.IncludeHyphenWordsOnXhtml(preProcessor.ProcessedXhtml); preProcessor.GetTempFolderPath(); preProcessor.GetDefaultLanguage(projInfo); projInfo.DefaultXhtmlFileWithPath = preProcessor.PreserveSpace(); InsertFrontMatter(projInfo); preProcessor.MoveBookcodeFRTtoFront(projInfo.DefaultXhtmlFileWithPath); preProcessor.GetfigureNode(); preProcessor.InsertKeepWithNextOnStyles(cssFile); preProcessor.InsertBookPageBreak(); preProcessor.ArrangeImages(); isMultiLanguageHeader = preProcessor.GetMultiLanguageHeader(); Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>(); CssTree cssTree = new CssTree(); cssTree.OutputType = Common.OutputType.ODT; cssClass = cssTree.CreateCssProperty(cssFile, true); SetHeaderFontName(projInfo, cssClass); HandledInCss(ref projInfo, ref cssClass); int pageWidth = GetPictureWidth(cssClass); // BEGIN Generate Styles.Xml File Dictionary<string, Dictionary<string, string>> idAllClass = new Dictionary<string, Dictionary<string, string>>(); LOStyles inStyles = new LOStyles(); inStyles.MultiLanguageHeader = isMultiLanguageHeader; idAllClass = inStyles.CreateStyles(projInfo, cssClass, "styles.xml"); projInfo.IncludeFootnoteSymbol = inStyles.CustomFootnoteCaller; projInfo.IncludeXRefSymbol = inStyles.CustomXRefCaller; projInfo.SplitFileByLetter = inStyles.SplitFileByLetter; projInfo.HideSpaceVerseNumber = inStyles.HideSpaceVerseNumber; //To set Constent variables for User Desire string fname = Common.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath); string macroFileName = Common.PathCombine(projInfo.DictionaryPath, fname); string isToc; var isCoverImageInserted = EditCssValues(idAllClass, out isToc); _refFormat = Common.GetReferenceFormat(idAllClass, _refFormat); IncludeTextinMacro(strMacroPath, _refFormat, macroFileName, projInfo.IsExtraProcessing, isCoverImageInserted, isToc); // BEGIN Generate Meta.Xml File var metaXML = new LOMetaXML(projInfo.ProjectInputType); metaXML.CreateMeta(projInfo); // BEGIN Generate Content.Xml File var cXML = new LOContent(); preProcessor.MovePictureAsLastChild(preProcessor.ProcessedXhtml); preProcessor.ImagePreprocess(false); preProcessor.ReplaceSlashToREVERSE_SOLIDUS(); if (projInfo.SwapHeadword) preProcessor.SwapHeadWordAndReversalForm(); Dictionary<string, string> pageSize = new Dictionary<string, string>(); pageSize["height"] = cssClass["@page"]["page-height"]; pageSize["width"] = cssClass["@page"]["page-width"]; projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml; AfterBeforeProcess afterBeforeProcess = new AfterBeforeProcess(); afterBeforeProcess.RemoveAfterBefore(projInfo, cssClass, cssTree.SpecificityClass, cssTree.CssClassOrder); projInfo.TempOutputFolder += Path.DirectorySeparatorChar; cXML._multiLanguageHeader = isMultiLanguageHeader; cXML.CreateStory(projInfo, idAllClass, cssTree.SpecificityClass, cssTree.CssClassOrder, pageWidth, pageSize); PostProcess(projInfo); if (projInfo.FileSequence != null && projInfo.FileSequence.Count > 1) { var ul = new OOUtility(); ul.CreateMasterContents(strContentPath, projInfo.FileSequence); } if (projInfo.MoveStyleToContent) MoveStylesToContent(strStylePath, strContentPath); var mODT = new ZipFolder(); string fileNameNoPath = outputFileName + "." + projInfo.OutputExtension; mODT.CreateZip(projInfo.TempOutputFolder, fileNameNoPath, verboseClass.ErrorCount); projInfo.DictionaryOutputName = fileNameNoPath; try { if (File.Exists(fileNameNoPath)) { returnValue = true; if (projInfo.IsOpenOutput) { Common.OpenOutput(fileNameNoPath); } } } catch (System.ComponentModel.Win32Exception ex) { if (ex.NativeErrorCode == 1155) { string installedLocation = string.Empty; if (File.Exists(fileNameNoPath)) { installedLocation = fileNameNoPath; var msg = new[] { "LibreOffice application from http://www.libreoffice.org site.\nAfter downloading and installing Libre Office, please consult release notes about how to change the macro security setting to enable the macro that creates the headers." }; LocDB.Message("errInstallFile", "The output has been saved in " + installedLocation + ".", "Please install " + msg, msg, LocDB.MessageTypes.Error, LocDB.MessageDefault.First); return false; } else { var msg = new[] { "LibreOffice application from http://www.libreoffice.org site.\nAfter downloading and installing Libre Office, please consult release notes about how to change the macro security setting to enable the macro that creates the headers." }; LocDB.Message("errInstallFile", "Please install " + msg, msg, LocDB.MessageTypes.Error, LocDB.MessageDefault.First); return false; } } } finally { projInfo.DefaultXhtmlFileWithPath = defaultXhtml; if (preProcessor != null) { DirectoryInfo di = new DirectoryInfo(preProcessor.GetCreatedTempFolderPath); Common.CleanDirectory(di); } if (projInfo.TempOutputFolder != null) { DirectoryInfo di = new DirectoryInfo(projInfo.TempOutputFolder); Common.CleanDirectory(di); } } return returnValue; }
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; }
private static void XhtmlPreprocessing(PublicationInformation projInfo, PreExportProcess preProcessor) { Common.StreamReplaceInFile(preProcessor.ProcessedXhtml, " ", Common.NonBreakingSpace); preProcessor.GetTempFolderPath(); preProcessor.ImagePreprocess(false); preProcessor.MoveBookcodeFRTtoFront(preProcessor.ProcessedXhtml); preProcessor.SetTitleValueOnReversal(projInfo.DefaultXhtmlFileWithPath); if (projInfo.SwapHeadword) { preProcessor.SwapHeadWordAndReversalForm(); } }
public void Picture_ImageAttrib_Node() { _projInfo.ProjectInputType = "Dictionary"; const string file = "ImageAttrib"; _projInfo.DefaultCssFileWithPath = FileInput(file + ".css"); _projInfo.DefaultXhtmlFileWithPath = FileInput(file + ".xhtml"); PreExportProcess preProcessor = new PreExportProcess(_projInfo); preProcessor.GetTempFolderPath(); preProcessor.ImagePreprocess(false); _projInfo.DefaultXhtmlFileWithPath = preProcessor.ProcessedXhtml; string styleOutput = GetStyleOutput(_projInfo); //Content Test - First _validate = new ValidateXMLFile(_projInfo.TempOutputFolder); _validate.ClassName = string.Empty; _validate.GetOuterXml = true; _validate.XPath = "//draw:frame[@draw:style-name='fr2']"; string content = "<draw:frame draw:style-name=\"fr2\" draw:name=\"Frame2\" text:anchor-type=\"paragraph\" draw:z-index=\"1\" svg:width=\"288pt\" svg:height=\"144pt\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"><draw:text-box fo:min-height=\"1in\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"><draw:frame draw:style-name=\"gr2\" draw:name=\"Graphics2\" text:anchor-type=\"paragraph\" svg:width=\"288pt\" svg:height=\"144pt\"><draw:image xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\" xlink:href=\"Pictures/1.jpg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" /><svg:title>1.jpg</svg:title></draw:frame><text:span text:style-name=\"image_firstoftype sense_article_sectionletter_dictionary\"> Flea </text:span></draw:text-box></draw:frame>"; bool returnValue = _validate.ValidateOfficeTextNode(0, content, "para"); Assert.IsTrue(returnValue); _validate.XPath = "//draw:frame[@draw:name='Graphics2']"; content = "<draw:frame draw:style-name=\"gr2\" draw:name=\"Graphics2\" text:anchor-type=\"paragraph\" svg:width=\"288pt\" svg:height=\"144pt\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"><draw:image xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\" xlink:href=\"Pictures/1.jpg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" /><svg:title>1.jpg</svg:title></draw:frame>"; returnValue = _validate.ValidateOfficeTextNode(0, content, "para"); Assert.IsTrue(returnValue); //Style Test - Second _validate = new ValidateXMLFile(styleOutput); _validate.ClassName = "fr2"; _validate.ClassProperty.Add("style:vertical-pos", "from-top"); _validate.ClassProperty.Add("style:vertical-rel", "paragraph-content"); _validate.ClassProperty.Add("style:horizontal-pos", "center"); _validate.ClassProperty.Add("style:horizontal-rel", "paragraph"); _validate.ClassProperty.Add("run-through", "foreground"); _validate.ClassProperty.Add("number-wrapped-paragraphs", "no-limit"); _validate.ClassProperty.Add("wrap-contour", "false"); _validate.ClassProperty.Add("text:anchor-type", "paragraph"); //_validate.ClassProperty.Add("svg:x", "0in"); //_validate.ClassProperty.Add("svg:y", "0in"); //_validate.ClassProperty.Add("style:mirror", "none"); //_validate.ClassProperty.Add("fo:clip", "rect(0in 0in 0in 0in)"); //_validate.ClassProperty.Add("draw:luminance", "0%"); //_validate.ClassProperty.Add("draw:red", "0%"); //_validate.ClassProperty.Add("draw:green", "0%"); //_validate.ClassProperty.Add("draw:blue", "0%"); //_validate.ClassProperty.Add("draw:gamma", "100%"); //_validate.ClassProperty.Add("draw:color-inversion", "false"); //_validate.ClassProperty.Add("draw:image-opacity", "100%"); //_validate.ClassProperty.Add("draw:color-mode", "standard"); //_validate.ClassProperty.Add("style:wrap", "parallel"); returnValue = _validate.ValidateNodeAttributesNS(1, string.Empty); Assert.IsTrue(returnValue); _validate.ClassName = "fr3"; _validate.ClassProperty.Add("style:vertical-pos", "from-top"); _validate.ClassProperty.Add("style:vertical-rel", "paragraph-content"); _validate.ClassProperty.Add("style:horizontal-pos", "center"); _validate.ClassProperty.Add("style:horizontal-rel", "paragraph"); _validate.ClassProperty.Add("run-through", "foreground"); _validate.ClassProperty.Add("number-wrapped-paragraphs", "no-limit"); _validate.ClassProperty.Add("wrap-contour", "false"); _validate.ClassProperty.Add("text:anchor-type", "paragraph"); //_validate.ClassProperty.Add("svg:x", "0in"); //_validate.ClassProperty.Add("svg:y", "0in"); //_validate.ClassProperty.Add("style:mirror", "none"); //_validate.ClassProperty.Add("fo:clip", "rect(0in 0in 0in 0in)"); //_validate.ClassProperty.Add("draw:luminance", "0%"); //_validate.ClassProperty.Add("draw:red", "0%"); //_validate.ClassProperty.Add("draw:green", "0%"); //_validate.ClassProperty.Add("draw:blue", "0%"); //_validate.ClassProperty.Add("draw:gamma", "100%"); //_validate.ClassProperty.Add("draw:color-inversion", "false"); //_validate.ClassProperty.Add("draw:image-opacity", "100%"); //_validate.ClassProperty.Add("draw:color-mode", "standard"); //_validate.ClassProperty.Add("style:wrap", "parallel"); returnValue = _validate.ValidateNodeAttributesNS(1, string.Empty); Assert.IsTrue(returnValue); }
/// <summary> /// Entry point for epub converter /// </summary> /// <param name="projInfo">values passed including xhtml and css names</param> /// <returns>true if succeeds</returns> public bool Export(PublicationInformation projInfo) { Common.SetupLocalization(); if (projInfo == null) return false; const bool success = true; #region Set up progress reporting #if (TIME_IT) DateTime dt1 = DateTime.Now; // time this thing #endif var myCursor = UseWaitCursor(); var curdir = Environment.CurrentDirectory; var inProcess = SetupProgressReporting(20); #endregion Set up progress reporting #region Setup inProcess.SetStatus("Setup"); var bookId = Guid.NewGuid(); // NOTE: this creates a new ID each time Pathway is run. PageBreak = InputType.ToLower() == "dictionary" && GetPageBreakStatus(projInfo.SelectedTemplateStyle); #region LoadXslts var addRevId = LoadAddRevIdXslt(); var noXmlSpace = LoadNoXmlSpaceXslt(); var fixEpub = LoadFixEpubXslt(); #endregion #region Create EpubFolder if (!Common.Testing) { CreateEpubFolder(projInfo); } else { projInfo.ProjectPath = projInfo.DictionaryPath; } #endregion var preProcessor = new PreExportProcess(projInfo); preProcessor.RemoveBrokenImage(); _isUnixOs = Common.UnixVersionCheck(); if (_isUnixOs) { Common.RemoveDTDForLinuxProcess(projInfo.DefaultXhtmlFileWithPath, "epub"); } _isIncludeImage = GetIncludeImageStatus(projInfo.SelectedTemplateStyle); _isNoteTargetReferenceExists = Common.NodeExists(projInfo.DefaultXhtmlFileWithPath, ""); _epubFont = new EpubFont(this); _epubManifest = new EpubManifest(this, _epubFont); _epubManifest.LoadPropertiesFromSettings(); LoadOtherFeatures(); var epubToc = new EpubToc(projInfo.ProjectInputType, TocLevel); inProcess.PerformStep(); #endregion Setup #region Xhtml preprocessing inProcess.SetStatus("Preprocessing content"); var glossorywords = WriteGlossaryLink(projInfo); GlossaryLinkReferencing(projInfo,glossorywords); InsertBeforeAfterInXhtml(projInfo); var outputFolder = SetOutputFolderAndCurrentDirectory(projInfo); Common.SetProgressBarValue(projInfo.ProgressBar, projInfo.DefaultXhtmlFileWithPath); XhtmlPreprocessing(projInfo, preProcessor); var langArray = _epubFont.InitializeLangArray(projInfo); inProcess.PerformStep(); #endregion Xhtml preprocessing #region Css preprocessing inProcess.SetStatus("Preprocessing stylesheet"); var cssFullPath = CssFullPath(projInfo); Common.WriteDefaultLanguages(projInfo, cssFullPath); var tempFolder = Path.GetDirectoryName(preProcessor.ProcessedXhtml); var mergedCss = MergeAndFilterCss(preProcessor, tempFolder, cssFullPath); /* Modify the content in css file for before after css style process */ preProcessor.InsertPseudoContentProperty(mergedCss, PseudoClass); CustomizeCss(mergedCss); var niceNameCss = NiceNameCss(projInfo, tempFolder, ref mergedCss); var defaultCss = Path.GetFileName(niceNameCss); string tempCssFile = mergedCss.Replace(".css", "tmp.css"); File.Copy(mergedCss, tempCssFile, true); Common.SetDefaultCSS(projInfo.DefaultXhtmlFileWithPath, defaultCss); Common.SetDefaultCSS(preProcessor.ProcessedXhtml, defaultCss); if (!File.Exists(mergedCss)) { File.Copy(tempCssFile, mergedCss, true); } inProcess.PerformStep(); #endregion Css preprocessing #region Hacks XhtmlNamespaceHack(projInfo, preProcessor, langArray); Common.ApplyXslt(preProcessor.ProcessedXhtml, noXmlSpace); Common.ApplyXslt(preProcessor.ProcessedXhtml, fixEpub); inProcess.PerformStep(); #endregion Hacks #region Adding Navigation and Front Matter inProcess.SetStatus("Adding Navigation"); preProcessor.PrepareBookNameAndChapterCount(); inProcess.PerformStep(); // insert the front matter items as separate files in the output folder inProcess.SetStatus("Adding Front Matter"); preProcessor.SkipChapterInformation = TocLevel; var frontMatter = preProcessor.InsertFrontMatter(tempFolder, false); inProcess.PerformStep(); #endregion Adding Navigation and Front Matter #region Add Sections inProcess.SetStatus("Add Sections"); var htmlFiles = new List<string>(); var splitFiles = new List<string>(); splitFiles.AddRange(frontMatter); SplittingFrontMatter(projInfo, preProcessor, defaultCss, splitFiles); SplittingReversal(projInfo, addRevId, langArray, defaultCss, splitFiles); AddBooksMoveNotes(inProcess, htmlFiles, splitFiles); inProcess.PerformStep(); #endregion Add Sections #region Create structure and add end notes inProcess.SetStatus("Creating structure"); string contentFolder = CreateContentStructure(projInfo, tempFolder); inProcess.PerformStep(); // extract references file if specified if (References.Contains("End") && InputType.ToLower().Equals("scripture")) { inProcess.SetStatus("Creating endnote references file"); CreateReferencesFile(contentFolder, preProcessor.ProcessedXhtml); splitFiles.Add(Common.PathCombine(contentFolder, ReferencesFilename)); } #endregion Create structure and add end notes #region Font embedding inProcess.SetStatus("Processing fonts"); if (!FontProcessing(projInfo, langArray, mergedCss, contentFolder)) { // user cancelled the epub conversion - clean up and exit Environment.CurrentDirectory = curdir; Cursor.Current = myCursor; inProcess.Close(); return false; } inProcess.PerformStep(); #endregion Font Embedding #region Copy to Epub inProcess.SetStatus("Copy contents and styles to Epub"); CopyStylesAndContentToEpub(mergedCss, defaultCss, htmlFiles, contentFolder); inProcess.PerformStep(); #endregion Copy to Epub #region Insert Chapter Links inProcess.SetStatus("Insert Chapter Links"); InsertChapterLinkBelowBookName(contentFolder); InsertReferenceLinkInTocFile(contentFolder); inProcess.PerformStep(); #endregion Insert Chapter Links #region Process hyperlinks #if (TIME_IT) DateTime dtRefStart = DateTime.Now; #endif inProcess.SetStatus("Processing hyperlinks"); if (InputType.ToLower() == "scripture" && References.Contains("End")) { UpdateReferenceHyperlinks(contentFolder, inProcess); UpdateReferenceSourcelinks(contentFolder, inProcess); } FixRelativeHyperlinks(contentFolder); #if (TIME_IT) TimeSpan tsRefTotal = DateTime.Now - dtRefStart; Debug.WriteLine("Exportepub: time spent fixing reference hyperlinks: " + tsRefTotal); #endif inProcess.PerformStep(); #endregion Process hyperlinks #region Process images inProcess.SetStatus("Processing images"); ProcessImages(tempFolder, contentFolder); inProcess.PerformStep(); #endregion Process images #region Manifest and Table of Contents inProcess.SetStatus("Generating .epub TOC and manifest"); _epubManifest.CreateOpf(projInfo, contentFolder, bookId); epubToc.CreateNcx(projInfo, contentFolder, bookId); ModifyTOCFile(contentFolder); ReplaceEmptyHref(contentFolder); if (File.Exists(tempCssFile)) { File.Delete(tempCssFile); } inProcess.PerformStep(); #endregion Manifest and Table of Contents #region Copy Epub2 package for Epub3 string epub3Path = projInfo.ProjectPath; epub3Path = Common.PathCombine(epub3Path, "Epub3"); Common.CopyFolderandSubFolder(projInfo.TempOutputFolder, epub3Path, true); if (File.Exists(projInfo.DefaultXhtmlFileWithPath)) File.Copy(projInfo.DefaultXhtmlFileWithPath, Common.PathCombine(epub3Path, Path.GetFileName(projInfo.DefaultXhtmlFileWithPath)), true); if (File.Exists(projInfo.DefaultCssFileWithPath)) File.Copy(projInfo.DefaultCssFileWithPath, Common.PathCombine(epub3Path, Path.GetFileName(projInfo.DefaultCssFileWithPath)), true); if (File.Exists(projInfo.DefaultRevCssFileWithPath)) File.Copy(projInfo.DefaultRevCssFileWithPath, Common.PathCombine(epub3Path, Path.GetFileName(projInfo.DefaultRevCssFileWithPath)), true); _exportEpub3 = new Epub3Transformation(this, _epubFont); _exportEpub3.Epub3Directory = epub3Path; _exportEpub3.Export(projInfo); #endregion Copy Epub2 package for Epub3 #region Packaging for Epub2 and Epub3 inProcess.SetStatus("Packaging for Epub2"); if (_isUnixOs) { AddDtdInXhtml(contentFolder); } string fileName = CreateFileNameFromTitle(projInfo); Compress(projInfo.TempOutputFolder, Common.PathCombine(outputFolder, fileName)); var outputPathWithFileName = Common.PathCombine(outputFolder, fileName) + ".epub"; if (!Common.Testing) { inProcess.SetStatus("Copy html files"); string htmlFolderPath = Common.PathCombine(Path.GetDirectoryName(epub3Path), "HTML5"); string oebpsFolderPath = Common.PathCombine(epub3Path, "OEBPS"); Common.CustomizedFileCopy(oebpsFolderPath, htmlFolderPath, "content.opf, toc.html"); } inProcess.SetStatus("Packaging for Epub3"); string fileNameV3 = CreateFileNameFromTitle(projInfo); string outputPathWithFileNameV3 = null; if (epub3Path != null) { Compress(epub3Path, Common.PathCombine(epub3Path, fileNameV3)); outputPathWithFileNameV3 = Common.PathCombine(epub3Path, fileNameV3) + ".epub"; } #if (TIME_IT) TimeSpan tsTotal = DateTime.Now - dt1; Debug.WriteLine("Exportepub: time spent in .epub conversion: " + tsTotal); #endif inProcess.PerformStep(); #endregion Packaging #region Validate inProcess.SetStatus("Validate"); #region Option Dialog box bool isOutputDilalogNeeded = true; if (!Common.Testing) { string caption = LocalizationManager.GetString("EpubExportTypeDlg.ValidateAndDisplay.Caption", "Export Complete", ""); if (Utils.MsgBox(LocalizationManager.GetString("Exportepub.ValidateMsgBox", Resources.ExportCallingEpubValidator + "\r\n Do you want to Validate ePub files?"), caption, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { ValidateResult(outputPathWithFileName); // Epub2 ExportType ValidateResult(outputPathWithFileNameV3); //Epub3 ExportType } #region Option Dialog box if (!Common.Testing && isOutputDilalogNeeded) { outputPathWithFileName = RenameEpubFileName(outputPathWithFileName, "epub2"); outputPathWithFileNameV3 = RenameEpubFileName(outputPathWithFileNameV3, "epub3"); var exportTypeDlg = new EpubExportTypeDlg(); exportTypeDlg.ShowDialog(); if (exportTypeDlg._exportType == "epub2") { outputFolder = Path.GetDirectoryName(outputPathWithFileName); DisplayOutput(outputFolder, fileName, ref outputPathWithFileName); } else if (exportTypeDlg._exportType == "epub3") { outputFolder = Path.GetDirectoryName(outputPathWithFileNameV3); DisplayOutput(outputFolder, fileName, ref outputPathWithFileNameV3); } else if (exportTypeDlg._exportType == "folder") { if (_isUnixOs) { SubProcess.Run("", "nautilus", Common.HandleSpaceinLinuxPath(Path.GetDirectoryName(outputFolder)), false); } else { SubProcess.Run(Path.GetDirectoryName(outputFolder), "explorer.exe", Path.GetDirectoryName(outputFolder), false); } } } #endregion Option Dialog box } #endregion Option Dialog box inProcess.PerformStep(); #endregion Validate #region Clean up inProcess.SetStatus("Clean up"); Common.CleanupExportFolder(outputPathWithFileName, ".tmp,.de", "_1", string.Empty); if (!Common.Testing) { Common.CleanupExportFolder(outputPathWithFileNameV3, ".tmp,.de,.zip", "_1", "META-INF,OEBPS"); } inProcess.PerformStep(); #endregion Clean up #region Archive inProcess.SetStatus("Archive"); CreateRAMP(projInfo); if (!Common.Testing) { projInfo.DefaultXhtmlFileWithPath = Common.PathCombine(epub3Path, Path.GetFileName(projInfo.DefaultXhtmlFileWithPath)); CreateRAMP(projInfo); } inProcess.PerformStep(); #endregion Archive #region Clean up inProcess.SetStatus("Final Clean up"); Common.CleanupExportFolder(outputPathWithFileName, ".xhtml,.xml,.css", string.Empty, "Test"); if (!Common.Testing) { Common.CleanupExportFolder(outputPathWithFileNameV3, ".xhtml,.xml,.css", string.Empty, "Test"); } inProcess.PerformStep(); #endregion Clean up #region Close Reporting inProcess.Close(); Environment.CurrentDirectory = curdir; Cursor.Current = myCursor; #endregion Close Reporting return success; }
private void Preprocess() { PreExportProcess preProcessor = new PreExportProcess(_projInfo); preProcessor.GetReferenceList(_projInfo.DefaultXhtmlFileWithPath, _sourceList, _targetList); preProcessor.GetGlossaryList(_projInfo.DefaultXhtmlFileWithPath, _glossaryList); //TD-2912 if (_projInfo.ProjectInputType.ToLower() == "dictionary") { _entryIdList = preProcessor.GetMultiPictureEntryId(_projInfo.DefaultXhtmlFileWithPath); _headwordVariable = preProcessor.PrepareCurrentNextHeadwordPair(); } }
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; }