From 749a238c776cdeb83efaf0fc065bcc3441326fd9 Mon Sep 17 00:00:00 2001 From: Gunnsteinn Hall Date: Thu, 26 Jul 2018 14:57:57 +0000 Subject: [PATCH] golint --- pdf/creator/filled_curve.go | 48 ++++++++++++++++++------------------- pdf/creator/image.go | 5 ++-- pdf/creator/paragraph.go | 8 +++---- pdf/creator/table.go | 14 +++++------ 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/pdf/creator/filled_curve.go b/pdf/creator/filled_curve.go index 5714ff7e..1b5e1a25 100644 --- a/pdf/creator/filled_curve.go +++ b/pdf/creator/filled_curve.go @@ -30,38 +30,38 @@ func NewFilledCurve() *FilledCurve { } // AppendCurve appends a Bezier curve to the filled curve. -func (this *FilledCurve) AppendCurve(curve draw.CubicBezierCurve) *FilledCurve { - this.curves = append(this.curves, curve) - return this +func (fc *FilledCurve) AppendCurve(curve draw.CubicBezierCurve) *FilledCurve { + fc.curves = append(fc.curves, curve) + return fc } // SetFillColor sets the fill color for the path. -func (this *FilledCurve) SetFillColor(color Color) { - this.fillColor = pdf.NewPdfColorDeviceRGB(color.ToRGB()) +func (fc *FilledCurve) SetFillColor(color Color) { + fc.fillColor = pdf.NewPdfColorDeviceRGB(color.ToRGB()) } // SetBorderColor sets the border color for the path. -func (this *FilledCurve) SetBorderColor(color Color) { - this.borderColor = pdf.NewPdfColorDeviceRGB(color.ToRGB()) +func (fc *FilledCurve) SetBorderColor(color Color) { + fc.borderColor = pdf.NewPdfColorDeviceRGB(color.ToRGB()) } // draw draws the filled curve. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty (""). // Returns the content stream as a byte array, the bounding box and an error on failure. -func (this *FilledCurve) draw(gsName string) ([]byte, *pdf.PdfRectangle, error) { +func (fc *FilledCurve) draw(gsName string) ([]byte, *pdf.PdfRectangle, error) { bpath := draw.NewCubicBezierPath() - for _, c := range this.curves { + for _, c := range fc.curves { bpath = bpath.AppendCurve(c) } creator := pdfcontent.NewContentCreator() creator.Add_q() - if this.FillEnabled { - creator.Add_rg(this.fillColor.R(), this.fillColor.G(), this.fillColor.B()) + if fc.FillEnabled { + creator.Add_rg(fc.fillColor.R(), fc.fillColor.G(), fc.fillColor.B()) } - if this.BorderEnabled { - creator.Add_RG(this.borderColor.R(), this.borderColor.G(), this.borderColor.B()) - creator.Add_w(this.BorderWidth) + if fc.BorderEnabled { + creator.Add_RG(fc.borderColor.R(), fc.borderColor.G(), fc.borderColor.B()) + creator.Add_w(fc.BorderWidth) } if len(gsName) > 1 { // If a graphics state is provided, use it. (can support transparency). @@ -71,23 +71,23 @@ func (this *FilledCurve) draw(gsName string) ([]byte, *pdf.PdfRectangle, error) draw.DrawBezierPathWithCreator(bpath, creator) creator.Add_h() // Close the path. - if this.FillEnabled && this.BorderEnabled { + if fc.FillEnabled && fc.BorderEnabled { creator.Add_B() // fill and stroke. - } else if this.FillEnabled { + } else if fc.FillEnabled { creator.Add_f() // Fill. - } else if this.BorderEnabled { + } else if fc.BorderEnabled { creator.Add_S() // Stroke. } creator.Add_Q() // Get bounding box. pathBbox := bpath.GetBoundingBox() - if this.BorderEnabled { + if fc.BorderEnabled { // Account for stroke width. - pathBbox.Height += this.BorderWidth - pathBbox.Width += this.BorderWidth - pathBbox.X -= this.BorderWidth / 2 - pathBbox.Y -= this.BorderWidth / 2 + pathBbox.Height += fc.BorderWidth + pathBbox.Width += fc.BorderWidth + pathBbox.X -= fc.BorderWidth / 2 + pathBbox.Y -= fc.BorderWidth / 2 } // Bounding box - global coordinate system. @@ -100,10 +100,10 @@ func (this *FilledCurve) draw(gsName string) ([]byte, *pdf.PdfRectangle, error) } // GeneratePageBlocks draws the filled curve on page blocks. -func (this *FilledCurve) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) { +func (fc *FilledCurve) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) { block := NewBlock(ctx.PageWidth, ctx.PageHeight) - contents, _, err := this.draw("") + contents, _, err := fc.draw("") err = block.addContentsByString(string(contents)) if err != nil { return nil, ctx, err diff --git a/pdf/creator/image.go b/pdf/creator/image.go index ae5bbe59..1b2c860d 100644 --- a/pdf/creator/image.go +++ b/pdf/creator/image.go @@ -332,8 +332,7 @@ func drawImageOnBlock(blk *Block, img *Image, ctx DrawContext) (DrawContext, err ctx.Y += img.Height() ctx.Height -= img.Height() return ctx, nil - } else { - // Absolute positioning - return original context. - return origCtx, nil } + // Absolute positioning - return original context. + return origCtx, nil } diff --git a/pdf/creator/paragraph.go b/pdf/creator/paragraph.go index 70ec4af8..c9857830 100644 --- a/pdf/creator/paragraph.go +++ b/pdf/creator/paragraph.go @@ -193,9 +193,8 @@ func (p *Paragraph) SetWidth(width float64) { func (p *Paragraph) Width() float64 { if p.enableWrap { return p.wrapWidth - } else { - return p.getTextWidth() / 1000.0 } + return p.getTextWidth() / 1000.0 } // Height returns the height of the Paragraph. The height is calculated based on the input text and how it is wrapped @@ -382,10 +381,9 @@ func (p *Paragraph) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, ctx.X -= p.margins.left // Move back. ctx.Width = origContext.Width return blocks, ctx, nil - } else { - // Absolute: not changing the context. - return blocks, origContext, nil } + // Absolute: not changing the context. + return blocks, origContext, nil } // Draw block on specified location on Page, adding to the content stream. diff --git a/pdf/creator/table.go b/pdf/creator/table.go index 73c233a1..c012957d 100644 --- a/pdf/creator/table.go +++ b/pdf/creator/table.go @@ -390,14 +390,14 @@ func (table *Table) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, if table.positioning.isAbsolute() { return blocks, origCtx, nil - } else { - // Move back X after. - ctx.X = origCtx.X - // Return original width - ctx.Width = origCtx.Width - // Add the bottom margin - ctx.Y += table.margins.bottom } + // Relative mode. + // Move back X after. + ctx.X = origCtx.X + // Return original width + ctx.Width = origCtx.Width + // Add the bottom margin + ctx.Y += table.margins.bottom return blocks, ctx, nil }