Compare commits

...

9 Commits

Author SHA1 Message Date
3320a9c19d v0.0.508
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m25s
2024-08-25 17:36:20 +02:00
8dcd8a270a v0.0.507 fix jsonfilter:"-" not working
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 7m7s
2024-08-25 15:41:17 +02:00
03a9b276d8 v0.0.506 allow empty-string as value for enum
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 7m36s
2024-08-22 11:45:02 +02:00
9c8cde384f v0.0.505
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 6m17s
2024-08-08 15:57:05 +02:00
99b000ecf4 v0.0.504
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m53s
2024-08-07 19:44:45 +02:00
a173e30090 v0.0.503
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m52s
2024-08-07 19:37:38 +02:00
a3481a7d2d v0.0.502
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
2024-08-07 19:35:23 +02:00
a8e6f98a89 v0.0.501
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
2024-08-07 19:31:36 +02:00
ab805403b9 v0.0.500
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
2024-08-07 19:30:38 +02:00
11 changed files with 328 additions and 51 deletions

View File

@@ -46,7 +46,7 @@ var rexEnumPackage = rext.W(regexp.MustCompile(`^package\s+(?P<name>[A-Za-z0-9_]
var rexEnumDef = rext.W(regexp.MustCompile(`^\s*type\s+(?P<name>[A-Za-z0-9_]+)\s+(?P<type>[A-Za-z0-9_]+)\s*//\s*(@enum:type).*$`))
var rexEnumValueDef = rext.W(regexp.MustCompile(`^\s*(?P<name>[A-Za-z0-9_]+)\s+(?P<type>[A-Za-z0-9_]+)\s*=\s*(?P<value>("[A-Za-z0-9_:\s\-.]+"|[0-9]+))\s*(//(?P<comm>.*))?.*$`))
var rexEnumValueDef = rext.W(regexp.MustCompile(`^\s*(?P<name>[A-Za-z0-9_]+)\s+(?P<type>[A-Za-z0-9_]+)\s*=\s*(?P<value>("[A-Za-z0-9_:\s\-.]*"|[0-9]+))\s*(//(?P<comm>.*))?.*$`))
var rexEnumChecksumConst = rext.W(regexp.MustCompile(`const ChecksumEnumGenerator = "(?P<cs>[A-Za-z0-9_]*)"`))

8
go.mod
View File

@@ -6,11 +6,11 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/glebarez/go-sqlite v1.22.0 // only needed for tests -.-
github.com/jmoiron/sqlx v1.4.0
github.com/rs/xid v1.5.0
github.com/rs/xid v1.6.0
github.com/rs/zerolog v1.33.0
go.mongodb.org/mongo-driver v1.16.0
go.mongodb.org/mongo-driver v1.16.1
golang.org/x/crypto v0.26.0
golang.org/x/sys v0.23.0
golang.org/x/sys v0.24.0
golang.org/x/term v0.23.0
)
@@ -45,7 +45,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect

8
go.sum
View File

@@ -175,6 +175,8 @@ github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtos
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/phpdave11/gofpdi v1.0.7/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -184,6 +186,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
@@ -234,6 +238,8 @@ go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7
go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4=
go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
@@ -335,6 +341,8 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=

View File

@@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.499"
const GoextVersion = "0.0.508"
const GoextVersionTimestamp = "2024-08-07T18:34:22+0200"
const GoextVersionTimestamp = "2024-08-25T17:36:20+0200"

View File

@@ -1353,7 +1353,7 @@ func typeFields(t reflect.Type, tagkey string) structFields {
var jsonfilter []string
jsonfilterTag := sf.Tag.Get("jsonfilter")
if jsonfilterTag != "" && jsonfilterTag != "-" {
if jsonfilterTag != "" {
jsonfilter = strings.Split(jsonfilterTag, ",")
}

15
langext/io.go Normal file
View File

@@ -0,0 +1,15 @@
package langext
import "io"
type nopCloser struct {
io.Writer
}
func (n nopCloser) Close() error {
return nil // no op
}
func WriteNopCloser(w io.Writer) io.WriteCloser {
return nopCloser{w}
}

View File

@@ -12,7 +12,11 @@ import (
func (c *Coll[TData]) FindOne(ctx context.Context, filter bson.M) (TData, error) {
r, err := c.findOneInternal(ctx, filter, false)
if err != nil {
return *new(TData), exerr.Wrap(err, "mongo-query[find-one] failed").Str("collection", c.Name()).Build()
if filterId, ok := filter["_id"]; ok {
return *new(TData), exerr.Wrap(err, "mongo-query[find-one] failed").Str("collection", c.Name()).Any("filter", filter).Any("filter_id", filterId).Build()
} else {
return *new(TData), exerr.Wrap(err, "mongo-query[find-one] failed").Str("collection", c.Name()).Any("filter", filter).Build()
}
}
return *r, nil
@@ -21,7 +25,7 @@ func (c *Coll[TData]) FindOne(ctx context.Context, filter bson.M) (TData, error)
func (c *Coll[TData]) FindOneOpt(ctx context.Context, filter bson.M) (*TData, error) {
r, err := c.findOneInternal(ctx, filter, true)
if err != nil {
return nil, exerr.Wrap(err, "mongo-query[find-one-opt] failed").Str("collection", c.Name()).Build()
return nil, exerr.Wrap(err, "mongo-query[find-one-opt] failed").Str("collection", c.Name()).Any("filter", filter).Build()
}
return r, nil
@@ -58,7 +62,11 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN
return nil, nil
}
if err != nil {
return nil, exerr.Wrap(err, "mongo-query[find-one] failed").Any("filter", filter).Str("collection", c.Name()).NoLog().Build()
if filterId, ok := filter["_id"]; ok {
return nil, exerr.Wrap(err, "mongo-query[find-one|internal] failed").Str("collection", c.Name()).Any("filter", filter).Any("filter_id", filterId).NoLog().Build()
} else {
return nil, exerr.Wrap(err, "mongo-query[find-one|internal] failed").Str("collection", c.Name()).Any("filter", filter).NoLog().Build()
}
}
return &res, nil

View File

@@ -38,24 +38,6 @@ type TableBuilder struct {
debug *bool
}
type TableCell struct {
Content string
Style TableCellStyleOpt
}
type TableCellStyleOpt struct {
MultiCell *bool
Ellipsize *bool
PaddingHorz *float64
MinWidth *float64
PDFCellOpt
}
type tableRow struct {
cells []TableCell
}
func (r tableRow) maxFontSize(defaultFontSize float64) float64 {
mfs := defaultFontSize
for _, cell := range r.cells {
@@ -71,8 +53,8 @@ func (b *TableBuilder) Widths(v ...string) *TableBuilder {
return b
}
func (b *TableBuilder) DefaultStyle(s TableCellStyleOpt) *TableBuilder {
b.defaultCellStyle = &s
func (b *TableBuilder) DefaultStyle(s *TableCellStyleOpt) *TableBuilder {
b.defaultCellStyle = s
return b
}
@@ -91,10 +73,10 @@ func (b *TableBuilder) AddRow(cells ...TableCell) *TableBuilder {
return b
}
func (b *TableBuilder) AddRowWithStyle(style TableCellStyleOpt, cells ...string) *TableBuilder {
func (b *TableBuilder) AddRowWithStyle(style *TableCellStyleOpt, cells ...string) *TableBuilder {
tcels := make([]TableCell, 0, len(cells))
for _, cell := range cells {
tcels = append(tcels, TableCell{Content: cell, Style: style})
tcels = append(tcels, TableCell{Content: cell, Style: *style})
}
b.rows = append(b.rows, tableRow{cells: tcels})
@@ -113,6 +95,10 @@ func (b *TableBuilder) AddRowDefaultStyle(cells ...string) *TableBuilder {
return b
}
func (b *TableBuilder) BuildRow() *TableRowBuilder {
return &TableRowBuilder{tabbuilder: b, cells: make([]TableCell, 0)}
}
func (b *TableBuilder) Build() {
builder := b.builder
@@ -148,15 +134,19 @@ func (b *TableBuilder) Build() {
str := cell.Content
style := cell.Style
ellipsize := langext.Coalesce(style.Ellipsize, true)
cellPaddingHorz := langext.Coalesce(style.PaddingHorz, 2)
ellipsize := langext.Coalesce(style.ellipsize, true)
cellPaddingHorz := langext.Coalesce(style.paddingHorz, 2)
fillHeight := langext.Coalesce(style.fillHeight, false)
bx := builder.GetX()
by := builder.GetY()
cellWidth := columnWidths[cellIdx]
if langext.Coalesce(style.MultiCell, true) {
_ = fillHeight // TODO implement, but how?? ( cells with fillHeight=true should have a border of the full column height, even if another column is growing it, but we do not know teh height beforehand ... )
if langext.Coalesce(style.multiCell, true) {
builder.MultiCell(str, style.PDFCellOpt.Copy().ToMulti().Width(cellWidth).Debug(debug))
@@ -230,8 +220,8 @@ func (b *TableBuilder) calculateColumns() []float64 {
for _, row := range b.rows {
if len(row.cells) > colIdx {
ph := langext.Coalesce(row.cells[colIdx].Style.PaddingHorz, 2)
mw := langext.Coalesce(row.cells[colIdx].Style.MinWidth, 0)
ph := langext.Coalesce(row.cells[colIdx].Style.paddingHorz, 2)
mw := langext.Coalesce(row.cells[colIdx].Style.minWidth, 0)
minWidth = max(minWidth, ph+mw)
@@ -344,8 +334,8 @@ func defaultTableStyle() *TableCellStyleOpt {
FillColorHex(uint32(0xF0F0F0)).
TextColorHex(uint32(0x000000)).
FillBackground(true),
MinWidth: langext.Ptr(float64(5)),
Ellipsize: langext.PTrue,
MultiCell: langext.PFalse,
minWidth: langext.Ptr(float64(5)),
ellipsize: langext.PTrue,
multiCell: langext.PFalse,
}
}

187
wpdf/wpdfTableCell.go Normal file
View File

@@ -0,0 +1,187 @@
package wpdf
import (
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
)
type TableCell struct {
Content string
Style TableCellStyleOpt
}
type TableCellStyleOpt struct {
multiCell *bool
ellipsize *bool
paddingHorz *float64
minWidth *float64
fillHeight *bool
PDFCellOpt
}
func NewTableCellStyleOpt() *TableCellStyleOpt {
return &TableCellStyleOpt{}
}
func (o *TableCellStyleOpt) FillHeight(b bool) *TableCellStyleOpt {
o.fillHeight = &b
return o
}
func (o *TableCellStyleOpt) MultiCell(v bool) *TableCellStyleOpt {
o.multiCell = &v
return o
}
func (o *TableCellStyleOpt) Ellipsize(v bool) *TableCellStyleOpt {
o.ellipsize = &v
return o
}
func (o *TableCellStyleOpt) PaddingHorz(v float64) *TableCellStyleOpt {
o.paddingHorz = &v
return o
}
func (o *TableCellStyleOpt) MinWidth(v float64) *TableCellStyleOpt {
o.minWidth = &v
return o
}
func (o *TableCellStyleOpt) CellStyle(v PDFCellOpt) *TableCellStyleOpt {
o.PDFCellOpt = v
return o
}
func (o *TableCellStyleOpt) Width(v float64) *TableCellStyleOpt {
o.PDFCellOpt.width = &v
return o
}
func (o *TableCellStyleOpt) Height(v float64) *TableCellStyleOpt {
o.PDFCellOpt.height = &v
return o
}
func (o *TableCellStyleOpt) Border(v PDFBorder) *TableCellStyleOpt {
o.PDFCellOpt.border = &v
return o
}
func (o *TableCellStyleOpt) LnPos(v PDFTextBreak) *TableCellStyleOpt {
o.PDFCellOpt.ln = &v
return o
}
func (o *TableCellStyleOpt) Align(v PDFTextAlign) *TableCellStyleOpt {
o.PDFCellOpt.align = &v
return o
}
func (o *TableCellStyleOpt) FillBackground(v bool) *TableCellStyleOpt {
o.PDFCellOpt.fill = &v
return o
}
func (o *TableCellStyleOpt) Link(v int) *TableCellStyleOpt {
o.PDFCellOpt.link = &v
return o
}
func (o *TableCellStyleOpt) LinkStr(v string) *TableCellStyleOpt {
o.PDFCellOpt.linkStr = &v
return o
}
func (o *TableCellStyleOpt) Font(fontName PDFFontFamily, fontStyle PDFFontStyle, fontSize float64) *TableCellStyleOpt {
o.PDFCellOpt.fontNameOverride = &fontName
o.PDFCellOpt.fontStyleOverride = &fontStyle
o.PDFCellOpt.fontSizeOverride = &fontSize
return o
}
func (o *TableCellStyleOpt) FontName(v PDFFontFamily) *TableCellStyleOpt {
o.PDFCellOpt.fontNameOverride = &v
return o
}
func (o *TableCellStyleOpt) FontStyle(v PDFFontStyle) *TableCellStyleOpt {
o.PDFCellOpt.fontStyleOverride = &v
return o
}
func (o *TableCellStyleOpt) FontSize(v float64) *TableCellStyleOpt {
o.PDFCellOpt.fontSizeOverride = &v
return o
}
func (o *TableCellStyleOpt) Bold() *TableCellStyleOpt {
o.PDFCellOpt.fontStyleOverride = langext.Ptr(Bold)
return o
}
func (o *TableCellStyleOpt) Italic() *TableCellStyleOpt {
o.PDFCellOpt.fontStyleOverride = langext.Ptr(Italic)
return o
}
func (o *TableCellStyleOpt) LnAfter(v float64) *TableCellStyleOpt {
o.PDFCellOpt.extraLn = &v
return o
}
func (o *TableCellStyleOpt) X(v float64) *TableCellStyleOpt {
o.PDFCellOpt.x = &v
return o
}
func (o *TableCellStyleOpt) AutoWidth() *TableCellStyleOpt {
o.PDFCellOpt.autoWidth = langext.PTrue
return o
}
func (o *TableCellStyleOpt) AutoWidthPaddingX(v float64) *TableCellStyleOpt {
o.PDFCellOpt.autoWidthPaddingX = &v
return o
}
func (o *TableCellStyleOpt) TextColor(cr, cg, cb int) *TableCellStyleOpt {
o.PDFCellOpt.textColor = langext.Ptr(rgbToColor(cr, cg, cb))
return o
}
func (o *TableCellStyleOpt) TextColorHex(c uint32) *TableCellStyleOpt {
o.PDFCellOpt.textColor = langext.Ptr(hexToColor(c))
return o
}
func (o *TableCellStyleOpt) BorderColor(cr, cg, cb int) *TableCellStyleOpt {
o.PDFCellOpt.borderColor = langext.Ptr(rgbToColor(cr, cg, cb))
return o
}
func (o *TableCellStyleOpt) BorderColorHex(c uint32) *TableCellStyleOpt {
o.PDFCellOpt.borderColor = langext.Ptr(hexToColor(c))
return o
}
func (o *TableCellStyleOpt) FillColor(cr, cg, cb int) *TableCellStyleOpt {
o.PDFCellOpt.fillColor = langext.Ptr(rgbToColor(cr, cg, cb))
return o
}
func (o *TableCellStyleOpt) FillColorHex(c uint32) *TableCellStyleOpt {
o.PDFCellOpt.fillColor = langext.Ptr(hexToColor(c))
return o
}
func (o *TableCellStyleOpt) Alpha(alpha float64, blendMode PDFBlendMode) *TableCellStyleOpt {
o.PDFCellOpt.alphaOverride = &dataext.Tuple[float64, PDFBlendMode]{V1: alpha, V2: blendMode}
return o
}
func (o *TableCellStyleOpt) Debug(v bool) *TableCellStyleOpt {
o.PDFCellOpt.debug = &v
return o
}

52
wpdf/wpdfTableRow.go Normal file
View File

@@ -0,0 +1,52 @@
package wpdf
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
type tableRow struct {
cells []TableCell
}
type TableRowBuilder struct {
tabbuilder *TableBuilder
defaultStyle *TableCellStyleOpt
cells []TableCell
}
func (r *TableRowBuilder) RowStyle(style *TableCellStyleOpt) *TableRowBuilder {
r.defaultStyle = style
return r
}
func (r *TableRowBuilder) Cell(cell string) *TableRowBuilder {
r.cells = append(r.cells, TableCell{Content: cell, Style: langext.Coalesce3(r.defaultStyle, r.tabbuilder.defaultCellStyle, TableCellStyleOpt{})})
return r
}
func (r *TableRowBuilder) Cells(cells ...string) *TableRowBuilder {
for _, cell := range cells {
r.cells = append(r.cells, TableCell{Content: cell, Style: langext.Coalesce3(r.defaultStyle, r.tabbuilder.defaultCellStyle, TableCellStyleOpt{})})
}
return r
}
func (r *TableRowBuilder) CellObject(cell TableCell) *TableRowBuilder {
r.cells = append(r.cells, cell)
return r
}
func (r *TableRowBuilder) CellObjects(cells ...TableCell) *TableRowBuilder {
for _, cell := range cells {
r.cells = append(r.cells, cell)
}
return r
}
func (r *TableRowBuilder) CellWithStyle(cell string, style *TableCellStyleOpt) *TableRowBuilder {
r.cells = append(r.cells, TableCell{Content: cell, Style: *style})
return r
}
func (r *TableRowBuilder) BuildRow() *TableBuilder {
r.tabbuilder.AddRow(r.cells...)
return r.tabbuilder
}

View File

@@ -2,9 +2,11 @@ package wpdf
import (
_ "embed"
"fmt"
"gogs.mikescher.com/BlackForestBytes/goext/imageext"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"os"
"path"
"testing"
)
@@ -38,7 +40,7 @@ func TestPDFBuilder(t *testing.T) {
builder.Ln(4)
cellStyleHeader := TableCellStyleOpt{
cellStyleHeader := &TableCellStyleOpt{
PDFCellOpt: *NewPDFCellOpt().
FontSize(float64(8)).
BorderColorHex(uint32(0x666666)).
@@ -48,12 +50,12 @@ func TestPDFBuilder(t *testing.T) {
TextColorHex(uint32(0x000000)).
Align(AlignHorzCenter).
Bold(),
MinWidth: langext.Ptr(float64(5)),
Ellipsize: langext.PTrue,
MultiCell: langext.PFalse,
minWidth: langext.Ptr(float64(5)),
ellipsize: langext.PTrue,
multiCell: langext.PFalse,
}
cellStyleMulti := TableCellStyleOpt{
cellStyleMulti := &TableCellStyleOpt{
PDFCellOpt: *NewPDFCellOpt().
FontSize(float64(8)).
BorderColorHex(uint32(0x666666)).
@@ -61,9 +63,9 @@ func TestPDFBuilder(t *testing.T) {
FillColorHex(uint32(0xC060C0)).
FillBackground(true).
TextColorHex(uint32(0x000000)),
MinWidth: langext.Ptr(float64(5)),
Ellipsize: langext.PFalse,
MultiCell: langext.PTrue,
minWidth: langext.Ptr(float64(5)),
ellipsize: langext.PFalse,
multiCell: langext.PTrue,
}
builder.Table().
@@ -74,7 +76,20 @@ func TestPDFBuilder(t *testing.T) {
AddRowDefaultStyle("test", "hello", "123", "end").
AddRowDefaultStyle("123", "helasdsalo", "a", "enwqad").
AddRowDefaultStyle("123asd", "TrimMeTrimMeTrimMeTrimMe", "a", "enwqad").
AddRowWithStyle(cellStyleMulti, "123", "helasdsalo", "a", "MultiCell: enwqad enw\nqad enwqad enwqad enwqad enwqad enwqad enwqad enwqad").
AddRowWithStyle(cellStyleMulti, "123", "helasdsalo", "a", "MultiCell: enwqad enw\nqad enwqad enwqad enwqad enwqad").
AddRowDefaultStyle("123", "helasdsalo", "a", "enwqad").
Debug(false).
Build()
builder.Ln(8)
builder.Table().
Widths("auto", "20", "1fr", "20").
PadX(2).
PadY(2).
BuildRow().RowStyle(cellStyleHeader).Cells("test", "hello", "123", "end").BuildRow().
BuildRow().Cells("test", "hello", "123", "end").BuildRow().
BuildRow().RowStyle(cellStyleMulti.FillHeight(true)).Cell("123").Cell("helasdsalo").Cell("a").Cell("MultiCell: enwqad enw\nqad enwqad enwqad enwqad enwqad").BuildRow().
AddRowDefaultStyle("123", "helasdsalo", "a", "enwqad").
Debug(false).
Build()
@@ -84,5 +99,7 @@ func TestPDFBuilder(t *testing.T) {
t.Fatal(err)
}
_ = os.WriteFile("wpdf_test.pdf", bin, 0644)
fn := "wpdf_test.pdf"
_ = os.WriteFile(fn, bin, 0644)
fmt.Println("file://" + path.Join(langext.Must(os.Getwd()), fn))
}