mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
improve alignment on spread images for landscape
This commit is contained in:
parent
5b0051720f
commit
bcad0389fa
@ -77,7 +77,7 @@ func (e *ePub) writeImage(wz *epubzip.EPUBZip, img *epubimage.Image, zipImg *zip
|
|||||||
"Title": fmt.Sprintf("Image %d Part %d", img.Id, img.Part),
|
"Title": fmt.Sprintf("Image %d Part %d", img.Id, img.Part),
|
||||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
||||||
"ImagePath": img.ImgPath(),
|
"ImagePath": img.ImgPath(),
|
||||||
"ImageStyle": img.ImgStyle(e.Image.View.Width, e.Image.View.Height, e.Image.Manga),
|
"ImageStyle": img.ImgStyle(e.Image.View.Width, e.Image.View.Height, ""),
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -251,6 +251,10 @@ func (e *ePub) Write() error {
|
|||||||
if totalParts > 1 {
|
if totalParts > 1 {
|
||||||
title = fmt.Sprintf("%s [%d/%d]", title, i+1, totalParts)
|
title = fmt.Sprintf("%s [%d/%d]", title, i+1, totalParts)
|
||||||
}
|
}
|
||||||
|
titleAlign := "left:0"
|
||||||
|
if e.Image.Manga {
|
||||||
|
titleAlign = "right:0"
|
||||||
|
}
|
||||||
|
|
||||||
content := []zipContent{
|
content := []zipContent{
|
||||||
{"META-INF/container.xml", epubtemplates.Container},
|
{"META-INF/container.xml", epubtemplates.Container},
|
||||||
@ -280,7 +284,7 @@ func (e *ePub) Write() error {
|
|||||||
"Title": title,
|
"Title": title,
|
||||||
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
|
||||||
"ImagePath": "Images/title.jpg",
|
"ImagePath": "Images/title.jpg",
|
||||||
"ImageStyle": part.Cover.ImgStyle(e.Image.View.Width, e.Image.View.Height, e.Image.Manga),
|
"ImageStyle": part.Cover.ImgStyle(e.Image.View.Width, e.Image.View.Height, titleAlign),
|
||||||
})},
|
})},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ type Image struct {
|
|||||||
DoublePage bool
|
DoublePage bool
|
||||||
Path string
|
Path string
|
||||||
Name string
|
Name string
|
||||||
|
Position string
|
||||||
}
|
}
|
||||||
|
|
||||||
// key name of the blank plage after the image
|
// key name of the blank plage after the image
|
||||||
@ -70,24 +71,17 @@ func (i *Image) EPUBImgPath() string {
|
|||||||
//
|
//
|
||||||
// center by default.
|
// center by default.
|
||||||
// align to left or right if it's part of the splitted double page.
|
// align to left or right if it's part of the splitted double page.
|
||||||
func (i *Image) ImgStyle(viewWidth, viewHeight int, manga bool) string {
|
func (i *Image) ImgStyle(viewWidth, viewHeight int, align string) string {
|
||||||
marginW, marginH := float64(viewWidth-i.Width)/2, float64(viewHeight-i.Height)/2
|
marginW, marginH := float64(viewWidth-i.Width)/2, float64(viewHeight-i.Height)/2
|
||||||
left, top := marginW*100/float64(viewWidth), marginH*100/float64(viewHeight)
|
|
||||||
var align string
|
if align == "" {
|
||||||
switch i.Part {
|
switch i.Position {
|
||||||
case 0:
|
case "rendition:page-spread-left":
|
||||||
align = fmt.Sprintf("left:%.2f%%", left)
|
|
||||||
case 1:
|
|
||||||
if manga {
|
|
||||||
align = "left:0"
|
|
||||||
} else {
|
|
||||||
align = "right:0"
|
align = "right:0"
|
||||||
}
|
case "rendition:page-spread-right":
|
||||||
case 2:
|
|
||||||
if manga {
|
|
||||||
align = "right:0"
|
|
||||||
} else {
|
|
||||||
align = "left:0"
|
align = "left:0"
|
||||||
|
default:
|
||||||
|
align = fmt.Sprintf("left:%.2f%%", marginW*100/float64(viewWidth))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +89,7 @@ func (i *Image) ImgStyle(viewWidth, viewHeight int, manga bool) string {
|
|||||||
"width:%dpx; height:%dpx; top:%.2f%%; %s;",
|
"width:%dpx; height:%dpx; top:%.2f%%; %s;",
|
||||||
i.Width,
|
i.Width,
|
||||||
i.Height,
|
i.Height,
|
||||||
top,
|
marginH*100/float64(viewHeight),
|
||||||
align,
|
align,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -195,9 +195,11 @@ func getSpine(o *ContentOptions) []tag {
|
|||||||
"",
|
"",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// register position for style adjustment
|
||||||
|
img.Position = getSpread(img.DoublePage)
|
||||||
spine = append(spine, tag{
|
spine = append(spine, tag{
|
||||||
"itemref",
|
"itemref",
|
||||||
tagAttrs{"idref": img.PageKey(), "properties": getSpread(img.DoublePage)},
|
tagAttrs{"idref": img.PageKey(), "properties": img.Position},
|
||||||
"",
|
"",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user