mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-13 11:09:06 +00:00
Added cover page
This commit is contained in:
@@ -38,10 +38,20 @@ namespace QuickLook.Plugin.EpubViewer
|
|||||||
|
|
||||||
protected override async void OnImageLoad(HtmlImageLoadEventArgs args)
|
protected override async void OnImageLoad(HtmlImageLoadEventArgs args)
|
||||||
{
|
{
|
||||||
string imageFilePath = GetFullPath(ChapterRef.ContentFileName, args.Src);
|
string imageFilePath = ChapterRef != null ? GetFullPath(ChapterRef.ContentFileName, args.Src) : null;
|
||||||
if (EpubBook.Content.Images.TryGetValue(imageFilePath, out EpubByteContentFileRef imageContent))
|
byte[] imageBytes = null;
|
||||||
|
if (args.Src == "COVER")
|
||||||
{
|
{
|
||||||
using (MemoryStream imageStream = new MemoryStream(await imageContent.ReadContentAsBytesAsync()))
|
imageBytes = await EpubBook.ReadCoverAsync();
|
||||||
|
}
|
||||||
|
else if (EpubBook.Content.Images.TryGetValue(imageFilePath, out EpubByteContentFileRef imageContent))
|
||||||
|
{
|
||||||
|
imageBytes = await imageContent.ReadContentAsBytesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageBytes != null)
|
||||||
|
{
|
||||||
|
using (MemoryStream imageStream = new MemoryStream(imageBytes))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -24,7 +24,7 @@ namespace QuickLook.Plugin.EpubViewer
|
|||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
public string Chapter => chapterRefs != null ? $"{chapterRefs?[currChapter].Title} ({currChapter + 1}/{chapterRefs?.Count})" : "";
|
public string Chapter => chapterRefs != null && currChapter >= 0 ? $"{chapterRefs?[currChapter].Title} ({currChapter + 1}/{chapterRefs?.Count})" : "";
|
||||||
|
|
||||||
public EpubViewerControl()
|
public EpubViewerControl()
|
||||||
{
|
{
|
||||||
@@ -42,7 +42,7 @@ namespace QuickLook.Plugin.EpubViewer
|
|||||||
this.chapterRefs = Flatten(epubBook.GetChapters());
|
this.chapterRefs = Flatten(epubBook.GetChapters());
|
||||||
this.currChapter = -1;
|
this.currChapter = -1;
|
||||||
this.pagePanel.EpubBook = epubBook;
|
this.pagePanel.EpubBook = epubBook;
|
||||||
this.NextChapter();
|
this.UpdateChapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<EpubChapterRef> Flatten(List<EpubChapterRef> list)
|
private List<EpubChapterRef> Flatten(List<EpubChapterRef> list)
|
||||||
@@ -60,11 +60,7 @@ namespace QuickLook.Plugin.EpubViewer
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.currChapter = Math.Min(this.currChapter + 1, chapterRefs.Count - 1);
|
this.currChapter = Math.Min(this.currChapter + 1, chapterRefs.Count - 1);
|
||||||
this.pagePanel.ChapterRef = chapterRefs[currChapter];
|
this.UpdateChapter();
|
||||||
if (chapterRefs[currChapter].Anchor != null)
|
|
||||||
{
|
|
||||||
this.pagePanel.ScrollToElement(chapterRefs[currChapter].Anchor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -84,12 +80,8 @@ namespace QuickLook.Plugin.EpubViewer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.currChapter = Math.Max(this.currChapter - 1, 0);
|
this.currChapter = Math.Max(this.currChapter - 1, -1);
|
||||||
this.pagePanel.ChapterRef = chapterRefs[currChapter];
|
this.UpdateChapter();
|
||||||
if (chapterRefs[currChapter].Anchor != null)
|
|
||||||
{
|
|
||||||
this.pagePanel.ScrollToElement(chapterRefs[currChapter].Anchor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -138,5 +130,26 @@ namespace QuickLook.Plugin.EpubViewer
|
|||||||
|
|
||||||
public int NewChapter { get; set; }
|
public int NewChapter { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateChapter()
|
||||||
|
{
|
||||||
|
if (currChapter < 0)
|
||||||
|
{
|
||||||
|
this.pagePanel.ChapterRef = null;
|
||||||
|
this.pagePanel.Text = string.Format(@"
|
||||||
|
<div style=""margin:4pt; text-align: center;"">
|
||||||
|
<img src=""COVER"" alt=""COVER"" style=""height:500px;""/>
|
||||||
|
<div style=""word-wrap: break-word;"">{0}</div>
|
||||||
|
</div>", epubBook.Title);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.pagePanel.ChapterRef = chapterRefs[currChapter];
|
||||||
|
if (chapterRefs[currChapter].Anchor != null)
|
||||||
|
{
|
||||||
|
this.pagePanel.ScrollToElement(chapterRefs[currChapter].Anchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user