Пример #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, ElementStylesV3.PoemTitle);
     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, ElementStylesV3.PoemTitle);
            return(title);
        }
Пример #3
0
        /// <summary>
        /// Converts FB2 epigraph element
        /// </summary>
        /// <param name="epigraphItem"></param>
        /// <param name="epigraphConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public Div Convert(EpigraphItem epigraphItem, EpigraphConverterParamsV3 epigraphConverterParams)
        {
            if (epigraphItem == null)
            {
                throw new ArgumentNullException("epigraphItem");
            }
            var content = new Div(HTMLElementType.HTML5);

            foreach (var element in epigraphItem.EpigraphData)
            {
                if (element is ParagraphItem)
                {
                    var paragraphConverter = new ParagraphConverterV3();
                    content.Add(paragraphConverter.Convert(element as ParagraphItem,
                                                           new ParagraphConverterParamsV3 {
                        ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphConverterParams.Settings, StartSection = false
                    }));
                }
                if (element is PoemItem)
                {
                    var poemConverter = new PoemConverterV3();
                    content.Add(poemConverter.Convert(element as PoemItem,
                                                      new PoemConverterParamsV3 {
                        Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings
                    }
                                                      ));
                }
                if (element is CiteItem)
                {
                    var citationConverter = new CitationConverterV3();
                    content.Add(citationConverter.Convert(element as CiteItem,
                                                          new CitationConverterParamsV3 {
                        Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings
                    }));
                }
                if (element is EmptyLineItem)
                {
                    var emptyLineConverter = new EmptyLineConverterV3();
                    content.Add(emptyLineConverter.Convert());
                }
            }

            foreach (var author in epigraphItem.TextAuthors)
            {
                var epigraphAuthorConverter = new EpigraphAuthorConverterV3();
                content.Add(epigraphAuthorConverter.Convert(author as TextAuthorItem, new EpigraphAuthorConverterParamsV3 {
                    Settings = epigraphConverterParams.Settings
                }));
            }

            SetClassType(content, ElementStylesV3.EpigraphMain);

            content.GlobalAttributes.ID.Value = epigraphConverterParams.Settings.ReferencesManager.AddIdUsed(epigraphItem.ID, content);

            return(content);
        }
 /// <summary>
 /// Convert epigraph author FB2 element
 /// </summary>
 /// <param name="textAuthorItem">item to convert</param>
 /// <param name="epigraphAuthorConverterParams"></param>
 /// <returns>XHTML representation</returns>
 public IHTMLItem Convert(TextAuthorItem textAuthorItem, EpigraphAuthorConverterParamsV3 epigraphAuthorConverterParams)
 {
     if (textAuthorItem == null)
     {
         throw new ArgumentNullException("textAuthorItem");
     }
     var epigraphAuthor = new Div(HTMLElementType.HTML5);
     var paragraphConverter = new ParagraphConverterV3();
     epigraphAuthor.Add(paragraphConverter.Convert(textAuthorItem,
         new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphAuthorConverterParams.Settings, StartSection = false }));
     SetClassType(epigraphAuthor, ElementStylesV3.EpigraphAuthor);
     return epigraphAuthor;
 }
Пример #5
0
        /// <summary>
        /// Converts FB2 poem  author element
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="poemAuthorConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(ParagraphItem paragraphItem, PoemAuthorConverterParamsV3 poemAuthorConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }

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

            SetClassType(item, ElementStylesV3.PoemAuthor);
            return item;
        }
        /// <summary>
        /// Converts FB2 poem  author element
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="poemAuthorConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(ParagraphItem paragraphItem, PoemAuthorConverterParamsV3 poemAuthorConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }

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

            SetClassType(item, ElementStylesV3.PoemAuthor);
            return(item);
        }
        /// <summary>
        /// Converts FB2 epigraph element
        /// </summary>
        /// <param name="epigraphItem"></param>
        /// <param name="epigraphConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public Div Convert(EpigraphItem epigraphItem, EpigraphConverterParamsV3 epigraphConverterParams)
        {
            if (epigraphItem == null)
            {
                throw new ArgumentNullException("epigraphItem");
            }
            var content = new Div(HTMLElementType.HTML5);

            foreach (var element in epigraphItem.EpigraphData)
            {
                if (element is ParagraphItem)
                {
                    var paragraphConverter = new ParagraphConverterV3();
                    content.Add(paragraphConverter.Convert(element as ParagraphItem,
                        new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphConverterParams.Settings, StartSection = false }));
                }
                if (element is PoemItem)
                {
                    var poemConverter = new PoemConverterV3();
                    content.Add(poemConverter.Convert(element as PoemItem,
                        new PoemConverterParamsV3 { Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings }
                        ));
                }
                if (element is CiteItem)
                {
                    var citationConverter = new CitationConverterV3();
                    content.Add(citationConverter.Convert(element as CiteItem,
                        new CitationConverterParamsV3 { Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings }));
                }
                if (element is EmptyLineItem)
                {
                    var emptyLineConverter = new EmptyLineConverterV3();
                    content.Add(emptyLineConverter.Convert());
                }
            }

            foreach (var author in epigraphItem.TextAuthors)
            {
                var epigraphAuthorConverter = new EpigraphAuthorConverterV3();
                content.Add(epigraphAuthorConverter.Convert(author as TextAuthorItem, new EpigraphAuthorConverterParamsV3 { Settings = epigraphConverterParams.Settings }));
            }

            SetClassType(content, ElementStylesV3.Epigraph);

            content.GlobalAttributes.ID.Value = epigraphConverterParams.Settings.ReferencesManager.AddIdUsed(epigraphItem.ID, content);

            return content;
        }
        /// <summary>
        /// Convert epigraph author FB2 element
        /// </summary>
        /// <param name="textAuthorItem">item to convert</param>
        /// <param name="epigraphAuthorConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(TextAuthorItem textAuthorItem, EpigraphAuthorConverterParamsV3 epigraphAuthorConverterParams)
        {
            if (textAuthorItem == null)
            {
                throw new ArgumentNullException("textAuthorItem");
            }
            var epigraphAuthor     = new Div(HTMLElementType.HTML5);
            var paragraphConverter = new ParagraphConverterV3();

            epigraphAuthor.Add(paragraphConverter.Convert(textAuthorItem,
                                                          new ParagraphConverterParamsV3 {
                ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphAuthorConverterParams.Settings, StartSection = false
            }));
            SetClassType(epigraphAuthor, ElementStylesV3.EpigraphAuthor);
            return(epigraphAuthor);
        }
Пример #9
0
        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.PoemSubTitle);
            //subtitle.Add(internalData);

            //SetClassType(subtitle);
            //return subtitle;
            return internalData;
        }
        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.PoemSubTitle);
            //subtitle.Add(internalData);

            //SetClassType(subtitle);
            //return subtitle;
            return(internalData);
        }
Пример #11
0
        /// <summary>
        /// Converts "v" (poem) sub-element
        /// </summary>
        /// <returns>XHTML formatted representation</returns>
        public IHTMLItem Convert(VPoemParagraph paragraphItem, VElementConverterParamsV3 vElementConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var paragraphConverter = new ParagraphConverterV3();
            var item = paragraphConverter.Convert(paragraphItem,
                                                  new ParagraphConverterParamsV3
            {
                ResultType =
                    ParagraphConvTargetEnumV3.Paragraph,
                Settings     = vElementConverterParams.Settings,
                StartSection = false,
            });

            SetClassType(item, ElementStylesV3.VElement);

            //item.ID.Value = Settings.ReferencesManager.AddIdUsed(paragraphItem.ID, item);

            return(item);
        }
Пример #12
0
        /// <summary>
        /// Converts "v" (poem) sub-element
        /// </summary>
        /// <returns>XHTML formatted representation</returns>
        public IHTMLItem Convert(VPoemParagraph paragraphItem, VElementConverterParamsV3 vElementConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var paragraphConverter = new ParagraphConverterV3();
            var item = paragraphConverter.Convert(paragraphItem,
                new ParagraphConverterParamsV3
                {
                    ResultType =
                        ParagraphConvTargetEnumV3.Paragraph,
                    Settings = vElementConverterParams.Settings,
                    StartSection = false,
                });

            SetClassType(item, ElementStylesV3.VElement);

            //item.ID.Value = Settings.ReferencesManager.AddIdUsed(paragraphItem.ID, item);

            return item;
        }
Пример #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tableRowItem"></param>
        /// <param name="rowConverterParams"></param>
        /// <returns></returns>
        public IHTMLItem Convert(TableRowItem tableRowItem, RowConverterParamsV3 rowConverterParams)
        {
            if (tableRowItem == null)
            {
                throw new ArgumentNullException("tableRowItem");
            }
            var tableRow = new TableRow(HTMLElementType.HTML5);

            foreach (var element in tableRowItem.Cells)
            {
                if (element is TableHeadingItem)
                {
                    var th = element as TableHeadingItem;
                    var cell = new TableHeaderCell(HTMLElementType.HTML5);
                    var paragraphConverter = new ParagraphConverterV3();
                    var cellData = paragraphConverter.Convert(th,
                        new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = rowConverterParams.Settings, StartSection = false });
                    if (cellData.SubElements() != null)
                    {
                        foreach (var subElement in cellData.SubElements())
                        {
                            cell.Add(subElement);
                        }
                    }
                    else
                    {
                        cell.Add(cellData);
                    }
                    //cell.Add(new SimpleHTML5Text { Text = th.Text });
                    if (th.ColSpan.HasValue)
                    {
                        cell.ColSpan.Value = th.ColSpan.ToString();
                    }
                    if (th.RowSpan.HasValue)
                    {
                        cell.RowSpan.Value = th.RowSpan.ToString();
                    }
                    switch (th.Align)
                    {
                        case TableAlignmentsEnum.Center:
                            cell.Align.Value = "center";
                            break;
                        case TableAlignmentsEnum.Left:
                            cell.Align.Value = "left";
                            break;
                        case TableAlignmentsEnum.Right:
                            cell.Align.Value = "right";
                            break;
                    }
                    switch (th.VAlign)
                    {
                        case TableVAlignmentsEnum.Top:
                            cell.VAlign.Value = "top";
                            break;
                        case TableVAlignmentsEnum.Middle:
                            cell.VAlign.Value = "middle";
                            break;
                        case TableVAlignmentsEnum.Bottom:
                            cell.VAlign.Value = "bottom";
                            break;
                    }
                    tableRow.Add(cell);
                }
                else if (element is TableCellItem)
                {
                    var td = element as TableCellItem;
                    var cell = new TableData(HTMLElementType.HTML5);
                    var paragraphConverter = new ParagraphConverterV3();
                    var cellData = paragraphConverter.Convert(td,
                        new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = rowConverterParams.Settings, StartSection = false });
                    if (cellData.SubElements() != null)
                    {
                        foreach (var subElement in cellData.SubElements())
                        {
                            cell.Add(subElement);
                        }
                    }
                    else
                    {
                        cell.Add(cellData);
                    }
                    //cell.Add(new SimpleHTML5Text { Text = td.Text });
                    if (td.ColSpan.HasValue)
                    {
                        cell.ColSpan.Value = td.ColSpan.ToString();
                    }
                    if (td.RowSpan.HasValue)
                    {
                        cell.RowSpan.Value = td.RowSpan.ToString();
                    }
                    switch (td.Align)
                    {
                        case TableAlignmentsEnum.Center:
                            cell.Align.Value = "center";
                            break;
                        case TableAlignmentsEnum.Left:
                            cell.Align.Value = "left";
                            break;
                        case TableAlignmentsEnum.Right:
                            cell.Align.Value = "right";
                            break;
                    }
                    switch (td.VAlign)
                    {
                        case TableVAlignmentsEnum.Top:
                            cell.VAlign.Value = "top";
                            break;
                        case TableVAlignmentsEnum.Middle:
                            cell.VAlign.Value = "middle";
                            break;
                        case TableVAlignmentsEnum.Bottom:
                            cell.VAlign.Value = "bottom";
                            break;
                    }
                    tableRow.Add(cell);
                }
                else
                {
                    // invalid structure , we ignore
                    Logger.Log.ErrorFormat("Invalid/unexpected table row sub element type : {0}", element.GetType());
                    //continue;
                }
            }
            tableRow.Align.Value = tableRowItem.Align ?? "left";
            return tableRow;
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableRowItem"></param>
        /// <param name="rowConverterParams"></param>
        /// <returns></returns>
        public IHTMLItem Convert(TableRowItem tableRowItem, RowConverterParamsV3 rowConverterParams)
        {
            if (tableRowItem == null)
            {
                throw new ArgumentNullException("tableRowItem");
            }
            var tableRow = new TableRow(HTMLElementType.HTML5);

            foreach (var element in tableRowItem.Cells)
            {
                if (element is TableHeadingItem)
                {
                    var th   = element as TableHeadingItem;
                    var cell = new TableHeaderCell(HTMLElementType.HTML5);
                    var paragraphConverter = new ParagraphConverterV3();
                    var cellData           = paragraphConverter.Convert(th,
                                                                        new ParagraphConverterParamsV3 {
                        ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = rowConverterParams.Settings, StartSection = false
                    });
                    if (cellData.SubElements() != null)
                    {
                        foreach (var subElement in cellData.SubElements())
                        {
                            cell.Add(subElement);
                        }
                    }
                    else
                    {
                        cell.Add(cellData);
                    }
                    //cell.Add(new SimpleHTML5Text { Text = th.Text });
                    if (th.ColSpan.HasValue)
                    {
                        cell.ColSpan.Value = th.ColSpan.ToString();
                    }
                    if (th.RowSpan.HasValue)
                    {
                        cell.RowSpan.Value = th.RowSpan.ToString();
                    }
                    switch (th.Align)
                    {
                    case TableAlignmentsEnum.Center:
                        cell.Align.Value = "center";
                        break;

                    case TableAlignmentsEnum.Left:
                        cell.Align.Value = "left";
                        break;

                    case TableAlignmentsEnum.Right:
                        cell.Align.Value = "right";
                        break;
                    }
                    switch (th.VAlign)
                    {
                    case TableVAlignmentsEnum.Top:
                        cell.VAlign.Value = "top";
                        break;

                    case TableVAlignmentsEnum.Middle:
                        cell.VAlign.Value = "middle";
                        break;

                    case TableVAlignmentsEnum.Bottom:
                        cell.VAlign.Value = "bottom";
                        break;
                    }
                    tableRow.Add(cell);
                }
                else if (element is TableCellItem)
                {
                    var td   = element as TableCellItem;
                    var cell = new TableData(HTMLElementType.HTML5);
                    var paragraphConverter = new ParagraphConverterV3();
                    var cellData           = paragraphConverter.Convert(td,
                                                                        new ParagraphConverterParamsV3 {
                        ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = rowConverterParams.Settings, StartSection = false
                    });
                    if (cellData.SubElements() != null)
                    {
                        foreach (var subElement in cellData.SubElements())
                        {
                            cell.Add(subElement);
                        }
                    }
                    else
                    {
                        cell.Add(cellData);
                    }
                    //cell.Add(new SimpleHTML5Text { Text = td.Text });
                    if (td.ColSpan.HasValue)
                    {
                        cell.ColSpan.Value = td.ColSpan.ToString();
                    }
                    if (td.RowSpan.HasValue)
                    {
                        cell.RowSpan.Value = td.RowSpan.ToString();
                    }
                    switch (td.Align)
                    {
                    case TableAlignmentsEnum.Center:
                        cell.Align.Value = "center";
                        break;

                    case TableAlignmentsEnum.Left:
                        cell.Align.Value = "left";
                        break;

                    case TableAlignmentsEnum.Right:
                        cell.Align.Value = "right";
                        break;
                    }
                    switch (td.VAlign)
                    {
                    case TableVAlignmentsEnum.Top:
                        cell.VAlign.Value = "top";
                        break;

                    case TableVAlignmentsEnum.Middle:
                        cell.VAlign.Value = "middle";
                        break;

                    case TableVAlignmentsEnum.Bottom:
                        cell.VAlign.Value = "bottom";
                        break;
                    }
                    tableRow.Add(cell);
                }
                else
                {
                    // invalid structure , we ignore
                    Logger.Log.ErrorFormat("Invalid/unexpected table row sub element type : {0}", element.GetType());
                    //continue;
                }
            }
            tableRow.Align.Value = tableRowItem.Align ?? "left";
            return(tableRow);
        }