Example #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;
        }
 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;
 }
Example #3
0
        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);
        }
        /// <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);
        }