private void GenerateSingleFootnote(Anchor anchor, string targetID) { BaseXHTMLFileV3 anchorDocument = GetItemParentDocument(anchor); // get document containing anchor pointing to target ID if (anchorDocument == null) // if anchor not contained (not found) in any document { Logger.Log.Error(string.Format("Internal consistency error - anchor ({0}) for id ({1}) not contained (not found) in any document", anchor, _linkTargetItem)); return; } if (anchorDocument is FB2NotesPageSectionFile) // if anchor in FB2 Notes section (meaning link from FB2 notes to FB2 notes) no need to do anything as we do not save notes files in this mode { return; } // update reference link for an anchor, local one (without file name) anchor.HRef.Value = GenerateLocalLinkReference(targetID); // mark anchor (link reference) as note reference to make it pop-up able EPubV3VocabularyStyles linkStyles = new EPubV3VocabularyStyles(); linkStyles.SetType(EpubV3Vocabulary.NoteRef); anchor.CustomAttributes.Add(linkStyles.GetAsCustomAttribute()); // add footnote object to the same document that contains link ,so the pop up point and pop up content will be in a same document var footnoteToAdd = CreateFootnoteItemFromTargetNoteItem(targetID); anchorDocument.AddFootNote(targetID, footnoteToAdd); // if footnote target ID already exist it will not add it }
private void RemepLinkSectionV2Style() { foreach (var anchor in _link.Value) { BaseXHTMLFileV3 anchorDocument = GetItemParentDocument(anchor); // get document containing anchor pointing to target ID if (anchorDocument == null) // if anchor not contained (not found) in any document { Logger.Log.Error(string.Format("Internal consistency error - anchor ({0}) for id ({1}) not contained (not found) in any document", anchor, _linkTargetItem)); continue; } string backlinkRef; if (anchorDocument == _linkTargetDocument) // if anchor (link) and target (id) located in same document { anchor.HRef.Value = GenerateLocalLinkReference(_idString); // update reference link for an anchor, local one (without file name) backlinkRef = GenerateLocalLinkReference(anchor.GlobalAttributes.ID.Value as string); // in case we going to insert backlin - create a local reference } else // if they are located in different documents { anchor.HRef.Value = GenerateFarLinkReference(_idString, _linkTargetDocument.FileName); // update reference link for an anchor, "far" one (with, pointing to another file name) backlinkRef = GenerateFarLinkReference(anchor.GlobalAttributes.ID.Value as string, anchorDocument.FileName); // in case we going to insert backlin - create a "far" reference } var backLinkAnchor = new Anchor(_linkParentContainer.HTMLStandard); backLinkAnchor.HRef.Value = backlinkRef; backLinkAnchor.GlobalAttributes.Class.Value = ElementStylesV3.NoteAnchor; _linkParentContainer.Add(new EmptyLine(_linkParentContainer.HTMLStandard)); _linkParentContainer.Add(backLinkAnchor); _linksCount++; backLinkAnchor.Add(new SimpleHTML5Text(backLinkAnchor.HTMLStandard) { Text = (_link.Value.Count > 1) ? string.Format("(<< back {0}) ", _linksCount) : string.Format("(<< back) ") }); } }
/// <summary> /// Passes FB2 info to the EPub file to be added at the end of the book /// </summary> /// <param name="epubFile">destination epub object</param> /// <param name="fb2File">source fb2 object</param> private void PassFb2InfoToEpub(EPubFileV3 epubFile, FB2File fb2File) { if (!Settings.ConversionSettings.Fb2Info) { return; } var infoDocument = new BaseXHTMLFileV3 { PageTitle = "FB2 Info", FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), FileName = "fb2info.xhtml", GuideRole = GuideTypeEnum.Notes, NotPartOfNavigation = true }; var converterSettings = new ConverterOptionsV3 { CapitalDrop = false, Images = Images, MaxSize = Settings.V3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var infoConverter = new Fb2EpubInfoConverterV3(); infoDocument.Content = infoConverter.Convert(fb2File, converterSettings); epubFile.AddXHTMLFile(infoDocument); }
private static int GetRecursionLevel(BaseXHTMLFileV3 navParent) { if (navParent == null) { return(1); } return(navParent.NavigationLevel + 1); }
private List <FB2NotesPageSectionFile> AddSection(SectionItem section, BaseXHTMLFileV3 navParent) { List <FB2NotesPageSectionFile> documents = new List <FB2NotesPageSectionFile>(); string docTitle = string.Empty; if (section.Title != null) { docTitle = section.Title.ToString(); } Logger.Log.DebugFormat("Adding notes section : {0}", docTitle); FB2NotesPageSectionFile sectionDocument = null; bool firstDocumentOfSplit = true; var converterSettings = new ConverterOptionsV3 { CapitalDrop = false, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var sectionConverter = new SectionConverterV3 { LinkSection = true, RecursionLevel = GetRecursionLevel(navParent), Settings = converterSettings }; foreach (var subitem in sectionConverter.Convert(section)) { sectionDocument = new FB2NotesPageSectionFile { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = (navParent == null) ? GuideTypeEnum.Text : navParent.GuideRole, Content = subitem, NavigationParent = navParent, FileName = BuildSectionFileName() }; if (!firstDocumentOfSplit || ((navParent != null) && navParent.NotPartOfNavigation)) { sectionDocument.NotPartOfNavigation = true; } firstDocumentOfSplit = false; documents.Add(sectionDocument); } Logger.Log.Debug("Adding sub-sections"); foreach (var subSection in section.SubSections) { documents.AddRange(AddSection(subSection, sectionDocument)); } return(documents); }
public void RemapAnchors(EPubFileV3 epubFile) { foreach (var link in _references) { if (!ReferencesUtils.IsExternalLink(link.Key)) { string idString = ReferencesUtils.GetIdFromLink(link.Key); BaseXHTMLFileV3 iDDocument = GetIDParentDocument(epubFile, _ids[idString]); if (iDDocument != null) { int count = 0; foreach (var anchor in link.Value) { BaseXHTMLFileV3 idDocument = GetIDParentDocument(epubFile, anchor); var referencedItem = _ids[(string)anchor.HRef.Value]; var newParent = DetectParentContainer(referencedItem); if (newParent == null) { continue; } var newAnchor = new Anchor(newParent.HTMLStandard); if (idDocument == iDDocument) { anchor.HRef.Value = string.Format("#{0}", idString); newAnchor.HRef.Value = string.Format("#{0}", anchor.GlobalAttributes.ID.Value); } else { anchor.HRef.Value = string.Format("{0}#{1}", iDDocument.FileName, idString); if (idDocument == null) { continue; } newAnchor.HRef.Value = string.Format("{0}#{1}", idDocument.FileName, anchor.GlobalAttributes.ID.Value); } //if (iDDocument.Type == SectionTypeEnum.Links)) // if it's FBE notes section //{ // newAnchor.GlobalAttributes.Class.Value = ElementStylesV3.NoteAnchor; // newParent.Add(new EmptyLine(newParent.HTMLStandard)); // newParent.Add(newAnchor); // count++; // newAnchor.Add(new SimpleHTML5Text(newAnchor.HTMLStandard) { Text = (link.Value.Count > 1) ? string.Format("(<< back {0}) ", count) : string.Format("(<< back) ") }); //} } } else { //throw new Exception("Internal consistency error - Used ID has to be in one of the book documents objects"); Logger.Log.Error("Internal consistency error - Used ID has to be in one of the book documents objects"); //continue; } } } }
private void RemapNormalReference() { foreach (var anchor in _link.Value) // iterate over all anchors (references) pointing to this link target (destination) { BaseXHTMLFileV3 anchorDocument = GetItemParentDocument(anchor); // get document containing anchor (link) pointing to target ID if (anchorDocument == null) // if anchor not contained (not found) in any document { Logger.Log.Error(string.Format("Internal consistency error - anchor ({0}) for id ({1}) not contained (not found) in any document", anchor, _linkTargetItem)); continue; } // if in same document - local reference (link) , if in different - create link to that document anchor.HRef.Value = (anchorDocument == _linkTargetDocument) ? GenerateLocalLinkReference(_idString) : GenerateFarLinkReference(_idString, _linkTargetDocument.FileName); } }
public LinkReMapperV3(KeyValuePair <string, List <Anchor> > link, IDictionary <string, HTMLItem> ids, BookStructureManager structureManager, IEPubV3Settings v3Settings) { _link = link; _ids = ids; _v3Settings = v3Settings; _structureManager = structureManager; _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target; _linkTargetItem = ids[_idString]; // get object targeted by link _linkTargetDocument = GetItemParentDocument(_linkTargetItem); // get parent document (file) containing targeted object if (_linkTargetDocument != null) // if link target container document (document containing item with ID we jump to) found { _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item } }
/// <summary> /// Add and convert generic secondary body section /// </summary> /// <param name="bookStructureManager"></param> /// <param name="bodyItem"></param> private void AddSecondaryBody(BookStructureManager bookStructureManager, BodyItem bodyItem) { string docTitle = string.Empty; if (string.IsNullOrEmpty(bodyItem.Name)) { if (bodyItem.Title != null) { docTitle = bodyItem.Title.ToString(); } } else { docTitle = bodyItem.Name; } Logger.Log.DebugFormat("Adding section : {0}", docTitle); var sectionDocument = new BaseXHTMLFileV3 { FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Text, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, NotPartOfNavigation = false, FileName = BuildSectionFileName(), PageTitle = docTitle, }; if (bodyItem.Title != null) { var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV3(); sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title, new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 1 })); } bookStructureManager.AddBookPage(sectionDocument); Logger.Log.Debug("Adding sub-sections"); foreach (var section in bodyItem.Sections) { AddSection(bookStructureManager, section, sectionDocument); } }
private void AddSection(EPubFileV3 epubFile, SectionItem section, BaseXHTMLFileV3 navParent, bool fbeNotesSection) { string docTitle = string.Empty; if (section.Title != null) { docTitle = section.Title.ToString(); } Logger.Log.DebugFormat("Adding section : {0}", docTitle); BaseXHTMLFileV3 sectionDocument = null; bool firstDocumentOfSplit = true; var converterSettings = new ConverterOptionsV3 { CapitalDrop = !fbeNotesSection && _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var sectionConverter = new SectionConverterV3 { LinkSection = fbeNotesSection, RecursionLevel = GetRecursionLevel(navParent), Settings = converterSettings }; foreach (var subitem in sectionConverter.Convert(section)) { sectionDocument = new BaseXHTMLFileV3 { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = (navParent == null) ? GuideTypeEnum.Text : navParent.GuideRole, Content = subitem, NavigationParent = navParent, FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; if (!firstDocumentOfSplit || ((navParent != null) && navParent.NotPartOfNavigation)) { sectionDocument.NotPartOfNavigation = true; } firstDocumentOfSplit = false; epubFile.AddXHTMLFile(sectionDocument); } Logger.Log.Debug("Adding sub-sections"); foreach (var subSection in section.SubSections) { AddSection(epubFile, subSection, sectionDocument, fbeNotesSection); } }
/// <summary> /// Add and convert FBE style generated notes sections /// </summary> /// <param name="epubFile"></param> /// <param name="bodyItem"></param> private void AddFbeNotesBody(EPubFileV3 epubFile, BodyItem bodyItem) { string docTitle = bodyItem.Name; Logger.Log.DebugFormat("Adding section : {0}", docTitle); var sectionDocument = new BaseXHTMLFileV3 { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Glossary, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, NotPartOfNavigation = true, FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; if (bodyItem.Title != null) { var converterSettings = new ConverterOptionsV3 { CapitalDrop = false, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV3(); sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title, new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 1 })); } epubFile.AddXHTMLFile(sectionDocument); Logger.Log.Debug("Adding sub-sections"); foreach (var section in bodyItem.Sections) { AddSection(epubFile, section, sectionDocument, true); } }
public void Convert(BookStructureManager bookStructureManager, FB2File fb2File) { // create second title page if ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) { string docTitle = fb2File.MainBody.Title.ToString(); Logger.Log.DebugFormat("Adding section : {0}", docTitle); var addTitlePage = new BaseXHTMLFileV3 { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.TitlePage, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, FileName = BuildSectionFileName(), NotPartOfNavigation = true }; var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV3(); addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title, new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 2 })); bookStructureManager.AddTitlePage(addTitlePage); } BaseXHTMLFileV3 mainDocument = null; if (!string.IsNullOrEmpty(fb2File.MainBody.Name)) { string docTitle = fb2File.MainBody.Name; Logger.Log.DebugFormat("Adding section : {0}", docTitle); mainDocument = new BaseXHTMLFileV3 { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Text, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, FileName = BuildSectionFileName() }; bookStructureManager.AddBookPage(mainDocument); } if ((fb2File.MainBody.ImageName != null) && !string.IsNullOrEmpty(fb2File.MainBody.ImageName.HRef)) { if (mainDocument == null) { string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main"; mainDocument = new BaseXHTMLFileV3 { PageTitle = newDocTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Text, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, FileName = BuildSectionFileName() }; bookStructureManager.AddBookPage(mainDocument); } if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef)) { var enclosing = new Div(HTMLElementType.HTML5); // we use the enclosing so the user can style center it var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var imageConverter = new ImageConverterV3(); enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV3 { Settings = converterSettings })); SetClassType(enclosing, ElementStylesV3.BodyImage); mainDocument.Content.Add(enclosing); } } foreach (var ep in fb2File.MainBody.Epigraphs) { if (mainDocument == null) { string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main"; mainDocument = new BaseXHTMLFileV3 { PageTitle = newDocTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Text, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, FileName = BuildSectionFileName() }; bookStructureManager.AddBookPage(mainDocument); } var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var epigraphConverter = new MainEpigraphConverterV3(); mainDocument.Content.Add(epigraphConverter.Convert(ep, new EpigraphConverterParamsV3 { Settings = converterSettings, Level = 1 })); } Logger.Log.Debug("Adding main sections"); foreach (var section in fb2File.MainBody.Sections) { AddSection(bookStructureManager, section, mainDocument); } Logger.Log.Debug("Adding secondary bodies"); foreach (var bodyItem in fb2File.Bodies) { if (bodyItem == fb2File.MainBody) { continue; } bool fbeNotesSection = FBENotesSection(bodyItem.Name); if (fbeNotesSection) { _notesManager.AddNotesBody(bodyItem); } else { AddSecondaryBody(bookStructureManager, bodyItem); } } foreach (var footNotesAdditionalDocument in _notesManager.GetFootNotesAdditionalDocuments()) { bookStructureManager.AddFootnote(footNotesAdditionalDocument); } }