fix naming

This commit is contained in:
Celogeek 2024-02-09 10:46:20 +02:00
parent 07ba350d82
commit 139acd864b
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
12 changed files with 52 additions and 52 deletions

View File

@ -197,7 +197,7 @@ func (e *ePub) writeTitleImage(wz *epubzip.EPUBZip, img *epubimage.Image, title
} }
// extract image and split it into part // extract image and split it into part
func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorageImageReader, err error) { func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.StorageImageReader, err error) {
images, err := e.imageProcessor.Load() images, err := e.imageProcessor.Load()
if err != nil { if err != nil {
@ -226,7 +226,7 @@ func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorage
return parts, nil, nil return parts, nil, nil
} }
imgStorage, err = epubzip.NewEPUBZipStorageImageReader(e.ImgStorage()) imgStorage, err = epubzip.NewStorageImageReader(e.ImgStorage())
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -268,17 +268,17 @@ func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorage
// create a tree from the directories. // create a tree from the directories.
// //
// this is used to simulate the toc. // this is used to simulate the toc.
func (e *ePub) getTree(images []*epubimage.Image, skip_files bool) string { func (e *ePub) getTree(images []*epubimage.Image, skipFiles bool) string {
t := epubtree.New() t := epubtree.New()
for _, img := range images { for _, img := range images {
if skip_files { if skipFiles {
t.Add(img.Path) t.Add(img.Path)
} else { } else {
t.Add(filepath.Join(img.Path, img.Name)) t.Add(filepath.Join(img.Path, img.Name))
} }
} }
c := t.Root() c := t.Root()
if skip_files && e.StripFirstDirectoryFromToc && len(c.Children) == 1 { if skipFiles && e.StripFirstDirectoryFromToc && len(c.Children) == 1 {
c = c.Children[0] c = c.Children[0]
} }

View File

@ -76,7 +76,7 @@ func (i *Image) ImgStyle(viewWidth, viewHeight int, align string) string {
relWidth, relHeight := i.RelSize(viewWidth, viewHeight) relWidth, relHeight := i.RelSize(viewWidth, viewHeight)
marginW, marginH := float64(viewWidth-relWidth)/2, float64(viewHeight-relHeight)/2 marginW, marginH := float64(viewWidth-relWidth)/2, float64(viewHeight-relHeight)/2
style := []string{} var style []string
style = append(style, fmt.Sprintf("width:%dpx", relWidth)) style = append(style, fmt.Sprintf("width:%dpx", relWidth))
style = append(style, fmt.Sprintf("height:%dpx", relHeight)) style = append(style, fmt.Sprintf("height:%dpx", relHeight))

View File

@ -31,7 +31,7 @@ func (p *coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangl
} }
// Draw blur the src image, and create a box with the title in the middle // Draw blur the src image, and create a box with the title in the middle
func (p *coverTitle) Draw(dst draw.Image, src image.Image, options *gift.Options) { func (p *coverTitle) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src) draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
if p.title == "" { if p.title == "" {
return return

View File

@ -27,7 +27,7 @@ func (p *pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
return return
} }
func (p *pixel) Draw(dst draw.Image, src image.Image, options *gift.Options) { func (p *pixel) Draw(dst draw.Image, src image.Image, _ *gift.Options) {
if dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1 { if dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1 {
dst.Set(0, 0, color.White) dst.Set(0, 0, color.White)
return return

View File

@ -60,7 +60,7 @@ func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) {
}) })
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
imgStorage, err := epubzip.NewEPUBZipStorageImageWriter(e.ImgStorage(), e.Image.Format) imgStorage, err := epubzip.NewStorageImageWriter(e.ImgStorage(), e.Image.Format)
if err != nil { if err != nil {
bar.Close() bar.Close()
return nil, err return nil, err
@ -279,22 +279,22 @@ type CoverTitleDataOptions struct {
func (e *EPUBImageProcessor) Cover16LevelOfGray(bounds image.Rectangle) draw.Image { func (e *EPUBImageProcessor) Cover16LevelOfGray(bounds image.Rectangle) draw.Image {
return image.NewPaletted(bounds, color.Palette{ return image.NewPaletted(bounds, color.Palette{
color.Gray{0x00}, color.Gray{},
color.Gray{0x11}, color.Gray{Y: 0x11},
color.Gray{0x22}, color.Gray{Y: 0x22},
color.Gray{0x33}, color.Gray{Y: 0x33},
color.Gray{0x44}, color.Gray{Y: 0x44},
color.Gray{0x55}, color.Gray{Y: 0x55},
color.Gray{0x66}, color.Gray{Y: 0x66},
color.Gray{0x77}, color.Gray{Y: 0x77},
color.Gray{0x88}, color.Gray{Y: 0x88},
color.Gray{0x99}, color.Gray{Y: 0x99},
color.Gray{0xAA}, color.Gray{Y: 0xAA},
color.Gray{0xBB}, color.Gray{Y: 0xBB},
color.Gray{0xCC}, color.Gray{Y: 0xCC},
color.Gray{0xDD}, color.Gray{Y: 0xDD},
color.Gray{0xEE}, color.Gray{Y: 0xEE},
color.Gray{0xFF}, color.Gray{Y: 0xFF},
}) })
} }

View File

@ -208,7 +208,7 @@ func (e *EPUBImageProcessor) loadCbz() (totalImages int, output chan *task, err
return return
} }
names := []string{} var names []string
for _, img := range images { for _, img := range images {
names = append(names, img.Name) names = append(names, img.Name)
} }

View File

@ -5,20 +5,20 @@ import (
"os" "os"
) )
type EpubProgressJson struct { type Json struct {
o Options o Options
e *json.Encoder e *json.Encoder
current int current int
} }
func newEpubProgressJson(o Options) EpubProgress { func newEpubProgressJson(o Options) EpubProgress {
return &EpubProgressJson{ return &Json{
o: o, o: o,
e: json.NewEncoder(os.Stdout), e: json.NewEncoder(os.Stdout),
} }
} }
func (p *EpubProgressJson) Add(num int) error { func (p *Json) Add(num int) error {
p.current += num p.current += num
p.e.Encode(map[string]any{ p.e.Encode(map[string]any{
"type": "progress", "type": "progress",
@ -37,6 +37,6 @@ func (p *EpubProgressJson) Add(num int) error {
return nil return nil
} }
func (p *EpubProgressJson) Close() error { func (p *Json) Close() error {
return nil return nil
} }

View File

@ -214,7 +214,7 @@ func getSpineAuto(o *ContentOptions) []tag {
return fmt.Sprintf("%s layout-blank", getSpread(false)) return fmt.Sprintf("%s layout-blank", getSpread(false))
} }
spine := []tag{} var spine []tag
if o.HasTitlePage { if o.HasTitlePage {
if !o.ImageOptions.AppleBookCompatibility { if !o.ImageOptions.AppleBookCompatibility {
spine = append(spine, spine = append(spine,
@ -255,7 +255,7 @@ func getSpineAuto(o *ContentOptions) []tag {
} }
func getSpinePortrait(o *ContentOptions) []tag { func getSpinePortrait(o *ContentOptions) []tag {
spine := []tag{} var spine []tag
if o.HasTitlePage { if o.HasTitlePage {
spine = append(spine, spine = append(spine,
tag{"itemref", tagAttrs{"idref": "page_title"}, ""}, tag{"itemref", tagAttrs{"idref": "page_title"}, ""},

View File

@ -7,23 +7,23 @@ import (
"sync" "sync"
) )
type EPUBZipStorageImageWriter struct { type StorageImageWriter struct {
fh *os.File fh *os.File
fz *zip.Writer fz *zip.Writer
format string format string
mut *sync.Mutex mut *sync.Mutex
} }
func NewEPUBZipStorageImageWriter(filename string, format string) (*EPUBZipStorageImageWriter, error) { func NewStorageImageWriter(filename string, format string) (*StorageImageWriter, error) {
fh, err := os.Create(filename) fh, err := os.Create(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }
fz := zip.NewWriter(fh) fz := zip.NewWriter(fh)
return &EPUBZipStorageImageWriter{fh, fz, format, &sync.Mutex{}}, nil return &StorageImageWriter{fh, fz, format, &sync.Mutex{}}, nil
} }
func (e *EPUBZipStorageImageWriter) Close() error { func (e *StorageImageWriter) Close() error {
if err := e.fz.Close(); err != nil { if err := e.fz.Close(); err != nil {
e.fh.Close() e.fh.Close()
return err return err
@ -31,7 +31,7 @@ func (e *EPUBZipStorageImageWriter) Close() error {
return e.fh.Close() return e.fh.Close()
} }
func (e *EPUBZipStorageImageWriter) Add(filename string, img image.Image, quality int) error { func (e *StorageImageWriter) Add(filename string, img image.Image, quality int) error {
zipImage, err := CompressImage(filename, e.format, img, quality) zipImage, err := CompressImage(filename, e.format, img, quality)
if err != nil { if err != nil {
return err return err
@ -51,7 +51,7 @@ func (e *EPUBZipStorageImageWriter) Add(filename string, img image.Image, qualit
return nil return nil
} }
type EPUBZipStorageImageReader struct { type StorageImageReader struct {
filename string filename string
fh *os.File fh *os.File
fz *zip.Reader fz *zip.Reader
@ -59,7 +59,7 @@ type EPUBZipStorageImageReader struct {
files map[string]*zip.File files map[string]*zip.File
} }
func NewEPUBZipStorageImageReader(filename string) (*EPUBZipStorageImageReader, error) { func NewStorageImageReader(filename string) (*StorageImageReader, error) {
fh, err := os.Open(filename) fh, err := os.Open(filename)
if err != nil { if err != nil {
return nil, err return nil, err
@ -76,14 +76,14 @@ func NewEPUBZipStorageImageReader(filename string) (*EPUBZipStorageImageReader,
for _, z := range fz.File { for _, z := range fz.File {
files[z.Name] = z files[z.Name] = z
} }
return &EPUBZipStorageImageReader{filename, fh, fz, files}, nil return &StorageImageReader{filename, fh, fz, files}, nil
} }
func (e *EPUBZipStorageImageReader) Get(filename string) *zip.File { func (e *StorageImageReader) Get(filename string) *zip.File {
return e.files[filename] return e.files[filename]
} }
func (e *EPUBZipStorageImageReader) Size(filename string) uint64 { func (e *StorageImageReader) Size(filename string) uint64 {
img := e.Get(filename) img := e.Get(filename)
if img != nil { if img != nil {
return img.CompressedSize64 + 30 + uint64(len(img.Name)) return img.CompressedSize64 + 30 + uint64(len(img.Name))
@ -91,10 +91,10 @@ func (e *EPUBZipStorageImageReader) Size(filename string) uint64 {
return 0 return 0
} }
func (e *EPUBZipStorageImageReader) Close() error { func (e *StorageImageReader) Close() error {
return e.fh.Close() return e.fh.Close()
} }
func (e *EPUBZipStorageImageReader) Remove() error { func (e *StorageImageReader) Remove() error {
return os.Remove(e.filename) return os.Remove(e.filename)
} }

View File

@ -41,7 +41,7 @@ func (b by) Swap(i, j int) {
// By use sortpath.By with sort.Sort // By use sortpath.By with sort.Sort
func By(filenames []string, mode int) by { func By(filenames []string, mode int) by {
p := [][]part{} var p [][]part
for _, filename := range filenames { for _, filename := range filenames {
p = append(p, parse(filename, mode)) p = append(p, parse(filename, mode))
} }

View File

@ -8,7 +8,7 @@ import (
) )
// Strings follow with numbers like: s1, s1.2, s2-3, ... // Strings follow with numbers like: s1, s1.2, s2-3, ...
var split_path_regex = regexp.MustCompile(`^(.*?)(\d+(?:\.\d+)?)(?:-(\d+(?:\.\d+)?))?$`) var splitPathRegex = regexp.MustCompile(`^(.*?)(\d+(?:\.\d+)?)(?:-(\d+(?:\.\d+)?))?$`)
type part struct { type part struct {
fullname string fullname string
@ -31,7 +31,7 @@ func (a part) compare(b part) float64 {
// separate from the string the number part. // separate from the string the number part.
func parsePart(p string) part { func parsePart(p string) part {
r := split_path_regex.FindStringSubmatch(p) r := splitPathRegex.FindStringSubmatch(p)
if len(r) == 0 { if len(r) == 0 {
return part{p, p, 0} return part{p, p, 0}
} }
@ -51,7 +51,7 @@ func parse(filename string, mode int) []part {
ext := filepath.Ext(name) ext := filepath.Ext(name)
name = name[0 : len(name)-len(ext)] name = name[0 : len(name)-len(ext)]
f := []part{} var f []part
for _, p := range strings.Split(pathname, string(filepath.Separator)) { for _, p := range strings.Split(pathname, string(filepath.Separator)) {
if mode > 0 { // alphanumeric for path if mode > 0 { // alphanumeric for path
f = append(f, parsePart(p)) f = append(f, parsePart(p))

View File

@ -43,7 +43,7 @@ func main() {
fmt.Fprintln(os.Stderr, "failed to fetch the latest version") fmt.Fprintln(os.Stderr, "failed to fetch the latest version")
os.Exit(1) os.Exit(1)
} }
latest_version := v.Versions[0] latestVersion := v.Versions[0]
fmt.Fprintf(os.Stderr, `go-comic-converter fmt.Fprintf(os.Stderr, `go-comic-converter
Path : %s Path : %s
@ -57,9 +57,9 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
bi.Main.Path, bi.Main.Path,
bi.Main.Sum, bi.Main.Sum,
bi.Main.Version, bi.Main.Version,
latest_version.Original(), latestVersion.Original(),
latest_version.Segments()[0], latestVersion.Segments()[0],
latest_version.Original(), latestVersion.Original(),
) )
return return
} }