unicode.go 681 B

123456789101112131415161718192021222324252627
  1. package qr
  2. import (
  3. "errors"
  4. "github.com/boombuler/barcode/utils"
  5. )
  6. func encodeUnicode(content string, ecl ErrorCorrectionLevel) (*utils.BitList, *versionInfo, error) {
  7. data := []byte(content)
  8. vi := findSmallestVersionInfo(ecl, byteMode, len(data)*8)
  9. if vi == nil {
  10. return nil, nil, errors.New("To much data to encode")
  11. }
  12. // It's not correct to add the unicode bytes to the result directly but most readers can't handle the
  13. // required ECI header...
  14. res := new(utils.BitList)
  15. res.AddBits(int(byteMode), 4)
  16. res.AddBits(len(content), vi.charCountBits(byteMode))
  17. for _, b := range data {
  18. res.AddByte(b)
  19. }
  20. addPaddingAndTerminator(res, vi)
  21. return res, vi, nil
  22. }