public void Convert(EPubFileV2 epubFile, FB2File fb2File)
        {
            // create second title page
            if ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString())))
            {
                string docTitle = fb2File.MainBody.Title.ToString();
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                BaseXHTMLFileV2 addTitlePage = new BaseXHTMLFileV2
                {
                    GuideRole = GuideTypeEnum.TitlePage,
                    Content = new Div(BaseXHTMLFileV2.Compatibility),
                    Type = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent = null,
                    FileName = string.Format("section{0}.xhtml", ++_sectionCounter),
                    NotPartOfNavigation = true,
                    PageTitle = docTitle,
                };
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                    new TitleConverterParamsV2 { Settings = converterSettings, TitleLevel = 2 }));
                epubFile.AddXHTMLFile(addTitlePage);
            }

            BaseXHTMLFileV2 mainDocument = null;
            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV2
                {
                    PageTitle = docTitle,
                    GuideRole = GuideTypeEnum.Text,
                    Content = new Div(BaseXHTMLFileV2.Compatibility),
                    Type = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent = null,
                    FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                };
                epubFile.AddXHTMLFile(mainDocument);
            }

            if ((fb2File.MainBody.ImageName != null) && !string.IsNullOrEmpty(fb2File.MainBody.ImageName.HRef))
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle = newDocTitle,
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent = null,
                        Type = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    epubFile.AddXHTMLFile(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing = new Div(HTMLElementType.XHTML11); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV2
                    {
                        CapitalDrop = _commonSettings.CapitalDrop,
                        Images = _images,
                        MaxSize = _maxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV2();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV2 { Settings = converterSettings }));
                    SetClassType(enclosing, ElementStylesV2.BodyImage);
                    mainDocument.Content.Add(enclosing);
                }


            }
            foreach (var ep in fb2File.MainBody.Epigraphs)
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle = newDocTitle,
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent = null,
                        Type = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                }
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV2();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                    new EpigraphConverterParamsV2 { Settings = converterSettings, Level = 1 }));
                epubFile.AddXHTMLFile(mainDocument);
            }

            Logger.Log.Debug("Adding main sections");
            foreach (var section in fb2File.MainBody.Sections)
            {
                AddSection(epubFile, section, mainDocument, false);
            }

            Logger.Log.Debug("Adding secondary bodies");
            foreach (var bodyItem in fb2File.Bodies)
            {
                if (bodyItem == fb2File.MainBody)
                {
                    continue;
                }
                bool fbeNotesSection = FBENotesSection(bodyItem.Name);
                if (fbeNotesSection)
                {
                    AddFbeNotesBody(epubFile, bodyItem);
                }
                else
                {
                    AddSecondaryBody(epubFile, bodyItem);
                }
            }          
        }
 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;
 }
Beispiel #3
0
        public void Convert(BookStructureManager bookStructureManager, FB2File fb2File)
        {
            // create second title page
            if ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString())))
            {
                string docTitle = fb2File.MainBody.Title.ToString();
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                BaseXHTMLFileV2 addTitlePage = new BaseXHTMLFileV2
                {
                    GuideRole            = GuideTypeEnum.TitlePage,
                    Content              = new Div(BaseXHTMLFileV2.Compatibility),
                    Type                 = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent     = null,
                    FileName             = string.Format("section{0}.xhtml", ++_sectionCounter),
                    NotPartOfNavigation  = true,
                    PageTitle            = docTitle,
                };
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                                                                new TitleConverterParamsV2 {
                    Settings = converterSettings, TitleLevel = 2
                }));
                bookStructureManager.AddTitlePage(addTitlePage);
            }

            BaseXHTMLFileV2 mainDocument = null;

            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV2
                {
                    PageTitle            = docTitle,
                    GuideRole            = GuideTypeEnum.Text,
                    Content              = new Div(BaseXHTMLFileV2.Compatibility),
                    Type                 = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent     = null,
                    FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
                };
                bookStructureManager.AddBookPage(mainDocument);
            }

            if ((fb2File.MainBody.ImageName != null) && !string.IsNullOrEmpty(fb2File.MainBody.ImageName.HRef))
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle            = newDocTitle,
                        GuideRole            = GuideTypeEnum.Text,
                        Content              = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent     = null,
                        Type                 = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    bookStructureManager.AddBookPage(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing         = new Div(HTMLElementType.XHTML11); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV2
                    {
                        CapitalDrop       = _commonSettings.CapitalDrop,
                        Images            = _images,
                        MaxSize           = _maxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV2();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV2 {
                        Settings = converterSettings
                    }));
                    SetClassType(enclosing, ElementStylesV2.BodyImage);
                    mainDocument.Content.Add(enclosing);
                }
            }
            foreach (var ep in fb2File.MainBody.Epigraphs)
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle            = newDocTitle,
                        GuideRole            = GuideTypeEnum.Text,
                        Content              = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent     = null,
                        Type                 = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                }
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV2();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                                                                   new EpigraphConverterParamsV2 {
                    Settings = converterSettings, Level = 1
                }));
                bookStructureManager.AddBookPage(mainDocument);
            }

            Logger.Log.Debug("Adding main sections");
            foreach (var section in fb2File.MainBody.Sections)
            {
                AddSection(bookStructureManager, section, mainDocument, false);
            }

            Logger.Log.Debug("Adding secondary bodies");
            foreach (var bodyItem in fb2File.Bodies)
            {
                if (bodyItem == fb2File.MainBody)
                {
                    continue;
                }
                bool fbeNotesSection = FBENotesSection(bodyItem.Name);
                if (fbeNotesSection)
                {
                    AddFbeNotesBody(bookStructureManager, bodyItem);
                }
                else
                {
                    AddSecondaryBody(bookStructureManager, bodyItem);
                }
            }
        }
Beispiel #4
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);
        }