Compare commits
	
		
			10 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8dcd8a270a | |||
| 03a9b276d8 | |||
| 9c8cde384f | |||
| 99b000ecf4 | |||
| a173e30090 | |||
| a3481a7d2d | |||
| a8e6f98a89 | |||
| ab805403b9 | |||
| 1e98d351ce | |||
| c40bdc8e9e | 
| @@ -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 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_]*)"`)) | var rexEnumChecksumConst = rext.W(regexp.MustCompile(`const ChecksumEnumGenerator = "(?P<cs>[A-Za-z0-9_]*)"`)) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.mod
									
									
									
									
									
								
							| @@ -6,11 +6,11 @@ require ( | |||||||
| 	github.com/gin-gonic/gin v1.10.0 | 	github.com/gin-gonic/gin v1.10.0 | ||||||
| 	github.com/glebarez/go-sqlite v1.22.0 // only needed for tests -.- | 	github.com/glebarez/go-sqlite v1.22.0 // only needed for tests -.- | ||||||
| 	github.com/jmoiron/sqlx v1.4.0 | 	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 | 	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/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 | 	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/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||||||
| 	github.com/modern-go/reflect2 v1.0.2 // indirect | 	github.com/modern-go/reflect2 v1.0.2 // indirect | ||||||
| 	github.com/montanaflynn/stats v0.7.1 // 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/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||||||
| 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||||||
| 	github.com/ugorji/go/codec v1.2.12 // indirect | 	github.com/ugorji/go/codec v1.2.12 // indirect | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.sum
									
									
									
									
									
								
							| @@ -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.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 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.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/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.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||||||
| github.com/pkg/errors v0.9.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/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 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= | ||||||
| github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= | 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 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= | ||||||
| github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= | 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= | 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.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 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4= | ||||||
| go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= | 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.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 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= | ||||||
| golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= | 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.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||||
| golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= | 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.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-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.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||||||
| golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= | golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| package goext | package goext | ||||||
|  |  | ||||||
| const GoextVersion = "0.0.497" | const GoextVersion = "0.0.507" | ||||||
|  |  | ||||||
| const GoextVersionTimestamp = "2024-08-07T17:04:59+0200" | const GoextVersionTimestamp = "2024-08-25T15:41:17+0200" | ||||||
|   | |||||||
| @@ -1353,7 +1353,7 @@ func typeFields(t reflect.Type, tagkey string) structFields { | |||||||
|  |  | ||||||
| 				var jsonfilter []string | 				var jsonfilter []string | ||||||
| 				jsonfilterTag := sf.Tag.Get("jsonfilter") | 				jsonfilterTag := sf.Tag.Get("jsonfilter") | ||||||
| 				if jsonfilterTag != "" && jsonfilterTag != "-" { | 				if jsonfilterTag != "" { | ||||||
| 					jsonfilter = strings.Split(jsonfilterTag, ",") | 					jsonfilter = strings.Split(jsonfilterTag, ",") | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,11 @@ import ( | |||||||
| func (c *Coll[TData]) FindOne(ctx context.Context, filter bson.M) (TData, error) { | func (c *Coll[TData]) FindOne(ctx context.Context, filter bson.M) (TData, error) { | ||||||
| 	r, err := c.findOneInternal(ctx, filter, false) | 	r, err := c.findOneInternal(ctx, filter, false) | ||||||
| 	if err != nil { | 	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 | 	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) { | func (c *Coll[TData]) FindOneOpt(ctx context.Context, filter bson.M) (*TData, error) { | ||||||
| 	r, err := c.findOneInternal(ctx, filter, true) | 	r, err := c.findOneInternal(ctx, filter, true) | ||||||
| 	if err != nil { | 	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 | 	return r, nil | ||||||
| @@ -58,7 +62,11 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN | |||||||
| 			return nil, nil | 			return nil, nil | ||||||
| 		} | 		} | ||||||
| 		if err != 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 | 		return &res, nil | ||||||
|   | |||||||
| @@ -245,6 +245,10 @@ func (b *WPDFBuilder) PageNo() int { | |||||||
| 	return b.b.PageNo() | 	return b.b.PageNo() | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (b *WPDFBuilder) Bookmark(txtStr string, level int, y float64) { | ||||||
|  | 	b.b.Bookmark(b.tr(txtStr), level, y) | ||||||
|  | } | ||||||
|  |  | ||||||
| func (b *WPDFBuilder) GetStringWidth(str string, opts ...PDFCellOpt) float64 { | func (b *WPDFBuilder) GetStringWidth(str string, opts ...PDFCellOpt) float64 { | ||||||
|  |  | ||||||
| 	var fontNameOverride *PDFFontFamily | 	var fontNameOverride *PDFFontFamily | ||||||
|   | |||||||
| @@ -293,7 +293,7 @@ func (b *WPDFBuilder) Cell(txt string, opts ...*PDFCellOpt) { | |||||||
| 		} else if ln == BreakToRight { | 		} else if ln == BreakToRight { | ||||||
| 			b.Rect(b.GetX()-xBefore, *height, RectOutline, NewPDFRectOpt().X(xBefore).Y(yBefore).LineWidth(0.25).DrawColor(0, 128, 0)) | 			b.Rect(b.GetX()-xBefore, *height, RectOutline, NewPDFRectOpt().X(xBefore).Y(yBefore).LineWidth(0.25).DrawColor(0, 128, 0)) | ||||||
| 		} else if ln == BreakToBelow { | 		} else if ln == BreakToBelow { | ||||||
| 			b.Rect(b.GetPageWidth(), *height, RectOutline, NewPDFRectOpt().X(xBefore).Y(yBefore).LineWidth(0.25).DrawColor(0, 128, 0)) | 			b.Rect(b.GetPageWidth()-xBefore-b.GetMarginRight(), *height, RectOutline, NewPDFRectOpt().X(xBefore).Y(yBefore).LineWidth(0.25).DrawColor(0, 128, 0)) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -38,24 +38,6 @@ type TableBuilder struct { | |||||||
| 	debug            *bool | 	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 { | func (r tableRow) maxFontSize(defaultFontSize float64) float64 { | ||||||
| 	mfs := defaultFontSize | 	mfs := defaultFontSize | ||||||
| 	for _, cell := range r.cells { | 	for _, cell := range r.cells { | ||||||
| @@ -71,8 +53,8 @@ func (b *TableBuilder) Widths(v ...string) *TableBuilder { | |||||||
| 	return b | 	return b | ||||||
| } | } | ||||||
|  |  | ||||||
| func (b *TableBuilder) DefaultStyle(s TableCellStyleOpt) *TableBuilder { | func (b *TableBuilder) DefaultStyle(s *TableCellStyleOpt) *TableBuilder { | ||||||
| 	b.defaultCellStyle = &s | 	b.defaultCellStyle = s | ||||||
| 	return b | 	return b | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -91,10 +73,10 @@ func (b *TableBuilder) AddRow(cells ...TableCell) *TableBuilder { | |||||||
| 	return b | 	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)) | 	tcels := make([]TableCell, 0, len(cells)) | ||||||
| 	for _, cell := range 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}) | 	b.rows = append(b.rows, tableRow{cells: tcels}) | ||||||
| @@ -113,6 +95,10 @@ func (b *TableBuilder) AddRowDefaultStyle(cells ...string) *TableBuilder { | |||||||
| 	return b | 	return b | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (b *TableBuilder) BuildRow() *TableRowBuilder { | ||||||
|  | 	return &TableRowBuilder{tabbuilder: b, cells: make([]TableCell, 0)} | ||||||
|  | } | ||||||
|  |  | ||||||
| func (b *TableBuilder) Build() { | func (b *TableBuilder) Build() { | ||||||
| 	builder := b.builder | 	builder := b.builder | ||||||
|  |  | ||||||
| @@ -148,15 +134,19 @@ func (b *TableBuilder) Build() { | |||||||
| 			str := cell.Content | 			str := cell.Content | ||||||
| 			style := cell.Style | 			style := cell.Style | ||||||
|  |  | ||||||
| 			ellipsize := langext.Coalesce(style.Ellipsize, true) | 			ellipsize := langext.Coalesce(style.ellipsize, true) | ||||||
| 			cellPaddingHorz := langext.Coalesce(style.PaddingHorz, 2) | 			cellPaddingHorz := langext.Coalesce(style.paddingHorz, 2) | ||||||
|  |  | ||||||
|  | 			fillHeight := langext.Coalesce(style.fillHeight, false) | ||||||
|  |  | ||||||
| 			bx := builder.GetX() | 			bx := builder.GetX() | ||||||
| 			by := builder.GetY() | 			by := builder.GetY() | ||||||
|  |  | ||||||
| 			cellWidth := columnWidths[cellIdx] | 			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)) | 				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 { | 		for _, row := range b.rows { | ||||||
| 			if len(row.cells) > colIdx { | 			if len(row.cells) > colIdx { | ||||||
|  |  | ||||||
| 				ph := langext.Coalesce(row.cells[colIdx].Style.PaddingHorz, 2) | 				ph := langext.Coalesce(row.cells[colIdx].Style.paddingHorz, 2) | ||||||
| 				mw := langext.Coalesce(row.cells[colIdx].Style.MinWidth, 0) | 				mw := langext.Coalesce(row.cells[colIdx].Style.minWidth, 0) | ||||||
|  |  | ||||||
| 				minWidth = max(minWidth, ph+mw) | 				minWidth = max(minWidth, ph+mw) | ||||||
|  |  | ||||||
| @@ -344,8 +334,8 @@ func defaultTableStyle() *TableCellStyleOpt { | |||||||
| 			FillColorHex(uint32(0xF0F0F0)). | 			FillColorHex(uint32(0xF0F0F0)). | ||||||
| 			TextColorHex(uint32(0x000000)). | 			TextColorHex(uint32(0x000000)). | ||||||
| 			FillBackground(true), | 			FillBackground(true), | ||||||
| 		MinWidth:  langext.Ptr(float64(5)), | 		minWidth:  langext.Ptr(float64(5)), | ||||||
| 		Ellipsize: langext.PTrue, | 		ellipsize: langext.PTrue, | ||||||
| 		MultiCell: langext.PFalse, | 		multiCell: langext.PFalse, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										187
									
								
								wpdf/wpdfTableCell.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								wpdf/wpdfTableCell.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										52
									
								
								wpdf/wpdfTableRow.go
									
									
									
									
									
										Normal 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 | ||||||
|  | } | ||||||
| @@ -2,9 +2,11 @@ package wpdf | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	_ "embed" | 	_ "embed" | ||||||
|  | 	"fmt" | ||||||
| 	"gogs.mikescher.com/BlackForestBytes/goext/imageext" | 	"gogs.mikescher.com/BlackForestBytes/goext/imageext" | ||||||
| 	"gogs.mikescher.com/BlackForestBytes/goext/langext" | 	"gogs.mikescher.com/BlackForestBytes/goext/langext" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"path" | ||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -38,7 +40,7 @@ func TestPDFBuilder(t *testing.T) { | |||||||
|  |  | ||||||
| 	builder.Ln(4) | 	builder.Ln(4) | ||||||
|  |  | ||||||
| 	cellStyleHeader := TableCellStyleOpt{ | 	cellStyleHeader := &TableCellStyleOpt{ | ||||||
| 		PDFCellOpt: *NewPDFCellOpt(). | 		PDFCellOpt: *NewPDFCellOpt(). | ||||||
| 			FontSize(float64(8)). | 			FontSize(float64(8)). | ||||||
| 			BorderColorHex(uint32(0x666666)). | 			BorderColorHex(uint32(0x666666)). | ||||||
| @@ -48,12 +50,12 @@ func TestPDFBuilder(t *testing.T) { | |||||||
| 			TextColorHex(uint32(0x000000)). | 			TextColorHex(uint32(0x000000)). | ||||||
| 			Align(AlignHorzCenter). | 			Align(AlignHorzCenter). | ||||||
| 			Bold(), | 			Bold(), | ||||||
| 		MinWidth:  langext.Ptr(float64(5)), | 		minWidth:  langext.Ptr(float64(5)), | ||||||
| 		Ellipsize: langext.PTrue, | 		ellipsize: langext.PTrue, | ||||||
| 		MultiCell: langext.PFalse, | 		multiCell: langext.PFalse, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	cellStyleMulti := TableCellStyleOpt{ | 	cellStyleMulti := &TableCellStyleOpt{ | ||||||
| 		PDFCellOpt: *NewPDFCellOpt(). | 		PDFCellOpt: *NewPDFCellOpt(). | ||||||
| 			FontSize(float64(8)). | 			FontSize(float64(8)). | ||||||
| 			BorderColorHex(uint32(0x666666)). | 			BorderColorHex(uint32(0x666666)). | ||||||
| @@ -61,9 +63,9 @@ func TestPDFBuilder(t *testing.T) { | |||||||
| 			FillColorHex(uint32(0xC060C0)). | 			FillColorHex(uint32(0xC060C0)). | ||||||
| 			FillBackground(true). | 			FillBackground(true). | ||||||
| 			TextColorHex(uint32(0x000000)), | 			TextColorHex(uint32(0x000000)), | ||||||
| 		MinWidth:  langext.Ptr(float64(5)), | 		minWidth:  langext.Ptr(float64(5)), | ||||||
| 		Ellipsize: langext.PFalse, | 		ellipsize: langext.PFalse, | ||||||
| 		MultiCell: langext.PTrue, | 		multiCell: langext.PTrue, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	builder.Table(). | 	builder.Table(). | ||||||
| @@ -74,7 +76,20 @@ func TestPDFBuilder(t *testing.T) { | |||||||
| 		AddRowDefaultStyle("test", "hello", "123", "end"). | 		AddRowDefaultStyle("test", "hello", "123", "end"). | ||||||
| 		AddRowDefaultStyle("123", "helasdsalo", "a", "enwqad"). | 		AddRowDefaultStyle("123", "helasdsalo", "a", "enwqad"). | ||||||
| 		AddRowDefaultStyle("123asd", "TrimMeTrimMeTrimMeTrimMe", "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"). | 		AddRowDefaultStyle("123", "helasdsalo", "a", "enwqad"). | ||||||
| 		Debug(false). | 		Debug(false). | ||||||
| 		Build() | 		Build() | ||||||
| @@ -84,5 +99,7 @@ func TestPDFBuilder(t *testing.T) { | |||||||
| 		t.Fatal(err) | 		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)) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user