mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
simplify content opf, revamp needspace
This commit is contained in:
parent
393bba0266
commit
8a77bda99e
@ -60,27 +60,10 @@ func NewEpub(options *EpubOptions) *ePub {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var spreadRight = options.Manga
|
|
||||||
|
|
||||||
tmpl := template.New("parser")
|
tmpl := template.New("parser")
|
||||||
tmpl.Funcs(template.FuncMap{
|
tmpl.Funcs(template.FuncMap{
|
||||||
"mod": func(i, j int) bool { return i%j == 0 },
|
"mod": func(i, j int) bool { return i%j == 0 },
|
||||||
"zoom": func(s int, z float32) int { return int(float32(s) * z) },
|
"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 !options.NoBlankPage && part == 1 && spreadRight == options.Manga {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return &ePub{
|
return &ePub{
|
||||||
@ -118,14 +101,6 @@ func (e *ePub) getParts() ([]*epubPart, error) {
|
|||||||
if e.HasCover {
|
if e.HasCover {
|
||||||
images = images[1:]
|
images = images[1:]
|
||||||
}
|
}
|
||||||
if e.LimitMb == 0 {
|
|
||||||
parts = append(parts, &epubPart{
|
|
||||||
Cover: cover,
|
|
||||||
Images: images,
|
|
||||||
})
|
|
||||||
return parts, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
maxSize := uint64(e.LimitMb * 1024 * 1024)
|
maxSize := uint64(e.LimitMb * 1024 * 1024)
|
||||||
|
|
||||||
xhtmlSize := uint64(1024)
|
xhtmlSize := uint64(1024)
|
||||||
@ -135,20 +110,24 @@ func (e *ePub) getParts() ([]*epubPart, error) {
|
|||||||
currentSize := baseSize
|
currentSize := baseSize
|
||||||
currentImages := make([]*Image, 0)
|
currentImages := make([]*Image, 0)
|
||||||
part := 1
|
part := 1
|
||||||
|
imgIsOnRightSide := false
|
||||||
|
|
||||||
for _, img := range images {
|
for _, img := range images {
|
||||||
imgSize := img.Data.CompressedSize() + xhtmlSize
|
imgSize := img.Data.CompressedSize() + xhtmlSize
|
||||||
if len(currentImages) > 0 && currentSize+imgSize > maxSize {
|
if maxSize > 0 && len(currentImages) > 0 && currentSize+imgSize > maxSize {
|
||||||
parts = append(parts, &epubPart{
|
parts = append(parts, &epubPart{
|
||||||
Cover: cover,
|
Cover: cover,
|
||||||
Images: currentImages,
|
Images: currentImages,
|
||||||
})
|
})
|
||||||
part += 1
|
part += 1
|
||||||
|
imgIsOnRightSide = false
|
||||||
currentSize = baseSize
|
currentSize = baseSize
|
||||||
currentImages = make([]*Image, 0)
|
currentImages = make([]*Image, 0)
|
||||||
}
|
}
|
||||||
currentSize += imgSize
|
currentSize += imgSize
|
||||||
|
img.NeedSpace = img.Part == 1 && imgIsOnRightSide
|
||||||
currentImages = append(currentImages, img)
|
currentImages = append(currentImages, img)
|
||||||
|
imgIsOnRightSide = !imgIsOnRightSide
|
||||||
}
|
}
|
||||||
if len(currentImages) > 0 {
|
if len(currentImages) > 0 {
|
||||||
parts = append(parts, &epubPart{
|
parts = append(parts, &epubPart{
|
||||||
@ -235,7 +214,7 @@ func (e *ePub) Write() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !e.NoBlankPage && img.Part == 1 {
|
if img.NeedSpace {
|
||||||
if err := wz.WriteFile(
|
if err := wz.WriteFile(
|
||||||
fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id),
|
fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id),
|
||||||
e.render(blankTmpl, map[string]any{
|
e.render(blankTmpl, map[string]any{
|
||||||
|
@ -22,12 +22,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
Id int
|
Id int
|
||||||
Part int
|
Part int
|
||||||
Data *ImageData
|
Data *ImageData
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
IsCover bool
|
IsCover bool
|
||||||
|
NeedSpace bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type imageTask struct {
|
type imageTask struct {
|
||||||
@ -154,6 +155,7 @@ func LoadImages(path string, options *ImageOptions) ([]*Image, error) {
|
|||||||
dst.Bounds().Dx(),
|
dst.Bounds().Dx(),
|
||||||
dst.Bounds().Dy(),
|
dst.Bounds().Dy(),
|
||||||
img.Id == 0,
|
img.Id == 0,
|
||||||
|
false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto split double page
|
// Auto split double page
|
||||||
@ -176,6 +178,7 @@ func LoadImages(path string, options *ImageOptions) ([]*Image, error) {
|
|||||||
dst.Bounds().Dx(),
|
dst.Bounds().Dx(),
|
||||||
dst.Bounds().Dy(),
|
dst.Bounds().Dy(),
|
||||||
false,
|
false,
|
||||||
|
false, // NeedSpace reajust during parts computation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,51 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<package version="3.0" unique-identifier="BookID" xmlns="http://www.idpf.org/2007/opf">
|
<package version="3.0" unique-identifier="BookID" xmlns="http://www.idpf.org/2007/opf">
|
||||||
{{ $info := .Info }}
|
{{ $info := .Info }}
|
||||||
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||||
<dc:title>{{ $info.Title }}</dc:title>
|
<dc:title>{{ $info.Title }}</dc:title>
|
||||||
<dc:language>en-US</dc:language>
|
<dc:language>en-US</dc:language>
|
||||||
<dc:identifier id="BookID">urn:uuid:{{ $info.UID }}</dc:identifier>
|
<dc:identifier id="BookID">urn:uuid:{{ $info.UID }}</dc:identifier>
|
||||||
<dc:contributor id="contributor">GO Comic Converter</dc:contributor>
|
<dc:contributor id="contributor">GO Comic Converter</dc:contributor>
|
||||||
<dc:creator>GO Comic Converter</dc:creator>
|
<dc:creator>GO Comic Converter</dc:creator>
|
||||||
<meta property="dcterms:modified">{{ $info.UpdatedAt }}</meta>
|
<meta property="dcterms:modified">{{ $info.UpdatedAt }}</meta>
|
||||||
<meta name="cover" content="cover"/>
|
<meta name="fixed-layout" content="true"/>
|
||||||
<meta name="fixed-layout" content="true"/>
|
<meta name="original-resolution" content="{{ $info.ViewWidth }}x{{ $info.ViewHeight }}"/>
|
||||||
<meta name="original-resolution" content="{{ $info.ViewWidth }}x{{ $info.ViewHeight }}"/>
|
<meta name="book-type" content="comic"/>
|
||||||
<meta name="book-type" content="comic"/>
|
<meta name="primary-writing-mode" content="horizontal-{{ if $info.Manga }}rl{{ else }}lr{{ end }}"/>
|
||||||
<meta name="primary-writing-mode" content="horizontal-{{ if $info.Manga }}rl{{ else }}lr{{ end }}"/>
|
<meta property="rendition:orientation">portrait</meta>
|
||||||
<meta name="zero-gutter" content="true"/>
|
<meta name="orientation-lock" content="portrait"/>
|
||||||
<meta name="zero-margin" content="true"/>
|
|
||||||
<meta name="ke-border-color" content="#FFFFFF"/>
|
|
||||||
<meta name="ke-border-width" content="0"/>
|
|
||||||
<meta name="orientation-lock" content="portrait"/>
|
|
||||||
<meta name="region-mag" content="true"/>
|
|
||||||
</metadata>
|
|
||||||
<manifest>
|
|
||||||
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
|
||||||
<item id="nav" href="nav.xhtml" properties="nav" media-type="application/xhtml+xml"/>
|
|
||||||
<item id="cover" href="Images/{{ .Cover.Id }}_p{{ .Cover.Part }}.jpg" media-type="image/jpeg" properties="cover-image"/>
|
|
||||||
<item id="style_css" href="Text/style.css" media-type="text/css"/>
|
|
||||||
{{ if eq $info.AddPanelView true }}
|
{{ if eq $info.AddPanelView true }}
|
||||||
<item id="panelview_css" href="Text/panelview.css" media-type="text/css"/>
|
<meta name="region-mag" content="true"/>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<item id="page_part" href="Text/part.xhtml" media-type="application/xhtml+xml"/>
|
</metadata>
|
||||||
|
<manifest>
|
||||||
|
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
||||||
|
<item id="nav" href="nav.xhtml" properties="nav" media-type="application/xhtml+xml"/>
|
||||||
|
<item id="style_css" href="Text/style.css" media-type="text/css"/>
|
||||||
|
{{ if eq $info.AddPanelView true }}
|
||||||
|
<item id="panelview_css" href="Text/panelview.css" media-type="text/css"/>
|
||||||
|
{{ end }}
|
||||||
|
<item id="cover" href="Images/{{ .Cover.Id }}_p{{ .Cover.Part }}.jpg" media-type="image/jpeg" properties="cover-image"/>
|
||||||
{{ range .Images }}
|
{{ range .Images }}
|
||||||
<item id="page_{{ .Id }}_p{{ .Part}}" href="Text/{{ .Id }}_p{{ .Part}}.xhtml" media-type="application/xhtml+xml"/>
|
|
||||||
{{ if eq .IsCover false }}
|
{{ if eq .IsCover false }}
|
||||||
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
||||||
{{ end }}
|
|
||||||
{{ if eq $info.NoBlankPage false }}
|
|
||||||
{{ if eq .Part 1 }}
|
|
||||||
<item id="page_{{ .Id }}_sp" href="Text/{{ .Id }}_sp.xhtml" media-type="application/xhtml+xml"/>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
<item id="page_part" href="Text/part.xhtml" media-type="application/xhtml+xml"/>
|
||||||
</manifest>
|
|
||||||
<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 }}
|
{{ range .Images }}
|
||||||
{{ if spread_blank .Part }}
|
<item id="page_{{ .Id }}_p{{ .Part}}" href="Text/{{ .Id }}_p{{ .Part}}.xhtml" media-type="application/xhtml+xml"/>
|
||||||
<itemref idref="page_{{ .Id }}_sp" linear="yes" properties="page-spread-{{ spread }}"/>
|
{{ if eq .NeedSpace true }}
|
||||||
|
<item id="page_{{ .Id }}_sp" href="Text/{{ .Id }}_sp.xhtml" media-type="application/xhtml+xml"/>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<itemref idref="page_{{ .Id }}_p{{ .Part }}" linear="yes" properties="page-spread-{{ spread }}"/>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</spine>
|
</manifest>
|
||||||
|
<spine toc="ncx" page-progression-direction="{{ if $info.Manga }}rtl{{ else }}ltr{{ end }}">
|
||||||
|
<itemref idref="page_part" linear="yes"/>
|
||||||
|
{{ range .Images }}
|
||||||
|
{{ if eq .NeedSpace true }}
|
||||||
|
<itemref idref="page_{{ .Id }}_sp" linear="yes"/>
|
||||||
|
{{ end }}
|
||||||
|
<itemref idref="page_{{ .Id }}_p{{ .Part }}" linear="yes"/>
|
||||||
|
{{ end }}
|
||||||
|
</spine>
|
||||||
</package>
|
</package>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user