Пример #1
0
        /// <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,AnnotationConverterParamsV2 converterParams)
        {
            if (annotationItem == null)
            {
                throw new ArgumentNullException("annotationItem");
            }
            var resAnnotation = new Div(HTMLElementType.XHTML11);

            foreach (var element in annotationItem.Content)
            {
                if (element is SubTitleItem)
                {
                    var subtitleConverter = new SubtitleConverterV2();
                    resAnnotation.Add(subtitleConverter.Convert(element as SubTitleItem,
                        new SubtitleConverterParamsV2{Settings = converterParams.Settings}));
                }
                else if (element is ParagraphItem)
                {
                    var paragraphConverter = new ParagraphConverterV2();
                    resAnnotation.Add(paragraphConverter.Convert(element as ParagraphItem,
                        new ParagraphConverterParamsV2{ Settings = converterParams.Settings,ResultType = ParagraphConvTargetEnumV2.Paragraph, StartSection = false}));
                }
                else if (element is PoemItem)
                {
                    var poemConverter = new PoemConverterV2();
                    resAnnotation.Add(poemConverter.Convert(element as PoemItem,
                        new PoemConverterParamsV2 { Level = converterParams.Level + 1, Settings = converterParams.Settings}));
                }
                else if (element is CiteItem)
                {
                    var citationConverter = new CitationConverterV2();
                    resAnnotation.Add(citationConverter.Convert(element as CiteItem,
                        new CitationConverterParamsV2 {Level = converterParams.Level + 1,Settings = converterParams.Settings}));
                }
                else if (element is TableItem)
                {
                    var tableConverter = new TableConverterV2();
                    resAnnotation.Add(tableConverter.Convert(element as TableItem,
                        new TableConverterParamsV2 { Settings = converterParams.Settings}
                        ));
                }
                else if (element is EmptyLineItem)
                {
                    var emptyLineConverter = new EmptyLineConverterV2();
                    resAnnotation.Add(emptyLineConverter.Convert());
                }
            }

            resAnnotation.GlobalAttributes.ID.Value = converterParams.Settings.ReferencesManager.AddIdUsed(annotationItem.ID, resAnnotation);

            SetClassType(resAnnotation, ElementStylesV2.Annotation);
            return resAnnotation;
        }
Пример #2
0
        /// <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 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;
 }