mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 16:22:37 +02:00
create title page
This commit is contained in:
parent
e79cd346c4
commit
5960c56938
@ -122,6 +122,10 @@ func (e *ePub) writeBlank(wz *epubZip, img *Image) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e ePub) getTitleImageData(img *Image, currentPart, totalPart int) *ImageData {
|
||||||
|
return newData("OEBPS/Images/title.jpg", img.Raw, e.Quality)
|
||||||
|
}
|
||||||
|
|
||||||
func (e *ePub) getParts() ([]*epubPart, error) {
|
func (e *ePub) getParts() ([]*epubPart, error) {
|
||||||
images, err := e.LoadImages()
|
images, err := e.LoadImages()
|
||||||
|
|
||||||
@ -243,10 +247,11 @@ func (e *ePub) Write() error {
|
|||||||
"PageWidth": e.ViewWidth,
|
"PageWidth": e.ViewWidth,
|
||||||
"PageHeight": e.ViewHeight,
|
"PageHeight": e.ViewHeight,
|
||||||
})},
|
})},
|
||||||
{"OEBPS/Text/title.xhtml", e.render(titleTmpl, map[string]any{
|
{"OEBPS/Text/title.xhtml", e.render(textTmpl, map[string]any{
|
||||||
"Info": e,
|
"Title": title,
|
||||||
"Part": i + 1,
|
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.ViewWidth, e.ViewHeight),
|
||||||
"Total": totalParts,
|
"ImagePath": "Images/title.jpg",
|
||||||
|
"ImageStyle": part.Cover.ImgStyle(e.ViewWidth, e.ViewHeight, e.Manga),
|
||||||
})},
|
})},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,6 +263,9 @@ func (e *ePub) Write() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := wz.WriteImage(e.getTitleImageData(part.Cover, i+1, totalParts)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Cover exist or part > 1
|
// Cover exist or part > 1
|
||||||
// If no cover, part 2 and more will include the image as a cover
|
// If no cover, part 2 and more will include the image as a cover
|
||||||
|
@ -75,6 +75,8 @@ func (e *ePub) getManifest(title string, part *epubPart, currentPart, totalPart
|
|||||||
items := []Tag{
|
items := []Tag{
|
||||||
{"item", TagAttrs{"id": "toc", "href": "toc.xhtml", "properties": "nav", "media-type": "application/xhtml+xml"}, ""},
|
{"item", TagAttrs{"id": "toc", "href": "toc.xhtml", "properties": "nav", "media-type": "application/xhtml+xml"}, ""},
|
||||||
{"item", TagAttrs{"id": "css", "href": "Text/style.css", "media-type": "text/css"}, ""},
|
{"item", TagAttrs{"id": "css", "href": "Text/style.css", "media-type": "text/css"}, ""},
|
||||||
|
{"item", TagAttrs{"id": "page_title", "href": "Text/title.xhtml", "media-type": "application/xhtml+xml"}, ""},
|
||||||
|
{"item", TagAttrs{"id": "img_title", "href": "Images/title.jpg", "media-type": "image/jpeg"}, ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.HasCover || currentPart > 1 {
|
if e.HasCover || currentPart > 1 {
|
||||||
@ -93,7 +95,6 @@ func (e *ePub) getManifest(title string, part *epubPart, currentPart, totalPart
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *ePub) getSpine(title string, part *epubPart, currentPart, totalPart int) []Tag {
|
func (e *ePub) getSpine(title string, part *epubPart, currentPart, totalPart int) []Tag {
|
||||||
spine := []Tag{}
|
|
||||||
isOnTheRight := !e.Manga
|
isOnTheRight := !e.Manga
|
||||||
getSpread := func(doublePageNoBlank bool) string {
|
getSpread := func(doublePageNoBlank bool) string {
|
||||||
isOnTheRight = !isOnTheRight
|
isOnTheRight = !isOnTheRight
|
||||||
@ -108,6 +109,10 @@ func (e *ePub) getSpine(title string, part *epubPart, currentPart, totalPart int
|
|||||||
return "rendition:page-spread-left"
|
return "rendition:page-spread-left"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spine := []Tag{
|
||||||
|
{"itemref", TagAttrs{"idref": "page_title", "properties": getSpread(false)}, ""},
|
||||||
|
}
|
||||||
for _, img := range part.Images {
|
for _, img := range part.Images {
|
||||||
spine = append(spine, Tag{
|
spine = append(spine, Tag{
|
||||||
"itemref",
|
"itemref",
|
||||||
|
@ -22,6 +22,10 @@ func (img *ImageData) CompressedSize() uint64 {
|
|||||||
|
|
||||||
func newImageData(id int, part int, img image.Image, quality int) *ImageData {
|
func newImageData(id int, part int, img image.Image, quality int) *ImageData {
|
||||||
name := fmt.Sprintf("OEBPS/Images/%d_p%d.jpg", id, part)
|
name := fmt.Sprintf("OEBPS/Images/%d_p%d.jpg", id, part)
|
||||||
|
return newData(name, img, quality)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newData(name string, img image.Image, quality int) *ImageData {
|
||||||
data := bytes.NewBuffer([]byte{})
|
data := bytes.NewBuffer([]byte{})
|
||||||
if err := jpeg.Encode(data, img, &jpeg.Options{Quality: quality}); err != nil {
|
if err := jpeg.Encode(data, img, &jpeg.Options{Quality: quality}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
type Image struct {
|
type Image struct {
|
||||||
Id int
|
Id int
|
||||||
Part int
|
Part int
|
||||||
|
Raw image.Image
|
||||||
Data *ImageData
|
Data *ImageData
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
@ -180,15 +181,9 @@ func (e *ePub) LoadImages() ([]*Image, error) {
|
|||||||
for img := range imageInput {
|
for img := range imageInput {
|
||||||
img.Reader.Close()
|
img.Reader.Close()
|
||||||
images = append(images, &Image{
|
images = append(images, &Image{
|
||||||
Id: img.Id,
|
Id: img.Id,
|
||||||
Part: 0,
|
Path: img.Path,
|
||||||
Data: nil,
|
Name: img.Name,
|
||||||
Width: 0,
|
|
||||||
Height: 0,
|
|
||||||
IsCover: false,
|
|
||||||
DoublePage: false,
|
|
||||||
Path: img.Path,
|
|
||||||
Name: img.Name,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,9 +224,15 @@ func (e *ePub) LoadImages() ([]*Image, error) {
|
|||||||
dst := image.NewGray(g.Bounds(src.Bounds()))
|
dst := image.NewGray(g.Bounds(src.Bounds()))
|
||||||
g.Draw(dst, src)
|
g.Draw(dst, src)
|
||||||
|
|
||||||
|
var raw image.Image
|
||||||
|
if img.Id == 0 {
|
||||||
|
raw = dst
|
||||||
|
}
|
||||||
|
|
||||||
imageOutput <- &Image{
|
imageOutput <- &Image{
|
||||||
Id: img.Id,
|
Id: img.Id,
|
||||||
Part: 0,
|
Part: 0,
|
||||||
|
Raw: raw,
|
||||||
Data: newImageData(img.Id, 0, dst, e.ImageOptions.Quality),
|
Data: newImageData(img.Id, 0, dst, e.ImageOptions.Quality),
|
||||||
Width: dst.Bounds().Dx(),
|
Width: dst.Bounds().Dx(),
|
||||||
Height: dst.Bounds().Dy(),
|
Height: dst.Bounds().Dy(),
|
||||||
|
@ -11,9 +11,6 @@ var appleBooksTmpl string
|
|||||||
//go:embed "templates/epub_templates_style.css.tmpl"
|
//go:embed "templates/epub_templates_style.css.tmpl"
|
||||||
var styleTmpl string
|
var styleTmpl string
|
||||||
|
|
||||||
//go:embed "templates/epub_templates_title.xhtml.tmpl"
|
|
||||||
var titleTmpl string
|
|
||||||
|
|
||||||
//go:embed "templates/epub_templates_text.xhtml.tmpl"
|
//go:embed "templates/epub_templates_text.xhtml.tmpl"
|
||||||
var textTmpl string
|
var textTmpl string
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ func (e *ePub) getToc(title string, images []*Image) string {
|
|||||||
|
|
||||||
beginning := etree.NewElement("li")
|
beginning := etree.NewElement("li")
|
||||||
beginningLink := beginning.CreateElement("a")
|
beginningLink := beginning.CreateElement("a")
|
||||||
beginningLink.CreateAttr("href", images[0].TextPath())
|
beginningLink.CreateAttr("href", "Text/title.xhtml")
|
||||||
beginningLink.CreateText("Start of the book")
|
beginningLink.CreateText(title)
|
||||||
ol.InsertChildAt(0, beginning)
|
ol.InsertChildAt(0, beginning)
|
||||||
|
|
||||||
nav.AddChild(ol)
|
nav.AddChild(ol)
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>Part {{ .Part }}</title>
|
|
||||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
|
||||||
<meta name="viewport" content="width={{ .Info.ViewWidth }}, height={{ .Info.ViewHeight }}"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h2>{{ .Info.Title }}</h2>
|
|
||||||
{{ if gt .Total 1 }}
|
|
||||||
<h3>Part {{ .Part }} / {{ .Total }}</h3>
|
|
||||||
{{ end }}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
x
Reference in New Issue
Block a user