public void AddNotesBody(BodyItem bodyItem) { if (!_bodyItems.Contains(bodyItem)) { _bodyItems.Add(bodyItem); } }
/// <summary> /// Add and convert generic secondary body section /// </summary> /// <param name="epubFile"></param> /// <param name="bodyItem"></param> private void AddSecondaryBody(EPubFileV2 epubFile, 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 })); } epubFile.AddXHTMLFile(sectionDocument); Logger.Log.Debug("Adding sub-sections"); foreach (var section in bodyItem.Sections) { AddSection(epubFile, section, sectionDocument, false); } }
/// <summary> /// Add and convert FBE style generated notes sections /// </summary> /// <param name="bookStructureManager"></param> /// <param name="bodyItem"></param> private void AddFbeNotesBody(BookStructureManager bookStructureManager, BodyItem bodyItem) { string docTitle = bodyItem.Name; Logger.Log.DebugFormat("Adding section : {0}", docTitle); var sectionDocument = new BaseXHTMLFileV2 { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Glossary, Type = SectionTypeEnum.Links, Content = new Div(BaseXHTMLFileV2.Compatibility), NavigationParent = null, NotPartOfNavigation = true, FileName = string.Format("section{0}.xhtml", ++_sectionCounter), }; if (bodyItem.Title != null) { var converterSettings = new ConverterOptionsV2 { CapitalDrop = false, 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, true); } }
/// <summary> /// Loads the file as data from XML data /// </summary> /// <param name="fileDocument">XML document containing the file</param> /// <param name="loadHeaderOnly">if true loads only header information</param> public void Load(XDocument fileDocument,bool loadHeaderOnly) { if (fileDocument == null) { throw new ArgumentNullException("fileDocument"); } if (fileDocument.Root == null) { throw new ArgumentException("Document's root is NULL (empty document passed)"); } // theoretically the namespace should be "http://www.gribuser.ru/xml/fictionbook/2.0" but just to be sure with invalid files _fileNameSpace = fileDocument.Root.GetDefaultNamespace(); _styles.Clear(); IEnumerable<XElement> xStyles = fileDocument.Elements(_fileNameSpace + StyleElement.StyleElementName).ToArray(); // attempt to load some bad FB2 with wrong namespace if (!xStyles.Any()) { xStyles = fileDocument.Elements(StyleElement.StyleElementName); } foreach (var style in xStyles) { var element = new StyleElement(); try { element.Load(style); _styles.Add(element); } catch { // ignored } } LoadDescriptionSection(fileDocument); if (!loadHeaderOnly) { XNamespace namespaceUsed = _fileNameSpace; // Load body elements (first is main text) if (fileDocument.Root != null) { IEnumerable<XElement> xBodys = fileDocument.Root.Elements(_fileNameSpace + Fb2TextBodyElementName).ToArray(); // try to read some badly formatted FB2 files if (!xBodys.Any()) { namespaceUsed = ""; xBodys = fileDocument.Root.Elements(namespaceUsed + Fb2TextBodyElementName); } foreach (var body in xBodys) { var bodyItem = new BodyItem() { NameSpace = namespaceUsed }; try { bodyItem.Load(body); } catch (Exception) { continue; } _bodiesList.Add(bodyItem); } } if (_bodiesList.Count > 0) { _mainBody = _bodiesList[0]; } // Load binaries sections (currently images only) if (fileDocument.Root != null) { IEnumerable<XElement> xBinaryes = fileDocument.Root.Elements(namespaceUsed + Fb2BinaryElementName).ToArray(); if (!xBinaryes.Any()) { xBinaryes = fileDocument.Root.Elements(Fb2BinaryElementName); } foreach (var binarye in xBinaryes) { var item = new BinaryItem(); try { item.Load(binarye); } catch { continue; } // add just unique IDs to fix some invalid FB2s if (!_binaryObjects.ContainsKey(item.Id)) { _binaryObjects.Add(item.Id, item); } } } } }
private List<FB2NotesPageSectionFile> AddV2StyleFbeNotesBody(BodyItem bodyItem) { List<FB2NotesPageSectionFile> documents = new List<FB2NotesPageSectionFile>(); string docTitle = bodyItem.Name; Logger.Log.DebugFormat("Adding notes section : {0}", docTitle); var sectionDocument = new FB2NotesPageSectionFile { PageTitle = docTitle, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Glossary, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, NotPartOfNavigation = true, FileName = BuildSectionFileName() }; if (bodyItem.Title != null) { var converterSettings = new ConverterOptionsV3 { CapitalDrop = false, Images = _images, MaxSize = _v3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV3(); sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title, new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 1 })); } documents.Add(sectionDocument); Logger.Log.Debug("Adding sub-sections"); foreach (var section in bodyItem.Sections) { documents.AddRange(AddSection(section, sectionDocument)); } return documents; }
/// <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); } }