Documentation ¶
Overview ¶
Package tableimage generates a table inside of a image (png or jpg format) based on the provided data
Index ¶
- Constants
- Variables
- func ColorFromHex(hexColor string) color.RGBA
- func Save(filepath string, img *image.RGBA, imageType ImageType) error
- func Write(w io.Writer, img *image.RGBA, imageType ImageType) error
- type Align
- type Border
- type Cell
- type DefaultImageCache
- type Font
- type Image
- type ImageCache
- type ImageType
- type Line
- type Option
- func WithAlign(align Align) Option
- func WithBgColor(bgColor string) Option
- func WithBorder(border *Border) Option
- func WithBorderColor(color string) Option
- func WithBorderWidth(width int) Option
- func WithColor(color string) Option
- func WithDPI(dpi int) Option
- func WithFont(font *truetype.Font) Option
- func WithFontCache(cache draw2d.FontCache) Option
- func WithFontData(font *draw2d.FontData) Option
- func WithFontFolder(fontFolder string) Option
- func WithFontSize(size float64) Option
- func WithLineHeight(height float64) Option
- func WithMargin(margin *Padding) Option
- func WithPadding(padding *Padding) Option
- func WithStyle(style *Style) Option
- func WithVAlign(align VAlign) Option
- type Padding
- type Row
- type Style
- func (s Style) BorderPadding() Padding
- func (s Style) BorderSize() image.Point
- func (s *Style) Inherit(s1 *Style, cache draw2d.FontCache) error
- func (s Style) InnerBounds(bounds image.Rectangle) image.Rectangle
- func (s Style) InnerEnd() image.Point
- func (s Style) InnerStart() image.Point
- func (s *Style) LoadFont(cache draw2d.FontCache) error
- type Table
- func (r Table) CellBounds(rowIdx int, cellIdx int) image.Rectangle
- func (r Table) DrawCaption(img *image.RGBA, pt image.Point)
- func (r Table) DrawFooter(img *image.RGBA, pt image.Point)
- func (r Table) Rows() []Row
- func (r Table) RowsSize() image.Point
- func (r Table) RowsStartPoint() image.Point
- func (r Table) Size() image.Point
- type TableImage
- func (ti *TableImage) BorderSize() image.Point
- func (ti *TableImage) CacheImage(k string, img image.Image) error
- func (ti *TableImage) Draw(rows []Row, caption *Cell, footer *Cell) (*image.RGBA, error)
- func (ti *TableImage) GetImage(k string) (image.Image, error)
- func (ti *TableImage) Size(table *Table) image.Point
- type Text
- type VAlign
- type Word
Constants ¶
const ( // DefaultLineHeight default row space DefaultLineHeight = 1.2 // DefaultFontSize default font size DefaultFontSize = 13 // DefaultPadding default padding DefaultPadding = 10 // DefaultWrapWords default wrap words count DefaultWrapWords = 20 // DefaultColor default text color DefaultColor = "#212121" // DefaultBorderWidth default stroke line width DefaultBorderWidth = 1 // DefaultDPI default font dpi DefaultDPI = 72 )
Variables ¶
var DefaultBorder = func() *Border { return &Border{ Top: DefaultLine(), Right: DefaultLine(), Bottom: DefaultLine(), Left: DefaultLine(), } }
DefaultBorder default border setting
var DefaultCaptionStyle = func() *Style { return &Style{ Color: DefaultColor, Border: NoBorder(), LineHeight: DefaultLineHeight, Padding: NewPaddingY(DefaultPadding), Align: LEFT, VAlign: TOP, Font: &Font{ Size: DefaultFontSize, }, } }
DefaultCaptionStyle default caption style setting
Style{ Color: DefaultColor, Border: NoBorder(), LineHeight: DefaultLineHeight, Padding: NewPaddingY(DefaultPadding), Align: RIGHT, VAlign: TOP, Font: &Font{ Size: DefaultFontSize, }, } }return &
DefaultFooterStyle default table footer style setting
var DefaultLine = func() Line { return Line{ Color: DefaultColor, Width: DefaultBorderWidth, } }
DefaultLine default line setting
var DefaultStyle = func() *Style { return &Style{ Color: DefaultColor, Border: DefaultBorder(), LineHeight: DefaultLineHeight, Padding: NewPadding(DefaultPadding), Align: LEFT, VAlign: MIDDLE, Font: &Font{ Size: DefaultFontSize, }, } }
DefaultStyle default style setting
var NoBorder = func() *Border { return &Border{} }
NoBorder no border setting
var ZeroPadding = Padding{}
ZeroPadding zero padding object
Functions ¶
Types ¶
type Border ¶
type Border struct { Top Line `json:"top,omitempty"` Right Line `json:"right,omitempty"` Bottom Line `json:"bottom,omitempty"` Left Line `json:"left,omitempty"` }
Border border setting
func (*Border) ChangeColor ¶
ChangeColor change border color
func (*Border) ChangeWidth ¶
ChangeWidth change border width
type Cell ¶
type Cell struct { // Text content of a cell Text string `json:"text,omitempty"` // Image image for a cell Image *Image `json:"image,omitempty"` // Style for cell Style *Style `json:"style,omitempty"` // IgnoreInlineStyle ignore inline text style parsing IgnoreInlineStyle bool `json:"ignore_inline_style,omitempty"` }
Cell in table
func (Cell) InnerBounds ¶
InnerBounds cell content bounds
type DefaultImageCache ¶
DefaultImageCache default ImageCache implement
type Font ¶
type Font struct { // Size font size Size float64 `json:"size,omitempty"` // Data font setting Data *draw2d.FontData `json:"data,omitempty"` // Font Font *truetype.Font `json:"-"` // DPI DPI int `json:"dpi,omitempty"` }
Font font info
type Image ¶
type Image struct { // URL image link URL string `json:"url,omitempty"` // Data image data Data image.Image // Inline display inline Inline bool `json:"inline,omitempty"` // Size image width/height Size image.Point `json:"size,omitempty"` // Align image text alignment Align Align `json:"align,omitempty"` // VAlign image text vertical alignment VAlign VAlign `json:"valign,omitempty"` // Padding image padding Padding *Padding `json:"padding,omitempty"` }
Image image setting
func (*Image) UpdateSize ¶
func (i *Image) UpdateSize()
UpdateSize update Size based on image bounds
type ImageCache ¶
type ImageCache interface { // Get get image from cache Get(k string) (image.Image, error) // Set set image to cache Set(k string, img image.Image) error }
ImageCache image cache interface
type ImageType ¶
type ImageType int
ImageType image type for writer
const ( // JPEG jpeg image JPEG ImageType // PNG png image PNG )
type Line ¶
Line border line
func (Line) ChangeColor ¶
ChangeColor return a line with new color
func (Line) ChangeWidth ¶
ChangeWidth return a line with new width
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option tableimage option interface
type Padding ¶
type Padding struct { // Top padding Top int `json:"top,omitempty"` // Right padding Right int `json:"right,omitempty"` // Bottom padding Bottom int `json:"bottom,omitempty"` // Left padding Left int `json:"left,omitempty"` }
Padding cell padding
func NewPaddingXY ¶
NewPaddingXY init padding for both x / y
type Row ¶
type Row struct { // Cells in row Cells []Cell `json:"cells,omitempty"` // Style for row Style *Style `json:"style,omitempty"` }
Row in table
type Style ¶
type Style struct { // Color text color Color string `json:"color,omitempty"` // Border cell border setting Border *Border `json:"border,omitempty"` // BgColor cell background color BgColor string `json:"bg_color,omitempty"` // Lineheight lineheight for paragraph LineHeight float64 `json:"line_height,omitempty"` // Margin cell margin Margin *Padding `json:"margin,omitempty"` // Padding cell padding Padding *Padding `json:"padding,omitempty"` // MaxWidth max width MaxWidth int `json:"max_width,omitempty"` // Align alignment Align Align `json:"align,omitempty"` // VAlign vertical alignment VAlign VAlign `json:"valign,omitempty"` // Font font setting Font *Font `json:"font,omitempty"` }
Style for drawing
func (Style) InnerBounds ¶
InnerBounds content bounds
type Table ¶ added in v1.0.1
type Table struct {
// contains filtered or unexported fields
}
Table table struct
func (Table) CellBounds ¶ added in v1.0.1
CellBounds get a cell bounds
func (Table) DrawCaption ¶ added in v1.0.1
DrawCaption draw table caption
func (Table) DrawFooter ¶ added in v1.0.1
DrawFooter draw table footer
func (Table) RowsStartPoint ¶ added in v1.0.1
RowsStartPoint table rows start point
type TableImage ¶
type TableImage struct {
// contains filtered or unexported fields
}
TableImage core struct
func (*TableImage) BorderSize ¶
func (ti *TableImage) BorderSize() image.Point
BorderSize get border width of tableimage
func (*TableImage) CacheImage ¶
func (ti *TableImage) CacheImage(k string, img image.Image) error
CacheImage cache image
type Text ¶
Text string with width
func TextFromText ¶ added in v1.0.1
TextFromText create Text from Text