MCPcopy Create free account
hub / github.com/boombuler/barcode / EncodeWithColor

Function EncodeWithColor

datamatrix/encoder.go:18–39  ·  view source on GitHub ↗

Encode returns a Datamatrix barcode for the given content and color scheme

(content string, color barcode.ColorScheme)

Source from the content-addressed store, hash-verified

16
17// Encode returns a Datamatrix barcode for the given content and color scheme
18func EncodeWithColor(content string, color barcode.ColorScheme) (barcode.Barcode, error) {
19 data := encodeText(content)
20
21 var size *dmCodeSize
22 for _, s := range codeSizes {
23 if s.DataCodewords() >= len(data) {
24 size = s
25 break
26 }
27 }
28 if size == nil {
29 return nil, errors.New("to much data to encode")
30 }
31 data = addPadding(data, size.DataCodewords())
32 data = ec.calcECC(data, size)
33 code := render(data, size, color)
34 if code != nil {
35 code.content = content
36 return code, nil
37 }
38 return nil, errors.New("unable to render barcode")
39}
40
41// Encode returns a Datamatrix barcode for the given content
42func Encode(content string) (barcode.Barcode, error) {

Callers 1

EncodeFunction · 0.70

Calls 5

DataCodewordsMethod · 0.95
addPaddingFunction · 0.85
encodeTextFunction · 0.70
renderFunction · 0.70
calcECCMethod · 0.45

Tested by

no test coverage detected