Exemplo n.º 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, 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;
        }
 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;
 }
        /// <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, CitationConverterParamsV3 citationConverterParams)
        {
            if (citeItem == null)
            {
                throw new ArgumentNullException("citeItem");
            }

            if (citationConverterParams == null)
            {
                throw new ArgumentNullException("citationConverterParams");
            }

            var citation = new Div(HTMLElementType.HTML5);
            foreach (var item in citeItem.CiteData)
            {
                if (item is SubTitleItem)
                {
                    var subtitleConverter = new SubtitleConverterV3();
                    citation.Add(subtitleConverter.Convert(item as SubTitleItem,
                        new SubtitleConverterParamsV3 { Settings = citationConverterParams.Settings }));
                }
                else if (item is ParagraphItem)
                {
                    var paragraphConverter = new ParagraphConverterV3();
                    citation.Add(paragraphConverter.Convert(item as ParagraphItem,
                        new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = citationConverterParams.Settings, StartSection = false }));
                }
                else if (item is PoemItem)
                {
                    var poemConverter = new PoemConverterV3();
                    citation.Add(poemConverter.Convert(item as PoemItem,
                        new PoemConverterParamsV3 { Settings = citationConverterParams.Settings, Level = citationConverterParams.Level + 1 }
                        ));
                }
                else if (item is EmptyLineItem)
                {
                    var emptyLineConverter = new EmptyLineConverterV3();
                    citation.Add(emptyLineConverter.Convert());
                }
                else if (item is TableItem)
                {
                    var tableConverter = new TableConverterV3();
                    citation.Add(tableConverter.Convert(item as TableItem,
                        new TableConverterParamsV3 { Settings = citationConverterParams.Settings }));
                }
            }

            foreach (var author in citeItem.TextAuthors)
            {
                var citationAuthorConverter = new CitationAuthorConverterV3();
                citation.Add(citationAuthorConverter.Convert(author, new CitationAuthorConverterParamsV3 { 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, ElementStylesV3.Citation);
            return citation;
        }