mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
Compare commits
7 Commits
9809de878a
...
a2eeda8479
Author | SHA1 | Date | |
---|---|---|---|
a2eeda8479 | |||
17d8161d99 | |||
02583cc715 | |||
8d24f95579 | |||
a7a29d6326 | |||
ed1a312027 | |||
b9115f7f6f |
@ -124,7 +124,6 @@ Options:
|
||||
NoBlankPage : false
|
||||
Manga : true
|
||||
HasCover : true
|
||||
AddPanelView : false
|
||||
LimitMb : 200 Mb
|
||||
StripFirstDirectoryFromToc: true
|
||||
SortPathMode : path=alphanum, file=alpha
|
||||
@ -162,7 +161,6 @@ Options:
|
||||
NoBlankPage : false
|
||||
Manga : true
|
||||
HasCover : true
|
||||
AddPanelView : false
|
||||
LimitMb : 200 Mb
|
||||
StripFirstDirectoryFromToc: true
|
||||
SortPathMode : path=alphanum, file=alphanum
|
||||
@ -210,7 +208,6 @@ Options:
|
||||
NoBlankPage : false
|
||||
Manga : false
|
||||
HasCover : true
|
||||
AddPanelView : false
|
||||
LimitMb : nolimit
|
||||
StripFirstDirectoryFromToc: false
|
||||
SortPathMode : path=alphanum, file=alpha
|
||||
@ -233,7 +230,6 @@ Options:
|
||||
NoBlankPage : false
|
||||
Manga : true
|
||||
HasCover : true
|
||||
AddPanelView : false
|
||||
LimitMb : 200 Mb
|
||||
StripFirstDirectoryFromToc: false
|
||||
SortPathMode : path=alphanum, file=alpha
|
||||
@ -258,7 +254,6 @@ Options:
|
||||
NoBlankPage : false
|
||||
Manga : false
|
||||
HasCover : true
|
||||
AddPanelView : false
|
||||
LimitMb : 200 Mb
|
||||
StripFirstDirectoryFromToc: false
|
||||
SortPathMode : path=alphanum, file=alpha
|
||||
@ -284,7 +279,6 @@ Options:
|
||||
NoBlankPage : false
|
||||
Manga : false
|
||||
HasCover : true
|
||||
AddPanelView : false
|
||||
LimitMb : nolimit
|
||||
|
||||
Reset default to ~/.go-comic-converter.yaml
|
||||
@ -360,8 +354,6 @@ Config:
|
||||
Manga mode (right to left)
|
||||
-hascover (default true)
|
||||
Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.
|
||||
-addpanelview
|
||||
Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle.
|
||||
-limitmb int
|
||||
Limit size of the ePub: Default nolimit (0), Minimum 20
|
||||
-strip
|
||||
|
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module github.com/celogeek/go-comic-converter/v2
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/beevik/etree v1.1.0
|
||||
github.com/disintegration/gift v1.2.1
|
||||
github.com/gofrs/uuid v4.4.0+incompatible
|
||||
github.com/nwaples/rardecode v1.1.3
|
||||
@ -20,6 +21,7 @@ require (
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/stretchr/testify v1.8.2 // indirect
|
||||
golang.org/x/net v0.9.0 // indirect
|
||||
golang.org/x/sys v0.7.0 // indirect
|
||||
golang.org/x/term v0.7.0 // indirect
|
||||
|
16
go.sum
16
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
|
||||
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -31,15 +33,18 @@ github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
|
||||
github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE=
|
||||
github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k=
|
||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4=
|
||||
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0=
|
||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
||||
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@ -47,7 +52,6 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
|
||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
@ -61,14 +65,12 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
@ -76,7 +78,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
@ -86,5 +87,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@ -95,7 +95,6 @@ func (c *Converter) InitParse() {
|
||||
c.AddBoolParam(&c.Options.NoBlankPage, "noblankpage", c.Options.NoBlankPage, "Remove blank pages")
|
||||
c.AddBoolParam(&c.Options.Manga, "manga", c.Options.Manga, "Manga mode (right to left)")
|
||||
c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.")
|
||||
c.AddBoolParam(&c.Options.AddPanelView, "addpanelview", c.Options.AddPanelView, "Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle.")
|
||||
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
||||
c.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1")
|
||||
c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file")
|
||||
|
@ -31,7 +31,6 @@ type Options struct {
|
||||
NoBlankPage bool `yaml:"no_blank_page"`
|
||||
Manga bool `yaml:"manga"`
|
||||
HasCover bool `yaml:"has_cover"`
|
||||
AddPanelView bool `yaml:"add_panel_view"`
|
||||
LimitMb int `yaml:"limit_mb"`
|
||||
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"`
|
||||
SortPathMode int `yaml:"sort_path_mode"`
|
||||
@ -61,7 +60,6 @@ func New() *Options {
|
||||
NoBlankPage: false,
|
||||
Manga: false,
|
||||
HasCover: true,
|
||||
AddPanelView: false,
|
||||
LimitMb: 0,
|
||||
StripFirstDirectoryFromToc: false,
|
||||
SortPathMode: 1,
|
||||
@ -150,7 +148,6 @@ func (o *Options) ShowDefault() string {
|
||||
NoBlankPage : %v
|
||||
Manga : %v
|
||||
HasCover : %v
|
||||
AddPanelView : %v
|
||||
LimitMb : %s
|
||||
StripFirstDirectoryFromToc: %v
|
||||
SortPathMode : %s`,
|
||||
@ -164,7 +161,6 @@ func (o *Options) ShowDefault() string {
|
||||
o.NoBlankPage,
|
||||
o.Manga,
|
||||
o.HasCover,
|
||||
o.AddPanelView,
|
||||
limitmb,
|
||||
o.StripFirstDirectoryFromToc,
|
||||
sortpathmode,
|
||||
|
197
internal/epub/content.go
Normal file
197
internal/epub/content.go
Normal file
@ -0,0 +1,197 @@
|
||||
package epub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
type Content struct {
|
||||
doc *etree.Document
|
||||
}
|
||||
|
||||
type TagAttrs map[string]string
|
||||
|
||||
type Tag struct {
|
||||
name string
|
||||
attrs TagAttrs
|
||||
value string
|
||||
}
|
||||
|
||||
func (e *ePub) getMeta(title string, part *epubPart, currentPart, totalPart int) []Tag {
|
||||
metas := []Tag{
|
||||
{"meta", TagAttrs{"property": "dcterms:modified"}, e.UpdatedAt},
|
||||
{"meta", TagAttrs{"property": "rendition:layout"}, "pre-paginated"},
|
||||
{"meta", TagAttrs{"property": "rendition:spread"}, "auto"},
|
||||
{"meta", TagAttrs{"property": "rendition:orientation"}, "auto"},
|
||||
{"meta", TagAttrs{"property": "ibooks:specified-fonts"}, "true"},
|
||||
{"meta", TagAttrs{"property": "schema:accessMode"}, "visual"},
|
||||
{"meta", TagAttrs{"property": "schema:accessModeSufficient"}, "visual"},
|
||||
{"meta", TagAttrs{"property": "schema:accessibilityHazard"}, "noFlashingHazard"},
|
||||
{"meta", TagAttrs{"property": "schema:accessibilityHazard"}, "noMotionSimulationHazard"},
|
||||
{"meta", TagAttrs{"property": "schema:accessibilityHazard"}, "noSoundHazard"},
|
||||
{"meta", TagAttrs{"name": "book-type", "content": "comic"}, ""},
|
||||
{"opf:meta", TagAttrs{"name": "fixed-layout", "content": "true"}, ""},
|
||||
{"opf:meta", TagAttrs{"name": "original-resolution", "content": fmt.Sprintf("%dx%d", e.ViewWidth, e.ViewHeight)}, ""},
|
||||
{"dc:title", TagAttrs{}, title},
|
||||
{"dc:identifier", TagAttrs{"id": "ean"}, fmt.Sprintf("urn:uuid:%s", e.UID)},
|
||||
{"dc:language", TagAttrs{}, "en"},
|
||||
{"dc:creator", TagAttrs{}, e.Author},
|
||||
{"dc:publisher", TagAttrs{}, e.Publisher},
|
||||
{"dc:contributor", TagAttrs{}, "Go Comic Convertor"},
|
||||
{"dc:date", TagAttrs{}, e.UpdatedAt},
|
||||
}
|
||||
|
||||
if e.Manga {
|
||||
metas = append(metas, Tag{"meta", TagAttrs{"name": "primary-writing-mode", "content": "horizontal-rl"}, ""})
|
||||
} else {
|
||||
metas = append(metas, Tag{"meta", TagAttrs{"name": "primary-writing-mode", "content": "horizontal-lr"}, ""})
|
||||
}
|
||||
|
||||
if part.Cover != nil {
|
||||
metas = append(metas, Tag{"meta", TagAttrs{"name": "cover", "content": part.Cover.Key("img")}, ""})
|
||||
}
|
||||
|
||||
if totalPart > 1 {
|
||||
metas = append(
|
||||
metas,
|
||||
Tag{"meta", TagAttrs{"name": "calibre:series", "content": e.Title}, ""},
|
||||
Tag{"meta", TagAttrs{"name": "calibre:series_index", "content": fmt.Sprint(currentPart)}, ""},
|
||||
)
|
||||
}
|
||||
|
||||
return metas
|
||||
}
|
||||
|
||||
func (e *ePub) getManifest(title string, part *epubPart, currentPart, totalPart int) []Tag {
|
||||
iTag := func(img *Image) Tag {
|
||||
return Tag{"item", TagAttrs{"id": img.Key("img"), "href": img.ImgPath(), "media-type": "image/jpeg"}, ""}
|
||||
}
|
||||
hTag := func(img *Image) Tag {
|
||||
return Tag{"item", TagAttrs{"id": img.Key("page"), "href": img.TextPath(), "media-type": "application/xhtml+xml"}, ""}
|
||||
}
|
||||
sTag := func(img *Image) Tag {
|
||||
return Tag{"item", TagAttrs{"id": img.SpaceKey("page"), "href": img.SpacePath(), "media-type": "application/xhtml+xml"}, ""}
|
||||
}
|
||||
items := []Tag{
|
||||
{"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"}, ""},
|
||||
}
|
||||
|
||||
if part.Cover != nil {
|
||||
items = append(items, iTag(part.Cover), hTag(part.Cover))
|
||||
}
|
||||
|
||||
for _, img := range part.Images {
|
||||
if img.Part == 1 {
|
||||
items = append(items, sTag(img))
|
||||
}
|
||||
items = append(items, iTag(img), hTag(img))
|
||||
}
|
||||
items = append(items, sTag(part.Images[len(part.Images)-1]))
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
func (e *ePub) getSpine(title string, part *epubPart, currentPart, totalPart int) []Tag {
|
||||
spine := []Tag{}
|
||||
isOnTheRight := !e.Manga
|
||||
getSpread := func(doublePageNoBlank bool) string {
|
||||
isOnTheRight = !isOnTheRight
|
||||
if doublePageNoBlank {
|
||||
// Center the double page then start back to comic mode (mange/normal)
|
||||
isOnTheRight = !e.Manga
|
||||
return "rendition:page-spread-center"
|
||||
}
|
||||
if isOnTheRight {
|
||||
return "rendition:page-spread-right"
|
||||
} else {
|
||||
return "rendition:page-spread-left"
|
||||
}
|
||||
}
|
||||
for _, img := range part.Images {
|
||||
spine = append(spine, Tag{
|
||||
"itemref",
|
||||
TagAttrs{"idref": img.Key("page"), "properties": getSpread(img.DoublePage && e.NoBlankPage)},
|
||||
"",
|
||||
})
|
||||
if img.DoublePage && isOnTheRight && !e.NoBlankPage {
|
||||
spine = append(spine, Tag{
|
||||
"itemref",
|
||||
TagAttrs{"idref": img.SpaceKey("page"), "properties": getSpread(false)},
|
||||
"",
|
||||
})
|
||||
}
|
||||
}
|
||||
if e.Manga == isOnTheRight {
|
||||
spine = append(spine, Tag{
|
||||
"itemref",
|
||||
TagAttrs{"idref": part.Images[len(part.Images)-1].SpaceKey("page"), "properties": getSpread(false)},
|
||||
"",
|
||||
})
|
||||
}
|
||||
|
||||
return spine
|
||||
}
|
||||
|
||||
func (e *ePub) getGuide(title string, part *epubPart, currentPart, totalPart int) []Tag {
|
||||
guide := []Tag{}
|
||||
if part.Cover != nil {
|
||||
guide = append(guide, Tag{"reference", TagAttrs{"type": "cover", "title": "cover", "href": part.Cover.TextPath()}, ""})
|
||||
}
|
||||
guide = append(guide, Tag{"reference", TagAttrs{"type": "text", "title": "content", "href": part.Images[0].TextPath()}, ""})
|
||||
return guide
|
||||
}
|
||||
|
||||
func (e *ePub) getContent(title string, part *epubPart, currentPart, totalPart int) *Content {
|
||||
doc := etree.NewDocument()
|
||||
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
|
||||
|
||||
pkg := doc.CreateElement("package")
|
||||
pkg.CreateAttr("xmlns", "http://www.idpf.org/2007/opf")
|
||||
pkg.CreateAttr("unique-identifier", "ean")
|
||||
pkg.CreateAttr("version", "3.0")
|
||||
pkg.CreateAttr("prefix", "rendition: http://www.idpf.org/vocab/rendition/# ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/")
|
||||
|
||||
addToElement := func(elm *etree.Element, meth func(title string, part *epubPart, currentPart, totalPart int) []Tag) {
|
||||
for _, p := range meth(title, part, currentPart, totalPart) {
|
||||
meta := elm.CreateElement(p.name)
|
||||
for k, v := range p.attrs {
|
||||
meta.CreateAttr(k, v)
|
||||
}
|
||||
meta.SortAttrs()
|
||||
if p.value != "" {
|
||||
meta.CreateText(p.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metadata := pkg.CreateElement("metadata")
|
||||
metadata.CreateAttr("xmlns:dc", "http://purl.org/dc/elements/1.1/")
|
||||
metadata.CreateAttr("xmlns:opf", "http://www.idpf.org/2007/opf")
|
||||
addToElement(metadata, e.getMeta)
|
||||
|
||||
manifest := pkg.CreateElement("manifest")
|
||||
addToElement(manifest, e.getManifest)
|
||||
|
||||
spine := pkg.CreateElement("spine")
|
||||
if e.Manga {
|
||||
spine.CreateAttr("page-progression-direction", "rtl")
|
||||
} else {
|
||||
spine.CreateAttr("page-progression-direction", "ltr")
|
||||
}
|
||||
addToElement(spine, e.getSpine)
|
||||
|
||||
guide := pkg.CreateElement("guide")
|
||||
addToElement(guide, e.getGuide)
|
||||
|
||||
return &Content{
|
||||
doc,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Content) String() string {
|
||||
c.doc.Indent(2)
|
||||
r, _ := c.doc.WriteToString()
|
||||
return r
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package epub
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -27,7 +26,6 @@ type ImageOptions struct {
|
||||
NoBlankPage bool
|
||||
Manga bool
|
||||
HasCover bool
|
||||
AddPanelView bool
|
||||
Workers int
|
||||
}
|
||||
|
||||
@ -95,6 +93,38 @@ func (e *ePub) render(templateString string, data any) string {
|
||||
return stripBlank.ReplaceAllString(result.String(), "\n")
|
||||
}
|
||||
|
||||
func (e *ePub) writeImage(wz *epubZip, img *Image) error {
|
||||
err := wz.WriteFile(
|
||||
fmt.Sprintf("OEBPS/%s", img.TextPath()),
|
||||
e.render(textTmpl, map[string]any{
|
||||
"Title": fmt.Sprintf("Image %d Part %d", img.Id, img.Part),
|
||||
"ViewPort": fmt.Sprintf("width=%d, height=%d", e.ViewWidth, e.ViewHeight),
|
||||
"ImageStyle": fmt.Sprintf(
|
||||
"width:%dpx; height:%dpx;",
|
||||
img.Width,
|
||||
img.Height,
|
||||
),
|
||||
"ImagePath": img.ImgPath(),
|
||||
}),
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
err = wz.WriteImage(img.Data)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *ePub) writeBlank(wz *epubZip, img *Image) error {
|
||||
return wz.WriteFile(
|
||||
fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id),
|
||||
e.render(blankTmpl, map[string]any{
|
||||
"Title": fmt.Sprintf("Blank Page %d", img.Id),
|
||||
"ViewPort": fmt.Sprintf("width=%d, height=%d", e.ViewWidth, e.ViewHeight),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
func (e *ePub) getParts() ([]*epubPart, error) {
|
||||
images, err := e.LoadImages()
|
||||
|
||||
@ -135,7 +165,6 @@ func (e *ePub) getParts() ([]*epubPart, error) {
|
||||
currentSize := baseSize
|
||||
currentImages := make([]*Image, 0)
|
||||
part := 1
|
||||
imgIsOnRightSide := false
|
||||
|
||||
for _, img := range images {
|
||||
imgSize := img.Data.CompressedSize() + xhtmlSize
|
||||
@ -145,14 +174,11 @@ func (e *ePub) getParts() ([]*epubPart, error) {
|
||||
Images: currentImages,
|
||||
})
|
||||
part += 1
|
||||
imgIsOnRightSide = false
|
||||
currentSize = baseSize
|
||||
currentImages = make([]*Image, 0)
|
||||
}
|
||||
currentSize += imgSize
|
||||
img.NeedSpace = img.Part == 1 && imgIsOnRightSide
|
||||
currentImages = append(currentImages, img)
|
||||
imgIsOnRightSide = !imgIsOnRightSide
|
||||
}
|
||||
if len(currentImages) > 0 {
|
||||
parts = append(parts, &epubPart{
|
||||
@ -164,59 +190,6 @@ func (e *ePub) getParts() ([]*epubPart, error) {
|
||||
return parts, nil
|
||||
}
|
||||
|
||||
func (e *ePub) getToc(images []*Image) *TocChildren {
|
||||
paths := map[string]*TocPart{
|
||||
".": {},
|
||||
}
|
||||
for _, img := range images {
|
||||
currentPath := "."
|
||||
for _, path := range strings.Split(img.Path, string(filepath.Separator)) {
|
||||
parentPath := currentPath
|
||||
currentPath = filepath.Join(currentPath, path)
|
||||
if _, ok := paths[currentPath]; ok {
|
||||
continue
|
||||
}
|
||||
part := &TocPart{
|
||||
Title: TocTitle{
|
||||
Value: path,
|
||||
Link: fmt.Sprintf("Text/%d_p%d.xhtml", img.Id, img.Part),
|
||||
},
|
||||
}
|
||||
paths[currentPath] = part
|
||||
if paths[parentPath].Children == nil {
|
||||
paths[parentPath].Children = &TocChildren{}
|
||||
}
|
||||
paths[parentPath].Children.Tags = append(paths[parentPath].Children.Tags, part)
|
||||
}
|
||||
}
|
||||
|
||||
children := paths["."].Children
|
||||
|
||||
if children != nil && e.StripFirstDirectoryFromToc && len(children.Tags) == 1 {
|
||||
children = children.Tags[0].Children
|
||||
}
|
||||
|
||||
return children
|
||||
|
||||
}
|
||||
|
||||
func (e *ePub) getTree(images []*Image, skip_files bool) string {
|
||||
t := NewTree()
|
||||
for _, img := range images {
|
||||
if skip_files {
|
||||
t.Add(img.Path)
|
||||
} else {
|
||||
t.Add(filepath.Join(img.Path, img.Name))
|
||||
}
|
||||
}
|
||||
c := t.Root()
|
||||
if skip_files && e.StripFirstDirectoryFromToc && len(c.Children) == 1 {
|
||||
c = c.Children[0]
|
||||
}
|
||||
|
||||
return c.toString("")
|
||||
}
|
||||
|
||||
func (e *ePub) Write() error {
|
||||
type zipContent struct {
|
||||
Name string
|
||||
@ -264,43 +237,21 @@ func (e *ePub) Write() error {
|
||||
title = fmt.Sprintf("%s [%d/%d]", title, i+1, totalParts)
|
||||
}
|
||||
|
||||
tocChildren := e.getToc(part.Images)
|
||||
toc := []byte{}
|
||||
if tocChildren != nil {
|
||||
toc, err = xml.MarshalIndent(tocChildren.Tags, " ", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
content := []zipContent{
|
||||
{"META-INF/container.xml", containerTmpl},
|
||||
{"OEBPS/content.opf", e.render(contentTmpl, map[string]any{
|
||||
"Info": e,
|
||||
"Cover": part.Cover,
|
||||
"Images": part.Images,
|
||||
"Title": title,
|
||||
"Part": i + 1,
|
||||
"Total": totalParts,
|
||||
{"META-INF/com.apple.ibooks.display-options.xml", appleBooksTmpl},
|
||||
{"OEBPS/content.opf", e.getContent(title, part, i+1, totalParts).String()},
|
||||
{"OEBPS/toc.xhtml", e.getToc(title, part.Images)},
|
||||
{"OEBPS/Text/style.css", e.render(styleTmpl, map[string]any{
|
||||
"PageWidth": e.ViewWidth,
|
||||
"PageHeight": e.ViewHeight,
|
||||
})},
|
||||
{"OEBPS/toc.ncx", e.render(tocTmpl, map[string]any{
|
||||
"Info": e,
|
||||
"Title": title,
|
||||
})},
|
||||
{"OEBPS/nav.xhtml", e.render(navTmpl, map[string]any{
|
||||
"Title": title,
|
||||
"TOC": string(toc),
|
||||
})},
|
||||
{"OEBPS/Text/style.css", styleTmpl},
|
||||
{"OEBPS/Text/part.xhtml", e.render(partTmpl, map[string]any{
|
||||
{"OEBPS/Text/title.xhtml", e.render(titleTmpl, map[string]any{
|
||||
"Info": e,
|
||||
"Part": i + 1,
|
||||
"Total": totalParts,
|
||||
})},
|
||||
}
|
||||
if e.AddPanelView {
|
||||
content = append(content, zipContent{"OEBPS/Text/panelview.css", panelViewTmpl})
|
||||
}
|
||||
|
||||
if err = wz.WriteMagic(); err != nil {
|
||||
return err
|
||||
@ -314,41 +265,22 @@ func (e *ePub) Write() error {
|
||||
// Cover exist or part > 1
|
||||
// If no cover, part 2 and more will include the image as a cover
|
||||
if e.HasCover || i > 0 {
|
||||
wz.WriteImage(part.Cover.Data)
|
||||
if err := e.writeImage(wz, part.Cover); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, img := range part.Images {
|
||||
var content string
|
||||
if e.AddPanelView {
|
||||
content = e.render(textTmpl, map[string]any{
|
||||
"Image": img,
|
||||
"Manga": e.Manga,
|
||||
})
|
||||
} else {
|
||||
content = e.render(textNoPanelTmpl, map[string]any{
|
||||
"Image": img,
|
||||
})
|
||||
}
|
||||
|
||||
if err := wz.WriteFile(fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part), content); err != nil {
|
||||
for i, img := range part.Images {
|
||||
if err := e.writeImage(wz, img); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if img.NeedSpace {
|
||||
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 {
|
||||
// Double Page or Last Image
|
||||
if img.DoublePage || (i+1 == len(part.Images)) {
|
||||
if err := e.writeBlank(wz, img); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := wz.WriteImage(img.Data); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
bar.Add(1)
|
||||
}
|
||||
|
55
internal/epub/filters/position.go
Normal file
55
internal/epub/filters/position.go
Normal file
@ -0,0 +1,55 @@
|
||||
package filters
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/draw"
|
||||
|
||||
"github.com/disintegration/gift"
|
||||
)
|
||||
|
||||
const (
|
||||
PositionCenter = iota
|
||||
PositionLeft
|
||||
PositionRight
|
||||
)
|
||||
|
||||
func Position(viewWidth, viewHeight int, align int) gift.Filter {
|
||||
return &positionFilter{
|
||||
viewWidth, viewHeight, align,
|
||||
}
|
||||
}
|
||||
|
||||
type positionFilter struct {
|
||||
viewWidth, viewHeight, align int
|
||||
}
|
||||
|
||||
func (p *positionFilter) Bounds(srcBounds image.Rectangle) image.Rectangle {
|
||||
return image.Rect(0, 0, p.viewWidth, p.viewHeight)
|
||||
}
|
||||
|
||||
func (p *positionFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
||||
draw.Draw(dst, dst.Bounds(), image.White, dst.Bounds().Min, draw.Over)
|
||||
|
||||
srcBounds := src.Bounds()
|
||||
left, top := (p.viewWidth-srcBounds.Dx())/2, (p.viewHeight-srcBounds.Dy())/2
|
||||
if p.align == PositionLeft {
|
||||
left = 0
|
||||
}
|
||||
|
||||
if p.align == PositionRight {
|
||||
left = p.viewWidth - srcBounds.Dx()
|
||||
}
|
||||
|
||||
draw.Draw(
|
||||
dst,
|
||||
image.Rect(
|
||||
left,
|
||||
top,
|
||||
p.viewWidth,
|
||||
p.viewHeight,
|
||||
),
|
||||
src,
|
||||
srcBounds.Min,
|
||||
draw.Over,
|
||||
)
|
||||
}
|
@ -21,6 +21,7 @@ func NewGift(options *ImageOptions) *gift.GIFT {
|
||||
g.Add(
|
||||
filters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
||||
filters.Pixel(),
|
||||
filters.Position(options.ViewWidth, options.ViewHeight, filters.PositionCenter),
|
||||
)
|
||||
return g
|
||||
}
|
||||
@ -28,25 +29,30 @@ func NewGift(options *ImageOptions) *gift.GIFT {
|
||||
func NewGiftSplitDoublePage(options *ImageOptions) []*gift.GIFT {
|
||||
gifts := make([]*gift.GIFT, 2)
|
||||
|
||||
rightFirst := options.Manga
|
||||
|
||||
gifts[0] = gift.New(
|
||||
filters.CropSplitDoublePage(rightFirst),
|
||||
filters.CropSplitDoublePage(options.Manga),
|
||||
)
|
||||
|
||||
gifts[1] = gift.New(
|
||||
filters.CropSplitDoublePage(!rightFirst),
|
||||
filters.CropSplitDoublePage(!options.Manga),
|
||||
)
|
||||
|
||||
for _, g := range gifts {
|
||||
for i, g := range gifts {
|
||||
if options.Contrast != 0 {
|
||||
g.Add(gift.Contrast(float32(options.Contrast)))
|
||||
}
|
||||
if options.Brightness != 0 {
|
||||
g.Add(gift.Brightness(float32(options.Brightness)))
|
||||
}
|
||||
|
||||
position := filters.PositionLeft
|
||||
if (i == 1) == options.Manga {
|
||||
position = filters.PositionRight
|
||||
}
|
||||
|
||||
g.Add(
|
||||
gift.ResizeToFit(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
||||
filters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling),
|
||||
filters.Position(options.ViewWidth, options.ViewHeight, position),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -26,15 +26,35 @@ import (
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
Id int
|
||||
Part int
|
||||
Data *ImageData
|
||||
Width int
|
||||
Height int
|
||||
IsCover bool
|
||||
NeedSpace bool
|
||||
Path string
|
||||
Name string
|
||||
Id int
|
||||
Part int
|
||||
Data *ImageData
|
||||
Width int
|
||||
Height int
|
||||
IsCover bool
|
||||
DoublePage bool
|
||||
Path string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (i *Image) Key(prefix string) string {
|
||||
return fmt.Sprintf("%s_%d_p%d", prefix, i.Id, i.Part)
|
||||
}
|
||||
|
||||
func (i *Image) SpaceKey(prefix string) string {
|
||||
return fmt.Sprintf("%s_%d_sp", prefix, i.Id)
|
||||
}
|
||||
|
||||
func (i *Image) TextPath() string {
|
||||
return fmt.Sprintf("Text/%d_p%d.xhtml", i.Id, i.Part)
|
||||
}
|
||||
|
||||
func (i *Image) ImgPath() string {
|
||||
return fmt.Sprintf("Images/%d_p%d.jpg", i.Id, i.Part)
|
||||
}
|
||||
|
||||
func (i *Image) SpacePath() string {
|
||||
return fmt.Sprintf("Text/%d_sp.xhtml", i.Id)
|
||||
}
|
||||
|
||||
type imageTask struct {
|
||||
@ -130,15 +150,15 @@ func (e *ePub) LoadImages() ([]*Image, error) {
|
||||
for img := range imageInput {
|
||||
img.Reader.Close()
|
||||
images = append(images, &Image{
|
||||
Id: img.Id,
|
||||
Part: 0,
|
||||
Data: nil,
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
IsCover: false,
|
||||
NeedSpace: false, // NeedSpace reajust during parts computation
|
||||
Path: img.Path,
|
||||
Name: img.Name,
|
||||
Id: img.Id,
|
||||
Part: 0,
|
||||
Data: nil,
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
IsCover: false,
|
||||
DoublePage: false,
|
||||
Path: img.Path,
|
||||
Name: img.Name,
|
||||
})
|
||||
}
|
||||
|
||||
@ -180,15 +200,17 @@ func (e *ePub) LoadImages() ([]*Image, error) {
|
||||
g.Draw(dst, src)
|
||||
|
||||
imageOutput <- &Image{
|
||||
Id: img.Id,
|
||||
Part: 0,
|
||||
Data: newImageData(img.Id, 0, dst, e.ImageOptions.Quality),
|
||||
Width: dst.Bounds().Dx(),
|
||||
Height: dst.Bounds().Dy(),
|
||||
IsCover: img.Id == 0,
|
||||
NeedSpace: false,
|
||||
Path: img.Path,
|
||||
Name: img.Name,
|
||||
Id: img.Id,
|
||||
Part: 0,
|
||||
Data: newImageData(img.Id, 0, dst, e.ImageOptions.Quality),
|
||||
Width: dst.Bounds().Dx(),
|
||||
Height: dst.Bounds().Dy(),
|
||||
IsCover: img.Id == 0,
|
||||
DoublePage: src.Bounds().Dx() > src.Bounds().Dy() &&
|
||||
src.Bounds().Dx() > e.ImageOptions.ViewHeight &&
|
||||
src.Bounds().Dy() > e.ImageOptions.ViewWidth,
|
||||
Path: img.Path,
|
||||
Name: img.Name,
|
||||
}
|
||||
|
||||
// Auto split double page
|
||||
@ -204,16 +226,17 @@ func (e *ePub) LoadImages() ([]*Image, error) {
|
||||
part := i + 1
|
||||
dst := image.NewGray(g.Bounds(src.Bounds()))
|
||||
g.Draw(dst, src)
|
||||
|
||||
imageOutput <- &Image{
|
||||
Id: img.Id,
|
||||
Part: part,
|
||||
Data: newImageData(img.Id, part, dst, e.ImageOptions.Quality),
|
||||
Width: dst.Bounds().Dx(),
|
||||
Height: dst.Bounds().Dy(),
|
||||
IsCover: false,
|
||||
NeedSpace: false, // NeedSpace reajust during parts computation
|
||||
Path: img.Path,
|
||||
Name: img.Name,
|
||||
Id: img.Id,
|
||||
Part: part,
|
||||
Data: newImageData(img.Id, part, dst, e.ImageOptions.Quality),
|
||||
Width: dst.Bounds().Dx(),
|
||||
Height: dst.Bounds().Dy(),
|
||||
IsCover: false,
|
||||
DoublePage: false,
|
||||
Path: img.Path,
|
||||
Name: img.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,29 +5,17 @@ import _ "embed"
|
||||
//go:embed "templates/container.xml.tmpl"
|
||||
var containerTmpl string
|
||||
|
||||
//go:embed "templates/content.opf.tmpl"
|
||||
var contentTmpl string
|
||||
|
||||
//go:embed "templates/toc.ncx.tmpl"
|
||||
var tocTmpl string
|
||||
|
||||
//go:embed "templates/nav.xhtml.tmpl"
|
||||
var navTmpl string
|
||||
//go:embed "templates/applebooks.xml.tmpl"
|
||||
var appleBooksTmpl string
|
||||
|
||||
//go:embed "templates/style.css.tmpl"
|
||||
var styleTmpl string
|
||||
|
||||
//go:embed "templates/panelview.css.tmpl"
|
||||
var panelViewTmpl string
|
||||
|
||||
//go:embed "templates/part.xhtml.tmpl"
|
||||
var partTmpl string
|
||||
//go:embed "templates/title.xhtml.tmpl"
|
||||
var titleTmpl string
|
||||
|
||||
//go:embed "templates/text.xhtml.tmpl"
|
||||
var textTmpl string
|
||||
|
||||
//go:embed "templates/textnopanel.xhtml.tmpl"
|
||||
var textNoPanelTmpl string
|
||||
|
||||
//go:embed "templates/blank.xhtml.tmpl"
|
||||
var blankTmpl string
|
||||
|
6
internal/epub/templates/applebooks.xml.tmpl
Normal file
6
internal/epub/templates/applebooks.xml.tmpl
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<display_options>
|
||||
<platform name="*">
|
||||
<option name="fixed-layout">true</option>
|
||||
</platform>
|
||||
</display_options>
|
@ -2,11 +2,10 @@
|
||||
<!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>
|
||||
<title>{{ .Title }}</title>
|
||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
||||
<meta name="viewport" content="width={{ .Info.ViewWidth }}, height={{ .Info.ViewHeight }}"/>
|
||||
<meta name="viewport" content="{{ .ViewPort }}"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ if .Info.Manga }}←{{ else }}→{{ end }}</h1>
|
||||
</body>
|
||||
</html>
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
||||
<rootfiles>
|
||||
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
|
||||
</rootfiles>
|
||||
<container version="1.0"
|
||||
xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
||||
<rootfiles>
|
||||
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
|
||||
</rootfiles>
|
||||
</container>
|
@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<package version="3.0" unique-identifier="BookID" xmlns="http://www.idpf.org/2007/opf">
|
||||
{{ $info := .Info }}
|
||||
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<dc:title>{{ .Title }}</dc:title>
|
||||
<dc:language>en-US</dc:language>
|
||||
<dc:identifier id="BookID">urn:uuid:{{ $info.UID }}</dc:identifier>
|
||||
<dc:contributor id="contributor">{{ $info.Publisher }}</dc:contributor>
|
||||
<dc:publisher>{{ $info.Publisher }}</dc:publisher>
|
||||
<dc:date>{{ $info.UpdatedAt }}</dc:date>
|
||||
<dc:creator>{{ $info.Author }}</dc:creator>
|
||||
<meta property="dcterms:modified">{{ $info.UpdatedAt }}</meta>
|
||||
<meta name="original-resolution" content="{{ $info.ViewWidth }}x{{ $info.ViewHeight }}"/>
|
||||
<meta name="book-type" content="comic"/>
|
||||
<meta name="primary-writing-mode" content="horizontal-{{ if $info.Manga }}rl{{ else }}lr{{ end }}"/>
|
||||
<meta property="rendition:layout">pre-paginated</meta>
|
||||
<meta property="rendition:orientation">portrait</meta>
|
||||
<meta name="orientation-lock" content="portrait"/>
|
||||
{{ if eq $info.AddPanelView true }}
|
||||
<meta name="region-mag" content="true"/>
|
||||
{{ end }}
|
||||
{{ if gt .Total 1 }}
|
||||
<meta name="calibre:series" content="{{ $info.Title }}"/>
|
||||
<meta name="calibre:series_index" content="{{ .Part }}"/>
|
||||
{{ end }}
|
||||
</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 }}
|
||||
{{ if eq .IsCover false }}
|
||||
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
<item id="page_part" href="Text/part.xhtml" media-type="application/xhtml+xml"/>
|
||||
{{ range .Images }}
|
||||
<item id="page_{{ .Id }}_p{{ .Part}}" href="Text/{{ .Id }}_p{{ .Part}}.xhtml" media-type="application/xhtml+xml"/>
|
||||
{{ if eq .NeedSpace true }}
|
||||
<item id="page_{{ .Id }}_sp" href="Text/{{ .Id }}_sp.xhtml" media-type="application/xhtml+xml"/>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</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>
|
@ -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>
|
||||
<title>{{ .Title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav epub:type="toc" id="toc">
|
||||
<h2>Table of content</h2>
|
||||
<ol>
|
||||
<li><a href="Text/part.xhtml">{{ .Title }}</a></li>
|
||||
{{ .TOC }}
|
||||
</ol>
|
||||
</nav>
|
||||
</body>
|
||||
</html>
|
@ -1,103 +0,0 @@
|
||||
a.app-amzn-magnify {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#PV {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#PV-T {
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
}
|
||||
|
||||
#PV-B {
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
}
|
||||
|
||||
#PV-L {
|
||||
left: 0;
|
||||
width: 49.5%;
|
||||
height: 100%;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#PV-R {
|
||||
right: 0;
|
||||
width: 49.5%;
|
||||
height: 100%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
#PV-TL {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 49.5%;
|
||||
height: 50%;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#PV-TR {
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 49.5%;
|
||||
height: 50%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
#PV-BL {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 49.5%;
|
||||
height: 50%;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#PV-BR {
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
width: 49.5%;
|
||||
height: 50%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.PV-P {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
}
|
||||
|
||||
div#PV-TL-P img {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
div#PV-TR-P img {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
div#PV-BL-P img {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
div#PV-BR-P img {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
@ -1,77 +1,13 @@
|
||||
@charset "UTF-8";
|
||||
|
||||
html {
|
||||
body {
|
||||
color: #000;
|
||||
background: #FFF;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body,
|
||||
div,
|
||||
dl,
|
||||
dt,
|
||||
dd,
|
||||
ul,
|
||||
ol,
|
||||
li,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
th,
|
||||
td {
|
||||
margin: 0;
|
||||
padding: 0
|
||||
padding: 0;
|
||||
width: {{ .PageWidth }}px;
|
||||
height: {{ .PageHeight }}px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
fieldset,
|
||||
img {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
caption,
|
||||
th,
|
||||
var {
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
caption,
|
||||
th {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
font-size: 150%;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
sup {
|
||||
vertical-align: text-top;
|
||||
}
|
||||
|
||||
sub {
|
||||
vertical-align: text-bottom;
|
||||
div {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
@ -2,40 +2,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||
<head>
|
||||
<title>Page {{ .Image.Id }}_p{{ .Image.Part}}</title>
|
||||
<title>{{ .Title }}</title>
|
||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="panelview.css" type="text/css" rel="stylesheet"/>
|
||||
<meta name="viewport" content="width={{ .Image.Width }}, height={{ .Image.Height }}"/>
|
||||
<meta name="viewport" content="{{ .ViewPort }}"/>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<img style="width:{{ .Image.Width }}px; height:{{ .Image.Height }}px" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg"/>
|
||||
</div>
|
||||
<div id="PV">
|
||||
<div id="PV-TL">
|
||||
<a class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-TL-P", "ordinal":{{ if .Manga }}2{{ else }}1{{ end }}}'></a>
|
||||
</div>
|
||||
<div id="PV-TR">
|
||||
<a class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-TR-P", "ordinal":{{ if .Manga }}1{{ else }}2{{ end }}}'></a>
|
||||
</div>
|
||||
<div id="PV-BL">
|
||||
<a class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-BL-P", "ordinal":{{ if .Manga }}4{{ else }}3{{ end }}}'></a>
|
||||
</div>
|
||||
<div id="PV-BR">
|
||||
<a class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-BR-P", "ordinal":{{ if .Manga }}3{{ else }}4{{ end }}}'></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="PV-P" id="PV-TL-P">
|
||||
<img src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||
</div>
|
||||
<div class="PV-P" id="PV-TR-P">
|
||||
<img src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||
</div>
|
||||
<div class="PV-P" id="PV-BL-P">
|
||||
<img src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||
</div>
|
||||
<div class="PV-P" id="PV-BR-P">
|
||||
<img src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||
<img style="{{ .ImageStyle }}" src="../{{ .ImagePath }}"/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,14 +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>
|
||||
<title>Page {{ .Image.Id }}_p{{ .Image.Part}}</title>
|
||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
||||
<meta name="viewport" content="width={{ .Image.Width }}, height={{ .Image.Height }}"/>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<img style="width:{{ .Image.Width }}px; height:{{ .Image.Height }}px" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg"/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -7,9 +7,9 @@
|
||||
<meta name="viewport" content="width={{ .Info.ViewWidth }}, height={{ .Info.ViewHeight }}"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ .Info.Title }}</h1>
|
||||
<h2>{{ .Info.Title }}</h2>
|
||||
{{ if gt .Total 1 }}
|
||||
<h1>Part {{ .Part }} / {{ .Total }}</h1>
|
||||
<h3>Part {{ .Part }} / {{ .Total }}</h3>
|
||||
{{ end }}
|
||||
</body>
|
||||
</html>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ncx version="2005-1" xml:lang="en-US" xmlns="http://www.daisy.org/z3986/2005/ncx/">
|
||||
<head>
|
||||
<meta name="dtb:uid" content="urn:uuid:{{ .Info.UID }}"/>
|
||||
<meta name="dtb:depth" content="1"/>
|
||||
<meta name="dtb:totalPageCount" content="0"/>
|
||||
<meta name="dtb:maxPageNumber" content="0"/>
|
||||
<meta name="generated" content="true"/>
|
||||
</head>
|
||||
<docTitle><text>{{ .Title }}</text></docTitle>
|
||||
<navMap>
|
||||
<navPoint id="Text"><navLabel><text>{{ .Title }}</text></navLabel><content src="Text/part.xhtml"/></navPoint>
|
||||
</navMap>
|
||||
</ncx>
|
@ -1,22 +1,54 @@
|
||||
package epub
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
type TocTitle struct {
|
||||
XMLName xml.Name `xml:"a"`
|
||||
Value string `xml:",innerxml"`
|
||||
Link string `xml:"href,attr"`
|
||||
}
|
||||
func (e *ePub) getToc(title string, images []*Image) string {
|
||||
doc := etree.NewDocument()
|
||||
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
|
||||
doc.CreateDirective("DOCTYPE html")
|
||||
|
||||
type TocChildren struct {
|
||||
XMLName xml.Name `xml:"ol"`
|
||||
Tags []*TocPart
|
||||
}
|
||||
html := doc.CreateElement("html")
|
||||
html.CreateAttr("xmlns", "http://www.w3.org/1999/xhtml")
|
||||
html.CreateAttr("xmlns:epub", "http://www.idpf.org/2007/ops")
|
||||
|
||||
type TocPart struct {
|
||||
XMLName xml.Name `xml:"li"`
|
||||
Title TocTitle
|
||||
Children *TocChildren `xml:",omitempty"`
|
||||
html.CreateElement("head").CreateElement("title").CreateText(title)
|
||||
body := html.CreateElement("body")
|
||||
nav := body.CreateElement("nav")
|
||||
nav.CreateAttr("epub:type", "toc")
|
||||
nav.CreateAttr("id", "toc")
|
||||
nav.CreateElement("h2").CreateText(title)
|
||||
|
||||
ol := etree.NewElement("ol")
|
||||
paths := map[string]*etree.Element{".": ol}
|
||||
for _, img := range images {
|
||||
currentPath := "."
|
||||
for _, path := range strings.Split(img.Path, string(filepath.Separator)) {
|
||||
parentPath := currentPath
|
||||
currentPath = filepath.Join(currentPath, path)
|
||||
if _, ok := paths[currentPath]; ok {
|
||||
continue
|
||||
}
|
||||
t := paths[parentPath].CreateElement("li")
|
||||
link := t.CreateElement("a")
|
||||
link.CreateAttr("href", img.TextPath())
|
||||
link.CreateText(path)
|
||||
paths[currentPath] = t
|
||||
}
|
||||
}
|
||||
|
||||
if len(ol.ChildElements()) == 1 && e.StripFirstDirectoryFromToc {
|
||||
ol = ol.ChildElements()[0]
|
||||
}
|
||||
if len(ol.ChildElements()) > 0 {
|
||||
nav.AddChild(ol)
|
||||
}
|
||||
|
||||
doc.Indent(2)
|
||||
r, _ := doc.WriteToString()
|
||||
return r
|
||||
}
|
||||
|
@ -51,3 +51,20 @@ func (n *Node) toString(indent string) string {
|
||||
}
|
||||
return r.String()
|
||||
}
|
||||
|
||||
func (e *ePub) getTree(images []*Image, skip_files bool) string {
|
||||
t := NewTree()
|
||||
for _, img := range images {
|
||||
if skip_files {
|
||||
t.Add(img.Path)
|
||||
} else {
|
||||
t.Add(filepath.Join(img.Path, img.Name))
|
||||
}
|
||||
}
|
||||
c := t.Root()
|
||||
if skip_files && e.StripFirstDirectoryFromToc && len(c.Children) == 1 {
|
||||
c = c.Children[0]
|
||||
}
|
||||
|
||||
return c.toString("")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user