1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package lib
- import "github.com/signintech/gopdf"
- const (
- ValignTop = 1
- ValignMiddle = 2
- ValignBottom = 3
- )
- const (
- AlignLeft = 4
- AlignCenter = 5
- AlignRight = 6
- )
- func RectFillColor(pdf *gopdf.GoPdf,
- text string,
- fontSize int,
- x, y, w, h float64,
- r, g, b uint8,
- align, valign int,
- ) {
- pdf.SetLineWidth(0.1)
- pdf.SetFillColor(r, g, b) //setup fill color
- pdf.SetLineType("") // 线条样式
- pdf.RectFromUpperLeftWithStyle(x, y, w, h, "FD")
- pdf.SetFillColor(0, 0, 0)
- if align == AlignCenter {
- textw, _ := pdf.MeasureTextWidth(text)
- x = x + (w / 2) - (textw / 2)
- } else if align == AlignRight {
- textw, _ := pdf.MeasureTextWidth(text)
- x = x + w - textw
- }
- pdf.SetX(x)
- if valign == ValignMiddle {
- y = y + (h / 2) - (float64(fontSize) / 2)
- } else if valign == ValignBottom {
- y = y + h - float64(fontSize)
- }
- pdf.SetY(y)
- pdf.Cell(nil, text)
- }
|