Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix WpfDemo: image not displayed #36

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<Authors>vers</Authors>
<Company />
Expand Down
4 changes: 3 additions & 1 deletion Source/VersOne.Epub.WpfDemo/Controls/BookHtmlContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions Source/VersOne.Epub/Readers/BookCoverReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ namespace VersOne.Epub.Internal
{
internal static class BookCoverReader
{
public static EpubByteContentFileRef ReadBookCoverVersion3(EpubSchema epubSchema, Dictionary<string, EpubByteContentFileRef> 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<string, EpubByteContentFileRef> imageContentRefs)
{
List<EpubMetadataMeta> metaItems = epubSchema.Package.Metadata.MetaItems;
Expand Down
6 changes: 5 additions & 1 deletion Source/VersOne.Epub/Readers/ContentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion Source/VersOne.Epub/Readers/NavigationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ public static List<EpubNavigationItemRef> 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<EpubNavigationItemRef>(); // if Ncx is missing, return an empty list
}
}

Expand Down
12 changes: 10 additions & 2 deletions Source/VersOne.Epub/Readers/SchemaReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO.Compression;
using System;
using System.IO.Compression;
using System.Threading.Tasks;
using VersOne.Epub.Schema;

Expand All @@ -15,7 +16,14 @@ public static async Task<EpubSchema> 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;
}
}
Expand Down