/// <summary>
        /// Passes FB2 info to the EPub file to be added at the end of the book
        /// </summary>
        /// <param name="epubFile">destination epub object</param>
        /// <param name="fb2File">source fb2 object</param>
        private void PassFb2InfoToEpub(EPubFileV2 epubFile, FB2File fb2File)
        {
            if (!Settings.ConversionSettings.Fb2Info)
            {
                return;
            }
            var infoDocument = new BaseXHTMLFileV2
            {
                Id   = "FB2 Info",
                Type = SectionTypeEnum.Text,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                FileName             = "fb2info.xhtml",
                GuideRole            = GuideTypeEnum.Notes,
                NotPartOfNavigation  = true
            };

            var converterSettings = new ConverterOptionsV2
            {
                CapitalDrop       = false,
                Images            = Images,
                MaxSize           = Settings.V2Settings.HTMLFileMaxSize,
                ReferencesManager = _referencesManager,
            };
            var infoConverter = new Fb2EpubInfoConverterV2();

            infoDocument.Content = infoConverter.Convert(fb2File, converterSettings);

            StructureManager.AddAboutPage(infoDocument);
        }
Exemplo n.º 2
0
 public AnnotationPageFileV2()
 {
     InternalPageTitle = "Annotation";
     GuideRole         = GuideTypeEnum.Preface;
     FileName          = "annotation.xhtml";
     Id = "annotation";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
 }
Exemplo n.º 3
0
 public AboutPageFileV2()
 {
     GuideRole         = GuideTypeEnum.CopyrightPage;
     InternalPageTitle = "About";
     Id = "about";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     FileName             = "about.xhtml";
 }
Exemplo n.º 4
0
 public AboutPageFileV3()
 {
     GuideRole         = GuideTypeEnum.CopyrightPage;
     InternalPageTitle = "About";
     Id = "about";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     FileName             = "about.xhtml";
     SetDocumentEpubType(EpubV3Vocabulary.Imprint);
 }
Exemplo n.º 5
0
 public CoverPageFileV2(InlineImageItem item, HRefManagerV2 refManagerV2)
 {
     _coverImage       = CreateCoverImage(item, refManagerV2);
     InternalPageTitle = "Cover";
     GuideRole         = GuideTypeEnum.Cover;
     Id = "cover";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     FileName             = "cover.xhtml";
 }
Exemplo n.º 6
0
 public AnnotationPageFileV3()
 {
     InternalPageTitle = "Annotation";
     GuideRole         = GuideTypeEnum.Preface;
     FileName          = "annotation.xhtml";
     Id = "annotation";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     SetDocumentEpubType(EpubV3Vocabulary.Foreword);
 }
Exemplo n.º 7
0
 public CoverPageFileV3(InlineImageItem item, HRefManagerV3 refManagerV3)
 {
     _coverImage       = CreateCoverImage(item, refManagerV3);
     InternalPageTitle = "Cover";
     GuideRole         = GuideTypeEnum.Cover;
     Id = "cover";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     FileName             = "cover.xhtml";
     SetDocumentEpubType(EpubV3Vocabulary.Cover);
 }
Exemplo n.º 8
0
 internal LicenseFileV2()
 {
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultLicenseFolder);
     Id                  = "license";
     FileName            = "license.xhtml";
     GuideRole           = GuideTypeEnum.Ignore;
     InternalPageTitle   = "License";
     NotPartOfNavigation = true;
     AddContent();
 }
Exemplo n.º 9
0
        private List <FB2NotesPageSectionFile> AddSection(SectionItem section, BaseXHTMLFileV3 navParent)
        {
            List <FB2NotesPageSectionFile> documents = new List <FB2NotesPageSectionFile>();

            string docTitle = string.Empty;

            if (section.Title != null)
            {
                docTitle = section.Title.ToString();
            }
            Logger.Log.DebugFormat("Adding notes section : {0}", docTitle);
            FB2NotesPageSectionFile sectionDocument = null;
            bool firstDocumentOfSplit = true;
            var  converterSettings    = new ConverterOptionsV3
            {
                CapitalDrop       = false,
                Images            = _images,
                MaxSize           = _v3Settings.HTMLFileMaxSize,
                ReferencesManager = _referencesManager,
            };
            var sectionConverter = new SectionConverterV3
            {
                LinkSection    = true,
                RecursionLevel = GetRecursionLevel(navParent),
                Settings       = converterSettings
            };

            foreach (var subitem in sectionConverter.Convert(section))
            {
                sectionDocument = new FB2NotesPageSectionFile
                {
                    PageTitle            = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole            = (navParent == null) ? GuideTypeEnum.Text : navParent.GuideRole,
                    Content          = subitem,
                    NavigationParent = navParent,
                    FileName         = BuildSectionFileName()
                };

                if (!firstDocumentOfSplit ||
                    ((navParent != null) && navParent.NotPartOfNavigation))
                {
                    sectionDocument.NotPartOfNavigation = true;
                }
                firstDocumentOfSplit = false;
                documents.Add(sectionDocument);
            }

            Logger.Log.Debug("Adding sub-sections");
            foreach (var subSection in section.SubSections)
            {
                documents.AddRange(AddSection(subSection, sectionDocument));
            }
            return(documents);
        }
Exemplo n.º 10
0
 internal LicenseFileV3()
 {
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultLicenseFolder);
     Id                  = "license";
     FileName            = "license.xhtml";
     GuideRole           = GuideTypeEnum.Ignore;
     InternalPageTitle   = "License";
     NotPartOfNavigation = true;
     SetDocumentEpubType(EpubV3Vocabulary.Imprint);
     SetDocumentEpubType(EpubV3Vocabulary.CopyRightPage);
     AddContent();
 }
Exemplo n.º 11
0
        public TitlePageFileV2(IBookInformationData titleInformation)
        {
            Authors.AddRange(titleInformation.Authors);
            Series.AddRange(titleInformation.Series);
            BookTitle = titleInformation.BookMainTitle;

            InternalPageTitle    = "Title";
            GuideRole            = GuideTypeEnum.TitlePage;
            FileName             = "title.xhtml";
            FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
            Id = "title";
        }
Exemplo n.º 12
0
        private List <BaseXHTMLFileV2> SplitSimpleText(SimpleHTML5Text simpleEPubText)
        {
            var list   = new List <BaseXHTMLFileV2>();
            var newDoc = new BaseXHTMLFileV2 {
                PageTitle = PageTitle, NotPartOfNavigation = true, Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder)
            };

            newDoc.StyleFiles.AddRange(StyleFiles);
            newDoc.GuideRole        = GuideRole;
            newDoc.NavigationParent = NavigationParent;
            newDoc.Content          = new Div(Compatibility);
            var newParagraph = new Paragraph(Compatibility);

            newDoc.Content.Add(newParagraph);
            var newText = new SimpleHTML5Text(Compatibility)
            {
                Text = ""
            };

            newParagraph.Add(newText);
            foreach (var word in simpleEPubText.Text.Split(' '))
            {
                newText.Text += ' ';
                newText.Text += word;
                ulong itemSize = EstimateSize(newParagraph);
                if (itemSize >= MaxSize)
                {
                    list.Add(newDoc);
                    newDoc = new BaseXHTMLFileV2
                    {
                        PageTitle           = InternalPageTitle,
                        NotPartOfNavigation = true,
                        Type = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole            = GuideRole,
                        NavigationParent     = NavigationParent,
                        Content = new Div(Compatibility)
                    };
                    newParagraph = new Paragraph(Compatibility);
                    newDoc.Content.Add(newParagraph);
                    newDoc.StyleFiles.AddRange(StyleFiles);
                    newText = new SimpleHTML5Text(Compatibility)
                    {
                        Text = ""
                    };
                    newParagraph.Add(newText);
                }
            }
            list.Add(newDoc);

            return(list);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Add and convert generic secondary body section
        /// </summary>
        /// <param name="bookStructureManager"></param>
        /// <param name="bodyItem"></param>
        private void AddSecondaryBody(BookStructureManager bookStructureManager, BodyItem bodyItem)
        {
            string docTitle = string.Empty;

            if (string.IsNullOrEmpty(bodyItem.Name))
            {
                if (bodyItem.Title != null)
                {
                    docTitle = bodyItem.Title.ToString();
                }
            }
            else
            {
                docTitle = bodyItem.Name;
            }
            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            var sectionDocument = new BaseXHTMLFileV2
            {
                Id                   = docTitle,
                GuideRole            = GuideTypeEnum.Text,
                Type                 = SectionTypeEnum.Text,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                Content              = new Div(BaseXHTMLFileV2.Compatibility),
                NavigationParent     = null,
                NotPartOfNavigation  = false,
                FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                                                                   new TitleConverterParamsV2 {
                    Settings = converterSettings, TitleLevel = 1
                }));
            }
            bookStructureManager.AddBookPage(sectionDocument);


            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(bookStructureManager, section, sectionDocument, false);
            }
        }
Exemplo n.º 14
0
        private void AddSection(BookStructureManager bookStructureManager, SectionItem section, BaseXHTMLFileV2 navParent, bool fbeNotesSection)
        {
            string docTitle = string.Empty;

            if (section.Title != null)
            {
                docTitle = section.Title.ToString();
            }
            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            BaseXHTMLFileV2 sectionDocument      = null;
            bool            firstDocumentOfSplit = true;
            var             converterSettings    = new ConverterOptionsV2
            {
                CapitalDrop       = !fbeNotesSection && _commonSettings.CapitalDrop,
                Images            = _images,
                MaxSize           = _maxSize,
                ReferencesManager = _referencesManager,
            };
            var sectionConverter = new SectionConverterV2
            {
                LinkSection    = fbeNotesSection,
                RecursionLevel = GetRecursionLevel(navParent),
                Settings       = converterSettings
            };

            foreach (var subitem in sectionConverter.Convert(section))
            {
                sectionDocument = new BaseXHTMLFileV2
                {
                    PageTitle            = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole            = (navParent == null) ? GuideTypeEnum.Text : navParent.GuideRole,
                    Type             = (navParent == null) ? SectionTypeEnum.Text : navParent.Type,
                    Content          = subitem,
                    NavigationParent = navParent,
                    FileName         = string.Format("section{0}.xhtml", ++_sectionCounter)
                };
                if (!firstDocumentOfSplit || (sectionDocument.Type == SectionTypeEnum.Links))
                {
                    sectionDocument.NotPartOfNavigation = true;
                }
                firstDocumentOfSplit = false;
                bookStructureManager.AddBookPage(sectionDocument);
            }
            Logger.Log.Debug("Adding sub-sections");
            foreach (var subSection in section.SubSections)
            {
                AddSection(bookStructureManager, subSection, sectionDocument, fbeNotesSection);
            }
        }
Exemplo n.º 15
0
        private List <FB2NotesPageSectionFile> AddV2StyleFbeNotesBody(BodyItem bodyItem)
        {
            List <FB2NotesPageSectionFile> documents = new List <FB2NotesPageSectionFile>();
            string docTitle = bodyItem.Name;

            Logger.Log.DebugFormat("Adding notes section : {0}", docTitle);
            var sectionDocument = new FB2NotesPageSectionFile
            {
                PageTitle            = docTitle,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole            = GuideTypeEnum.Glossary,
                Content             = new Div(HTMLElementType.HTML5),
                NavigationParent    = null,
                NotPartOfNavigation = true,
                FileName            = BuildSectionFileName()
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop       = false,
                    Images            = _images,
                    MaxSize           = _v3Settings.HTMLFileMaxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                                                                   new TitleConverterParamsV3 {
                    Settings = converterSettings, TitleLevel = 1
                }));
            }
            documents.Add(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                documents.AddRange(AddSection(section, sectionDocument));
            }
            return(documents);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Add and convert FBE style generated notes sections
        /// </summary>
        /// <param name="epubFile"></param>
        /// <param name="bodyItem"></param>
        private void AddFbeNotesBody(EPubFileV2 epubFile, BodyItem bodyItem)
        {
            string docTitle = bodyItem.Name;

            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            var sectionDocument = new BaseXHTMLFileV2
            {
                PageTitle            = docTitle,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole            = GuideTypeEnum.Glossary,
                Type                = SectionTypeEnum.Links,
                Content             = new Div(BaseXHTMLFileV2.Compatibility),
                NavigationParent    = null,
                NotPartOfNavigation = true,
                FileName            = string.Format("section{0}.xhtml", ++_sectionCounter),
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = false,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                                                                   new TitleConverterParamsV2 {
                    Settings = converterSettings, TitleLevel = 1
                }));
            }
            epubFile.AddXHTMLFile(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(epubFile, section, sectionDocument, true);
            }
        }
Exemplo n.º 17
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);
                }
            }
        }
Exemplo n.º 18
0
        public static string FormatImagePath(string validName, bool flatStructure)
        {
            EPubInternalPath imagePath = new EPubInternalPath(EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultImagesFolder), validName);

            return(imagePath.GetRelativePath(EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), flatStructure));
        }