public LinkReMapperV2(KeyValuePair<string, List<Anchor>> link, Dictionary<string, IHTMLItem> ids, BookStructureManager structureManager) { _link = link; _structureManager = structureManager; _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target; _linkTargetItem = ids[_idString]; // get object targeted by link _linkTargetDocument = GetIDParentDocument(structureManager, _linkTargetItem); // get parent document (file) containing targeted object if (_linkTargetDocument != null) { _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 BaseXHTMLFileV2 { Id = docTitle, GuideRole = GuideTypeEnum.Text, Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), Content = new Div(BaseXHTMLFileV2.Compatibility), NavigationParent = null, NotPartOfNavigation = false, FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; if (bodyItem.Title != null) { var converterSettings = new ConverterOptionsV2 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV2(); sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title, new TitleConverterParamsV2 { Settings = converterSettings, TitleLevel = 1 })); } bookStructureManager.AddBookPage(sectionDocument); Logger.Log.Debug("Adding sub-sections"); foreach (var section in bodyItem.Sections) { AddSection(bookStructureManager, section, sectionDocument, false); } }
private void AddSection(BookStructureManager bookStructureManager, SectionItem section, BaseXHTMLFileV3 navParent) { 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 = _commonSettings.CapitalDrop, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var sectionConverter = new SectionConverterV3 { LinkSection = false, 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 = BuildSectionFileName() }; if (!firstDocumentOfSplit || ((navParent != null) && navParent.NotPartOfNavigation)) { sectionDocument.NotPartOfNavigation = true; } firstDocumentOfSplit = false; bookStructureManager.AddBookPage(sectionDocument); } Logger.Log.Debug("Adding sub-sections"); foreach (var subSection in section.SubSections) { AddSection(bookStructureManager, subSection, sectionDocument); } }
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 } }
private void RemapInternalLink(BookStructureManager structureManager, KeyValuePair<string, List<Anchor>> link) { var linkRemaper = new LinkReMapperV2(link, _ids, structureManager); linkRemaper.Remap(); }
public void RemapAnchors(BookStructureManager structureManager) { var listToRemove = new List<string>(); foreach (var link in _references) { if (!ReferencesUtils.IsExternalLink(link.Key)) { if (IsIdUsed(link.Key)) { RemapInternalLink(structureManager, link); } else { listToRemove.Add(link.Key); RemoveInvalidAnchor(link); } } } // Remove the unused anchor (and their ID if they have one) // from the lists foreach (var toRemove in listToRemove) { _references.Remove(toRemove); } }
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); BaseXHTMLFileV2 addTitlePage = new BaseXHTMLFileV2 { GuideRole = GuideTypeEnum.TitlePage, Content = new Div(BaseXHTMLFileV2.Compatibility), Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), NavigationParent = null, FileName = string.Format("section{0}.xhtml", ++_sectionCounter), NotPartOfNavigation = true, PageTitle = docTitle, }; var converterSettings = new ConverterOptionsV2 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV2(); addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title, new TitleConverterParamsV2 { Settings = converterSettings, TitleLevel = 2 })); bookStructureManager.AddTitlePage(addTitlePage); } BaseXHTMLFileV2 mainDocument = null; if (!string.IsNullOrEmpty(fb2File.MainBody.Name)) { string docTitle = fb2File.MainBody.Name; Logger.Log.DebugFormat("Adding section : {0}", docTitle); mainDocument = new BaseXHTMLFileV2 { PageTitle = docTitle, GuideRole = GuideTypeEnum.Text, Content = new Div(BaseXHTMLFileV2.Compatibility), Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), NavigationParent = null, FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; 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 BaseXHTMLFileV2 { PageTitle = newDocTitle, GuideRole = GuideTypeEnum.Text, Content = new Div(BaseXHTMLFileV2.Compatibility), NavigationParent = null, Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; bookStructureManager.AddBookPage(mainDocument); } if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef)) { var enclosing = new Div(HTMLElementType.XHTML11); // we use the enclosing so the user can style center it var converterSettings = new ConverterOptionsV2 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var imageConverter = new ImageConverterV2(); enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV2 { Settings = converterSettings })); SetClassType(enclosing, ElementStylesV2.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 BaseXHTMLFileV2 { PageTitle = newDocTitle, GuideRole = GuideTypeEnum.Text, Content = new Div(BaseXHTMLFileV2.Compatibility), NavigationParent = null, Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; } var converterSettings = new ConverterOptionsV2 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var epigraphConverter = new MainEpigraphConverterV2(); mainDocument.Content.Add(epigraphConverter.Convert(ep, new EpigraphConverterParamsV2 { Settings = converterSettings, Level = 1 })); bookStructureManager.AddBookPage(mainDocument); } Logger.Log.Debug("Adding main sections"); foreach (var section in fb2File.MainBody.Sections) { AddSection(bookStructureManager, section, mainDocument, false); } Logger.Log.Debug("Adding secondary bodies"); foreach (var bodyItem in fb2File.Bodies) { if (bodyItem == fb2File.MainBody) { continue; } bool fbeNotesSection = FBENotesSection(bodyItem.Name); if (fbeNotesSection) { AddFbeNotesBody(bookStructureManager, bodyItem); } else { AddSecondaryBody(bookStructureManager, bodyItem); } } }
private BaseXHTMLFileV2 GetIDParentDocument(BookStructureManager structureManager, IHTMLItem value) { return structureManager.GetItemParentDocument(value) as BaseXHTMLFileV2; }
private void AddSection(BookStructureManager bookStructureManager, SectionItem section, BaseXHTMLFileV2 navParent, bool fbeNotesSection) { string docTitle = string.Empty; if (section.Title != null) { docTitle = section.Title.ToString(); } Logger.Log.DebugFormat("Adding section : {0}", docTitle); BaseXHTMLFileV2 sectionDocument = null; bool firstDocumentOfSplit = true; var converterSettings = new ConverterOptionsV2 { CapitalDrop = !fbeNotesSection && _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var sectionConverter = new SectionConverterV2 { LinkSection = fbeNotesSection, RecursionLevel = GetRecursionLevel(navParent), Settings = converterSettings }; foreach (var subitem in sectionConverter.Convert(section)) { sectionDocument = new BaseXHTMLFileV2 { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = (navParent == null) ? GuideTypeEnum.Text : navParent.GuideRole, Type = (navParent == null) ? SectionTypeEnum.Text : navParent.Type, Content = subitem, NavigationParent = navParent, FileName = string.Format("section{0}.xhtml", ++_sectionCounter) }; if (!firstDocumentOfSplit || (sectionDocument.Type == SectionTypeEnum.Links)) { sectionDocument.NotPartOfNavigation = true; } firstDocumentOfSplit = false; bookStructureManager.AddBookPage(sectionDocument); } Logger.Log.Debug("Adding sub-sections"); foreach (var subSection in section.SubSections) { AddSection(bookStructureManager, subSection, sectionDocument, fbeNotesSection); } }