Ejemplo n.º 1
0
        public byte[] Print2DCode(TwoDimensionCodeType type, string data, Size2DCode size = Size2DCode.NORMAL,
                                  CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
        {
            DataValidator.Validate2DCode(type, data);
            var command = new List <byte>();

            byte[] initial = { Cmd.GS, Barcodes.Set2DCode, Barcodes.PrintBarcode };
            switch (type)
            {
            case TwoDimensionCodeType.PDF417:
                command.AddRange(initial, Barcodes.SetPDF417NumberOfColumns, Barcodes.AutoEnding);
                command.AddRange(initial, Barcodes.SetPDF417NumberOfRows, Barcodes.AutoEnding);
                command.AddRange(initial, Barcodes.SetPDF417DotSize, (byte)size);
                command.AddRange(initial, Barcodes.SetPDF417CorrectionLevel, (byte)correction);

                // k = (pL + pH * 256) - 3 --> But pH is always 0.
                var k = data.Length;
                var l = k + 3;
                command.AddRange(initial, (byte)l, Barcodes.StorePDF417Data);
                command.AddRange(data.ToCharArray().Select(x => (byte)x));

                // Prints stored PDF417
                command.AddRange(initial, Barcodes.PrintPDF417);
                break;

            case TwoDimensionCodeType.QRCODE_MODEL1:
            case TwoDimensionCodeType.QRCODE_MODEL2:
            case TwoDimensionCodeType.QRCODE_MICRO:
                command.AddRange(initial, Barcodes.SelectQRCodeModel, (byte)type, Barcodes.AutoEnding);
                command.AddRange(initial, Barcodes.SetQRCodeDotSize, (byte)size);
                command.AddRange(initial, Barcodes.SetQRCodeCorrectionLevel, (byte)correction);
                var num = data.Length + 3;
                var pL  = num % 256;
                var pH  = num / 256;
                command.AddRange(initial, (byte)pL, (byte)pH, Barcodes.StoreQRCodeData);
                command.AddRange(data.ToCharArray().Select(x => (byte)x));

                // Prints stored QRCode
                command.AddRange(initial, Barcodes.PrintQRCode);
                break;

            default:
                throw new NotImplementedException($"2D Code '{type}' was not implemented yet.");
            }

            return(command.ToArray());
        }
Ejemplo n.º 2
0
        public void PrintQRCode_Success(TwoDimensionCodeType codeType, Size2DCode size2DCode, CorrectionLevel2DCode correctionLevel2DCode)
        {
            string data     = codeType == TwoDimensionCodeType.QRCODE_MICRO ? SHORTER_WEBSITE_STRING : WEBSITE_STRING;
            var    begining = new byte[] { 29, 40, 107, 4, 0, 49, 65, (byte)codeType, 0, 29, 40, 107, 3, 0, 49, 67, (byte)size2DCode, 29, 40, 107, 3, 0, 49, 69, (byte)correctionLevel2DCode, 29, 40, 107, (byte)(data.Length + 3), 0, 49, 80, 48, 104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47 };
            var    ending   = new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 };

            byte[] result;
            if (codeType == TwoDimensionCodeType.QRCODE_MICRO)
            {
                result = ByteSplicer.Combine(begining, ending);
            }
            else
            {
                var longerStr = new byte[] { 108, 117, 107, 101, 118, 112, 47, 69, 83, 67, 45, 80, 79, 83, 45, 46, 78, 69, 84, 47, };
                result = ByteSplicer.Combine(begining, longerStr, ending);
            }

            Assert.Equal(result, new EPSON().Print2DCode(codeType, data, size2DCode, correctionLevel2DCode));
        }
Ejemplo n.º 3
0
 public DirectPrinter Print2DCode(TwoDimensionCodeType type, string data, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
 {
     UpdateBuffer(this.Emitter.Print2DCode(type, data, size, correction));
     return(this);
 }
Ejemplo n.º 4
0
 public DirectPrinter PrintQRCode(string data, TwoDimensionCodeType type = TwoDimensionCodeType.QRCODE_MODEL2, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
 {
     UpdateBuffer(this.Emitter.PrintQRCode(data, type, size, correction));
     return(this);
 }
Ejemplo n.º 5
0
        public byte[] PrintQRCode(string data, TwoDimensionCodeType type = TwoDimensionCodeType.QRCODE_MODEL2, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
        {
            if (type == TwoDimensionCodeType.PDF417)
            {
                throw new ArgumentException($"{nameof(TwoDimensionCodeType.PDF417)} is not a valid QRCode type. Please use {nameof(Print2DCode)} method", nameof(type));
            }

            return(Print2DCode(type, data, size, correction));
        }
Ejemplo n.º 6
0
 public virtual byte[] Print2DCode(TwoDimensionCodeType type, string data, Size2DCode size = Size2DCode.NORMAL, CorrectionLevel2DCode correction = CorrectionLevel2DCode.PERCENT_7)
 {
     DataValidator.Validate2DCode(type, data);
     return(TwoDimensionCodeBytes(type, data, size, correction));
 }
Ejemplo n.º 7
0
        public void PrintQRCode_Success(TwoDimensionCodeType codeType, Size2DCode size2DCode, CorrectionLevel2DCode correctionLevel2DCode)
        {
            var result = new byte[] { 29, 40, 107, 4, 0, 49, 65, (byte)codeType, 0, 29, 40, 107, 3, 0, 49, 67, (byte)size2DCode, 29, 40, 107, 3, 0, 49, 69, (byte)correctionLevel2DCode, 29, 40, 107, 42, 0, 49, 80, 48, 104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 108, 117, 107, 101, 118, 112, 47, 69, 83, 67, 45, 80, 79, 83, 45, 46, 78, 69, 84, 47, 29, 40, 107, 3, 0, 49, 81, 48 };

            Assert.Equal(result, new EPSON().Print2DCode(codeType, WEBSITE_STRING, size2DCode, correctionLevel2DCode));
        }