mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Fix pagebreak generate page blocks. Support pagebreak in subchapter.
This commit is contained in:
parent
d95127579f
commit
e71bb34362
@ -11,9 +11,21 @@ func NewPageBreak() *PageBreak {
|
||||
|
||||
// GeneratePageBlocks generates a page break block.
|
||||
func (p *PageBreak) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) {
|
||||
// Return two empty blocks. First one simply means that there is nothing more to add at the current page.
|
||||
// The second one starts a new page.
|
||||
blocks := []*Block{
|
||||
NewBlock(ctx.Width, ctx.PageHeight),
|
||||
NewBlock(ctx.PageWidth, ctx.PageHeight-ctx.Y),
|
||||
NewBlock(ctx.PageWidth, ctx.PageHeight),
|
||||
}
|
||||
ctx.Y = ctx.PageHeight
|
||||
|
||||
// New Page. Place context in upper left corner (with margins).
|
||||
ctx.Page++
|
||||
newContext := ctx
|
||||
newContext.Y = ctx.Margins.top
|
||||
newContext.X = ctx.Margins.left
|
||||
newContext.Height = ctx.PageHeight - ctx.Margins.top - ctx.Margins.bottom
|
||||
newContext.Width = ctx.PageWidth - ctx.Margins.left - ctx.Margins.right
|
||||
ctx = newContext
|
||||
|
||||
return blocks, ctx, nil
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func (subchap *Subchapter) Add(d Drawable) {
|
||||
switch d.(type) {
|
||||
case *Chapter, *Subchapter:
|
||||
common.Log.Debug("Error: Cannot add chapter or subchapter to a subchapter")
|
||||
case *Paragraph, *Image, *Block, *Table:
|
||||
case *Paragraph, *Image, *Block, *Table, *PageBreak:
|
||||
subchap.contents = append(subchap.contents, d)
|
||||
default:
|
||||
common.Log.Debug("Unsupported: %T", d)
|
||||
|
Loading…
x
Reference in New Issue
Block a user