diff --git a/Source/VersOne.Epub.NetCoreDemo/VersOne.Epub.NetCoreDemo.csproj b/Source/VersOne.Epub.NetCoreDemo/VersOne.Epub.NetCoreDemo.csproj index 670dccf..4d7c763 100644 --- a/Source/VersOne.Epub.NetCoreDemo/VersOne.Epub.NetCoreDemo.csproj +++ b/Source/VersOne.Epub.NetCoreDemo/VersOne.Epub.NetCoreDemo.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp1.0 + net5.0 win10-x64 vers diff --git a/Source/VersOne.Epub.WpfDemo/Controls/BookHtmlContent.cs b/Source/VersOne.Epub.WpfDemo/Controls/BookHtmlContent.cs index 8fb9aa8..1d89c25 100644 --- a/Source/VersOne.Epub.WpfDemo/Controls/BookHtmlContent.cs +++ b/Source/VersOne.Epub.WpfDemo/Controls/BookHtmlContent.cs @@ -76,6 +76,8 @@ protected override void OnStylesheetLoad(HtmlStylesheetLoadEventArgs e) string styleSheetFilePath = GetFullPath(HtmlContentFile.HtmlFilePath, e.Src); if (HtmlContentFile.StyleSheets.TryGetValue(styleSheetFilePath, out string styleSheetContent)) { + // remove font-family? due to IndexOutOfRangeException in TheArtOfDev.HtmlRenderer.Core.Parse.CssParser.ParseFontFamilyProperty(string) + styleSheetContent = styleSheetContent.Replace("font-family", "delete-font-family"); // make it invalid e.SetStyleSheet = styleSheetContent; } base.OnStylesheetLoad(e); @@ -136,7 +138,7 @@ private string GetFullPath(string htmlFilePath, string relativePath) basePath = Path.GetDirectoryName(basePath); } string fullPath = String.Concat(basePath.Replace('\\', '/'), '/', relativePath); - return fullPath.Length > 1 ? fullPath.Substring(1) : String.Empty; + return fullPath.TrimStart('/'); } private void RegisterFonts() diff --git a/Source/VersOne.Epub/Readers/BookCoverReader.cs b/Source/VersOne.Epub/Readers/BookCoverReader.cs index 498b71c..1b0e23a 100644 --- a/Source/VersOne.Epub/Readers/BookCoverReader.cs +++ b/Source/VersOne.Epub/Readers/BookCoverReader.cs @@ -8,6 +8,21 @@ namespace VersOne.Epub.Internal { internal static class BookCoverReader { + public static EpubByteContentFileRef ReadBookCoverVersion3(EpubSchema epubSchema, Dictionary imageContentRefs) + { + // https://ebookflightdeck.com/handbook/coverimage + + var manifestItem = epubSchema.Package.Manifest.FirstOrDefault(m => m.Properties != null && m.Properties.Contains(ManifestProperty.COVER_IMAGE)); + if (manifestItem == null) + return null; + + EpubByteContentFileRef coverImageContentFileRef; + if (manifestItem.Href != null && imageContentRefs.TryGetValue(manifestItem.Href, out coverImageContentFileRef)) + return coverImageContentFileRef; + + return null; + } + public static EpubByteContentFileRef ReadBookCover(EpubSchema epubSchema, Dictionary imageContentRefs) { List metaItems = epubSchema.Package.Metadata.MetaItems; diff --git a/Source/VersOne.Epub/Readers/ContentReader.cs b/Source/VersOne.Epub/Readers/ContentReader.cs index f5d329f..5ab5c8d 100644 --- a/Source/VersOne.Epub/Readers/ContentReader.cs +++ b/Source/VersOne.Epub/Readers/ContentReader.cs @@ -70,7 +70,11 @@ public static EpubContentRef ParseContentMap(EpubBookRef bookRef) break; } } - result.Cover = BookCoverReader.ReadBookCover(bookRef.Schema, result.Images); + + result.Cover = BookCoverReader.ReadBookCoverVersion3(bookRef.Schema, result.Images); // try V3 first + if (result.Cover == null) + result.Cover = BookCoverReader.ReadBookCover(bookRef.Schema, result.Images); + return result; } diff --git a/Source/VersOne.Epub/Readers/NavigationReader.cs b/Source/VersOne.Epub/Readers/NavigationReader.cs index 805c96e..841fa81 100644 --- a/Source/VersOne.Epub/Readers/NavigationReader.cs +++ b/Source/VersOne.Epub/Readers/NavigationReader.cs @@ -18,7 +18,14 @@ public static List GetNavigationItems(EpubBookRef bookRef } else { - return GetNavigationItems(bookRef, bookRef.Schema.Epub3NavDocument); + if (bookRef.Schema.Epub3NavDocument != null) + return GetNavigationItems(bookRef, bookRef.Schema.Epub3NavDocument); + + // otherwise fallback to Epub2Ncx + if (null != bookRef.Schema.Epub2Ncx) + return GetNavigationItems(bookRef, bookRef.Schema.Epub2Ncx); + else + return new List(); // if Ncx is missing, return an empty list } } diff --git a/Source/VersOne.Epub/Readers/SchemaReader.cs b/Source/VersOne.Epub/Readers/SchemaReader.cs index 32a7e4d..aceccb1 100644 --- a/Source/VersOne.Epub/Readers/SchemaReader.cs +++ b/Source/VersOne.Epub/Readers/SchemaReader.cs @@ -1,4 +1,5 @@ -using System.IO.Compression; +using System; +using System.IO.Compression; using System.Threading.Tasks; using VersOne.Epub.Schema; @@ -15,7 +16,14 @@ public static async Task ReadSchemaAsync(ZipArchive epubArchive) EpubPackage package = await PackageReader.ReadPackageAsync(epubArchive, rootFilePath).ConfigureAwait(false); result.Package = package; result.Epub2Ncx = await Epub2NcxReader.ReadEpub2NcxAsync(epubArchive, contentDirectoryPath, package).ConfigureAwait(false); - result.Epub3NavDocument = await Epub3NavDocumentReader.ReadEpub3NavDocumentAsync(epubArchive, contentDirectoryPath, package).ConfigureAwait(false); + try + { + result.Epub3NavDocument = await Epub3NavDocumentReader.ReadEpub3NavDocumentAsync(epubArchive, contentDirectoryPath, package).ConfigureAwait(false); + } + catch (Exception ex) + { + result.Epub3NavDocument = null; + } return result; } }