PageBreak drawable implementation

This commit is contained in:
Jordi Llonch 2018-02-12 13:07:35 +11:00
parent 91660d88c4
commit 40f364059f
2 changed files with 20 additions and 1 deletions

View File

@ -115,7 +115,7 @@ func (chap *Chapter) Add(d Drawable) error {
case *Chapter: case *Chapter:
common.Log.Debug("Error: Cannot add chapter to a chapter") common.Log.Debug("Error: Cannot add chapter to a chapter")
return errors.New("Type check error") return errors.New("Type check error")
case *Paragraph, *Image, *Block, *Subchapter, *Table: case *Paragraph, *Image, *Block, *Subchapter, *Table, *PageBreak:
chap.contents = append(chap.contents, d) chap.contents = append(chap.contents, d)
default: default:
common.Log.Debug("Unsupported: %T", d) common.Log.Debug("Unsupported: %T", d)

19
pdf/creator/pagebreak.go Normal file
View File

@ -0,0 +1,19 @@
package creator
// PageBreak represents a page break for a chapter.
type PageBreak struct {
}
// NewPageBreak create a new page break.
func NewPageBreak() *PageBreak {
return &PageBreak{}
}
// GeneratePageBlocks generates a page break block.
func (p *PageBreak) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) {
blocks := []*Block{
NewBlock(ctx.Width, ctx.PageHeight),
}
ctx.Y = ctx.PageHeight
return blocks, ctx, nil
}