improve alignment on spread images for landscape

This commit is contained in:
Celogeek 2023-04-30 16:25:02 +02:00
parent 5b0051720f
commit bcad0389fa
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
3 changed files with 19 additions and 19 deletions

View File

@ -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),
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
"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 {
@ -251,6 +251,10 @@ func (e *ePub) Write() error {
if totalParts > 1 {
title = fmt.Sprintf("%s [%d/%d]", title, i+1, totalParts)
}
titleAlign := "left:0"
if e.Image.Manga {
titleAlign = "right:0"
}
content := []zipContent{
{"META-INF/container.xml", epubtemplates.Container},
@ -280,7 +284,7 @@ func (e *ePub) Write() error {
"Title": title,
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),
"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),
})},
}

View File

@ -19,6 +19,7 @@ type Image struct {
DoublePage bool
Path string
Name string
Position string
}
// key name of the blank plage after the image
@ -70,24 +71,17 @@ func (i *Image) EPUBImgPath() string {
//
// center by default.
// 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
left, top := marginW*100/float64(viewWidth), marginH*100/float64(viewHeight)
var align string
switch i.Part {
case 0:
align = fmt.Sprintf("left:%.2f%%", left)
case 1:
if manga {
align = "left:0"
} else {
if align == "" {
switch i.Position {
case "rendition:page-spread-left":
align = "right:0"
}
case 2:
if manga {
align = "right:0"
} else {
case "rendition:page-spread-right":
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;",
i.Width,
i.Height,
top,
marginH*100/float64(viewHeight),
align,
)
}

View File

@ -195,9 +195,11 @@ func getSpine(o *ContentOptions) []tag {
"",
})
}
// register position for style adjustment
img.Position = getSpread(img.DoublePage)
spine = append(spine, tag{
"itemref",
tagAttrs{"idref": img.PageKey(), "properties": getSpread(img.DoublePage)},
tagAttrs{"idref": img.PageKey(), "properties": img.Position},
"",
})
}