Address golint issues for creator Block

This commit is contained in:
Gunnsteinn Hall 2017-07-31 12:32:18 +00:00
parent 0420787b50
commit 416eb89964

View File

@ -15,7 +15,7 @@ import (
"github.com/unidoc/unidoc/pdf/model" "github.com/unidoc/unidoc/pdf/model"
) )
// A block can contain a portion of PDF Page contents. It has a width and a position and can // Block contains a portion of PDF Page contents. It has a width and a position and can
// be placed anywhere on a Page. It can even contain a whole Page, and is used in the creator // be placed anywhere on a Page. It can even contain a whole Page, and is used in the creator
// where each Drawable object can output one or more blocks, each representing content for separate pages // where each Drawable object can output one or more blocks, each representing content for separate pages
// (typically needed when Page breaks occur). // (typically needed when Page breaks occur).
@ -41,7 +41,7 @@ type Block struct {
margins margins margins margins
} }
// Create a new block with specified width and height. // NewBlock creates a new Block with specified width and height.
func NewBlock(width float64, height float64) *Block { func NewBlock(width float64, height float64) *Block {
b := &Block{} b := &Block{}
b.contents = &contentstream.ContentStreamOperations{} b.contents = &contentstream.ContentStreamOperations{}
@ -51,8 +51,8 @@ func NewBlock(width float64, height float64) *Block {
return b return b
} }
// Create a block from a PDF Page. Useful for loading template pages as blocks from a PDF document and additional // NewBlockFromPage creates a Block from a PDF Page. Useful for loading template pages as blocks from a PDF document
// content with the creator. // and additional content with the creator.
func NewBlockFromPage(page *model.PdfPage) (*Block, error) { func NewBlockFromPage(page *model.PdfPage) (*Block, error) {
b := &Block{} b := &Block{}
@ -91,7 +91,7 @@ func NewBlockFromPage(page *model.PdfPage) (*Block, error) {
return b, nil return b, nil
} }
// Set the rotation angle in degrees. // SetAngle sets the rotation angle in degrees.
func (blk *Block) SetAngle(angleDeg float64) { func (blk *Block) SetAngle(angleDeg float64) {
blk.angle = angleDeg blk.angle = angleDeg
} }
@ -112,7 +112,8 @@ func (blk *Block) duplicate() *Block {
return dup return dup
} }
// Draws the block contents on a template Page block. // GeneratePageBlocks draws the block contents on a template Page block.
// Implements the Drawable interface.
func (blk *Block) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) { func (blk *Block) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) {
blocks := []*Block{} blocks := []*Block{}
@ -156,12 +157,12 @@ func (blk *Block) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, er
return blocks, ctx, nil return blocks, ctx, nil
} }
// Get block height. // Height returns the Block's height.
func (blk *Block) Height() float64 { func (blk *Block) Height() float64 {
return blk.height return blk.height
} }
// Get block width. // Width returns the Block's width.
func (blk *Block) Width() float64 { func (blk *Block) Width() float64 {
return blk.width return blk.width
} }
@ -189,7 +190,7 @@ func (blk *Block) addContentsByString(contents string) error {
return nil return nil
} }
// Set block Margins. // SetMargins sets the Block's left, right, top, bottom, margins.
func (blk *Block) SetMargins(left, right, top, bottom float64) { func (blk *Block) SetMargins(left, right, top, bottom float64) {
blk.margins.left = left blk.margins.left = left
blk.margins.right = right blk.margins.right = right
@ -197,12 +198,12 @@ func (blk *Block) SetMargins(left, right, top, bottom float64) {
blk.margins.bottom = bottom blk.margins.bottom = bottom
} }
// Return block Margins: left, right, top, bottom Margins. // GetMargins returns the Block's margins: left, right, top, bottom.
func (blk *Block) GetMargins() (float64, float64, float64, float64) { func (blk *Block) GetMargins() (float64, float64, float64, float64) {
return blk.margins.left, blk.margins.right, blk.margins.top, blk.margins.bottom return blk.margins.left, blk.margins.right, blk.margins.top, blk.margins.bottom
} }
// Set block positioning to absolute and set the absolute position coordinates as specified. // SetPos sets the Block's positioning to absolute mode with the specified coordinates.
func (blk *Block) SetPos(x, y float64) { func (blk *Block) SetPos(x, y float64) {
blk.positioning = positionAbsolute blk.positioning = positionAbsolute
blk.xPos = x blk.xPos = x
@ -222,13 +223,13 @@ func (blk *Block) Scale(sx, sy float64) {
blk.height *= sy blk.height *= sy
} }
// Scale to a specified width, maintaining aspect ratio. // ScaleToWidth scales the Block to a specified width, maintaining the same aspect ratio.
func (blk *Block) ScaleToWidth(w float64) { func (blk *Block) ScaleToWidth(w float64) {
ratio := w / blk.width ratio := w / blk.width
blk.Scale(ratio, ratio) blk.Scale(ratio, ratio)
} }
// Scale to a specified height, maintaining aspect ratio. // ScaleToHeight scales the Block to a specified height, maintaining the same aspect ratio.
func (blk *Block) ScaleToHeight(h float64) { func (blk *Block) ScaleToHeight(h float64) {
ratio := h / blk.height ratio := h / blk.height
blk.Scale(ratio, ratio) blk.Scale(ratio, ratio)
@ -308,7 +309,7 @@ func (blk *Block) Draw(d Drawable) error {
return nil return nil
} }
// Draw with context. // DrawWithContext draws the Block using the specified drawing context.
func (blk *Block) DrawWithContext(d Drawable, ctx DrawContext) error { func (blk *Block) DrawWithContext(d Drawable, ctx DrawContext) error {
blocks, _, err := d.GeneratePageBlocks(ctx) blocks, _, err := d.GeneratePageBlocks(ctx)
if err != nil { if err != nil {