public override void GenerateBody() { base.GenerateBody(); Div page = new Div(Compatibility); page.GlobalAttributes.Class.Value = "about"; H1 heading = new H1(Compatibility); heading.Add(new SimpleHTML5Text(Compatibility) { Text = "About" }); page.Add(heading); foreach (var text in AboutTexts) { var p1 = new Paragraph(Compatibility); var text1 = new SimpleHTML5Text(Compatibility) {Text = text}; p1.Add(text1); page.Add(p1); } foreach (var text in AboutLinks) { var p1 = new Paragraph(Compatibility); var anch = new Anchor(Compatibility); anch.HRef.Value = text; anch.GlobalAttributes.Title.Value = text; var text3 = new SimpleHTML5Text(Compatibility) {Text = text}; anch.Add(text3); p1.Add(anch); page.Add(p1); } BodyElement.Add(page); }
/// <summary> /// Converts FB2 Title object to XHTML Title /// </summary> /// <param name="titleItem">title item to convert</param> /// <param name="titleConverterParams"></param> /// <returns></returns> public Div Convert(TitleItem titleItem, TitleConverterParamsV2 titleConverterParams) { if (titleItem == null) { throw new ArgumentNullException("titleItem"); } _level = titleConverterParams.TitleLevel; var title = new Div(HTMLElementType.XHTML11); foreach (var fb2TextItem in titleItem.TitleData) { if (fb2TextItem is ParagraphItem) { var paragraphStyle = GetParagraphStyleByLevel(_level); var paragraphConverter = new ParagraphConverterV2(); title.Add(paragraphConverter.Convert(fb2TextItem as ParagraphItem, new ParagraphConverterParamsV2 { ResultType = paragraphStyle, Settings = titleConverterParams.Settings, StartSection = false })); } else if (fb2TextItem is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV2(); title.Add(emptyLineConverter.Convert()); } else { Debug.WriteLine("invalid type in Title - {0}", fb2TextItem.GetType()); } } SetClassType(title, ElementStylesV2.PoemTitle); return title; }
/// <summary> /// Convert FB2 "notes" and "comments" and other "additional" sections /// </summary> /// <param name="linkSectionItem">item to convert</param> /// <param name="linkSectionConverterParams"></param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(SectionItem linkSectionItem,LinkSectionConverterParamsV2 linkSectionConverterParams) { if (linkSectionItem == null) { throw new ArgumentNullException("linkSectionItem"); } var content = new Div(HTMLElementType.XHTML11); var a = new Anchor(HTMLElementType.XHTML11); var titleConverter = new TitleConverterV2(); foreach (var item in titleConverter.Convert(linkSectionItem.Title,new TitleConverterParamsV2{Settings = linkSectionConverterParams.Settings,TitleLevel = 2}).SubElements()) { content.Add(item); } string newId = linkSectionConverterParams.Settings.ReferencesManager.EnsureGoodId(linkSectionItem.ID); a.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = newId }); a.HRef.Value = string.Format("{0}_back", newId); if (((string)a.HRef.Value).StartsWith("_back") == false) { SetClassType(a, ElementStylesV2.NoteAnchor); linkSectionConverterParams.Settings.ReferencesManager.AddBackReference((string)a.HRef.Value, a); //content.Add(a); } SetClassType(content, ElementStylesV2.NoteSection); return content; }
private void AddContent() { var pageData = new Div(Compatibility); var heading = new H1(Compatibility); heading.Add(new SimpleHTML5Text(Compatibility) { Text = "Converter use license" }); pageData.Add(heading); var p1 = new Paragraph(Compatibility); p1.Add(new SimpleHTML5Text(Compatibility) { Text = "This file was generated by Lord KiRon's FB2EPUB converter." }); p1.Add(new SimpleHTML5Text(Compatibility) { Text = "(This book might contain copyrighted material, author of the converter bears no responsibility for it's usage)" }); pageData.Add(p1); var anch = new Anchor(Compatibility); p1 = new Paragraph(Compatibility); anch.Add(new SimpleHTML5Text(Compatibility) { Text = @"http://www.fb2epub.net" }); anch.HRef.Value = @"http://www.fb2epub.net"; p1.Add(anch); pageData.Add(p1); anch = new Anchor(Compatibility); p1 = new Paragraph(Compatibility); anch.Add(new SimpleHTML5Text(Compatibility) { Text = @"https://code.google.com/p/fb2epub/" }); anch.HRef.Value = @"https://code.google.com/p/fb2epub/"; p1.Add(anch); pageData.Add(p1); Content = pageData; }
/// <summary> /// Converts FB2 Stanza element into XHTML representation /// </summary> /// <param name="stanzaItem">item to convert</param> /// <param name="stanzaConverterParams"></param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(StanzaItem stanzaItem, StanzaConverterParamsV3 stanzaConverterParams) { if (stanzaItem == null) { throw new ArgumentNullException("stanzaItem"); } var stanzaSection = new Div(HTMLElementType.HTML5); if (stanzaItem.Title != null) { var titleConverter = new TitleConverterV3(); stanzaSection.Add(titleConverter.Convert(stanzaItem.Title, new TitleConverterParamsV3 { TitleLevel = stanzaConverterParams.Level, Settings = stanzaConverterParams.Settings })); } if (stanzaItem.SubTitle != null) { var subtitleConverter = new SubtitleConverterV3(); stanzaSection.Add(subtitleConverter.Convert(stanzaItem.SubTitle, new SubtitleConverterParamsV3 { Settings = stanzaConverterParams.Settings })); } foreach (var line in stanzaItem.Lines) { var vElementConverter = new VElementConverterV3(); stanzaSection.Add(vElementConverter.Convert(line, new VElementConverterParamsV3 { Settings = stanzaConverterParams.Settings })); } if (stanzaItem.Lang != null) { stanzaSection.GlobalAttributes.Language.Value = stanzaItem.Lang; } SetClassType(stanzaSection, ElementStylesV3.Stanza); return stanzaSection; }
public override void GenerateBody() { base.GenerateBody(); var coverPage = new Div(Compatibility); coverPage.GlobalAttributes.Class.Value = ElementStylesV2.CoverPage; coverPage.Add(_coverImage); BodyElement.Add(coverPage); }
public override void GenerateBody() { base.GenerateBody(); BodyElement.CustomAttributes.Add(new CustomAttribute(EPubNamespaces.OpsNamespace + "type", TitleTypeAttributeValue)); var titlePage = new Div(Compatibility); titlePage.GlobalAttributes.Class.Value = "titlepage"; if (!string.IsNullOrEmpty(BookTitle)) { // try to use FB2 book's title var p = new H2(Compatibility); p.Add(new SimpleHTML5Text(Compatibility) { Text = BookTitle }); string itemClass = string.Format("title{0}", 1); p.GlobalAttributes.Class.Value = itemClass; titlePage.Add(p); } else { titlePage.Add(new SimpleHTML5Text(Compatibility) { Text = "Unnamed" }); } titlePage.Add(new EmptyLine(Compatibility)); var sbSeries = new StringBuilder(); foreach (var serie in _series) { if (!string.IsNullOrEmpty(sbSeries.ToString())) { sbSeries.Append(" , "); } sbSeries.Append(serie); } if (sbSeries.ToString() != string.Empty) { var seriesItem = new SimpleHTML5Text(Compatibility) { Text = string.Format("( {0} )", sbSeries) }; var containingText = new EmphasisedText(Compatibility); containingText.Add(seriesItem); var seriesHeading = new H3(Compatibility); seriesHeading.GlobalAttributes.Class.Value = "title_series"; seriesHeading.Add(containingText); titlePage.Add(seriesHeading); } foreach (var author in _authors) { var authorsHeading = new H3(Compatibility); var authorLine = new SimpleHTML5Text(Compatibility) { Text = author }; authorsHeading.Add(authorLine); authorsHeading.GlobalAttributes.Class.Value = "title_authors"; titlePage.Add(authorsHeading); } BodyElement.Add(titlePage); }
/// <summary> /// Converts FB2 annotation element /// </summary> /// <param name="annotationItem">item to convert</param> /// <param name="converterParams"></param> /// <returns>XHTML representation</returns> public HTMLItem Convert(AnnotationType annotationItem, AnnotationConverterParamsV3 converterParams) { if (annotationItem == null) { throw new ArgumentNullException("annotationItem"); } var resAnnotation = new Div(HTMLElementType.HTML5); foreach (var element in annotationItem.Content) { if (element is SubTitleItem) { var subtitleConverter = new SubtitleConverterV3(); resAnnotation.Add(subtitleConverter.Convert(element as SubTitleItem, new SubtitleConverterParamsV3 { Settings = converterParams.Settings })); } else if (element is ParagraphItem) { var paragraphConverter = new ParagraphConverterV3(); resAnnotation.Add(paragraphConverter.Convert(element as ParagraphItem, new ParagraphConverterParamsV3 { Settings = converterParams.Settings, ResultType = ParagraphConvTargetEnumV3.Paragraph, StartSection = false })); } else if (element is PoemItem) { var poemConverter = new PoemConverterV3(); resAnnotation.Add(poemConverter.Convert(element as PoemItem, new PoemConverterParamsV3 { Level = converterParams.Level + 1, Settings = converterParams.Settings })); } else if (element is CiteItem) { var citationConverter = new CitationConverterV3(); resAnnotation.Add(citationConverter.Convert(element as CiteItem, new CitationConverterParamsV3 { Level = converterParams.Level + 1, Settings = converterParams.Settings })); } else if (element is TableItem) { var tableConverter = new TableConverterV3(); resAnnotation.Add(tableConverter.Convert(element as TableItem, new TableConverterParamsV3 { Settings = converterParams.Settings } )); } else if (element is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV3(); resAnnotation.Add(emptyLineConverter.Convert()); } } resAnnotation.GlobalAttributes.ID.Value = converterParams.Settings.ReferencesManager.AddIdUsed(annotationItem.ID, resAnnotation); SetClassType(resAnnotation, ElementStylesV3.Annotation); return resAnnotation; }
public override void GenerateBody() { base.GenerateBody(); var titlePage = new Div(Compatibility); titlePage.GlobalAttributes.Class.Value = ElementStylesV3.TitlePage; if (!string.IsNullOrEmpty(BookTitle)) { // try to use FB2 book's title var p = new H2(Compatibility); p.Add(new SimpleHTML5Text(Compatibility) { Text = BookTitle }); p.GlobalAttributes.Class.Value = string.Format(ElementStylesV3.TitleItemFormat, 1); titlePage.Add(p); } else { titlePage.Add(new SimpleHTML5Text(Compatibility) { Text = "Unnamed" }); } titlePage.Add(new EmptyLine(Compatibility)); var sbSeries = new StringBuilder(); foreach (var serie in _series) { if (!string.IsNullOrEmpty(sbSeries.ToString())) { sbSeries.Append(" , "); } sbSeries.Append(serie); } if (sbSeries.ToString() != string.Empty) { var seriesItem = new SimpleHTML5Text(Compatibility) { Text = string.Format("( {0} )", sbSeries) }; var containingText = new EmphasisedText(Compatibility); containingText.Add(seriesItem); var seriesHeading = new H3(Compatibility); seriesHeading.GlobalAttributes.Class.Value = ElementStylesV3.TitleSeries; seriesHeading.Add(containingText); titlePage.Add(seriesHeading); } foreach (var author in _authors) { var authorsHeading = new H3(Compatibility); var authorLine = new SimpleHTML5Text(Compatibility) { Text = author }; authorsHeading.Add(authorLine); authorsHeading.GlobalAttributes.Class.Value = ElementStylesV3.TitleAuthors; titlePage.Add(authorsHeading); } BodyElement.Add(titlePage); }
/// <summary> /// Convert epigraph author FB2 element /// </summary> /// <param name="textAuthorItem">item to convert</param> /// <param name="epigraphAuthorConverterParams"></param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(TextAuthorItem textAuthorItem, EpigraphAuthorConverterParamsV3 epigraphAuthorConverterParams) { if (textAuthorItem == null) { throw new ArgumentNullException("textAuthorItem"); } var epigraphAuthor = new Div(HTMLElementType.HTML5); var paragraphConverter = new ParagraphConverterV3(); epigraphAuthor.Add(paragraphConverter.Convert(textAuthorItem, new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphAuthorConverterParams.Settings, StartSection = false })); SetClassType(epigraphAuthor, ElementStylesV3.EpigraphAuthor); return epigraphAuthor; }
/// <summary> /// Converts FB2 citation author element /// </summary> /// <param name="paragraphItem">item to convert</param> /// <param name="citationAuthorConverterParams"></param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(ParagraphItem paragraphItem, CitationAuthorConverterParamsV2 citationAuthorConverterParams) { if (paragraphItem == null) { throw new ArgumentNullException("paragraphItem"); } var cite = new Div(HTMLElementType.XHTML11); var paragraphConverter = new ParagraphConverterV2(); cite.Add(paragraphConverter.Convert(paragraphItem, new ParagraphConverterParamsV2 {Settings =citationAuthorConverterParams.Settings, ResultType = ParagraphConvTargetEnumV2.Paragraph, StartSection = false})); SetClassType(cite, ElementStylesV2.CitationAuthor); return cite; }
/// <summary> /// Converts FB2 epigraph element /// </summary> /// <param name="epigraphItem"></param> /// <param name="epigraphConverterParams"></param> /// <returns>XHTML representation</returns> public Div Convert(EpigraphItem epigraphItem, EpigraphConverterParamsV3 epigraphConverterParams) { if (epigraphItem == null) { throw new ArgumentNullException("epigraphItem"); } var content = new Div(HTMLElementType.HTML5); foreach (var element in epigraphItem.EpigraphData) { if (element is ParagraphItem) { var paragraphConverter = new ParagraphConverterV3(); content.Add(paragraphConverter.Convert(element as ParagraphItem, new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphConverterParams.Settings, StartSection = false })); } if (element is PoemItem) { var poemConverter = new PoemConverterV3(); content.Add(poemConverter.Convert(element as PoemItem, new PoemConverterParamsV3 { Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings } )); } if (element is CiteItem) { var citationConverter = new CitationConverterV3(); content.Add(citationConverter.Convert(element as CiteItem, new CitationConverterParamsV3 { Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings })); } if (element is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV3(); content.Add(emptyLineConverter.Convert()); } } foreach (var author in epigraphItem.TextAuthors) { var epigraphAuthorConverter = new EpigraphAuthorConverterV3(); content.Add(epigraphAuthorConverter.Convert(author as TextAuthorItem, new EpigraphAuthorConverterParamsV3 { Settings = epigraphConverterParams.Settings })); } SetClassType(content, ElementStylesV3.Epigraph); content.GlobalAttributes.ID.Value = epigraphConverterParams.Settings.ReferencesManager.AddIdUsed(epigraphItem.ID, content); return content; }
public override void GenerateBody() { base.GenerateBody(); var annotationPage = new Div(Compatibility); annotationPage.GlobalAttributes.Class.Value = "annotation"; if (BookAnnotation != null) { foreach (var item in BookAnnotation.SubElements()) { annotationPage.Add(item); } } else { annotationPage.Add(new SimpleHTML5Text(Compatibility) { Text = "Unnamed" }); } annotationPage.Add(new EmptyLine(Compatibility)); BodyElement.Add(annotationPage); }
private ulong ConvertSimpleSubItem(IFb2TextItem item, SectionItem sectionItem, Div content, List<IHTMLItem> resList, ref bool startSection, ulong documentSize) { ulong docSize = documentSize; IHTMLItem newItem = null; var subtitleItem = item as SubTitleItem; if (subtitleItem != null) { var subtitleConverter = new SubtitleConverterV3(); newItem = subtitleConverter.Convert(subtitleItem, new SubtitleConverterParamsV3 { Settings = Settings }); } else if (item is ParagraphItem) { var paragraphConverter = new ParagraphConverterV3(); newItem = paragraphConverter.Convert((ParagraphItem) item, new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, StartSection = startSection, Settings = Settings }); startSection = false; } else if (item is PoemItem) { var poemConverter = new PoemConverterV3(); newItem = poemConverter.Convert((PoemItem) item, new PoemConverterParamsV3 { Settings = Settings, Level = RecursionLevel + 1 }); } else if (item is CiteItem) { var citationConverter = new CitationConverterV3(); newItem = citationConverter.Convert((CiteItem) item, new CitationConverterParamsV3 { Level = RecursionLevel + 1, Settings = Settings }); } else if (item is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV3(); newItem = emptyLineConverter.Convert(); } else if (item is TableItem) { var tableConverter = new TableConverterV3(); newItem = tableConverter.Convert((TableItem) item, new TableConverterParamsV3 { Settings = Settings }); } else if ((item is ImageItem) && Settings.Images.HasRealImages()) { var fb2Img = item as ImageItem; // if it's not section image and it's used if ((sectionItem.SectionImages.Find(x => x == fb2Img) == null) && (fb2Img.HRef != null)) { if (Settings.Images.IsImageIdReal(fb2Img.HRef)) { var enclosing = new Div(HTMLElementType.HTML5); // we use the enclosing so the user can style center it var imageConverter = new ImageConverterV3(); enclosing.Add(imageConverter.Convert(fb2Img, new ImageConverterParamsV3 { Settings = Settings })); SetClassType(enclosing, ElementStylesV3.NormalImage); newItem = enclosing; } } } if (newItem != null) { docSize = SplitBlockHTMLItem(newItem, content, resList, docSize); } return docSize; }
private ulong ConvertSectionImage(ImageItem sectionImage, Div content, IList<IHTMLItem> resList, ulong documentSize) { ulong docSize = documentSize; if (sectionImage.HRef != null) { if (Settings.Images.IsImageIdReal(sectionImage.HRef)) { var container = new Div(HTMLElementType.HTML5); var sectionImagemage = new Image(HTMLElementType.HTML5); sectionImagemage.Alt.Value = sectionImage.AltText ?? string.Empty; sectionImagemage.Source.Value = Settings.ReferencesManager.AddImageRefferenced(sectionImage, sectionImagemage); sectionImagemage.GlobalAttributes.ID.Value = Settings.ReferencesManager.AddIdUsed(sectionImage.ID, sectionImagemage); if (sectionImage.Title != null) { sectionImagemage.GlobalAttributes.Title.Value = sectionImage.Title; } SetClassType(container, ElementStylesV3.SectionImage); container.Add(sectionImagemage); ulong itemSize = container.EstimateSize(); if (_checker.ExceedSizeLimit(documentSize + itemSize)) { var oldContent = content; resList.Add(content); content = new Div(HTMLElementType.HTML5); content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value; content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value; docSize = 0; } docSize += itemSize; content.Add(container); Settings.Images.ImageIdUsed(sectionImage.HRef); } } return docSize; }
protected virtual void GenerateFootnotes() { if (_footnotes.Any()) { var group = new Div(Compatibility); EPubV3VocabularyStyles groupStyles = new EPubV3VocabularyStyles(); groupStyles.SetType(EpubV3Vocabulary.FootNotes); group.CustomAttributes.Add(groupStyles.GetAsCustomAttribute()); foreach (var footnote in _footnotes) { var aside = new Aside(Compatibility); aside.GlobalAttributes.ID.Value = footnote.Key; aside.GlobalAttributes.Class.Value = ElementStylesV3.Footnote; EPubV3VocabularyStyles attributeStyles = new EPubV3VocabularyStyles(); attributeStyles.SetType(EpubV3Vocabulary.FootNote); aside.CustomAttributes.Add(attributeStyles.GetAsCustomAttribute()); aside.Add(footnote.Value); group.Add(aside); } BodyElement.Add(group); } }
public List<BaseXHTMLFileV2> Split() { var list = new List<BaseXHTMLFileV2>(); BaseXHTMLFileV2 newDoc = null; var listToRemove = new List<IHTMLItem>(); ulong totlaSize = 0; IHTMLItem oldContent = _content; var newContent = new Div(Compatibility); if (_content != null) { foreach (var subElement in _content.SubElements()) { ulong itemSize = EstimateSize(subElement); if (totlaSize + itemSize > MaxSize) { Content = newContent; newDoc = new BaseXHTMLFileV2() { Content = oldContent, PageTitle = InternalPageTitle, NotPartOfNavigation = true, }; newDoc.StyleFiles.AddRange(StyleFiles); newDoc.GuideRole = GuideRole; newDoc.NavigationParent = NavigationParent; break; } if (itemSize <= MaxSize) { totlaSize += itemSize; newContent.Add(subElement); } listToRemove.Add(subElement); } foreach (var item in listToRemove) { oldContent.Remove(item); } if (newDoc != null) { list.Add(newDoc); if (EstimateSize(newDoc.Content) > MaxSize) { if ((newDoc.Content.SubElements() != null) && (newDoc.Content.SubElements().Count > 1)) // in case we have only one sub-element we can't split { var subList = newDoc.Split(); list.AddRange(subList); list.Remove(newDoc); } else { if (newDoc.Content.SubElements()[0] is Paragraph) // in case element we about to split is paragraph { List<BaseXHTMLFileV2> subList = SplitParagraph(newDoc.Content.SubElements()[0] as Paragraph); list.AddRange(subList); } else if (newDoc.Content.SubElements()[0] is Div) { newDoc.Content = newDoc.Content.SubElements()[0]; List<BaseXHTMLFileV2> subList = newDoc.Split(); list.AddRange(subList); } } } } } return list; }
/// <summary> /// Convert poem FB2 element /// </summary> /// <param name="poemItem">item to convert</param> /// <param name="poemConverterParams"></param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(PoemItem poemItem, PoemConverterParamsV3 poemConverterParams) { if (poemItem == null) { throw new ArgumentNullException("poemItem"); } var poemContent = new Div(HTMLElementType.HTML5); if (poemItem.Title != null) { var titleConverter = new PoemTitleConverterV3(); poemContent.Add(titleConverter.Convert(poemItem.Title, new TitleConverterParamsV3 { TitleLevel = poemConverterParams.Level, Settings = poemConverterParams.Settings })); } foreach (var epigraph in poemItem.Epigraphs) { var epigraphConverter = new PoemEpigraphConverterV3(); poemContent.Add(epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV3 { Level = poemConverterParams.Level + 1, Settings = poemConverterParams.Settings } )); } foreach (var poemElement in poemItem.Content) { if (poemElement is StanzaItem) { var stanzaConverter = new StanzaConverterV3(); poemContent.Add(stanzaConverter.Convert(poemElement as StanzaItem, new StanzaConverterParamsV3 { Level = poemConverterParams.Level + 1, Settings = poemConverterParams.Settings })); } else if (poemElement is SubTitleItem) { var subtitleConverter = new PoemSubtitleConverterV3(); poemContent.Add(subtitleConverter.Convert(poemElement as SubTitleItem, new SubtitleConverterParamsV3 { Settings = poemConverterParams.Settings })); } } foreach (var author in poemItem.Authors) { var poemAuthorConverter = new PoemAuthorConverterV3(); poemContent.Add(poemAuthorConverter.Convert(author, new PoemAuthorConverterParamsV3 { Settings = poemConverterParams.Settings })); } if (poemItem.Date != null) { var poemDateConverter = new PoemDateConverterV3(); poemContent.Add(poemDateConverter.Convert(poemItem.Date)); } poemContent.GlobalAttributes.ID.Value = poemConverterParams.Settings.ReferencesManager.AddIdUsed(poemItem.ID, poemContent); if (poemItem.Lang != null) { poemContent.GlobalAttributes.Language.Value = poemItem.Lang; } SetClassType(poemContent, ElementStylesV3.Poem); return poemContent; }
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; }
/// <summary> /// Convert FB2 citation element /// </summary> /// <param name="citeItem">item to convert</param> /// <param name="citationConverterParams"></param> /// <returns>XHTML representation</returns> public Div Convert(CiteItem citeItem, CitationConverterParamsV2 citationConverterParams) { if (citeItem == null) { throw new ArgumentNullException("citeItem"); } if (citationConverterParams == null) { throw new ArgumentNullException("citationConverterParams"); } var citation = new Div(HTMLElementType.XHTML11); foreach (var item in citeItem.CiteData) { if (item is SubTitleItem) { var subtitleConverter = new SubtitleConverterV2(); citation.Add(subtitleConverter.Convert(item as SubTitleItem, new SubtitleConverterParamsV2 { Settings = citationConverterParams.Settings})); } else if (item is ParagraphItem) { var paragraphConverter = new ParagraphConverterV2(); citation.Add(paragraphConverter.Convert(item as ParagraphItem, new ParagraphConverterParamsV2 { ResultType = ParagraphConvTargetEnumV2.Paragraph, Settings = citationConverterParams.Settings, StartSection = false})); } else if (item is PoemItem) { var poemConverter = new PoemConverterV2(); citation.Add(poemConverter.Convert(item as PoemItem, new PoemConverterParamsV2 { Settings = citationConverterParams.Settings, Level = citationConverterParams.Level + 1 } )); } else if (item is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV2(); citation.Add(emptyLineConverter.Convert()); } else if (item is TableItem) { var tableConverter = new TableConverterV2(); citation.Add(tableConverter.Convert(item as TableItem, new TableConverterParamsV2 { Settings = citationConverterParams.Settings})); } } foreach (var author in citeItem.TextAuthors) { var citationAuthorConverter = new CitationAuthorConverterV2(); citation.Add(citationAuthorConverter.Convert(author,new CitationAuthorConverterParamsV2 { Settings = citationConverterParams.Settings})); } citation.GlobalAttributes.ID.Value = citationConverterParams.Settings.ReferencesManager.AddIdUsed(citeItem.ID, citation); if (citeItem.Lang != null) { citation.GlobalAttributes.Language.Value = citeItem.Lang; } SetClassType(citation, ElementStylesV2.Citation); return citation; }
private ulong SplitSimpleHTMLItem(IHTMLItem splitedItem, Div content, IList<IHTMLItem> resList, ulong documentSize) { ulong docSize = documentSize; ulong itemSize = splitedItem.EstimateSize(); if (_checker.ExceedSizeLimit(documentSize + itemSize)) { var oldContent = content; resList.Add(content); content = new Div(HTMLElementType.HTML5); content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value; content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value; docSize = 0; } if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document { docSize += itemSize; content.Add(splitedItem); } return docSize; }
private ulong SplitBlockHTMLItem(IHTMLItem item, Div content, IList<IHTMLItem> resList, ulong documentSize) { ulong docSize = documentSize; ulong itemSize = item.EstimateSize(); if (_checker.ExceedSizeLimit(documentSize + itemSize)) { var oldContent = content; resList.Add(content); content = new Div(HTMLElementType.HTML5); content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value; content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value; docSize = 0; } if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document { docSize += itemSize; content.Add(item); } else { var div = item as Div; if (div != null) // if the item that bigger than max size is Div block { foreach (var splitedItem in SplitDiv(div, documentSize)) { documentSize = SplitSimpleHTMLItem(splitedItem, content, resList, documentSize); } } } return docSize; }
private IEnumerable<IHTMLItem> SplitDiv(Div div, ulong documentSize) { var resList = new List<IHTMLItem>(); ulong newDocumentSize = documentSize; var container = new Div(HTMLElementType.HTML5); container.GlobalAttributes.ID.Value = div.GlobalAttributes.ID.Value; foreach (var element in div.SubElements()) { ulong elementSize = element.EstimateSize(); if (_checker.ExceedSizeLimit(elementSize + newDocumentSize)) { resList.Add(container); container = new Div(HTMLElementType.HTML5); container.GlobalAttributes.Class.Value = div.GlobalAttributes.Class.Value; container.GlobalAttributes.Language.Value = div.GlobalAttributes.Language.Value; newDocumentSize = 0; } if (!_checker.ExceedSizeLimit(elementSize)) { container.Add(element); newDocumentSize += elementSize; } } resList.Add(container); return resList; }
public void Convert(EPubFileV2 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); 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 })); epubFile.AddXHTMLFile(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) }; 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 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) }; epubFile.AddXHTMLFile(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 })); epubFile.AddXHTMLFile(mainDocument); } 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> /// Converts FB2 section element /// </summary> /// <param name="sectionItem">item to convert</param> /// <returns>XHTML representation</returns> public List<IHTMLItem> Convert(SectionItem sectionItem) { if (sectionItem == null) { throw new ArgumentNullException("sectionItem"); } var resList = new List<IHTMLItem>(); Logger.Log.Debug("Converting section"); var content = new Div(HTMLElementType.HTML5); ulong documentSize = 0; _checker.MaxSizeLimit = Settings.MaxSize; SetClassType(content, string.Format(ElementStylesV3.SectionItemFormat, RecursionLevel)); content.GlobalAttributes.ID.Value = Settings.ReferencesManager.AddIdUsed(sectionItem.ID, content); if (sectionItem.Lang != null) { content.GlobalAttributes.Language.Value = sectionItem.Lang; } // Load Title if (sectionItem.Title != null) { IHTMLItem titleItem; if (!LinkSection) { var titleConverter = new TitleConverterV3(); titleItem = titleConverter.Convert(sectionItem.Title, new TitleConverterParamsV3 { Settings = Settings, TitleLevel = RecursionLevel + 1 }); } else { var linkSectionConverter = new LinkSectionConverterV3(); titleItem = linkSectionConverter.Convert(sectionItem, new LinkSectionConverterParamsV3 { Settings = Settings }); } if (titleItem != null) { documentSize = SplitBlockHTMLItem(titleItem,content,resList,documentSize); } } // Load epigraphs documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV3() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV3 {Settings = Settings, Level = RecursionLevel + 1})).Aggregate(documentSize, (current, epigraphItem) => SplitBlockHTMLItem(epigraphItem, content, resList, current)); // Load section image if (Settings.Images.HasRealImages()) { documentSize = sectionItem.SectionImages.Aggregate(documentSize, (current, sectionImage) => ConvertSectionImage(sectionImage, content, resList, current)); } // Load annotations if (sectionItem.Annotation != null) { var annotationConverter = new AnnotationConverterV3(); IHTMLItem annotationItem = annotationConverter.Convert(sectionItem.Annotation, new AnnotationConverterParamsV3 { Level = RecursionLevel + 1, Settings = Settings }); documentSize = SplitBlockHTMLItem(annotationItem, content, resList, documentSize); } // Parse all elements only if section has no sub section if (sectionItem.SubSections.Count == 0) { bool startSection = true; sectionItem.Content.Aggregate(documentSize, (current, item) => ConvertSimpleSubItem(item, sectionItem, content, resList, ref startSection, current)); } resList.Add(content); return resList; }
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); } }