/// <summary> /// we update these so that the file continues to look the same when you just open it in firefox /// </summary> private void UpdateSupportFiles() { if (IsPathReadonly(_folderPath)) { Logger.WriteEvent("Not updating files in folder {0} because the directory is read-only.", _folderPath); } else { UpdateIfNewer("placeHolder.png"); UpdateIfNewer("basePage.css"); UpdateIfNewer("previewMode.css"); UpdateIfNewer("origami.css"); foreach (var path in Directory.GetFiles(_folderPath, "*.css")) { var file = Path.GetFileName(path); //if (file.ToLower().Contains("portrait") || file.ToLower().Contains("landscape")) UpdateIfNewer(file); } } //by default, this comes from the collection, but the book can select one, inlucing "null" to select the factory-supplied empty xmatter var nameOfXMatterPack = _dom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(_dom, nameOfXMatterPack, _fileLocator); UpdateIfNewer(Path.GetFileName(helper.PathToStyleSheetForPaperAndOrientation), helper.PathToStyleSheetForPaperAndOrientation); }
// NB: this knows nothing of book-specific css's... even "basic book.css" private void EnsureHasLinksToStylesheets(HtmlDom dom) { var nameOfXMatterPack = _dom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(_dom, nameOfXMatterPack, _fileLocator); EnsureHasLinkToStyleSheet(dom, Path.GetFileName(helper.PathToStyleSheetForPaperAndOrientation)); string autocssFilePath = ".." + Path.DirectorySeparatorChar + "settingsCollectionStyles.css"; if (File.Exists(Path.Combine(_folderPath, autocssFilePath))) { EnsureHasLinkToStyleSheet(dom, autocssFilePath); } var customCssFilePath = ".." + Path.DirectorySeparatorChar + "customCollectionStyles.css"; if (File.Exists(Path.Combine(_folderPath, customCssFilePath))) { EnsureHasLinkToStyleSheet(dom, customCssFilePath); } if (File.Exists(Path.Combine(_folderPath, "customBookStyles.css"))) { EnsureHasLinkToStyleSheet(dom, "customBookStyles.css"); } else { EnsureDoesntHaveLinkToStyleSheet(dom, "customBookStyles.css"); } }
private string SetupNewDocumentContents(string sourceFolderPath, string initialPath) { var storage = _bookStorageFactory(initialPath); var bookData = new BookData(storage.Dom, _collectionSettings, null); UpdateEditabilityMetadata(storage); //Path.GetFileName(initialPath).ToLower().Contains("template")); //NB: for a new book based on a page template, I think this should remove *everything*, because the rest is in the xmatter // for shells, we'll still have pages. //Remove from the new book any div-pages labelled as "extraPage" foreach (XmlElement initialPageDiv in storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]")) { initialPageDiv.ParentNode.RemoveChild(initialPageDiv); } XMatterHelper.RemoveExistingXMatter(storage.Dom); bookData.RemoveAllForms("ISBN"); //ISBN number of the original doesn't apply to derivatives var sizeAndOrientation = Layout.FromDom(storage.Dom, Layout.A5Portrait); //Note that we do this *before* injecting frontmatter, which is more likely to have a good reason for having English //Useful for things like Primers. Note that Lorem Ipsum and prefixing all text with "_" also work. // if ("true"==GetMetaValue(storage.Dom.RawDom, "removeTranslationsWhenMakingNewBook", "false")) // { // ClearAwayAllTranslations(storage.Dom.RawDom); // } InjectXMatter(initialPath, storage, sizeAndOrientation); SetLineageAndId(storage); SetBookTitle(storage, bookData); //Few sources will have this set at all. A template picture dictionary is one place where we might expect it to call for, say, bilingual int multilingualLevel = int.Parse(GetMetaValue(storage.Dom.RawDom, "defaultMultilingualLevel", "1")); TranslationGroupManager.SetInitialMultilingualSetting(bookData, multilingualLevel, _collectionSettings); var sourceDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(sourceFolderPath.CombineForPath(Path.GetFileName(GetPathToHtmlFile(sourceFolderPath))), false); //If this is a shell book, make elements to hold the vernacular foreach (XmlElement div in storage.Dom.RawDom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")) { XmlElement sourceDiv = sourceDom.SelectSingleNode("//div[@id='" + div.GetAttribute("id") + "']") as XmlElement; SetupIdAndLineage(sourceDiv, div); SetupPage(div, _collectionSettings, null, null); } ClearAwayDraftText(storage.Dom.RawDom); storage.Save(); //REVIEW this actually undoes the setting of the intial files name: // storage.UpdateBookFileAndFolderName(_librarySettings); return(storage.FolderPath); }
private void InjectXMatter(string initialPath, BookStorage storage, Layout sizeAndOrientation) { //now add in the xmatter from the currently selected xmatter pack if (!TestingSoSkipAddingXMatter) { var data = new DataSet(); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language1Iso639Code)); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language2Iso639Code)); data.WritingSystemAliases.Add("V", _collectionSettings.Language1Iso639Code); data.WritingSystemAliases.Add("N1", _collectionSettings.Language2Iso639Code); data.WritingSystemAliases.Add("N2", _collectionSettings.Language3Iso639Code); var helper = new XMatterHelper(storage.Dom, _collectionSettings.XMatterPackName, _fileLocator); helper.FolderPathForCopyingXMatterFiles = storage.FolderPath; helper.InjectXMatter(data.WritingSystemAliases, sizeAndOrientation, _collectionSettings.BrandingProjectKey, storage.FolderPath); //TranslationGroupManager.PrepareDataBookTranslationGroups(storage.Dom,languages); } }
private void InjectXMatter(string initialPath, BookStorage storage, Layout sizeAndOrientation) { //now add in the xmatter from the currently selected xmatter pack if (!TestingSoSkipAddingXMatter) { var data = new DataSet(); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language1Iso639Code)); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language2Iso639Code)); data.WritingSystemAliases.Add("V", _collectionSettings.Language1Iso639Code); data.WritingSystemAliases.Add("N1", _collectionSettings.Language2Iso639Code); data.WritingSystemAliases.Add("N2", _collectionSettings.Language3Iso639Code); //by default, this comes from the collection, but the book can select one, inlucing "null" to select the factory-supplied empty xmatter var xmatterName = storage.Dom.GetMetaValue("xmatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(storage.Dom, xmatterName, _fileLocator); helper.FolderPathForCopyingXMatterFiles = storage.FolderPath; helper.InjectXMatter(data.WritingSystemAliases, sizeAndOrientation); } }
private void InjectXMatter(string initialPath, BookStorage storage, Layout sizeAndOrientation) { //now add in the xmatter from the currently selected xmatter pack if (!TestingSoSkipAddingXMatter) { var data = new Dictionary <string, string>(); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language1.Iso639Code)); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language2.Iso639Code)); // Review: this sort of duplicates the knowledge in BookData.WritingSystemAliases // Is it worth creating a BookData here? Since we're just starting the new book, it can't // yet have any language settings different from the collection. data.Add("V", _collectionSettings.Language1.Iso639Code); data.Add("N1", _collectionSettings.Language2.Iso639Code); data.Add("N2", _collectionSettings.Language3.Iso639Code); var helper = new XMatterHelper(storage.Dom, _collectionSettings.XMatterPackName, _fileLocator); helper.FolderPathForCopyingXMatterFiles = storage.FolderPath; helper.InjectXMatter(data, sizeAndOrientation, false, _collectionSettings.Language2.Iso639Code); //TranslationGroupManager.PrepareDataBookTranslationGroups(storage.Dom,languages); } }
private static void AddLocalizedHintContentsToDictionary(HtmlDom singlePageHtmlDom, Dictionary <string, string> dictionary, CollectionSettings collectionSettings) { var nameOfXMatterPack = singlePageHtmlDom.GetMetaValue("xMatter", collectionSettings.XMatterPackName); string idPrefix = ""; var pageElement = singlePageHtmlDom.RawDom.SelectSingleNode("//div") as XmlElement; if (XMatterHelper.IsFrontMatterPage(pageElement)) { idPrefix = "FrontMatter." + nameOfXMatterPack + "."; } else if (XMatterHelper.IsBackMatterPage(pageElement)) { idPrefix = "BackMatter." + nameOfXMatterPack + "."; } foreach (XmlElement element in singlePageHtmlDom.RawDom.SelectNodes("//*[@data-hint]")) { //why aren't we just doing: element.SetAttribute("data-hint", translation); instead of bothering to write out a dictionary? //because (especially since we're currently just assuming it is in english), we would later save it with the translation, and then next time try to translate that, and poplute the //list of strings that we tell people to translate var key = element.GetAttribute("data-hint"); if (!dictionary.ContainsKey(key)) { string translation; var id = idPrefix + key; if (key.Contains("{lang}")) { translation = LocalizationManager.GetDynamicString("Bloom", id, key, "Put {lang} in your translation, so it can be replaced by the language name."); } else { translation = LocalizationManager.GetDynamicString("Bloom", id, key); } dictionary.Add(key, translation); } } }
private void InjectXMatter(string initialPath, BookStorage storage, Layout sizeAndOrientation) { //now add in the xmatter from the currently selected xmatter pack if (!TestingSoSkipAddingXMatter) { var data = new DataSet(); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language1Iso639Code)); Debug.Assert(!string.IsNullOrEmpty(_collectionSettings.Language2Iso639Code)); data.WritingSystemCodes.Add("V", _collectionSettings.Language1Iso639Code); data.WritingSystemCodes.Add("N1", _collectionSettings.Language2Iso639Code); data.WritingSystemCodes.Add("N2", _collectionSettings.Language3Iso639Code); //by default, this comes from the collection, but the book can select one, inlucing "null" to select the factory-supplied empty xmatter var xmatterName = storage.Dom.GetMetaValue("xmatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(storage.Dom, xmatterName, _fileLocator); helper.FolderPathForCopyingXMatterFiles = storage.FolderPath; helper.InjectXMatter(data.WritingSystemCodes, sizeAndOrientation); } }
private string SetupNewDocumentContents(string sourceFolderPath, string initialPath) { var storage = _bookStorageFactory(initialPath); bool usingTemplate = storage.MetaData.IsSuitableForMakingShells; bool makingTemplate = storage.MetaData.IsSuitableForMakingTemplates; var bookData = new BookData(storage.Dom, _collectionSettings, null); UpdateEditabilityMetadata(storage); //Path.GetFileName(initialPath).ToLower().Contains("template")); // NB: For a new book based on a page template, I think this should remove *everything*, // because the rest is in the xmatter. // For shells, we'll still have pages. //Remove from the new book any div-pages labeled as "extraPage" for (var initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]"); initialPageDivs.Count > 0; initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]")) { initialPageDivs[0].ParentNode.RemoveChild(initialPageDivs[0]); } XMatterHelper.RemoveExistingXMatter(storage.Dom); bookData.RemoveAllForms("ISBN"); //ISBN number of the original doesn't apply to derivatives var sizeAndOrientation = Layout.FromDomAndChoices(storage.Dom, Layout.A5Portrait, _fileLocator); //Note that we do this *before* injecting frontmatter, which is more likely to have a good reason for having English //Useful for things like Primers. Note that Lorem Ipsum and prefixing all text with "_" also work. // if ("true"==GetMetaValue(storage.Dom.RawDom, "removeTranslationsWhenMakingNewBook", "false")) // { // ClearAwayAllTranslations(storage.Dom.RawDom); // } ProcessXMatterMetaTags(storage); // If we are making a shell (from a template, as opposed to making a translation of a shell), // it should not have a pre-determined license. A default will be filled in later. // (But, if we're MAKING a template, we want to keep the CC0 from Template Starter.) if (usingTemplate && !makingTemplate) { BookCopyrightAndLicense.RemoveLicense(storage); } InjectXMatter(initialPath, storage, sizeAndOrientation); SetLineageAndId(storage, sourceFolderPath); SetBookTitle(storage, bookData, usingTemplate); if (!usingTemplate && // when people add a book to a source collection, they are assumed *editing* the book, not making a derivative (BL-4497) !_collectionSettings.IsSourceCollection) { BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(storage.Dom, bookData, _collectionSettings); } //Few sources will have this set at all. A template picture dictionary is one place where we might expect it to call for, say, bilingual int multilingualLevel = int.Parse(GetMetaValue(storage.Dom.RawDom, "defaultMultilingualLevel", "1")); TranslationGroupManager.SetInitialMultilingualSetting(bookData, multilingualLevel, _collectionSettings); var sourceDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(sourceFolderPath.CombineForPath(Path.GetFileName(GetPathToHtmlFile(sourceFolderPath))), false); //If this is a shell book, make elements to hold the vernacular foreach (XmlElement div in storage.Dom.RawDom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")) { XmlElement sourceDiv = sourceDom.SelectSingleNode("//div[@id='" + div.GetAttribute("id") + "']") as XmlElement; SetupIdAndLineage(sourceDiv, div); SetupPage(div, _collectionSettings, null, null); } ClearAwayDraftText(storage.Dom.RawDom); storage.Save(); //REVIEW this actually undoes the setting of the initial files name: // storage.UpdateBookFileAndFolderName(_librarySettings); return(storage.FolderPath); }
/// <summary> /// we update these so that the file continues to look the same when you just open it in firefox /// </summary> private void UpdateSupportFiles() { UpdateIfNewer("placeHolder.png"); UpdateIfNewer("basePage.css"); UpdateIfNewer("previewMode.css"); foreach (var path in Directory.GetFiles(_folderPath, "*.css")) { var file = Path.GetFileName(path); //if (file.ToLower().Contains("portrait") || file.ToLower().Contains("landscape")) UpdateIfNewer(file); } //by default, this comes from the collection, but the book can select one, inlucing "null" to select the factory-supplied empty xmatter var nameOfXMatterPack = _dom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(_dom, nameOfXMatterPack, _fileLocator); UpdateIfNewer(Path.GetFileName(helper.PathToStyleSheetForPaperAndOrientation), helper.PathToStyleSheetForPaperAndOrientation); }
// NB: this knows nothing of book-specific css's... even "basic book.css" private void EnsureHasLinksToStylesheets(HtmlDom dom) { var nameOfXMatterPack = _dom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(_dom, nameOfXMatterPack, _fileLocator); EnsureHasLinkToStyleSheet(dom, Path.GetFileName(helper.PathToStyleSheetForPaperAndOrientation)); string autocssFilePath = ".."+Path.DirectorySeparatorChar+"settingsCollectionStyles.css"; if (File.Exists(Path.Combine(_folderPath,autocssFilePath))) EnsureHasLinkToStyleSheet(dom, autocssFilePath); var customCssFilePath = ".." + Path.DirectorySeparatorChar + "customCollectionStyles.css"; if (File.Exists(Path.Combine(_folderPath, customCssFilePath))) EnsureHasLinkToStyleSheet(dom, customCssFilePath); if (File.Exists(Path.Combine(_folderPath, "customBookStyles.css"))) EnsureHasLinkToStyleSheet(dom,"customBookStyles.css"); }
private void BringBookUpToDate(HtmlDom bookDOM /* may be a 'preview' version*/, IProgress progress) { progress.WriteStatus("Gathering Data..."); //by default, this comes from the collection, but the book can select one, including "null" to select the factory-supplied empty xmatter var nameOfXMatterPack = OurHtmlDom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(bookDOM, nameOfXMatterPack, _storage.GetFileLocator()); XMatterHelper.RemoveExistingXMatter(bookDOM); Layout layout = Layout.FromDom(bookDOM, Layout.A5Portrait); //enhance... this is currently just for the whole book. would be better page-by-page, somehow... progress.WriteStatus("Injecting XMatter..."); helper.InjectXMatter(_bookData.GetWritingSystemCodes(), layout); TranslationGroupManager.PrepareElementsInPageOrDocument(bookDOM.RawDom, _collectionSettings); progress.WriteStatus("Updating Data..."); //hack if(bookDOM == OurHtmlDom)//we already have a data for this { _bookData.SynchronizeDataItemsThroughoutDOM(); // I think we should only mess with tags if we are updating the book for real. var oldTagsPath = Path.Combine(_storage.FolderPath, "tags.txt"); if (File.Exists(oldTagsPath)) { ConvertTagsToMetaData(oldTagsPath, BookInfo); File.Delete(oldTagsPath); } } else //used for making a preview dom { var bd = new BookData(bookDOM, _collectionSettings, UpdateImageMetadataAttributes); bd.SynchronizeDataItemsThroughoutDOM(); } bookDOM.RemoveMetaElement("bloomBookLineage", () => BookInfo.BookLineage, val => BookInfo.BookLineage = val); bookDOM.RemoveMetaElement("bookLineage", () => BookInfo.BookLineage, val => BookInfo.BookLineage = val); // BookInfo will always have an ID, the constructor makes one even if there is no json file. // To allow migration, pretend it has no ID if there is not yet a meta.json. bookDOM.RemoveMetaElement("bloomBookId", () => (File.Exists(BookInfo.MetaDataPath) ? BookInfo.Id : null), val => BookInfo.Id = val); // Title should be replicated in json //if (!string.IsNullOrWhiteSpace(Title)) // check just in case we somehow have more useful info in json. // bookDOM.Title = Title; // Bit of a kludge, but there's no way to tell whether a boolean is already set in the JSON, so we fake that it is not, // thus ensuring that if something is in the metadata we use it. bookDOM.RemoveMetaElement("SuitableForMakingShells", () => null, val => BookInfo.IsSuitableForMakingShells = val == "yes" || val == "definitely"); // If there is nothing there the default of true will survive. bookDOM.RemoveMetaElement("SuitableForMakingVernacularBooks", () => null, val => BookInfo.IsSuitableForVernacularLibrary = val == "yes" || val == "definitely"); }
/// <summary> /// we update these so that the file continues to look the same when you just open it in firefox /// </summary> private void UpdateSupportFiles() { if (IsPathReadonly(_folderPath)) { Logger.WriteEvent("Not updating files in folder {0} because the directory is read-only.", _folderPath); } else { Update("placeHolder.png"); Update("basePage.css"); Update("previewMode.css"); Update("origami.css"); Update("languageDisplay.css"); foreach (var path in Directory.GetFiles(_folderPath, "*.css")) { var file = Path.GetFileName(path); //if (file.ToLower().Contains("portrait") || file.ToLower().Contains("landscape")) Update(file); } } //by default, this comes from the collection, but the book can select one, including "null" to select the factory-supplied empty xmatter var nameOfXMatterPack = _dom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); nameOfXMatterPack = HandleRetiredXMatterPacks(_dom, nameOfXMatterPack); try { var helper = new XMatterHelper(_dom, nameOfXMatterPack, _fileLocator); Update(Path.GetFileName(helper.PathToStyleSheetForPaperAndOrientation), helper.PathToStyleSheetForPaperAndOrientation); } catch (Exception error) { ErrorMessagesHtml = WebUtility.HtmlEncode(error.Message); } }
private void BringXmatterHtmlUpToDate(HtmlDom bookDOM) { //by default, this comes from the collection, but the book can select one, including "null" to select the factory-supplied empty xmatter var nameOfXMatterPack = OurHtmlDom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); nameOfXMatterPack = Storage.HandleRetiredXMatterPacks(OurHtmlDom, nameOfXMatterPack); var helper = new XMatterHelper(bookDOM, nameOfXMatterPack, _storage.GetFileLocator()); //note, we determine this before removing xmatter to fix the situation where there is *only* xmatter, no content, so if //we wait until we've removed the xmatter, we no how no way of knowing what size/orientation they had before the update. Layout layout = Layout.FromDom(bookDOM, Layout.A5Portrait); XMatterHelper.RemoveExistingXMatter(bookDOM); layout = Layout.FromDom(bookDOM, layout); //this says, if you can't figure out the page size, use the one we got before we removed the xmatter helper.InjectXMatter(_bookData.GetWritingSystemCodes(), layout); var dataBookLangs = bookDOM.GatherDataBookLanguages(); TranslationGroupManager.PrepareDataBookTranslationGroups(RawDom, dataBookLangs); }
private string SetupNewDocumentContents(string sourceFolderPath, string initialPath) { var storage = _bookStorageFactory(initialPath); bool usingTemplate = storage.BookInfo.IsSuitableForMakingShells; bool makingTemplate = storage.BookInfo.IsSuitableForMakingTemplates; // If we're not making it from a template or making a template, we're deriving a translation from an existing book var makingTranslation = !usingTemplate && !makingTemplate; var bookData = new BookData(storage.Dom, _collectionSettings, null); UpdateEditabilityMetadata(storage); //Path.GetFileName(initialPath).ToLower().Contains("template")); // BL-7614 We don't want a derivative of a book downloaded from a "bookshelf" to have the same bookshelf storage.BookInfo.ClearBookshelf(); // NB: For a new book based on a page template, I think this should remove *everything*, // because the rest is in the xmatter. // For shells, we'll still have pages. // BL-6108: But if this is a template and we remove all the pages and xmatter, // there won't be anything left to tell us what the template's preferred layout was, // so we'll save that first. Layout templateLayout = null; if (usingTemplate) { templateLayout = Layout.FromDom(storage.Dom, Layout.A5Portrait); } // Remove from the new book any pages labeled as "extra". // Typically pages in a template are marked "extra" to indicate that they are options to insert with "Add Page" // but not pages (which a few templates have) that should be automatically inserted into every book // made from the template. // Originally we removed 'extra' pages in all cases, but we haven't actually used the capability // of deleting 'extra' pages from translations of shell books, and on the other hand, we did briefly release // a version of Bloom that incorrectly left shell book pages so marked. Something like 73 books in our library // may have this problem (BL-6392). Since we don't actually need the capability for making translations // of shell books, we decided to simply disable it: all pages in a shell book, even those marked // 'extra', will be kept in the translation. if (!makingTranslation) { for (var initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]"); initialPageDivs.Count > 0; initialPageDivs = storage.Dom.SafeSelectNodes("/html/body/div[contains(@data-page,'extra')]")) { initialPageDivs[0].ParentNode.RemoveChild(initialPageDivs[0]); } } else { // When making a translation of an original move the 'publisher' (if there is one) to 'originalPublisher'. storage.BookInfo.MovePublisherToOriginalPublisher(); } XMatterHelper.RemoveExistingXMatter(storage.Dom); // BL-4586 Some old books ended up with background-image urls containing XML img tags // in the HTML-encoded string. This happened because the coverImage data-book element // contained an img tag instead of a bare filename. // Normally such a thing would get fixed on loading the book, but if the "old book" in question // is a shell downloaded from BloomLibrary.org, Bloom is not allowed to modify the book, // so if such a thing exists in this copied book here we will strip it out and replace it with the // filename in the img src attribute. Book.RemoveImgTagInDataDiv(storage.Dom); bookData.RemoveAllForms("ISBN"); //ISBN number of the original doesn't apply to derivatives var sizeAndOrientation = Layout.FromDomAndChoices(storage.Dom, templateLayout ?? Layout.A5Portrait, _fileLocator); //Note that we do this *before* injecting frontmatter, which is more likely to have a good reason for having English //Useful for things like Primers. Note that Lorem Ipsum and prefixing all text with "_" also work. // if ("true"==GetMetaValue(storage.Dom.RawDom, "removeTranslationsWhenMakingNewBook", "false")) // { // ClearAwayAllTranslations(storage.Dom.RawDom); // } ProcessXMatterMetaTags(storage); // If we are making a shell (from a template, as opposed to making a translation of a shell), // it should not have a pre-determined license. A default will be filled in later. // (But, if we're MAKING a template, we want to keep the CC0 from Template Starter.) if (usingTemplate && !makingTemplate) { BookCopyrightAndLicense.RemoveLicense(storage); } InjectXMatter(initialPath, storage, sizeAndOrientation); SetLineageAndId(storage, sourceFolderPath); if (makingTranslation) { storage.EnsureOriginalTitle(); // Before SetBookTitle, so we definitely won't use this book's new empty title } SetBookTitle(storage, bookData, usingTemplate); TransformCreditPageData(storage.Dom, bookData, _collectionSettings, storage, makingTranslation); //Few sources will have this set at all. A template picture dictionary is one place where we might expect it to call for, say, bilingual int multilingualLevel = int.Parse(GetMetaValue(storage.Dom.RawDom, "defaultMultilingualLevel", "1")); TranslationGroupManager.SetInitialMultilingualSetting(bookData, multilingualLevel, _collectionSettings); var sourceDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(sourceFolderPath.CombineForPath(Path.GetFileName(GetPathToHtmlFile(sourceFolderPath))), false); //If this is a shell book, make elements to hold the vernacular foreach (XmlElement div in storage.Dom.RawDom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")) { XmlElement sourceDiv = sourceDom.SelectSingleNode("//div[@id='" + div.GetAttribute("id") + "']") as XmlElement; SetupIdAndLineage(sourceDiv, div); SetupPage(div, _collectionSettings, null, null); } ClearAwayDraftText(storage.Dom.RawDom); storage.UpdateSupportFiles(); // Copy branding files etc. storage.Save(); //REVIEW this actually undoes the setting of the initial files name: // storage.UpdateBookFileAndFolderName(_librarySettings); return(storage.FolderPath); }
// NB: this knows nothing of book-specific css's... even "basic book.css" private void EnsureHasLinksToStylesheets(HtmlDom dom) { //clear out any old ones _dom.RemoveXMatterStyleSheets(); var nameOfXMatterPack = _dom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); nameOfXMatterPack = HandleRetiredXMatterPacks(dom, nameOfXMatterPack); var helper = new XMatterHelper(_dom, nameOfXMatterPack, _fileLocator); EnsureHasLinkToStyleSheet(dom, Path.GetFileName(helper.PathToStyleSheetForPaperAndOrientation)); string autocssFilePath = ".."+Path.DirectorySeparatorChar+"settingsCollectionStyles.css"; if (RobustFile.Exists(Path.Combine(_folderPath,autocssFilePath))) EnsureHasLinkToStyleSheet(dom, autocssFilePath); var customCssFilePath = ".." + Path.DirectorySeparatorChar + "customCollectionStyles.css"; if (RobustFile.Exists(Path.Combine(_folderPath, customCssFilePath))) EnsureHasLinkToStyleSheet(dom, customCssFilePath); if (RobustFile.Exists(Path.Combine(_folderPath, "customBookStyles.css"))) EnsureHasLinkToStyleSheet(dom, "customBookStyles.css"); else EnsureDoesntHaveLinkToStyleSheet(dom, "customBookStyles.css"); }
private void BringBookUpToDate(HtmlDom bookDOM /* may be a 'preview' version*/, IProgress progress) { progress.WriteStatus("Gathering Data..."); //by default, this comes from the collection, but the book can select one, inlucing "null" to select the factory-supplied empty xmatter var nameOfXMatterPack = OurHtmlDom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName); var helper = new XMatterHelper(bookDOM, nameOfXMatterPack, _storage.GetFileLocator()); XMatterHelper.RemoveExistingXMatter(bookDOM); Layout layout = Layout.FromDom(bookDOM, Layout.A5Portrait); //enhance... this is currently just for the whole book. would be better page-by-page, somehow... progress.WriteStatus("Injecting XMatter..."); helper.InjectXMatter(_bookData.GetWritingSystemCodes(), layout); TranslationGroupManager.PrepareElementsInPageOrDocument(bookDOM.RawDom, _collectionSettings); progress.WriteStatus("Updating Data..."); //hack if(bookDOM == OurHtmlDom)//we already have a data for this { _bookData.SynchronizeDataItemsThroughoutDOM(); } else //used for making a preview dom { var bd = new BookData(bookDOM, _collectionSettings, UpdateImageMetadataAttributes); bd.SynchronizeDataItemsThroughoutDOM(); } bookDOM.RenameMetaElement("bookLineage", "bloomBookLineage"); }