Exemplo n.º 1
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplDataMatrix dataMatrix)
            {
                float x = dataMatrix.PositionX;
                float y = dataMatrix.PositionY;

                if (dataMatrix.FieldTypeset != null)
                {
                    y -= dataMatrix.Height;
                }

                var writer = new DataMatrixWriter();
                var result = writer.encode(dataMatrix.Content, BarcodeFormat.DATA_MATRIX, 0, 0);

                int size = dataMatrix.Height;
                using var image = new SKBitmap(result.Width + size - 1, result.Height + size - 1);

                for (int row = 0; row < result.Height; row++)
                {
                    for (int col = 0; col < result.Width; col++)
                    {
                        var color = result[row, col] ? SKColors.Black : SKColors.White;
                        image.SetPixel(row, col, color);
                    }
                }

                using var resizedImage = image.Resize(new SKSizeI(image.Width * size, image.Height * size), SKFilterQuality.None);

                var png = resizedImage.Encode(SKEncodedImageFormat.Png, 100).ToArray();
                this.DrawBarcode(png, dataMatrix.Height, dataMatrix.Height, dataMatrix.FieldOrigin != null, x, y, dataMatrix.FieldOrientation);
            }
        }
        public void testDataMatrixTooSmall()
        {
            // The DataMatrix will not fit in this size, so the matrix should come back bigger
            const int tooSmall = 8;
            var       writer   = new DataMatrixWriter();
            var       matrix   = writer.encode("http://www.google.com/", BarcodeFormat.DATA_MATRIX, tooSmall, tooSmall, null);

            Assert.IsNotNull(matrix);
            Assert.IsTrue(tooSmall < matrix.Width);
            Assert.IsTrue(tooSmall < matrix.Height);
        }
Exemplo n.º 3
0
      public void testDataMatrixTooSmall()
      {
         // The DataMatrix will not fit in this size, so the matrix should come back bigger
         const int tooSmall = 8;
         var writer = new DataMatrixWriter();
         var matrix = writer.encode("http://www.google.com/", BarcodeFormat.DATA_MATRIX, tooSmall, tooSmall, null);

         Assert.IsNotNull(matrix);
         Assert.IsTrue(tooSmall < matrix.Width);
         Assert.IsTrue(tooSmall < matrix.Height);
      }
Exemplo n.º 4
0
      public void testDataMatrixWriter()
      {
         var writer = new DataMatrixWriter();

         var hints = new Dictionary<EncodeHintType, Object>
                        {{EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE}};

         const int bigEnough = 14;
         var matrix = writer.encode("Hello Me", BarcodeFormat.DATA_MATRIX, bigEnough, bigEnough, hints);

         Assert.IsNotNull(matrix);
         Assert.AreEqual(bigEnough, matrix.Width);
         Assert.AreEqual(bigEnough, matrix.Height);
      }
Exemplo n.º 5
0
        public void TestEncodeDecode(String data, SymbolShapeHint shape)
        {
            var writer  = new DataMatrixWriter();
            var options = new DatamatrixEncodingOptions {
                SymbolShape = shape
            };
            var matrix = writer.encode(data, BarcodeFormat.DATA_MATRIX, 0, 0, options.Hints);

            Assert.That(matrix, Is.Not.Null);

            var res = new Internal.Decoder().decode(matrix);

            Assert.That(res, Is.Not.Null);
            Assert.That(res.Text, Is.EqualTo(data));
        }
        public void testDataMatrixWriter()
        {
            var writer = new DataMatrixWriter();

            var hints = new Dictionary <EncodeHintType, Object>
            {
                { EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE }
            };

            const int bigEnough = 14;
            var       matrix    = writer.encode("Hello Me", BarcodeFormat.DATA_MATRIX, bigEnough, bigEnough, hints);

            Assert.IsNotNull(matrix);
            Assert.AreEqual(bigEnough, matrix.Width);
            Assert.AreEqual(bigEnough, matrix.Height);
        }
Exemplo n.º 7
0
        public void Should_Encode_FNC1()
        {
            var content = String.Format("{0}abcdefg{0}1223456", (char)29);

            var writer = new DataMatrixWriter();

            var hints = new Dictionary <EncodeHintType, Object>();

            var matrix = writer.encode(content, BarcodeFormat.DATA_MATRIX, 1, 1, hints);

            Assert.IsNotNull(matrix);

            var reader      = new DataMatrixReader();
            var readerhints = new Dictionary <DecodeHintType, Object>();

            readerhints.Add(DecodeHintType.PURE_BARCODE, true);

            var result = reader.decode(new BinaryBitmap(matrix), readerhints);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Text, Is.EqualTo(content));
        }