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 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); }
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"); }
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 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(); } }
/// <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; }
/// <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 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; }
/// <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) { } return xhtmlPreviewFilePath; }