v0.0.496 wpdf fixes and wpdf test.go
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m58s

This commit is contained in:
2024-08-07 15:34:06 +02:00
parent 133aeb8374
commit 741611a2e1
12 changed files with 228 additions and 18 deletions

View File

@@ -35,6 +35,7 @@ type TableBuilder struct {
rows []tableRow
defaultCellStyle *TableCellStyleOpt
columnWidths *[]string
debug *bool
}
type TableCell struct {
@@ -85,31 +86,38 @@ func (b *TableBuilder) PadY(v float64) *TableBuilder {
return b
}
func (b *TableBuilder) AddRow(cells ...TableCell) {
func (b *TableBuilder) AddRow(cells ...TableCell) *TableBuilder {
b.rows = append(b.rows, tableRow{cells: cells})
return b
}
func (b *TableBuilder) AddRowWithStyle(style TableCellStyleOpt, cells ...string) {
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})
}
b.rows = append(b.rows, tableRow{cells: tcels})
return b
}
func (b *TableBuilder) AddRowDefaultStyle(cells ...string) {
func (b *TableBuilder) AddRowDefaultStyle(cells ...string) *TableBuilder {
tcels := make([]TableCell, 0, len(cells))
for _, cell := range cells {
tcels = append(tcels, TableCell{Content: cell, Style: langext.Coalesce(b.defaultCellStyle, TableCellStyleOpt{})})
}
b.rows = append(b.rows, tableRow{cells: tcels})
return b
}
func (b *TableBuilder) Build() {
builder := b.builder
debug := langext.Coalesce(b.debug, b.builder.debug)
if len(b.rows) == 0 {
return // nothing to do
}
@@ -150,7 +158,7 @@ func (b *TableBuilder) Build() {
if langext.Coalesce(style.MultiCell, true) {
builder.MultiCell(str, style.PDFCellOpt.Copy().ToMulti().Width(cellWidth))
builder.MultiCell(str, style.PDFCellOpt.Copy().ToMulti().Width(cellWidth).Debug(debug))
} else {
@@ -163,7 +171,7 @@ func (b *TableBuilder) Build() {
}
}
builder.Cell(str, style.PDFCellOpt.Copy().Width(cellWidth))
builder.Cell(str, style.PDFCellOpt.Copy().Width(cellWidth).Debug(debug))
}
@@ -307,6 +315,11 @@ func (b *TableBuilder) RowCount() int {
return len(b.rows)
}
func (b *TableBuilder) Debug(v bool) *TableBuilder {
b.debug = &v
return b
}
func (b *WPDFBuilder) Table() *TableBuilder {
return &TableBuilder{
builder: b,
@@ -321,10 +334,11 @@ func defaultTableStyle() *TableCellStyleOpt {
return &TableCellStyleOpt{
PDFCellOpt: *NewPDFCellOpt().
FontSize(float64(8)).
BorderColorHex(uint32(0x888888)).
FillColorHex(uint32(0xFFFFFF)).
Border(BorderFull).
BorderColorHex(uint32(0x666666)).
FillColorHex(uint32(0xF0F0F0)).
TextColorHex(uint32(0x000000)).
FillBackground(false),
FillBackground(true),
MinWidth: langext.Ptr(float64(5)),
Ellipsize: langext.PTrue,
MultiCell: langext.PFalse,