From 7d3f021cc2c1183e0cc3503c5cc951b35456cf30 Mon Sep 17 00:00:00 2001 From: Maju Ansari Date: Fri, 21 Sep 2018 22:33:10 +0530 Subject: [PATCH] Added scale support for code39 Returned value of Encode method on code39 was not allowing barcode.scale method. So added EncodeWithoutChecksum method code39 encoder --- code39/encoder.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/code39/encoder.go b/code39/encoder.go index 63b3e71..4ecbe18 100644 --- a/code39/encoder.go +++ b/code39/encoder.go @@ -150,3 +150,37 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B } return utils.New1DCodeIntCheckSum(barcode.TypeCode39, content, result, int(checkSum)), nil } + +// Encode returns a code39 barcode for the given content and made sure returned value is scalable +func EncodeWithoutChecksum(content string, fullASCIIMode bool) (barcode.Barcode, error) { + + if fullASCIIMode { + var err error + content, err = prepare(content) + if err != nil { + return nil, err + } + } else if strings.ContainsRune(content, '*') { + return nil, errors.New("invalid data! try full ascii mode") + } + + data := "*" + content + "*" + + result := new(utils.BitList) + + for i, r := range data { + if i != 0 { + result.AddBit(false) + } + + info, ok := encodeTable[r] + if !ok { + return nil, errors.New("invalid data! try full ascii mode") + } + result.AddBit(info.data...) + } + + return utils.New1DCode(barcode.TypeCode39, content, result), nil +} + +