package wpdf import "gogs.mikescher.com/BlackForestBytes/goext/langext" type PDFCellOpt struct { width *float64 height *float64 border *PDFBorder ln *PDFTextBreak align *PDFTextAlign fill *bool link *int linkStr *string fontNameOverride *PDFFontFamily fontStyleOverride *PDFFontStyle fontSizeOverride *float64 extraLn *float64 x *float64 autoWidth *bool } func NewPDFCellOpt() *PDFCellOpt { return &PDFCellOpt{} } func (opt *PDFCellOpt) Width(v float64) *PDFCellOpt { opt.width = &v return opt } func (opt *PDFCellOpt) Height(v float64) *PDFCellOpt { opt.height = &v return opt } func (opt *PDFCellOpt) Border(v PDFBorder) *PDFCellOpt { opt.border = &v return opt } func (opt *PDFCellOpt) LnPos(v PDFTextBreak) *PDFCellOpt { opt.ln = &v return opt } func (opt *PDFCellOpt) Align(v PDFTextAlign) *PDFCellOpt { opt.align = &v return opt } func (opt *PDFCellOpt) FillBackground(v bool) *PDFCellOpt { opt.fill = &v return opt } func (opt *PDFCellOpt) Link(v int) *PDFCellOpt { opt.link = &v return opt } func (opt *PDFCellOpt) LinkStr(v string) *PDFCellOpt { opt.linkStr = &v return opt } func (opt *PDFCellOpt) Font(fontName PDFFontFamily, fontStyle PDFFontStyle, fontSize float64) *PDFCellOpt { opt.fontNameOverride = &fontName opt.fontStyleOverride = &fontStyle opt.fontSizeOverride = &fontSize return opt } func (opt *PDFCellOpt) FontName(v PDFFontFamily) *PDFCellOpt { opt.fontNameOverride = &v return opt } func (opt *PDFCellOpt) FontStyle(v PDFFontStyle) *PDFCellOpt { opt.fontStyleOverride = &v return opt } func (opt *PDFCellOpt) FontSize(v float64) *PDFCellOpt { opt.fontSizeOverride = &v return opt } func (opt *PDFCellOpt) Bold() *PDFCellOpt { opt.fontStyleOverride = langext.Ptr(Bold) return opt } func (opt *PDFCellOpt) Italic() *PDFCellOpt { opt.fontStyleOverride = langext.Ptr(Italic) return opt } func (opt *PDFCellOpt) LnAfter(v float64) *PDFCellOpt { opt.extraLn = &v return opt } func (opt *PDFCellOpt) X(v float64) *PDFCellOpt { opt.x = &v return opt } func (opt *PDFCellOpt) AutoWidth() *PDFCellOpt { opt.autoWidth = langext.PTrue return opt } func (b *WPDFBuilder) Cell(txt string, opts ...*PDFCellOpt) { txtTR := b.tr(txt) width := float64(0) height := b.cellHeight + b.cellSpacing border := BorderNone ln := BreakToNextLine align := AlignLeft fill := false link := 0 linkStr := "" var fontNameOverride *PDFFontFamily var fontStyleOverride *PDFFontStyle var fontSizeOverride *float64 extraLn := float64(0) var x *float64 autoWidth := false for _, opt := range opts { width = langext.Coalesce(opt.width, width) height = langext.Coalesce(opt.height, height) border = langext.Coalesce(opt.border, border) ln = langext.Coalesce(opt.ln, ln) align = langext.Coalesce(opt.align, align) fill = langext.Coalesce(opt.fill, fill) link = langext.Coalesce(opt.link, link) linkStr = langext.Coalesce(opt.linkStr, linkStr) fontNameOverride = langext.CoalesceOpt(opt.fontNameOverride, fontNameOverride) fontStyleOverride = langext.CoalesceOpt(opt.fontStyleOverride, fontStyleOverride) fontSizeOverride = langext.CoalesceOpt(opt.fontSizeOverride, fontSizeOverride) extraLn = langext.Coalesce(opt.extraLn, extraLn) x = langext.CoalesceOpt(opt.x, x) autoWidth = langext.Coalesce(opt.autoWidth, autoWidth) } if fontNameOverride != nil || fontStyleOverride != nil || fontSizeOverride != nil { oldFontName := b.fontName oldFontStyle := b.fontStyle oldFontSize := b.fontSize newFontName := langext.Coalesce(fontNameOverride, oldFontName) newFontStyle := langext.Coalesce(fontStyleOverride, oldFontStyle) newFontSize := langext.Coalesce(fontSizeOverride, oldFontSize) b.SetFont(newFontName, newFontStyle, newFontSize) defer func() { b.SetFont(oldFontName, oldFontStyle, oldFontSize) }() } if x != nil { b.b.SetX(*x) } if autoWidth { width = b.b.GetStringWidth(txtTR) } b.b.CellFormat(width, height, txtTR, string(border), int(ln), string(align), fill, link, linkStr) if extraLn != 0 { b.b.Ln(extraLn) } }