예제 #1
0
        private void AddAboutInformation(EPubFileV3 epubFile)
        {
            Assembly asm = Assembly.GetAssembly(GetType());
            string version = "???";
            if (asm != null)
            {
                version = asm.GetName().Version.ToString();
            }
            epubFile.CreatorSoftwareString = string.Format(@"Fb2epub v{0} [http://www.fb2epub.net]", version);

            if (!Settings.ConversionSettings.SkipAboutPage)
            {
                epubFile.AboutTexts.Add(
                    string.Format("This file was generated by Lord KiRon's FB2EPUB converter version {0}.",
                                  version));
                epubFile.AboutTexts.Add("(This book might contain copyrighted material, author of the converter bears no responsibility for it's usage)");
                epubFile.AboutTexts.Add(
                    string.Format("Этот файл создан при помощи конвертера FB2EPUB версии {0} написанного Lord KiRon.",
                        version));
                epubFile.AboutTexts.Add("(Эта книга может содержать материал который защищен авторским правом, автор конвертера не несет ответственности за его использование)");
                epubFile.AboutLinks.Add(@"http://www.fb2epub.net");
                epubFile.AboutLinks.Add(@"https://code.google.com/p/fb2epub/");
                epubFile.AddXHTMLFile(CreateLicenseFile());
            }
        }
예제 #2
0
 private void SetupFonts(EPubFileV3 epubFile)
 {
     if (Settings.ConversionSettings.Fonts == null)
     {
         Logger.Log.Warn("No fonts defined in configuration file.");
         return;
     }
     epubFile.SetEPubFonts(Settings.ConversionSettings.Fonts, Settings.ResourcesPath, Settings.ConversionSettings.DecorateFontNames);
 }
예제 #3
0
 private void SetupCSS(EPubFileV3 epubFile)
 {
     Assembly asm = Assembly.GetAssembly(GetType());
     string pathPreffix = Path.GetDirectoryName(asm.Location);
     if (!string.IsNullOrEmpty(Settings.ResourcesPath))
     {
         pathPreffix = Settings.ResourcesPath;
     }
     epubFile.CSSFiles.Add(new CSSFile { FilePathOnDisk = string.Format(@"{0}\CSS\{1}", pathPreffix, DefaultCSSFileName), FileName = DefaultCSSFileName });
 }
예제 #4
0
 private void ConvertAnnotation(ItemTitleInfo titleInfo, EPubFileV3 epubFile)
 {
     if (titleInfo.Annotation != null)
     {
         epubFile.BookInformation.Description = new Description {DescInfo = titleInfo.Annotation.ToString()};
         epubFile.AnnotationPage = new AnnotationPageFileV3();
         var converterSettings = new ConverterOptionsV3
         {
             CapitalDrop = Settings.CommonSettings.CapitalDrop,
             Images = Images,
             MaxSize = Settings.V3Settings.HTMLFileMaxSize,
             ReferencesManager = _referencesManager,
         };
         var annotationConverter = new AnnotationConverterV3();
         epubFile.AnnotationPage.BookAnnotation = (Div)annotationConverter.Convert(titleInfo.Annotation,
            new AnnotationConverterParamsV3 { Settings = converterSettings, Level = 1 });
     }
 }
예제 #5
0
        /// <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(EPubFileV3 epubFile, FB2File fb2File)
        {
            if (!Settings.ConversionSettings.Fb2Info)
            {
                return;
            }
            var infoDocument = new BaseXHTMLFileV3
            {
                PageTitle = "FB2 Info",
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                FileName = "fb2info.xhtml",
                GuideRole = GuideTypeEnum.Notes,
                NotPartOfNavigation = true
            };

            var converterSettings = new ConverterOptionsV3
            {
                CapitalDrop = false,
                Images = Images,
                MaxSize = Settings.V3Settings.HTMLFileMaxSize,
                ReferencesManager = _referencesManager,
            };
            var infoConverter = new Fb2EpubInfoConverterV3();
            infoDocument.Content = infoConverter.Convert(fb2File, converterSettings);

            epubFile.AddXHTMLFile(infoDocument);
        }
예제 #6
0
 private void PassCoverImageFromFB2(CoverPage coverPage, EPubFileV3 epubFile)
 {
     // if we have at least one coverpage image
     if ((coverPage != null) && (coverPage.HasImages()) && (coverPage.CoverpageImages[0].HRef != null))
     {
         var coverPageFile = new CoverPageFileV3(coverPage.CoverpageImages[0], _referencesManager);
         epubFile.AddXHTMLFile(coverPageFile);
         Images.ImageIdUsed(coverPage.CoverpageImages[0].HRef);
         epubFile.SetCoverImageID(coverPage.CoverpageImages[0].HRef);
     }
 }
예제 #7
0
 private void UpdateInternalLinks(EPubFileV3 epubFile, FB2File fb2File)
 {
     _referencesManager.RemoveInvalidAnchors();
     _referencesManager.RemoveInvalidImages(fb2File.Images);
     _referencesManager.RemapAnchors(epubFile);
 }
예제 #8
0
 private void PassTextFromFb2ToEpub(EPubFileV3 epubFile, FB2File fb2File)
 {
     var converter = new Fb2EPubTextConverterV3(Settings.CommonSettings, Images, _referencesManager, Settings.V3Settings.HTMLFileMaxSize);
     converter.Convert(epubFile, fb2File);
 }
 private void PassCoverImageFromFB2(CoverPage coverPage, EPubFileV3 epubFile)
 {
     // if we have at least one coverpage image
     if ((coverPage != null) && (coverPage.HasImages()) && (coverPage.CoverpageImages[0].HRef != null))
     {
         var coverPageFile = new CoverPageFileV3(coverPage.CoverpageImages[0], _referencesManager);
         StructureManager.AddCoverPage(coverPageFile);
         Images.ImageIdUsed(coverPage.CoverpageImages[0].HRef);
         epubFile.SetCoverImageID(ReferencesUtils.GetIdFromLink(coverPage.CoverpageImages[0].HRef));
     }
 }
예제 #10
0
 private void PassImagesDataFromFb2ToEpub(EPubFileV3 epubFile, FB2File fb2File)
 {
     Images.ConvertFb2ToEpubImages(fb2File.Images, epubFile.Images);
 }
예제 #11
0
        public void Convert(EPubFileV3 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);
                var addTitlePage = new BaseXHTMLFileV3
                {
                    PageTitle = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole = GuideTypeEnum.TitlePage,
                    Content = new Div(HTMLElementType.HTML5),
                    NavigationParent = null,
                    FileName = string.Format("section{0}.xhtml", ++_sectionCounter),
                    NotPartOfNavigation = true
                };
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                    new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 2 }));

                epubFile.AddXHTMLFile(addTitlePage);
            }

            BaseXHTMLFileV3 mainDocument = null;
            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV3
                {
                    PageTitle = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole = GuideTypeEnum.Text,
                    Content = new Div(HTMLElementType.HTML5),
                    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 BaseXHTMLFileV3
                    {
                        PageTitle = newDocTitle,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(HTMLElementType.HTML5),
                        NavigationParent = null,
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    epubFile.AddXHTMLFile(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing = new Div(HTMLElementType.HTML5); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV3
                    {
                        CapitalDrop = _commonSettings.CapitalDrop,
                        Images = _images,
                        MaxSize = _maxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV3();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV3 { Settings = converterSettings }));
                    SetClassType(enclosing, ElementStylesV3.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 BaseXHTMLFileV3
                    {
                        PageTitle = newDocTitle,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(HTMLElementType.HTML5),
                        NavigationParent = null,
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    epubFile.AddXHTMLFile(mainDocument);
                }
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV3();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                    new EpigraphConverterParamsV3 { Settings = converterSettings, Level = 1 }));
            }

            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);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Add and convert generic secondary body section
        /// </summary>
        /// <param name="epubFile"></param>
        /// <param name="bodyItem"></param>
        private void AddSecondaryBody(EPubFileV3 epubFile, 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 BaseXHTMLFileV3
            {
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole = GuideTypeEnum.Text,
                Content = new Div(HTMLElementType.HTML5),
                NavigationParent = null,
                NotPartOfNavigation = false,
                FileName = string.Format("section{0}.xhtml", ++_sectionCounter),
                PageTitle = docTitle,
            };
            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                    new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 1 }));
            }
            epubFile.AddXHTMLFile(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(epubFile, section, sectionDocument, false);
            }
        }
예제 #13
0
 private void AddSection(EPubFileV3 epubFile, SectionItem section, BaseXHTMLFileV3 navParent, bool fbeNotesSection)
 {
     string docTitle = string.Empty;
     if (section.Title != null)
     {
         docTitle = section.Title.ToString();
     }
     Logger.Log.DebugFormat("Adding section : {0}", docTitle);
     BaseXHTMLFileV3 sectionDocument = null;
     bool firstDocumentOfSplit = true;
     var converterSettings = new ConverterOptionsV3
     {
         CapitalDrop = !fbeNotesSection && _commonSettings.CapitalDrop,
         Images = _images,
         MaxSize = _maxSize,
         ReferencesManager = _referencesManager,
     };
     var sectionConverter = new SectionConverterV3
     {
         LinkSection = fbeNotesSection,
         RecursionLevel = GetRecursionLevel(navParent),
         Settings = converterSettings
     };
     foreach (var subitem in sectionConverter.Convert(section))
     {
         sectionDocument = new BaseXHTMLFileV3
         {
             PageTitle = docTitle,
             FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
             GuideRole = (navParent == null) ? GuideTypeEnum.Text : navParent.GuideRole,
             Content = subitem,
             NavigationParent = navParent,
             FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
         };
         if (!firstDocumentOfSplit || 
             ((navParent!= null) && navParent.NotPartOfNavigation))
         {
             sectionDocument.NotPartOfNavigation = true;
         }
         firstDocumentOfSplit = false;
         epubFile.AddXHTMLFile(sectionDocument);
     }
     Logger.Log.Debug("Adding sub-sections");
     foreach (var subSection in section.SubSections)
     {
         AddSection(epubFile, subSection, sectionDocument, fbeNotesSection);
     }
 }
예제 #14
0
 private BaseXHTMLFileV3 GetIDParentDocument(EPubFileV3 file, IHTMLItem value)
 {
     if ((file.AnnotationPage != null) && file.AnnotationPage.PartOfDocument(value))
     {
         return file.AnnotationPage;
     }
     return file.GetIDOfParentDocument(value) as BaseXHTMLFileV3;
 }
예제 #15
0
 public void RemapAnchors(EPubFileV3 epubFile)
 {
     foreach (var link in _references)
     {
         if (!ReferencesUtils.IsExternalLink(link.Key))
         {
             string idString = ReferencesUtils.GetIdFromLink(link.Key);
             BaseXHTMLFileV3 iDDocument = GetIDParentDocument(epubFile, _ids[idString]);
             if (iDDocument != null)
             {
                 int count = 0;
                 foreach (var anchor in link.Value)
                 {
                     BaseXHTMLFileV3 idDocument = GetIDParentDocument(epubFile, anchor);
                     var referencedItem = _ids[(string)anchor.HRef.Value];
                     var newParent = DetectParentContainer(referencedItem);
                     if (newParent == null)
                     {
                         continue;
                     }
                     var newAnchor = new Anchor(newParent.HTMLStandard);
                     if (idDocument == iDDocument)
                     {
                         anchor.HRef.Value = string.Format("#{0}", idString);
                         newAnchor.HRef.Value = string.Format("#{0}", anchor.GlobalAttributes.ID.Value);
                     }
                     else
                     {
                         anchor.HRef.Value = string.Format("{0}#{1}", iDDocument.FileName, idString);
                         if (idDocument == null)
                         {
                             continue;
                         }
                         newAnchor.HRef.Value = string.Format("{0}#{1}", idDocument.FileName, anchor.GlobalAttributes.ID.Value);
                     }
                     //if (iDDocument.Type == SectionTypeEnum.Links))  // if it's FBE notes section
                     //{
                     //    newAnchor.GlobalAttributes.Class.Value = ElementStylesV3.NoteAnchor;
                     //    newParent.Add(new EmptyLine(newParent.HTMLStandard));
                     //    newParent.Add(newAnchor);
                     //    count++;
                     //    newAnchor.Add(new SimpleHTML5Text(newAnchor.HTMLStandard) { Text = (link.Value.Count > 1) ? string.Format("(<< back {0})  ", count) : string.Format("(<< back)  ") });
                     //}
                 }
             }
             else
             {
                 //throw new Exception("Internal consistency error - Used ID has to be in one of the book documents objects");
                 Logger.Log.Error("Internal consistency error - Used ID has to be in one of the book documents objects");
                 //continue;
             }
         }
     }
 }