Пример #1
0
        /// <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, TitleConverterParamsV3 titleConverterParams)
        {
            if (titleItem == null)
            {
                throw new ArgumentNullException("titleItem");
            }
            _level = titleConverterParams.TitleLevel;
            var title = new Div(HTMLElementType.HTML5);

            foreach (var fb2TextItem in titleItem.TitleData)
            {
                if (fb2TextItem is ParagraphItem)
                {
                    var paragraphStyle     = GetParagraphStyleByLevel(_level);
                    var paragraphConverter = new ParagraphConverterV3();
                    title.Add(paragraphConverter.Convert(fb2TextItem as ParagraphItem,
                                                         new ParagraphConverterParamsV3 {
                        ResultType = paragraphStyle, Settings = titleConverterParams.Settings, StartSection = false
                    }));
                }
                else if (fb2TextItem is EmptyLineItem)
                {
                    var emptyLineConverter = new EmptyLineConverterV3();
                    title.Add(emptyLineConverter.Convert());
                }
                else
                {
                    Debug.WriteLine("invalid type in Title - {0}", fb2TextItem.GetType());
                }
            }
            SetClassType(title, string.Format(ElementStylesV3.TitleItemFormat, _level));
            return(title);
        }
Пример #2
0
 /// <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, TitleConverterParamsV3 titleConverterParams)
 {
     if (titleItem == null)
     {
         throw new ArgumentNullException("titleItem");
     }
     _level = titleConverterParams.TitleLevel;
     var title = new Div(HTMLElementType.HTML5);
     foreach (var fb2TextItem in titleItem.TitleData)
     {
         if (fb2TextItem is ParagraphItem)
         {
             var paragraphStyle = GetParagraphStyleByLevel(_level);
             var paragraphConverter = new ParagraphConverterV3();
             title.Add(paragraphConverter.Convert(fb2TextItem as ParagraphItem,
                 new ParagraphConverterParamsV3 { ResultType = paragraphStyle, Settings = titleConverterParams.Settings, StartSection = false }));
         }
         else if (fb2TextItem is EmptyLineItem)
         {
             var emptyLineConverter = new EmptyLineConverterV3();
             title.Add(emptyLineConverter.Convert());
         }
         else
         {
             Debug.WriteLine("invalid type in Title - {0}", fb2TextItem.GetType());
         }
     }
     SetClassType(title, string.Format(ElementStylesV3.TitleItemFormat, _level));
     return title;
 }
Пример #3
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;
        }
        /// <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, CitationAuthorConverterParamsV3 citationAuthorConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var cite = new Div(HTMLElementType.HTML5);

            var paragraphConverter = new ParagraphConverterV3();
            cite.Add(paragraphConverter.Convert(paragraphItem,
                new ParagraphConverterParamsV3 { Settings = citationAuthorConverterParams.Settings, ResultType = ParagraphConvTargetEnumV3.Paragraph, StartSection = false }));

            SetClassType(cite, ElementStylesV3.CitationAuthor);
            return cite;
        }
        /// <summary>
        /// Converts FB2 subtitle element into XHTML representation
        /// </summary>
        /// <param name="subtitleItem">item to convert</param>
        /// <param name="subtitleConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(SubTitleItem subtitleItem, SubtitleConverterParamsV3 subtitleConverterParams)
        {
            if (subtitleItem == null)
            {
                throw new ArgumentNullException("subtitleItem");
            }
            //Div subtitle = new Div();
            var paragraphConverter = new ParagraphConverterV3();
            var internalData = paragraphConverter.Convert(subtitleItem,
                new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = subtitleConverterParams.Settings, StartSection = false });
            SetClassType(internalData, ElementStylesV3.SubTitle);
            //subtitle.Add(internalData);

            //SetClassType(subtitle);
            //return subtitle;
            return internalData;
        }
        /// <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, CitationAuthorConverterParamsV3 citationAuthorConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var cite = new Div(HTMLElementType.HTML5);

            var paragraphConverter = new ParagraphConverterV3();

            cite.Add(paragraphConverter.Convert(paragraphItem,
                                                new ParagraphConverterParamsV3 {
                Settings = citationAuthorConverterParams.Settings, ResultType = ParagraphConvTargetEnumV3.Paragraph, StartSection = false
            }));

            SetClassType(cite, ElementStylesV3.CitationAuthor);
            return(cite);
        }
Пример #7
0
        /// <summary>
        /// Converts FB2 subtitle element into XHTML representation
        /// </summary>
        /// <param name="subtitleItem">item to convert</param>
        /// <param name="subtitleConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(SubTitleItem subtitleItem, SubtitleConverterParamsV3 subtitleConverterParams)
        {
            if (subtitleItem == null)
            {
                throw new ArgumentNullException("subtitleItem");
            }
            //Div subtitle = new Div();
            var paragraphConverter = new ParagraphConverterV3();
            var internalData       = paragraphConverter.Convert(subtitleItem,
                                                                new ParagraphConverterParamsV3 {
                ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = subtitleConverterParams.Settings, StartSection = false
            });

            SetClassType(internalData, ElementStylesV3.SubTitle);
            //subtitle.Add(internalData);

            //SetClassType(subtitle);
            //return subtitle;
            return(internalData);
        }
 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;
        }
Пример #10
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, 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);
        }
Пример #11
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);
        }
Пример #12
0
        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);
        }