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 ConvertSimpleSubItem(IFb2TextItem item, SectionItem sectionItem, Div content, List <IHTMLItem> resList, ref bool startSection, ulong documentSize) { ulong docSize = documentSize; IHTMLItem newItem = null; if (item is SubTitleItem) { var subtitleConverter = new SubtitleConverterV2(); newItem = subtitleConverter.Convert((SubTitleItem)item, new SubtitleConverterParamsV2 { Settings = Settings }); } else if (item is ParagraphItem) { var paragraphConverter = new ParagraphConverterV2(); newItem = paragraphConverter.Convert((ParagraphItem)item, new ParagraphConverterParamsV2 { ResultType = ParagraphConvTargetEnumV2.Paragraph, StartSection = startSection, Settings = Settings }); startSection = false; } else if (item is PoemItem) { var poemConverter = new PoemConverterV2(); newItem = poemConverter.Convert((PoemItem)item, new PoemConverterParamsV2 { Settings = Settings, Level = RecursionLevel + 1 }); } else if (item is CiteItem) { var citationConverter = new CitationConverterV2(); newItem = citationConverter.Convert(item as CiteItem, new CitationConverterParamsV2 { Level = RecursionLevel + 1, Settings = Settings }); } else if (item is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV2(); newItem = emptyLineConverter.Convert(); } else if (item is TableItem) { var tableConverter = new TableConverterV2(); newItem = tableConverter.Convert((TableItem)item, new TableConverterParamsV2 { Settings = Settings }); } else if ((item is ImageItem) && Settings.Images.HasRealImages()) { var fb2Img = (ImageItem)item; // 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.XHTML11); // we use the enclosing so the user can style center it var imageConverter = new ImageConverterV2(); enclosing.Add(imageConverter.Convert(fb2Img, new ImageConverterParamsV2 { Settings = Settings })); SetClassType(enclosing, ElementStylesV2.NormalImage); newItem = enclosing; } } } if (newItem != null) { docSize = SplitBlockHTMLItem(newItem, content, resList, docSize); } return(docSize); }
private static void PrepareTextItem(IFb2TextItem textItem, FB2File file, List <ILine> lines, string bodyName, int headerLevel) { switch (textItem) { case CiteItem citeItem: var cite = new Epigraph(); PrepareTextItems(citeItem.CiteData, file, cite.Texts, bodyName, headerLevel); PrepareTextItems(citeItem.TextAuthors, file, cite.Authors, bodyName, headerLevel); lines.Add(cite); return; case PoemItem poemItem: { AddTitle(poemItem.Title, lines, poemItem.ID, headerLevel); PrepareTextItems(poemItem.Epigraphs, file, lines, bodyName, headerLevel + 1); PrepareTextItems(poemItem.Content, file, lines, bodyName, headerLevel + 1); return; } case SectionItem sectionItem: { if (bodyName == "notes") { var note = new NoteLine { Id = sectionItem.ID }; AddTitle(sectionItem.Title, note.Titles, sectionItem.ID, headerLevel); PrepareTextItems(sectionItem.Content, file, note.Texts, bodyName, headerLevel); lines.Add(note); } else { AddTitle(sectionItem.Title, lines, sectionItem.ID, headerLevel); PrepareTextItems(sectionItem.Epigraphs, file, lines, bodyName, headerLevel + 1); PrepareTextItems(sectionItem.Content, file, lines, bodyName, headerLevel + 1); } return; } case StanzaItem stanzaItem: { AddTitle(stanzaItem.Title, lines, string.Empty, headerLevel); PrepareTextItems(stanzaItem.Lines, file, lines, bodyName, headerLevel + 1); return; } case SimpleText text: { lines.Add(text.ToHtml().ToTextLine()); break; } case EmptyLineItem empty: { lines.Add(empty.ToString().ToTextLine()); break; } case TitleItem title: { AddTitle(title, lines, string.Empty, headerLevel + 1); break; } case SubTitleItem _: case ParagraphItem _: { var sb = new StringBuilder(); foreach (var paragraphData in ((ParagraphItem)textItem).ParagraphData) { sb.Append(paragraphData.ToHtml()); } lines.Add(sb.ToString().ToTextLine()); return; } case ImageItem imageItem: { var key = imageItem.HRef.Replace("#", string.Empty); if (file.Images.TryGetValue(key, out var image)) { lines.Add(image.ToImageLine(imageItem.ID)); } return; } case DateItem item: lines.Add(item.DateValue.ToString().ToTextLine()); return; case EpigraphItem epigraphItem: { var epigraph = new Epigraph(); PrepareTextItems(epigraphItem.EpigraphData, file, epigraph.Texts, bodyName, headerLevel); PrepareTextItems(epigraphItem.TextAuthors, file, epigraph.Authors, bodyName, headerLevel); lines.Add(epigraph); return; } default: throw new Exception(textItem.GetType().ToString()); } }
private static void AppendIFb2TextItem(IFb2TextItem item, int depth, List<AbstractTextPart> appendTo) { SectionItem sectionItem = item as SectionItem; if (sectionItem != null) { AppendSectionItem(sectionItem, depth + 1, appendTo); return; } ParagraphItem paragraphItem = item as ParagraphItem; if (paragraphItem != null) { AppendParagraphItem(appendTo, paragraphItem); return; } if (item is EmptyLineItem) { appendTo.Add(SimpleText.EmptyParagraph); return; } throw new NotImplementedException(); }
//record book strings to dictionary for read public virtual void PrepareTextItem(IFb2TextItem textItem) { if (textItem is CiteItem) { PrepareTextItems(((CiteItem)textItem).CiteData); return; } if (textItem is PoemItem) { var item = (PoemItem)textItem; AddTitle(item.Title); PrepareTextItems(item.Content); return; } if (textItem is SectionItem) { var item = (SectionItem)textItem; AddTitle(item.Title); PrepareTextItems(item.Content); return; } if (textItem is StanzaItem) { var item = (StanzaItem)textItem; AddTitle(item.Title); PrepareTextItems(item.Lines); return; } if (textItem is ParagraphItem || textItem is EmptyLineItem || textItem is TitleItem || textItem is SimpleText) { BookText.Add(textItem.ToString()); return; } if (textItem is ImageItem) { var item = (ImageItem)textItem; var key = item.HRef.Replace("#", string.Empty); if (Book.Images.ContainsKey(key)) { var data = Book.Images[key].BinaryData; Images = data; } return; } if (textItem is DateItem) { BookText.Add(((DateItem)textItem).DateValue.ToString()); return; } if (textItem is EpigraphItem) { var item = (EpigraphItem)textItem; PrepareTextItems(item.EpigraphData); return; } throw new Exception(textItem.GetType().ToString()); }