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); } }
/// <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); } }
/// <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); } }
private void ConvertAnnotation(ItemTitleInfo titleInfo, EPubFileV3 epubFile) { if (titleInfo.Annotation != null) { epubFile.BookInformation.Description = new Description {DescInfo = titleInfo.Annotation.ToString()}; epubFile.AnnotationPage = new AnnotationPageFileV3(); var converterSettings = new ConverterOptionsV3 { CapitalDrop = Settings.CommonSettings.CapitalDrop, Images = Images, MaxSize = Settings.V3Settings.HTMLFileMaxSize, ReferencesManager = _referencesManager, }; var annotationConverter = new AnnotationConverterV3(); epubFile.AnnotationPage.BookAnnotation = (Div)annotationConverter.Convert(titleInfo.Annotation, new AnnotationConverterParamsV3 { Settings = converterSettings, Level = 1 }); } }
/// <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); }
public HTMLItem Convert(FB2File fb2File, ConverterOptionsV3 settings) { if (fb2File == null) { throw new ArgumentNullException("fb2File"); } var info = new Div(HTMLElementType.HTML5); var header = new H3(HTMLElementType.HTML5); header.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "FB2 document info" }); info.Add(header); if (fb2File.DocumentInfo != null) { if (!string.IsNullOrEmpty(fb2File.DocumentInfo.ID)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document ID: {0}", fb2File.DocumentInfo.ID) }); info.Add(p); } if (fb2File.DocumentInfo.DocumentVersion.HasValue) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document version: {0}", fb2File.DocumentInfo.DocumentVersion) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentDate != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.DocumentDate.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document creation date: {0}", fb2File.DocumentInfo.DocumentDate.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.ProgramUsed2Create != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.ProgramUsed2Create.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Created using: {0} software", fb2File.DocumentInfo.ProgramUsed2Create.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.SourceOCR != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.SourceOCR.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("OCR Source: {0}", fb2File.DocumentInfo.SourceOCR.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentAuthors != null) && (fb2File.DocumentInfo.DocumentAuthors.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document authors :" }); info.Add(heading); var authors = new UnorderedList(HTMLElementType.HTML5); foreach (var author in fb2File.DocumentInfo.DocumentAuthors) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(author) }); authors.Add(li); } info.Add(authors); } if ((fb2File.DocumentInfo.DocumentPublishers != null) && (fb2File.DocumentInfo.DocumentPublishers.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document publishers :" }); info.Add(heading); var publishers = new UnorderedList(HTMLElementType.HTML5); foreach (var publisher in fb2File.DocumentInfo.DocumentPublishers) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(publisher) }); publishers.Add(li); } info.Add(publishers); } if ((fb2File.DocumentInfo.SourceURLs != null) && (fb2File.DocumentInfo.SourceURLs.Any())) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Source URLs :" }); info.Add(heading); var urls = new UnorderedList(HTMLElementType.HTML5); foreach (var url in fb2File.DocumentInfo.SourceURLs) { var li = new ListItem(HTMLElementType.HTML5); if (ReferencesUtils.IsExternalLink(url)) { var link = new Anchor(HTMLElementType.HTML5); link.HRef.Value = url; link.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); li.Add(link); } else { li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); } urls.Add(li); } info.Add(urls); } if (fb2File.DocumentInfo.History != null) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document history:" }); info.Add(heading); var annotationConverter = new AnnotationConverterV3(); info.Add(annotationConverter.Convert(fb2File.DocumentInfo.History, new AnnotationConverterParamsV3 { Level = 1, Settings = settings })); //Paragraph p = new Paragraph(); //p.Add(new SimpleHTML5Text() { Text = fb2File.DocumentInfo.History.ToString() }); //info.Add(p); } } // in case there is no elements - no need for a header if (info.SubElements().Count <= 1) { info.Remove(header); } SetClassType(info, ElementStylesV3.FB2Info); return info; }
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); } }
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; }
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; }
public void Convert(EPubFileV3 epubFile, 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 = string.Format("section{0}.xhtml", ++_sectionCounter), NotPartOfNavigation = true }; var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, ReferencesManager = _referencesManager, }; var titleConverter = new TitleConverterV3(); addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title, new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 2 })); epubFile.AddXHTMLFile(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 = string.Format("section{0}.xhtml", ++_sectionCounter) }; epubFile.AddXHTMLFile(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 = string.Format("section{0}.xhtml", ++_sectionCounter) }; epubFile.AddXHTMLFile(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 = _maxSize, 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 = string.Format("section{0}.xhtml", ++_sectionCounter) }; epubFile.AddXHTMLFile(mainDocument); } var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, Images = _images, MaxSize = _maxSize, 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(epubFile, 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(epubFile, bodyItem); } else { AddSecondaryBody(epubFile, bodyItem); } } }
/// <summary> /// Add and convert generic secondary body section /// </summary> /// <param name="epubFile"></param> /// <param name="bodyItem"></param> private void AddSecondaryBody(EPubFileV3 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 BaseXHTMLFileV3 { FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideTypeEnum.Text, Content = new Div(HTMLElementType.HTML5), NavigationParent = null, NotPartOfNavigation = false, FileName = string.Format("section{0}.xhtml", ++_sectionCounter), PageTitle = docTitle, }; if (bodyItem.Title != null) { var converterSettings = new ConverterOptionsV3 { CapitalDrop = _commonSettings.CapitalDrop, 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, false); } }
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); } }
public HTMLItem Convert(FB2File fb2File, ConverterOptionsV3 settings) { if (fb2File == null) { throw new ArgumentNullException("fb2File"); } var info = new Div(HTMLElementType.HTML5); var header = new H3(HTMLElementType.HTML5); header.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "FB2 document info" }); info.Add(header); if (fb2File.DocumentInfo != null) { if (!string.IsNullOrEmpty(fb2File.DocumentInfo.ID)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document ID: {0}", fb2File.DocumentInfo.ID) }); info.Add(p); } if (fb2File.DocumentInfo.DocumentVersion.HasValue) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document version: {0}", fb2File.DocumentInfo.DocumentVersion) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentDate != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.DocumentDate.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document creation date: {0}", fb2File.DocumentInfo.DocumentDate.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.ProgramUsed2Create != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.ProgramUsed2Create.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Created using: {0} software", fb2File.DocumentInfo.ProgramUsed2Create.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.SourceOCR != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.SourceOCR.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("OCR Source: {0}", fb2File.DocumentInfo.SourceOCR.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentAuthors != null) && (fb2File.DocumentInfo.DocumentAuthors.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document authors :" }); info.Add(heading); var authors = new UnorderedList(HTMLElementType.HTML5); foreach (var author in fb2File.DocumentInfo.DocumentAuthors) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(author) }); authors.Add(li); } info.Add(authors); } if ((fb2File.DocumentInfo.DocumentPublishers != null) && (fb2File.DocumentInfo.DocumentPublishers.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document publishers :" }); info.Add(heading); var publishers = new UnorderedList(HTMLElementType.HTML5); foreach (var publisher in fb2File.DocumentInfo.DocumentPublishers) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(publisher) }); publishers.Add(li); } info.Add(publishers); } if ((fb2File.DocumentInfo.SourceURLs != null) && (fb2File.DocumentInfo.SourceURLs.Any())) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Source URLs :" }); info.Add(heading); var urls = new UnorderedList(HTMLElementType.HTML5); foreach (var url in fb2File.DocumentInfo.SourceURLs) { var li = new ListItem(HTMLElementType.HTML5); if (ReferencesUtils.IsExternalLink(url)) { var link = new Anchor(HTMLElementType.HTML5); link.HRef.Value = url; link.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); li.Add(link); } else { li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); } urls.Add(li); } info.Add(urls); } if (fb2File.DocumentInfo.History != null) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document history:" }); info.Add(heading); var annotationConverter = new AnnotationConverterV3(); info.Add(annotationConverter.Convert(fb2File.DocumentInfo.History, new AnnotationConverterParamsV3 { Level = 1, Settings = settings })); //Paragraph p = new Paragraph(); //p.Add(new SimpleHTML5Text() { Text = fb2File.DocumentInfo.History.ToString() }); //info.Add(p); } } // in case there is no elements - no need for a header if (info.SubElements().Count <= 1) { info.Remove(header); } SetClassType(info, ElementStylesV3.FB2Info); return(info); }