Example #1
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);
                }
            }
        }
        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);
                }
            }
        }