mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
rename epub
This commit is contained in:
parent
a76f29e91d
commit
577d51a819
@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/celogeek/go-comic-converter/v2/internal/utils"
|
"github.com/celogeek/go-comic-converter/v2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EPub struct {
|
type EPUB struct {
|
||||||
epuboptions.Options
|
epuboptions.Options
|
||||||
UID string
|
UID string
|
||||||
Publisher string
|
Publisher string
|
||||||
@ -40,7 +40,7 @@ type epubPart struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New initialize EPUB
|
// New initialize EPUB
|
||||||
func New(options epuboptions.Options) EPub {
|
func New(options epuboptions.Options) EPUB {
|
||||||
uid := uuid.Must(uuid.NewV4())
|
uid := uuid.Must(uuid.NewV4())
|
||||||
tmpl := template.New("parser")
|
tmpl := template.New("parser")
|
||||||
tmpl.Funcs(template.FuncMap{
|
tmpl.Funcs(template.FuncMap{
|
||||||
@ -48,7 +48,7 @@ func New(options epuboptions.Options) EPub {
|
|||||||
"zoom": func(s int, z float32) int { return int(float32(s) * z) },
|
"zoom": func(s int, z float32) int { return int(float32(s) * z) },
|
||||||
})
|
})
|
||||||
|
|
||||||
return EPub{
|
return EPUB{
|
||||||
Options: options,
|
Options: options,
|
||||||
UID: uid.String(),
|
UID: uid.String(),
|
||||||
Publisher: "GO Comic Converter",
|
Publisher: "GO Comic Converter",
|
||||||
@ -59,7 +59,7 @@ func New(options epuboptions.Options) EPub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// render templates
|
// render templates
|
||||||
func (e EPub) render(templateString string, data map[string]any) string {
|
func (e EPUB) render(templateString string, data map[string]any) string {
|
||||||
var result strings.Builder
|
var result strings.Builder
|
||||||
tmpl := template.Must(e.templateProcessor.Parse(templateString))
|
tmpl := template.Must(e.templateProcessor.Parse(templateString))
|
||||||
if err := tmpl.Execute(&result, data); err != nil {
|
if err := tmpl.Execute(&result, data); err != nil {
|
||||||
@ -69,7 +69,7 @@ func (e EPub) render(templateString string, data map[string]any) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write image to the zip
|
// write image to the zip
|
||||||
func (e EPub) writeImage(wz epubzip.EPUBZip, img epubimage.Image, zipImg *zip.File) error {
|
func (e EPUB) writeImage(wz epubzip.EPUBZip, img epubimage.Image, zipImg *zip.File) error {
|
||||||
err := wz.WriteContent(
|
err := wz.WriteContent(
|
||||||
img.EPUBPagePath(),
|
img.EPUBPagePath(),
|
||||||
[]byte(e.render(epubtemplates.Text, map[string]any{
|
[]byte(e.render(epubtemplates.Text, map[string]any{
|
||||||
@ -87,7 +87,7 @@ func (e EPub) writeImage(wz epubzip.EPUBZip, img epubimage.Image, zipImg *zip.Fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write blank page
|
// write blank page
|
||||||
func (e EPub) writeBlank(wz epubzip.EPUBZip, img epubimage.Image) error {
|
func (e EPUB) writeBlank(wz epubzip.EPUBZip, img epubimage.Image) error {
|
||||||
return wz.WriteContent(
|
return wz.WriteContent(
|
||||||
img.EPUBSpacePath(),
|
img.EPUBSpacePath(),
|
||||||
[]byte(e.render(epubtemplates.Blank, map[string]any{
|
[]byte(e.render(epubtemplates.Blank, map[string]any{
|
||||||
@ -98,7 +98,7 @@ func (e EPub) writeBlank(wz epubzip.EPUBZip, img epubimage.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write title image
|
// write title image
|
||||||
func (e EPub) writeCoverImage(wz epubzip.EPUBZip, img epubimage.Image, part, totalParts int) error {
|
func (e EPUB) writeCoverImage(wz epubzip.EPUBZip, img epubimage.Image, part, totalParts int) error {
|
||||||
title := "Cover"
|
title := "Cover"
|
||||||
text := ""
|
text := ""
|
||||||
if totalParts > 1 {
|
if totalParts > 1 {
|
||||||
@ -141,7 +141,7 @@ func (e EPub) writeCoverImage(wz epubzip.EPUBZip, img epubimage.Image, part, tot
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write title image
|
// write title image
|
||||||
func (e EPub) writeTitleImage(wz epubzip.EPUBZip, img epubimage.Image, title string) error {
|
func (e EPUB) writeTitleImage(wz epubzip.EPUBZip, img epubimage.Image, title string) error {
|
||||||
titleAlign := ""
|
titleAlign := ""
|
||||||
if !e.Image.View.PortraitOnly {
|
if !e.Image.View.PortraitOnly {
|
||||||
if e.Image.Manga {
|
if e.Image.Manga {
|
||||||
@ -197,7 +197,7 @@ func (e EPub) writeTitleImage(wz epubzip.EPUBZip, img epubimage.Image, title str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// extract image and split it into part
|
// extract image and split it into part
|
||||||
func (e EPub) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReader, 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 {
|
||||||
@ -268,7 +268,7 @@ func (e EPub) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReade
|
|||||||
// 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, skipFiles 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 skipFiles {
|
if skipFiles {
|
||||||
@ -285,7 +285,7 @@ func (e EPub) getTree(images []epubimage.Image, skipFiles bool) string {
|
|||||||
return c.WriteString("")
|
return c.WriteString("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EPub) computeAspectRatio(epubParts []epubPart) float64 {
|
func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
|
||||||
var (
|
var (
|
||||||
bestAspectRatio float64
|
bestAspectRatio float64
|
||||||
bestAspectRatioCount int
|
bestAspectRatioCount int
|
||||||
@ -312,7 +312,7 @@ func (e EPub) computeAspectRatio(epubParts []epubPart) float64 {
|
|||||||
return bestAspectRatio
|
return bestAspectRatio
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EPub) computeViewPort(epubParts []epubPart) {
|
func (e EPUB) computeViewPort(epubParts []epubPart) {
|
||||||
if e.Image.View.AspectRatio == -1 {
|
if e.Image.View.AspectRatio == -1 {
|
||||||
return //keep device size
|
return //keep device size
|
||||||
}
|
}
|
||||||
@ -331,7 +331,7 @@ func (e EPub) computeViewPort(epubParts []epubPart) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EPub) writePart(path string, currentPart, totalParts int, part epubPart, imgStorage epubzip.StorageImageReader) error {
|
func (e EPUB) writePart(path string, currentPart, totalParts int, part epubPart, imgStorage epubzip.StorageImageReader) error {
|
||||||
hasTitlePage := e.TitlePage == 1 || (e.TitlePage == 2 && totalParts > 1)
|
hasTitlePage := e.TitlePage == 1 || (e.TitlePage == 2 && totalParts > 1)
|
||||||
|
|
||||||
wz, err := epubzip.New(path)
|
wz, err := epubzip.New(path)
|
||||||
@ -412,7 +412,7 @@ func (e EPub) writePart(path string, currentPart, totalParts int, part epubPart,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the zip
|
// create the zip
|
||||||
func (e EPub) Write() error {
|
func (e EPUB) Write() error {
|
||||||
epubParts, imgStorage, err := e.getParts()
|
epubParts, imgStorage, err := e.getParts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user