From ef2748527348fcbd5cf84f5d33ae65174b6b3c74 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Mon, 17 Apr 2023 18:30:26 +0200 Subject: [PATCH] WIP --- internal/epub/filters/position.go | 7 ++++--- internal/epub/image_filters.go | 2 +- internal/epub/progress.go | 1 + internal/epub/toc.go | 11 ++++++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/epub/filters/position.go b/internal/epub/filters/position.go index 3c3d3b4..97f7c63 100644 --- a/internal/epub/filters/position.go +++ b/internal/epub/filters/position.go @@ -31,9 +31,10 @@ func (p *positionFilter) Draw(dst draw.Image, src image.Image, options *gift.Opt draw.Draw(dst, dst.Bounds(), image.White, dst.Bounds().Min, draw.Over) srcBounds := src.Bounds() - left, top := (p.viewWidth-srcBounds.Dx())/2, (p.viewHeight-srcBounds.Dy())/2 - if p.align == PositionLeft { - left = 0 + left, top := 0, (p.viewHeight-srcBounds.Dy())/2 + + if p.align == PositionCenter { + left = (p.viewWidth - srcBounds.Dx()) / 2 } if p.align == PositionRight { diff --git a/internal/epub/image_filters.go b/internal/epub/image_filters.go index 0eaa039..2714565 100644 --- a/internal/epub/image_filters.go +++ b/internal/epub/image_filters.go @@ -20,8 +20,8 @@ func NewGift(options *ImageOptions) *gift.GIFT { } g.Add( filters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling), - filters.Pixel(), filters.Position(options.ViewWidth, options.ViewHeight, filters.PositionCenter), + filters.Pixel(), ) return g } diff --git a/internal/epub/progress.go b/internal/epub/progress.go index f188d90..acda190 100644 --- a/internal/epub/progress.go +++ b/internal/epub/progress.go @@ -10,6 +10,7 @@ import ( func NewBar(max int, description string, currentJob, totalJob int) *progressbar.ProgressBar { fmtJob := fmt.Sprintf("%%0%dd", len(fmt.Sprint(totalJob))) fmtDesc := fmt.Sprintf("[%s/%s] %%-15s", fmtJob, fmtJob) + return progressbar.DefaultBytesSilent(int64(max)) return progressbar.NewOptions(max, progressbar.OptionSetWriter(os.Stderr), progressbar.OptionOnCompletion(func() { diff --git a/internal/epub/toc.go b/internal/epub/toc.go index d354457..7c625b3 100644 --- a/internal/epub/toc.go +++ b/internal/epub/toc.go @@ -44,9 +44,14 @@ func (e *ePub) getToc(title string, images []*Image) string { if len(ol.ChildElements()) == 1 && e.StripFirstDirectoryFromToc { ol = ol.ChildElements()[0] } - if len(ol.ChildElements()) > 0 { - nav.AddChild(ol) - } + + beginning := etree.NewElement("li") + beginningLink := beginning.CreateElement("a") + beginningLink.CreateAttr("href", images[0].TextPath()) + beginningLink.CreateText("Start of the book") + ol.InsertChildAt(0, beginning) + + nav.AddChild(ol) doc.Indent(2) r, _ := doc.WriteToString()