mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +02:00
move title generation into method
This commit is contained in:
parent
003a91a07e
commit
4a1ae516ea
@ -99,6 +99,53 @@ func (e *ePub) writeBlank(wz *epubzip.EPUBZip, img *epubimage.Image) error {
|
||||
)
|
||||
}
|
||||
|
||||
// write title image
|
||||
func (e *ePub) writeTitleImage(wz *epubzip.EPUBZip, img *epubimage.Image, title string) error {
|
||||
titleAlign := ""
|
||||
if !e.Image.View.PortraitOnly {
|
||||
if e.Image.Manga {
|
||||
titleAlign = "right:0"
|
||||
} else {
|
||||
titleAlign = "left:0"
|
||||
}
|
||||
}
|
||||
|
||||
if !e.Image.View.PortraitOnly {
|
||||
if err := wz.WriteContent(
|
||||
"OEBPS/Text/space_title.xhtml",
|
||||
[]byte(e.render(epubtemplates.Blank, map[string]any{
|
||||
"Title": "Blank Page Title",
|
||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
||||
})),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := wz.WriteContent(
|
||||
"OEBPS/Text/title.xhtml",
|
||||
[]byte(e.render(epubtemplates.Text, map[string]any{
|
||||
"Title": title,
|
||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
||||
"ImagePath": fmt.Sprintf("Images/title.%s", e.Image.Format),
|
||||
"ImageStyle": img.ImgStyle(e.Image.View.Width, e.Image.View.Height, titleAlign),
|
||||
})),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
coverTitle, err := e.imageProcessor.CoverTitleData(img.Raw, title)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := wz.WriteRaw(coverTitle); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// extract image and split it into part
|
||||
func (e *ePub) getParts() (parts []*epubPart, imgStorage *epubzip.EPUBZipStorageImageReader, err error) {
|
||||
images, err := e.imageProcessor.Load()
|
||||
@ -299,13 +346,6 @@ func (e *ePub) Write() error {
|
||||
if totalParts > 1 {
|
||||
title = fmt.Sprintf("%s [%d/%d]", title, i+1, totalParts)
|
||||
}
|
||||
titleAlign := ""
|
||||
if !e.Image.View.PortraitOnly {
|
||||
titleAlign = "left:0"
|
||||
if e.Image.Manga {
|
||||
titleAlign = "right:0"
|
||||
}
|
||||
}
|
||||
|
||||
content := []zipContent{
|
||||
{"META-INF/container.xml", epubtemplates.Container},
|
||||
@ -326,21 +366,6 @@ func (e *ePub) Write() error {
|
||||
{"OEBPS/Text/style.css", e.render(epubtemplates.Style, map[string]any{
|
||||
"View": e.Image.View,
|
||||
})},
|
||||
|
||||
{"OEBPS/Text/title.xhtml", e.render(epubtemplates.Text, map[string]any{
|
||||
"Title": title,
|
||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
||||
"ImagePath": fmt.Sprintf("Images/title.%s", e.Image.Format),
|
||||
"ImageStyle": part.Cover.ImgStyle(e.Image.View.Width, e.Image.View.Height, titleAlign),
|
||||
})},
|
||||
}
|
||||
if !e.Image.View.PortraitOnly {
|
||||
content = append(content, zipContent{
|
||||
"OEBPS/Text/space_title.xhtml", e.render(epubtemplates.Blank, map[string]any{
|
||||
"Title": "Blank Page Title",
|
||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
if err = wz.WriteMagic(); err != nil {
|
||||
@ -351,12 +376,8 @@ func (e *ePub) Write() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
coverTitle, err := e.imageProcessor.CoverTitleData(part.Cover.Raw, title)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := wz.WriteRaw(coverTitle); err != nil {
|
||||
if err = e.writeTitleImage(wz, part.Cover, title); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user