Added scale support for code39

Returned value of Encode method on code39 was not allowing barcode.scale method. So added EncodeWithoutChecksum method code39 encoder
This commit is contained in:
Maju Ansari 2018-09-21 22:33:10 +05:30 committed by GitHub
parent 34fff276c7
commit 7d3f021cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 0 deletions

View File

@ -150,3 +150,37 @@ func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.B
} }
return utils.New1DCodeIntCheckSum(barcode.TypeCode39, content, result, int(checkSum)), nil 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
}