mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-06-26 07:09:55 +02:00
improve spread, and blank for double page rendering
When autosplitdoublepage is activated, We will display a blank page after the full image, if necessary, for good rendering on a reader that support, double page rendering (like Apple Book).
This commit is contained in:
parent
f1fd7a9b77
commit
21b099ab33
internal/epub
@ -56,10 +56,27 @@ func NewEpub(options *EpubOptions) *ePub {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var spreadRight = options.Manga
|
||||
|
||||
tmpl := template.New("parser")
|
||||
tmpl.Funcs(template.FuncMap{
|
||||
"mod": func(i, j int) bool { return i%j == 0 },
|
||||
"zoom": func(s int, z float32) int { return int(float32(s) * z) },
|
||||
"spread": func() (spread string) {
|
||||
if spreadRight {
|
||||
spread = "right"
|
||||
} else {
|
||||
spread = "left"
|
||||
}
|
||||
spreadRight = !spreadRight
|
||||
return
|
||||
},
|
||||
"spread_blank": func(part int) bool {
|
||||
if part == 1 && spreadRight == options.Manga {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
})
|
||||
|
||||
return &ePub{
|
||||
@ -186,13 +203,28 @@ func (e *ePub) Write() error {
|
||||
wz.WriteImage(part.Cover.Data)
|
||||
|
||||
for _, img := range part.Images {
|
||||
text := fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part)
|
||||
if err := wz.WriteFile(text, e.render(textTmpl, map[string]any{
|
||||
"Image": img,
|
||||
"Manga": e.Manga,
|
||||
})); err != nil {
|
||||
if err := wz.WriteFile(
|
||||
fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part),
|
||||
e.render(textTmpl, map[string]any{
|
||||
"Image": img,
|
||||
"Manga": e.Manga,
|
||||
}),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if img.Part == 1 {
|
||||
if err := wz.WriteFile(
|
||||
fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id),
|
||||
e.render(blankTmpl, map[string]any{
|
||||
"Info": e,
|
||||
"Image": img,
|
||||
}),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := wz.WriteImage(img.Data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -22,3 +22,6 @@ var partTmpl string
|
||||
|
||||
//go:embed "templates/text.xhtml.tmpl"
|
||||
var textTmpl string
|
||||
|
||||
//go:embed "templates/blank.xhtml.tmpl"
|
||||
var blankTmpl string
|
||||
|
14
internal/epub/templates/blank.xhtml.tmpl
Normal file
14
internal/epub/templates/blank.xhtml.tmpl
Normal file
@ -0,0 +1,14 @@
|
||||
<?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>
|
||||
<title>Page {{ .Image.Id }} Space</title>
|
||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
||||
<meta name="viewport" content="width={{ .Info.ViewWidth }}, height={{ .Info.ViewHeight }}"/>
|
||||
</head>
|
||||
<body style="">
|
||||
<div style="text-align:center;top:0.0%;">
|
||||
<h1>{{ if .Info.Manga }}←{{ else }}→{{ end }}</h1>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -28,21 +28,18 @@
|
||||
{{ range .Images }}
|
||||
<item id="page_{{ .Id }}_p{{ .Part}}" href="Text/{{ .Id }}_p{{ .Part}}.xhtml" media-type="application/xhtml+xml"/>
|
||||
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
||||
{{ if eq .Part 1 }}
|
||||
<item id="page_{{ .Id }}_sp" href="Text/{{ .Id }}_sp.xhtml" media-type="application/xhtml+xml"/>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</manifest>
|
||||
{{ if .Info.Manga }}
|
||||
<spine page-progression-direction="rtl" toc="ncx">
|
||||
<itemref idref="page_part" linear="yes" properties="page-spread-right"/>
|
||||
{{ range $idx, $ := .Images }}
|
||||
<itemref idref="page_{{ $.Id }}_p{{ $.Part }}" linear="yes" properties="page-spread-{{ if mod $idx 2 }}left{{ else }}right{{ end }}"/>
|
||||
<spine page-progression-direction="{{ if .Info.Manga }}rtl{{ else }}ltr{{ end }}" toc="ncx">
|
||||
<itemref idref="page_part" linear="yes" properties="page-spread-{{ spread }}"/>
|
||||
{{ range .Images }}
|
||||
{{ if spread_blank .Part }}
|
||||
<itemref idref="page_{{ .Id }}_sp" linear="yes" properties="page-spread-{{ spread }}"/>
|
||||
{{ end }}
|
||||
<itemref idref="page_{{ .Id }}_p{{ .Part }}" linear="yes" properties="page-spread-{{ spread }}"/>
|
||||
{{ end }}
|
||||
</spine>
|
||||
{{ else }}
|
||||
<spine page-progression-direction="ltr" toc="ncx">
|
||||
<itemref idref="page_part" linear="yes" properties="page-spread-left"/>
|
||||
{{ range $idx, $ := .Images }}
|
||||
<itemref idref="page_{{ $.Id }}_p{{ $.Part }}" linear="yes" properties="page-spread-{{ if mod $idx 2 }}right{{ else }}end{{ end }}"/>
|
||||
{{ end }}
|
||||
</spine>
|
||||
{{ end }}
|
||||
</package>
|
||||
|
Loading…
x
Reference in New Issue
Block a user