Documentation ¶
Overview ¶
Package render renders images onto a canvas.
Index ¶
- func ExtractExclusiveProp(data []PropData, namedPropsMap map[string][]string) (returnedPropsMap map[string][]string, ExtractedValue interface{}, ...)
- func ExtractSingleProp(inputVal, propName string, typeName PropType, ...) (returnedPropsMap map[string][]string, ExtractedValue interface{}, err error)
- func RegisterComponent(name string, generator func(vfs.FileSystem) Component) error
- func StandardSetNamedProperties(properties NamedProperties, propMap map[string][]string, ...) (leftovers map[string][]string, err error)
- type BarcodeExtraData
- type BarcodeType
- type Canvas
- type Component
- type ComponentConditional
- type DeconstructedDataValue
- type ImageCanvas
- func (canvas ImageCanvas) Barcode(codeType BarcodeType, content []byte, extra BarcodeExtraData, ...) (Canvas, error)
- func (canvas ImageCanvas) Circle(centre image.Point, radius int, colour color.Color) (Canvas, error)
- func (canvas ImageCanvas) DrawImage(start image.Point, subImage image.Image) (Canvas, error)
- func (canvas ImageCanvas) GetHeight() int
- func (canvas ImageCanvas) GetPPI() float64
- func (canvas ImageCanvas) GetUnderlyingImage() image.Image
- func (canvas ImageCanvas) GetWidth() int
- func (canvas ImageCanvas) Rectangle(topLeft image.Point, width, height int, colour color.Color) (Canvas, error)
- func (canvas ImageCanvas) SetPPI(ppi float64) Canvas
- func (canvas ImageCanvas) SetUnderlyingImage(newImage image.Image) Canvas
- func (canvas ImageCanvas) Text(text string, start image.Point, typeFace font.Face, colour color.Color, ...) (Canvas, error)
- func (canvas ImageCanvas) TryText(text string, start image.Point, typeFace font.Face, colour color.Color, ...) (bool, int)
- type MockCanvas
- func (m *MockCanvas) Barcode(codeType BarcodeType, content []byte, extra BarcodeExtraData, ...) (Canvas, error)
- func (m *MockCanvas) Circle(centre image.Point, radius int, colour color.Color) (Canvas, error)
- func (m *MockCanvas) DrawImage(start image.Point, subImage image.Image) (Canvas, error)
- func (m *MockCanvas) GetHeight() int
- func (m *MockCanvas) GetPPI() float64
- func (m *MockCanvas) GetUnderlyingImage() image.Image
- func (m *MockCanvas) GetWidth() int
- func (m *MockCanvas) Rectangle(topLeft image.Point, width, height int, colour color.Color) (Canvas, error)
- func (m *MockCanvas) SetPPI(ppi float64) Canvas
- func (m *MockCanvas) SetUnderlyingImage(newImage image.Image) Canvas
- func (m *MockCanvas) Text(text string, start image.Point, typeFace font.Face, colour color.Color, ...) (Canvas, error)
- func (m *MockCanvas) TryText(text string, start image.Point, typeFace font.Face, colour color.Color, ...) (bool, int)
- type NamedProperties
- type PropData
- type PropType
- type PropertySetFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractExclusiveProp ¶
func ExtractExclusiveProp(data []PropData, namedPropsMap map[string][]string) (returnedPropsMap map[string][]string, ExtractedValue interface{}, validIndex int, err error)
ExtractExclusiveProp parses the loaded property configuration and application inputs and returns the desired property if it exists and if only one of the desired options exists.
func ExtractSingleProp ¶
func ExtractSingleProp(inputVal, propName string, typeName PropType, namedPropsMap map[string][]string) (returnedPropsMap map[string][]string, ExtractedValue interface{}, err error)
ExtractSingleProp parses the loaded property configuration and application inputs and returns the desired property if it exists.
func RegisterComponent ¶
func RegisterComponent(name string, generator func(vfs.FileSystem) Component) error
RegisterComponent adds a new component to the registry, returning an error if duplicate names exist.
func StandardSetNamedProperties ¶
func StandardSetNamedProperties(properties NamedProperties, propMap map[string][]string, setFunc PropertySetFunc) (leftovers map[string][]string, err error)
StandardSetNamedProperties iterates over all named properties, retrieves their value, and calls the provided function to map properties to inner component properties. Each implementation of Component should call this within its SetNamedProperties function.
Types ¶
type BarcodeExtraData ¶
type BarcodeExtraData struct { // AztecMinECCPercent is required for aztec barcodes AztecMinECCPercent int // AztecUserSpecifiedLayers is required for aztec barcodes AztecUserSpecifiedLayers int // Code39IncludeChecksum is required for code39 barcodes Code39IncludeChecksum bool // Code39FullASCIIMode is required for code39 barcodes Code39FullASCIIMode bool // Code93IncludeChecksum is required for code93 barcodes Code93IncludeChecksum bool // Code93FullASCIIMode is required for code93 barcodes Code93FullASCIIMode bool // PDFSecurityLevel is required for pdf417 barcodes PDFSecurityLevel byte // QRLevel is required for qr barcodes QRLevel qr.ErrorCorrectionLevel // QRMode is required for qr barcodes QRMode qr.Encoding }
BarcodeExtraData contains additional data required for some barcode formats, leave any fields not named for the type in use alone.
type BarcodeType ¶
type BarcodeType string
BarcodeType wraps the barcode types into a single enum.
const ( // BarcodeTypeAztec is an alias for an imported barcode type BarcodeTypeAztec BarcodeType = barcode.TypeAztec // BarcodeTypeCodabar is an alias for an imported barcode type BarcodeTypeCodabar BarcodeType = barcode.TypeCodabar // BarcodeTypeCode128 is an alias for an imported barcode type BarcodeTypeCode128 BarcodeType = barcode.TypeCode128 // BarcodeTypeCode39 is an alias for an imported barcode type BarcodeTypeCode39 BarcodeType = barcode.TypeCode39 // BarcodeTypeCode93 is an alias for an imported barcode type BarcodeTypeCode93 BarcodeType = barcode.TypeCode93 // BarcodeTypeDataMatrix is an alias for an imported barcode type BarcodeTypeDataMatrix BarcodeType = barcode.TypeDataMatrix // BarcodeTypeEAN8 is an alias for an imported barcode type BarcodeTypeEAN8 BarcodeType = barcode.TypeEAN8 // BarcodeTypeEAN13 is an alias for an imported barcode type BarcodeTypeEAN13 BarcodeType = barcode.TypeEAN13 // BarcodeTypePDF is an alias for an imported barcode type BarcodeTypePDF BarcodeType = barcode.TypePDF // BarcodeTypeQR is an alias for an imported barcode type BarcodeTypeQR BarcodeType = barcode.TypeQR // BarcodeType2of5 is an alias for an imported barcode type BarcodeType2of5 BarcodeType = barcode.Type2of5 // BarcodeType2of5Interleaved is an alias for an imported barcode type BarcodeType2of5Interleaved BarcodeType = barcode.Type2of5Interleaved )
func ToBarcodeType ¶ added in v3.0.1
func ToBarcodeType(raw string) (BarcodeType, error)
ToBarcodeType attempts to convert a barcode type string to a defined BarcodeType constant.
type Canvas ¶
type Canvas interface { SetUnderlyingImage(newImage image.Image) Canvas GetUnderlyingImage() image.Image GetWidth() int GetHeight() int GetPPI() float64 SetPPI(float64) Canvas Rectangle(topLeft image.Point, width, height int, colour color.Color) (Canvas, error) Circle(centre image.Point, radius int, colour color.Color) (Canvas, error) Text(text string, start image.Point, typeFace font.Face, colour color.Color, maxWidth int) (Canvas, error) TryText(text string, start image.Point, typeFace font.Face, colour color.Color, maxWidth int) (bool, int) DrawImage(start image.Point, subImage image.Image) (Canvas, error) Barcode(codeType BarcodeType, content []byte, extra BarcodeExtraData, start image.Point, width, height int, dataColour color.Color, bgColour color.Color) (Canvas, error) }
Canvas holds the image struct and associated properties.
type Component ¶
type Component interface { Write(canvas Canvas) (Canvas, error) SetNamedProperties(properties NamedProperties) (Component, error) GetJSONFormat() interface{} VerifyAndSetJSONData(interface{}) (Component, NamedProperties, error) }
Component provides a generic interface for operations to perform on a canvas.
type ComponentConditional ¶
type ComponentConditional struct { // Name is the variable to check against the specified value. Name string `json:"name"` // Not determines whether to negate the final result of the boolean operation. Not bool `json:"boolNot"` // Operator specifies which comparison operation to perform. Operator conditionalOperator `json:"operator"` // Value is the condition to operate against with the variable specified by Name. Value string `json:"value"` // Group is an optional set of other conditionals to check along with this one. Group conditionalGroup `json:"group"` // contains filtered or unexported fields }
ComponentConditional enables or disables a component based on named properties.
All properties will be assumed to be either strings or floats based on the operator.
String operators: "equals", "contains", "startswith", "endswith", "ci_equals", "ci_contains", "ci_startswith", "ci_endswith". Operators including "ci_" are case-insensitive variants.
Float operators: "=", ">", "<", "<=", ">=".
Group operators can be "and", "or", "nand", "nor", "xor".
func (ComponentConditional) GetNamedPropertiesList ¶
func (c ComponentConditional) GetNamedPropertiesList() NamedProperties
GetNamedPropertiesList returns a list of all named props found in the conditional.
func (ComponentConditional) SetValue ¶
func (c ComponentConditional) SetValue(name string, value interface{}) (conditional ComponentConditional, err error)
SetValue sets the value of a specific named property through this conditional chain, evaluating any conditions along the way.
func (ComponentConditional) Validate ¶
func (c ComponentConditional) Validate() (result bool, err error)
Validate validates this conditional chain, erroring if a value down the line has not been set and evaluated.
type DeconstructedDataValue ¶
type DeconstructedDataValue struct { // StaticValues are the true string components of the processed JSON value. StaticValues []string // PropNames are the extracted variable names from the processed JSON value. PropNames []string }
DeconstructedDataValue is a string broken down into static values and property names. The reconstruction always starts with a static value, always has one more static value than props, and always alternates static, prop, static, prop... if any props exist.
func ParseDataValue ¶
func ParseDataValue(value string) (hasNamedProperties bool, deconstructed DeconstructedDataValue, err error)
ParseDataValue determines whether a string represents raw data or a named variable and returns this information as well as the data cleaned of any variable definitions.
type ImageCanvas ¶
type ImageCanvas struct { // Image is the underlying drawable image used for rendering. Image draw.Image // contains filtered or unexported fields }
ImageCanvas uses golang's native Image package to implement the Canvas interface.
func NewCanvas ¶
func NewCanvas(width, height int) (ImageCanvas, error)
NewCanvas generates a new canvas of the given width and height.
func (ImageCanvas) Barcode ¶
func (canvas ImageCanvas) Barcode(codeType BarcodeType, content []byte, extra BarcodeExtraData, start image.Point, width, height int, dataColour color.Color, backgroundColour color.Color) (Canvas, error)
Barcode draws a barcode on the canvas.
func (ImageCanvas) Circle ¶
func (canvas ImageCanvas) Circle(centre image.Point, radius int, colour color.Color) (Canvas, error)
Circle draws a circle of a specific colour on the canvas.
func (ImageCanvas) GetHeight ¶
func (canvas ImageCanvas) GetHeight() int
GetHeight returns the height of the underlying Image. Returns 0 if no canvas is set.
func (ImageCanvas) GetPPI ¶
func (canvas ImageCanvas) GetPPI() float64
GetPPI returns the pixels per inch of the canvas.
func (ImageCanvas) GetUnderlyingImage ¶
func (canvas ImageCanvas) GetUnderlyingImage() image.Image
GetUnderlyingImage gets the internal Image property.
func (ImageCanvas) GetWidth ¶
func (canvas ImageCanvas) GetWidth() int
GetWidth returns the width of the underlying Image. Returns 0 if no canvas is set.
func (ImageCanvas) Rectangle ¶
func (canvas ImageCanvas) Rectangle(topLeft image.Point, width, height int, colour color.Color) (Canvas, error)
Rectangle draws a rectangle of a specific colour on the canvas.
func (ImageCanvas) SetPPI ¶
func (canvas ImageCanvas) SetPPI(ppi float64) Canvas
SetPPI sets the pixels per inch of the canvas.
func (ImageCanvas) SetUnderlyingImage ¶
func (canvas ImageCanvas) SetUnderlyingImage(newImage image.Image) Canvas
SetUnderlyingImage sets the internal Image property to the given object.
type MockCanvas ¶
MockCanvas is a mock implementation of the Canvas interface for testing purposes.
func (*MockCanvas) Barcode ¶
func (m *MockCanvas) Barcode(codeType BarcodeType, content []byte, extra BarcodeExtraData, start image.Point, width, height int, dataColour color.Color, bgColour color.Color) (Canvas, error)
Barcode returns the preset value(s).
func (*MockCanvas) GetHeight ¶
func (m *MockCanvas) GetHeight() int
GetHeight returns the preset value(s).
func (*MockCanvas) GetPPI ¶
func (m *MockCanvas) GetPPI() float64
GetPPI returns the preset value(s).
func (*MockCanvas) GetUnderlyingImage ¶
func (m *MockCanvas) GetUnderlyingImage() image.Image
GetUnderlyingImage returns the preset value(s).
func (*MockCanvas) GetWidth ¶
func (m *MockCanvas) GetWidth() int
GetWidth returns the preset value(s).
func (*MockCanvas) Rectangle ¶
func (m *MockCanvas) Rectangle(topLeft image.Point, width, height int, colour color.Color) (Canvas, error)
Rectangle returns the preset value(s).
func (*MockCanvas) SetPPI ¶
func (m *MockCanvas) SetPPI(ppi float64) Canvas
SetPPI returns the preset value(s).
func (*MockCanvas) SetUnderlyingImage ¶
func (m *MockCanvas) SetUnderlyingImage(newImage image.Image) Canvas
SetUnderlyingImage returns the preset value(s).
type NamedProperties ¶
type NamedProperties map[string]interface{}
NamedProperties is a map of property names to property values - application variables to be set.
type PropData ¶
type PropData struct { // InputValue is the raw JSON string data. InputValue string // PropName is the name of the property being sought, to associate with discovered variables. PropName string // Type is the conversion to attempt on the string. Type PropType }
PropData is a matched triplet of input property data for use with extraction of exclusive properties.
type PropType ¶
type PropType string
PropType represents the types of properties which can be parsed.
const ( // IntType is an int IntType PropType = "int" // StringType is a string StringType PropType = "string" // BoolType is a bool BoolType PropType = "bool" // Uint8Type is a uint8 Uint8Type PropType = "uint8" // Float64Type is a float64 Float64Type PropType = "float64" // TimeType is a *time.Time TimeType PropType = "time" )
type PropertySetFunc ¶
PropertySetFunc maps property names and values to component inner properties.