public void Convert(FB2File fb2File, IBookInformationData titleInformation) { _titleInfoConverter.Convert(fb2File.TitleInfo,titleInformation); _bookIDConverter.Convert(fb2File, titleInformation); _sourceInfoConverter.Convert(fb2File, titleInformation); _publisherInfoConverter.Convert(fb2File, titleInformation); _seriesDataConverter.Convert(fb2File, titleInformation); }
public MainPage() { InitializeComponent(); _file = new FB2File(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); }
public void Convert(FB2File fb2File,IBookInformationData titleInformation, ICalibreMetadata metadata) { _titleInfoConverter.Convert(fb2File.TitleInfo, titleInformation); _bookIDConverter.Convert(fb2File, titleInformation); _sourceInfoConverter.Convert(fb2File, titleInformation); _publisherInfoConverter.Convert(fb2File, titleInformation); _calibreMetadataConverter.Convert(fb2File, metadata); _seriesDataConverter.Convert(fb2File, titleInformation); }
public void Convert(FB2File fb2File, IBookInformationData titleInformation) { if (fb2File.PublishInfo.BookTitle != null) { var bookTitle = new Title { TitleName = Rus2Lat.Instance.Translate(fb2File.PublishInfo.BookTitle.Text, _conversionSettings.TransliterationSettings), Language = !string.IsNullOrEmpty(fb2File.PublishInfo.BookTitle.Language) ? fb2File.PublishInfo.BookTitle.Language : fb2File.TitleInfo.Language }; if (!SourceDataInclusionControl.Instance.IsIgnoreInfoSource(SourceDataInclusionControl.DataTypes.Publish, _conversionSettings.IgnoreTitle)) { bookTitle.TitleType = TitleType.PublishInfo; titleInformation.BookTitles.Add(bookTitle); } } if (fb2File.PublishInfo.ISBN != null) { var bookId = new Identifier { IdentifierName = "BookISBN", ID = fb2File.PublishInfo.ISBN.Text, Scheme = "ISBN" }; titleInformation.Identifiers.Add(bookId); } titleInformation.Publisher = new Publisher(); if (fb2File.PublishInfo.Publisher != null) { titleInformation.Publisher.PublisherName = Rus2Lat.Instance.Translate(fb2File.PublishInfo.Publisher.Text, _conversionSettings.TransliterationSettings); } try { if (fb2File.PublishInfo.Year.HasValue) { var date = new DateTime(fb2File.PublishInfo.Year.Value, 1, 1); titleInformation.DatePublished = date; } } catch (FormatException ex) { Logger.Log.DebugFormat("Date reading format exception: {0}", ex); } catch (Exception exAll) { Logger.Log.ErrorFormat("Date reading exception: {0}", exAll); } }
private async void OpenFileTest_OnClick(object sender, RoutedEventArgs e) { FileOpenPicker fp = new FileOpenPicker(); fp.ViewMode = PickerViewMode.Thumbnail; fp.FileTypeFilter.Add(".fb2"); var storageFile = await fp.PickSingleFileAsync(); XDocument fb2 = XDocument.Load(storageFile.Path); FB2File fb = new FB2File(); fb.Load(fb2, false); }
/// <summary> /// Read Fb2 file from string. /// </summary> /// <param name="xml">Fb2 file content as a string.</param> /// <returns></returns> public Task<FB2File> ReadAsync(string xml) { return Task.Factory.StartNew(() => { var file = new FB2File(); var fb2Document = XDocument.Parse(xml); file.Load(fb2Document, false); return file; }); }
/// <summary> /// Read Fb2 file from string. /// </summary> /// <param name="xml">Fb2 file content as a string.</param> /// <returns></returns> public Task <FB2File> ReadAsync(string xml) { return(Task.Factory.StartNew(() => { var file = new FB2File(); var fb2Document = XDocument.Parse(xml); file.Load(fb2Document, false); return file; })); }
private async void TestButton_OnClick(object sender, RoutedEventArgs e) { FileOpenPicker fp = new FileOpenPicker(); fp.ViewMode = PickerViewMode.Thumbnail; fp.FileTypeFilter.Add(".fb2"); var storageFile = await fp.PickSingleFileAsync(); var stream = await storageFile.OpenAsync(FileAccessMode.Read); XDocument fb2 = await Task.Run(() => XDocument.Load(stream.AsStreamForRead())); FB2File fb = new FB2File(); fb.Load(fb2, false); }
public void Convert(FB2File fb2File, IBookInformationData titleInformation) { // Getting information from FB2 document section var bookId = new Identifier { ID = !string.IsNullOrEmpty(fb2File.DocumentInfo.ID) ? fb2File.DocumentInfo.ID : Guid.NewGuid().ToString(), IdentifierName = "FB2BookID", Scheme = "URI" }; titleInformation.Identifiers.Add(bookId); }
/// <summary> /// Read Fb2 file from Stream. /// </summary> /// <param name="stream">Fb2 file as a stream.</param> /// <param name="settings">Settings for reading fb2 file.</param> /// <returns></returns> public Task<FB2File> ReadAsync(Stream stream, XmlLoadSettings settings) { return Task.Factory.StartNew(() => { var file = new FB2File(); using (var reader = XmlReader.Create(stream, settings.ReaderSettings)) { var fb2Document = XDocument.Load(reader, settings.Options); file.Load(fb2Document, false); } return file; }); }
/// <summary> /// Read Fb2 file from Stream. /// </summary> /// <param name="stream">Fb2 file as a stream.</param> /// <param name="settings">Settings for reading fb2 file.</param> /// <returns></returns> public Task <FB2File> ReadAsync(Stream stream, XmlLoadSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } return(Task.Factory.StartNew(() => { var file = new FB2File(); using (var reader = XmlReader.Create(stream, settings.ReaderSettings)) { var fb2Document = XDocument.Load(reader, settings.Options); file.Load(fb2Document, false); } return file; })); }
protected FB2File ReadFb2FileStream(Stream s) { Logger.Log.Debug("Starting to load FB2 stream"); var settings = new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Prohibit, CheckCharacters = false }; XDocument fb2Document; try { using (XmlReader reader = XmlReader.Create(s, settings)) { fb2Document = XDocument.Load(reader, LoadOptions.PreserveWhitespace); reader.Close(); } } catch (XmlException) // we handle this on top { throw; } catch (Exception ex) { Logger.Log.ErrorFormat("Error loading file : {0}", ex); throw; } var file = new FB2File(); try { file.Load(fb2Document, false); } catch (Exception ex) { Logger.Log.ErrorFormat("Error loading file : {0}", ex); throw; } Logger.Log.Debug("FB2 stream loaded"); return file; }
protected override void ConvertContent(FB2File fb2File, IEpubFile epubFile) { var epubFileV3 = epubFile as EPubFileV3; if (epubFileV3 == null) { throw new ArrayTypeMismatchException(string.Format("Invalid ePub object type passed, expected EPubFileV3, got {0}",epubFile.GetType())); } PassHeaderDataFromFb2ToEpub(fb2File,epubFile.BookInformation); PassCoverImageFromFB2(fb2File.TitleInfo.Cover, epubFileV3); ConvertAnnotation(fb2File.TitleInfo, epubFileV3); SetupCSS(epubFileV3); SetupFonts(epubFileV3); PassTextFromFb2ToEpub(epubFileV3, fb2File); PassFb2InfoToEpub(epubFileV3, fb2File); UpdateInternalLinks(epubFileV3, fb2File); PassImagesDataFromFb2ToEpub(epubFileV3, fb2File); AddAboutInformation(epubFileV3); }
internal void Convert(FB2File fb2File, ICalibreMetadata metadata) { if (!_v2Settings.AddCalibreMetadata) { return; } if (fb2File.TitleInfo != null && fb2File.TitleInfo.BookTitle != null && !string.IsNullOrEmpty(fb2File.TitleInfo.BookTitle.Text)) { metadata.TitleForSort = fb2File.TitleInfo.BookTitle.Text; } if (fb2File.TitleInfo != null && fb2File.TitleInfo.Sequences.Count > 0 && !string.IsNullOrEmpty(fb2File.TitleInfo.Sequences[0].Name)) { metadata.SeriesName = fb2File.TitleInfo.Sequences[0].Name; if (fb2File.TitleInfo.Sequences[0].Number.HasValue) { metadata.SeriesIndex = fb2File.TitleInfo.Sequences[0].Number.Value; } } }
protected override void ConvertContent(FB2File fb2File, IEpubFile epubFile) { var epubFileV2 = epubFile as EPubFileV2; if (epubFileV2 == null) { throw new ArrayTypeMismatchException(string.Format("Invalid ePub object type passed, expected EPubFileV2, got {0}", epubFile.GetType())); } _referencesManager.FlatStructure = Settings.CommonSettings.FlatStructure; PassHeaderDataFromFb2ToEpub(fb2File, epubFileV2); var titlePage = new TitlePageFileV2(epubFileV2.BookInformation); StructureManager.AddTitlePage(titlePage); PassCoverImageFromFB2(fb2File.TitleInfo.Cover, epubFileV2); ConvertAnnotation(fb2File.TitleInfo, epubFileV2); SetupCSS(epubFileV2); SetupFonts(epubFileV2); PassTextFromFb2ToEpub(fb2File); PassFb2InfoToEpub(epubFileV2, fb2File); PassImagesDataFromFb2ToEpub(epubFileV2, fb2File); AddAboutInformation(epubFileV2); UpdateInternalLinks(fb2File); }
private async Task OpenFileAsync(StorageFile file) { loading.Visibility = Visibility.Visible; using (var s = await file.OpenStreamForReadAsync()) { try { var xml = await GetStringFromStreamAsync(s); _file = await new FB2Reader().ReadAsync(xml); //DisplayLines(); } catch (Exception ex) { bookInfo.Text = string.Format("Error loading file : {0}", ex.Message); } finally { loading.Visibility = Visibility.Collapsed; } } }
private async void DownloadClicked(object sender, EventArgs args) { textBlock.Text = "Start download..."; using (var httpClient = new HttpClient()) { var stream = await httpClient.GetStreamAsync("https://dl.dropboxusercontent.com/u/30506652/data/test.fb2"); textBlock.Text = "Reading..."; try { using (var reader = new FB2Reader()) { _file = await reader.LoadAsync(stream); } } catch (Exception ex) { bookInfo.Text = string.Format("Error loading file : {0}", ex.Message); } } PrepareFile(); }
/// <summary> /// Saves the loaded FB2 file(s) to the destination as ePub /// </summary> /// <param name="fb2File"></param> /// <param name="epubFile"></param> protected abstract void ConvertContent(FB2File fb2File, IEpubFile epubFile);
private void PassHeaderDataFromFb2ToEpub(FB2File fb2File,IBookInformationData titleInformation) { Logger.Log.Debug("Passing header data from FB2 to EPUB"); if (fb2File.MainBody == null) { throw new NullReferenceException("MainBody section of the file passed is null"); } var headerDataConverter = new HeaderDataConverterV3(Settings.ConversionSettings,Settings.V3Settings); headerDataConverter.Convert(fb2File, titleInformation); }
private void PassPublisherInfoFromFB2(FB2File fb2File, IBookInformationData titleInformation, IEPubConversionSettings settings) { if (fb2File.PublishInfo.BookTitle != null) { var bookTitle = new Title { TitleName = Rus2Lat.Instance.Translate(fb2File.PublishInfo.BookTitle.Text, settings.TransliterationSettings), Language = !string.IsNullOrEmpty(fb2File.PublishInfo.BookTitle.Language) ? fb2File.PublishInfo.BookTitle.Language : fb2File.TitleInfo.Language }; if ((Settings.ConversionSettings.IgnoreTitle != IgnoreInfoSourceOptions.IgnorePublishTitle) && (Settings.ConversionSettings.IgnoreTitle != IgnoreInfoSourceOptions.IgnoreMainAndPublish) && Settings.ConversionSettings.IgnoreTitle != IgnoreInfoSourceOptions.IgnoreSourceAndPublish) { bookTitle.TitleType = TitleType.PublishInfo; titleInformation.BookTitles.Add(bookTitle); } } if (fb2File.PublishInfo.ISBN != null) { var bookId = new Identifier { IdentifierName = "BookISBN", ID = fb2File.PublishInfo.ISBN.Text, Scheme = "ISBN" }; titleInformation.Identifiers.Add(bookId); } if (fb2File.PublishInfo.Publisher != null) { titleInformation.Publisher.PublisherName = Rus2Lat.Instance.Translate(fb2File.PublishInfo.Publisher.Text, settings.TransliterationSettings); } try { if (fb2File.PublishInfo.Year.HasValue) { var date = new DateTime(fb2File.PublishInfo.Year.Value, 1, 1); titleInformation.DatePublished = date; } } catch (FormatException ex) { Logger.Log.DebugFormat("Date reading format exception: {0}", ex); } catch (Exception exAll) { Logger.Log.ErrorFormat("Date reading exception: {0}", exAll); } }
private void PassTextFromFb2ToEpub(EPubFileV3 epubFile, FB2File fb2File) { var converter = new Fb2EPubTextConverterV3(Settings.CommonSettings, Images, _referencesManager, Settings.V3Settings.HTMLFileMaxSize); converter.Convert(epubFile, fb2File); }
/// <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); }
private void PassImagesDataFromFb2ToEpub(EPubFileV3 epubFile, FB2File fb2File) { Images.ConvertFb2ToEpubImages(fb2File.Images, epubFile.Images); }
private void UpdateInternalLinks(EPubFileV3 epubFile, FB2File fb2File) { _referencesManager.RemoveInvalidAnchors(); _referencesManager.RemoveInvalidImages(fb2File.Images); _referencesManager.RemapAnchors(epubFile); }
private void UpdateInternalLinks(FB2File fb2File) { _referencesManager.RemoveInvalidImages(fb2File.Images); _referencesManager.RemapAnchors(StructureManager); }
public void Convert(FB2File fb2File, IBookInformationData titleInformation) { foreach (var seq in fb2File.TitleInfo.Sequences) { if (!string.IsNullOrEmpty(seq.Name)) { var collectionMember = new SeriesCollectionMember { CollectionName = seq.Name, Type = CollectionType.Series, CollectionPosition = seq.Number }; titleInformation.SeriesCollection.AddCollectionMember(collectionMember); foreach (var subseq in seq.SubSections.Where(subseq => !string.IsNullOrEmpty(subseq.Name))) { collectionMember = new SeriesCollectionMember { CollectionName = subseq.Name, Type = CollectionType.Set, CollectionPosition = subseq.Number }; titleInformation.SeriesCollection.AddCollectionMember(collectionMember); } } } foreach (var seq in fb2File.SourceTitleInfo.Sequences) { if (!string.IsNullOrEmpty(seq.Name)) { var collectionMember = new SeriesCollectionMember { CollectionName = seq.Name, Type = CollectionType.Series, CollectionPosition = seq.Number }; titleInformation.SeriesCollection.AddCollectionMember(collectionMember); foreach (var subseq in seq.SubSections.Where(subseq => !string.IsNullOrEmpty(subseq.Name))) { collectionMember = new SeriesCollectionMember { CollectionName = subseq.Name, Type = CollectionType.Set, CollectionPosition = subseq.Number }; titleInformation.SeriesCollection.AddCollectionMember(collectionMember); } } } foreach (var seq in fb2File.PublishInfo.Sequences) { if (!string.IsNullOrEmpty(seq.Name)) { var collectionMember = new SeriesCollectionMember { CollectionName = seq.Name, Type = CollectionType.Series, CollectionPosition = seq.Number }; titleInformation.SeriesCollection.AddCollectionMember(collectionMember); foreach (var subseq in seq.SubSections.Where(subseq => !string.IsNullOrEmpty(subseq.Name))) { collectionMember = new SeriesCollectionMember { CollectionName = subseq.Name, Type = CollectionType.Set, CollectionPosition = subseq.Number }; titleInformation.SeriesCollection.AddCollectionMember(collectionMember); } } } }
public HTMLItem Convert(FB2File fb2File, ConverterOptionsV3 settings) { if (fb2File == null) { throw new ArgumentNullException("fb2File"); } var info = new Div(HTMLElementType.HTML5); var header = new H3(HTMLElementType.HTML5); header.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "FB2 document info" }); info.Add(header); if (fb2File.DocumentInfo != null) { if (!string.IsNullOrEmpty(fb2File.DocumentInfo.ID)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document ID: {0}", fb2File.DocumentInfo.ID) }); info.Add(p); } if (fb2File.DocumentInfo.DocumentVersion.HasValue) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document version: {0}", fb2File.DocumentInfo.DocumentVersion) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentDate != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.DocumentDate.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document creation date: {0}", fb2File.DocumentInfo.DocumentDate.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.ProgramUsed2Create != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.ProgramUsed2Create.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Created using: {0} software", fb2File.DocumentInfo.ProgramUsed2Create.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.SourceOCR != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.SourceOCR.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("OCR Source: {0}", fb2File.DocumentInfo.SourceOCR.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentAuthors != null) && (fb2File.DocumentInfo.DocumentAuthors.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document authors :" }); info.Add(heading); var authors = new UnorderedList(HTMLElementType.HTML5); foreach (var author in fb2File.DocumentInfo.DocumentAuthors) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(author) }); authors.Add(li); } info.Add(authors); } if ((fb2File.DocumentInfo.DocumentPublishers != null) && (fb2File.DocumentInfo.DocumentPublishers.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document publishers :" }); info.Add(heading); var publishers = new UnorderedList(HTMLElementType.HTML5); foreach (var publisher in fb2File.DocumentInfo.DocumentPublishers) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(publisher) }); publishers.Add(li); } info.Add(publishers); } if ((fb2File.DocumentInfo.SourceURLs != null) && (fb2File.DocumentInfo.SourceURLs.Any())) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Source URLs :" }); info.Add(heading); var urls = new UnorderedList(HTMLElementType.HTML5); foreach (var url in fb2File.DocumentInfo.SourceURLs) { var li = new ListItem(HTMLElementType.HTML5); if (ReferencesUtils.IsExternalLink(url)) { var link = new Anchor(HTMLElementType.HTML5); link.HRef.Value = url; link.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); li.Add(link); } else { li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); } urls.Add(li); } info.Add(urls); } if (fb2File.DocumentInfo.History != null) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document history:" }); info.Add(heading); var annotationConverter = new AnnotationConverterV3(); info.Add(annotationConverter.Convert(fb2File.DocumentInfo.History, new AnnotationConverterParamsV3 { Level = 1, Settings = settings })); //Paragraph p = new Paragraph(); //p.Add(new SimpleHTML5Text() { Text = fb2File.DocumentInfo.History.ToString() }); //info.Add(p); } } // in case there is no elements - no need for a header if (info.SubElements().Count <= 1) { info.Remove(header); } SetClassType(info, ElementStylesV3.FB2Info); return info; }
public void Convert(FB2File fb2File, IBookInformationData titleInformation) { }
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); } } }
public void Convert(FB2File fb2File, IBookInformationData titleInformation) { if ((fb2File.DocumentInfo.SourceOCR != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.SourceOCR.Text)) { titleInformation.Source = new Source { SourceData = fb2File.DocumentInfo.SourceOCR.Text }; } foreach (var docAuthor in fb2File.DocumentInfo.DocumentAuthors) { var person = new PersoneWithRole { PersonName = Rus2Lat.Instance.Translate(DescriptionConverters.GenerateAuthorString(docAuthor, _conversionSettings), _conversionSettings.TransliterationSettings), FileAs = DescriptionConverters.GenerateFileAsString(docAuthor, _conversionSettings), Role = RolesEnum.Adapter }; if (fb2File.TitleInfo != null) { person.Language = fb2File.TitleInfo.Language; } titleInformation.Contributors.Add(person); } // Getting information from FB2 Source Title Info section if (!SourceDataInclusionControl.Instance.IsIgnoreInfoSource(SourceDataInclusionControl.DataTypes.Source, _conversionSettings.IgnoreTitle) && (fb2File.SourceTitleInfo.BookTitle != null) && !string.IsNullOrEmpty(fb2File.SourceTitleInfo.BookTitle.Text)) { var bookTitle = new Title { TitleName = Rus2Lat.Instance.Translate(fb2File.SourceTitleInfo.BookTitle.Text, _conversionSettings.TransliterationSettings), Language = string.IsNullOrEmpty(fb2File.SourceTitleInfo.BookTitle.Language) && (fb2File.TitleInfo != null) ? fb2File.TitleInfo.Language : fb2File.SourceTitleInfo.BookTitle.Language, TitleType = TitleType.SourceInfo }; titleInformation.BookTitles.Add(bookTitle); titleInformation.Languages.Add(fb2File.SourceTitleInfo.Language); } // add authors foreach (var author in fb2File.SourceTitleInfo.BookAuthors) { var person = new PersoneWithRole { PersonName = Rus2Lat.Instance.Translate( string.Format("{0} {1} {2}", author.FirstName, author.MiddleName, author.LastName), _conversionSettings.TransliterationSettings), FileAs = DescriptionConverters.GenerateFileAsString(author, _conversionSettings), Role = RolesEnum.Author, Language = fb2File.SourceTitleInfo.Language }; titleInformation.Creators.Add(person); } TranslatorsInfoConverterV3.Convert(fb2File.SourceTitleInfo, titleInformation, _conversionSettings); GenresInfoConverterV3.Convert(fb2File.SourceTitleInfo, titleInformation,_conversionSettings); }
public void LoadFB2FileFromXML(XDocument fb2Document) { _fb2Files.Clear(); var file = new FB2File(); try { file.Load(fb2Document, false); _fb2Files.Add(file); } catch (Exception ex) { Logger.Log.ErrorFormat("Error loading XML document : {0}", ex); } }
private void LoadImagesInMemory(FB2File fb2File) { Images.RemoveAlpha = Settings.FB2ImportSettings.ConvertAlphaPng; Images.LoadFromBinarySection(fb2File.Images); }
public FB2File ReadFromFile(string path) { var file = new FB2File(); file.Load(XDocument.Load(path), false); return(file); }