Fix toc and outline link destination coordinates on content page break

This commit is contained in:
Adrian-George Bostan 2019-03-06 19:25:04 +02:00
parent 548af32929
commit b92e7562d5

View File

@ -182,19 +182,17 @@ func (chap *Chapter) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
ctx.Height -= chap.margins.top ctx.Height -= chap.margins.top
} }
origX := ctx.X blocks, c, err := chap.heading.GeneratePageBlocks(ctx)
origY := ctx.Y
blocks, ctx, err := chap.heading.GeneratePageBlocks(ctx)
if err != nil { if err != nil {
return blocks, ctx, err return blocks, ctx, err
} }
if len(blocks) > 1 { ctx = c
ctx.Page++ // Did not fit, moved to new Page block.
}
// Generate chapter title and number. // Generate chapter title and number.
posX := ctx.X
posY := ctx.Y - chap.heading.Height()
page := int64(ctx.Page) page := int64(ctx.Page)
chapNumber := chap.headingNumber() chapNumber := chap.headingNumber()
chapTitle := chap.headingText() chapTitle := chap.headingText()
@ -202,7 +200,7 @@ func (chap *Chapter) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
if chap.includeInTOC { if chap.includeInTOC {
line := chap.toc.Add(chapNumber, chap.title, strconv.FormatInt(page, 10), chap.level) line := chap.toc.Add(chapNumber, chap.title, strconv.FormatInt(page, 10), chap.level)
if chap.toc.showLinks { if chap.toc.showLinks {
line.SetLink(page, origX, origY) line.SetLink(page, posX, posY)
} }
} }
@ -210,7 +208,7 @@ func (chap *Chapter) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
if chap.outlineItem == nil { if chap.outlineItem == nil {
chap.outlineItem = model.NewOutlineItem( chap.outlineItem = model.NewOutlineItem(
chapTitle, chapTitle,
model.NewOutlineDest(page-1, origX, origY), model.NewOutlineDest(page-1, posX, posY),
) )
if chap.parent != nil { if chap.parent != nil {
@ -221,8 +219,8 @@ func (chap *Chapter) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
} else { } else {
outlineDest := &chap.outlineItem.Dest outlineDest := &chap.outlineItem.Dest
outlineDest.Page = page - 1 outlineDest.Page = page - 1
outlineDest.X = origX outlineDest.X = posX
outlineDest.Y = origY outlineDest.Y = posY
} }
for _, d := range chap.contents { for _, d := range chap.contents {