mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
golint
This commit is contained in:
parent
2c6c5b8fc8
commit
749a238c77
@ -30,38 +30,38 @@ func NewFilledCurve() *FilledCurve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AppendCurve appends a Bezier curve to the filled curve.
|
// AppendCurve appends a Bezier curve to the filled curve.
|
||||||
func (this *FilledCurve) AppendCurve(curve draw.CubicBezierCurve) *FilledCurve {
|
func (fc *FilledCurve) AppendCurve(curve draw.CubicBezierCurve) *FilledCurve {
|
||||||
this.curves = append(this.curves, curve)
|
fc.curves = append(fc.curves, curve)
|
||||||
return this
|
return fc
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFillColor sets the fill color for the path.
|
// SetFillColor sets the fill color for the path.
|
||||||
func (this *FilledCurve) SetFillColor(color Color) {
|
func (fc *FilledCurve) SetFillColor(color Color) {
|
||||||
this.fillColor = pdf.NewPdfColorDeviceRGB(color.ToRGB())
|
fc.fillColor = pdf.NewPdfColorDeviceRGB(color.ToRGB())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBorderColor sets the border color for the path.
|
// SetBorderColor sets the border color for the path.
|
||||||
func (this *FilledCurve) SetBorderColor(color Color) {
|
func (fc *FilledCurve) SetBorderColor(color Color) {
|
||||||
this.borderColor = pdf.NewPdfColorDeviceRGB(color.ToRGB())
|
fc.borderColor = pdf.NewPdfColorDeviceRGB(color.ToRGB())
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw draws the filled curve. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty ("").
|
// 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.
|
// 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()
|
bpath := draw.NewCubicBezierPath()
|
||||||
for _, c := range this.curves {
|
for _, c := range fc.curves {
|
||||||
bpath = bpath.AppendCurve(c)
|
bpath = bpath.AppendCurve(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
creator := pdfcontent.NewContentCreator()
|
creator := pdfcontent.NewContentCreator()
|
||||||
creator.Add_q()
|
creator.Add_q()
|
||||||
|
|
||||||
if this.FillEnabled {
|
if fc.FillEnabled {
|
||||||
creator.Add_rg(this.fillColor.R(), this.fillColor.G(), this.fillColor.B())
|
creator.Add_rg(fc.fillColor.R(), fc.fillColor.G(), fc.fillColor.B())
|
||||||
}
|
}
|
||||||
if this.BorderEnabled {
|
if fc.BorderEnabled {
|
||||||
creator.Add_RG(this.borderColor.R(), this.borderColor.G(), this.borderColor.B())
|
creator.Add_RG(fc.borderColor.R(), fc.borderColor.G(), fc.borderColor.B())
|
||||||
creator.Add_w(this.BorderWidth)
|
creator.Add_w(fc.BorderWidth)
|
||||||
}
|
}
|
||||||
if len(gsName) > 1 {
|
if len(gsName) > 1 {
|
||||||
// If a graphics state is provided, use it. (can support transparency).
|
// 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)
|
draw.DrawBezierPathWithCreator(bpath, creator)
|
||||||
creator.Add_h() // Close the path.
|
creator.Add_h() // Close the path.
|
||||||
|
|
||||||
if this.FillEnabled && this.BorderEnabled {
|
if fc.FillEnabled && fc.BorderEnabled {
|
||||||
creator.Add_B() // fill and stroke.
|
creator.Add_B() // fill and stroke.
|
||||||
} else if this.FillEnabled {
|
} else if fc.FillEnabled {
|
||||||
creator.Add_f() // Fill.
|
creator.Add_f() // Fill.
|
||||||
} else if this.BorderEnabled {
|
} else if fc.BorderEnabled {
|
||||||
creator.Add_S() // Stroke.
|
creator.Add_S() // Stroke.
|
||||||
}
|
}
|
||||||
creator.Add_Q()
|
creator.Add_Q()
|
||||||
|
|
||||||
// Get bounding box.
|
// Get bounding box.
|
||||||
pathBbox := bpath.GetBoundingBox()
|
pathBbox := bpath.GetBoundingBox()
|
||||||
if this.BorderEnabled {
|
if fc.BorderEnabled {
|
||||||
// Account for stroke width.
|
// Account for stroke width.
|
||||||
pathBbox.Height += this.BorderWidth
|
pathBbox.Height += fc.BorderWidth
|
||||||
pathBbox.Width += this.BorderWidth
|
pathBbox.Width += fc.BorderWidth
|
||||||
pathBbox.X -= this.BorderWidth / 2
|
pathBbox.X -= fc.BorderWidth / 2
|
||||||
pathBbox.Y -= this.BorderWidth / 2
|
pathBbox.Y -= fc.BorderWidth / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bounding box - global coordinate system.
|
// 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.
|
// 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)
|
block := NewBlock(ctx.PageWidth, ctx.PageHeight)
|
||||||
|
|
||||||
contents, _, err := this.draw("")
|
contents, _, err := fc.draw("")
|
||||||
err = block.addContentsByString(string(contents))
|
err = block.addContentsByString(string(contents))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ctx, err
|
return nil, ctx, err
|
||||||
|
@ -332,8 +332,7 @@ func drawImageOnBlock(blk *Block, img *Image, ctx DrawContext) (DrawContext, err
|
|||||||
ctx.Y += img.Height()
|
ctx.Y += img.Height()
|
||||||
ctx.Height -= img.Height()
|
ctx.Height -= img.Height()
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
} else {
|
}
|
||||||
// Absolute positioning - return original context.
|
// Absolute positioning - return original context.
|
||||||
return origCtx, nil
|
return origCtx, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -193,9 +193,8 @@ func (p *Paragraph) SetWidth(width float64) {
|
|||||||
func (p *Paragraph) Width() float64 {
|
func (p *Paragraph) Width() float64 {
|
||||||
if p.enableWrap {
|
if p.enableWrap {
|
||||||
return p.wrapWidth
|
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
|
// 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.X -= p.margins.left // Move back.
|
||||||
ctx.Width = origContext.Width
|
ctx.Width = origContext.Width
|
||||||
return blocks, ctx, nil
|
return blocks, ctx, nil
|
||||||
} else {
|
}
|
||||||
// Absolute: not changing the context.
|
// Absolute: not changing the context.
|
||||||
return blocks, origContext, nil
|
return blocks, origContext, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw block on specified location on Page, adding to the content stream.
|
// Draw block on specified location on Page, adding to the content stream.
|
||||||
|
@ -390,14 +390,14 @@ func (table *Table) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
|
|||||||
|
|
||||||
if table.positioning.isAbsolute() {
|
if table.positioning.isAbsolute() {
|
||||||
return blocks, origCtx, nil
|
return blocks, origCtx, nil
|
||||||
} else {
|
}
|
||||||
|
// Relative mode.
|
||||||
// Move back X after.
|
// Move back X after.
|
||||||
ctx.X = origCtx.X
|
ctx.X = origCtx.X
|
||||||
// Return original width
|
// Return original width
|
||||||
ctx.Width = origCtx.Width
|
ctx.Width = origCtx.Width
|
||||||
// Add the bottom margin
|
// Add the bottom margin
|
||||||
ctx.Y += table.margins.bottom
|
ctx.Y += table.margins.bottom
|
||||||
}
|
|
||||||
|
|
||||||
return blocks, ctx, nil
|
return blocks, ctx, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user