// Not passing?

        /*
         * [Test]
         * public void testDataURL() {
         *
         * byte[] data = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
         *    0x7E, 0x7F, (byte) 0x80, (byte) 0x81, (byte) 0x82};
         * String expected = encodeHighLevel(new String(data, Charset.forName("ISO-8859-1")));
         * String visualized = encodeHighLevel("url(data:text/plain;charset=iso-8859-1,"
         + "%00%01%02%03%04%05%06%07%08%09%0A%7E%7F%80%81%82)");
         + Assert.AreEqual(expected, visualized);
         + Assert.AreEqual("1 2 3 4 5 6 7 8 9 10 11 231 153 173 67 218 112 7", visualized);
         +
         + visualized = encodeHighLevel("url(data:;base64,flRlc3R+)");
         + Assert.AreEqual("127 85 102 116 117 127 129 56", visualized);
         + }
         */

        private static String encodeHighLevel(String msg)
        {
            String encoded = HighLevelEncoder.encodeHighLevel(msg);

            //DecodeHighLevel.decode(encoded);
            return(visualize(encoded));
        }
Exemple #2
0
        public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints)
        {
            if (String.IsNullOrEmpty(contents))
            {
                throw new ArgumentException("Found empty contents", contents);
            }

            if (format != BarcodeFormat.DATA_MATRIX)
            {
                throw new ArgumentException("Can only encode DATA_MATRIX, but got " + format);
            }

            if (width < 0 || height < 0)
            {
                throw new ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
            }

            // Try to get force shape & min / max size
            SymbolShapeHint shape   = SymbolShapeHint.FORCE_NONE;
            Dimension       minSize = null;
            Dimension       maxSize = null;

            if (hints != null)
            {
                var requestedShape = hints.ContainsKey(EncodeHintType.DATA_MATRIX_SHAPE) ? (SymbolShapeHint?)hints[EncodeHintType.DATA_MATRIX_SHAPE] : null;
                if (requestedShape != null)
                {
                    shape = requestedShape.Value;
                }
                var requestedMinSize = hints.ContainsKey(EncodeHintType.MIN_SIZE) ? (Dimension)hints[EncodeHintType.MIN_SIZE] : null;
                if (requestedMinSize != null)
                {
                    minSize = requestedMinSize;
                }
                var requestedMaxSize = hints.ContainsKey(EncodeHintType.MAX_SIZE) ? (Dimension)hints[EncodeHintType.MAX_SIZE] : null;
                if (requestedMaxSize != null)
                {
                    maxSize = requestedMaxSize;
                }
            }


            //1. step: Data encodation
            String encoded = HighLevelEncoder.encodeHighLevel(contents, shape, minSize, maxSize);

            SymbolInfo symbolInfo = SymbolInfo.lookup(encoded.Length, shape, minSize, maxSize, true);

            //2. step: ECC generation
            String codewords = ErrorCorrection.encodeECC200(encoded, symbolInfo);

            //3. step: Module placement in Matrix
            var placement =
                new DefaultPlacement(codewords, symbolInfo.getSymbolDataWidth(), symbolInfo.getSymbolDataHeight());

            placement.place();

            //4. step: low-level encoding
            return(encodeLowLevel(placement, symbolInfo));
        }
Exemple #3
0
        private static void testHighLevelEncodeString(String s, int expectedReceivedBits)
        {
            BitArray bits             = new HighLevelEncoder(LATIN_1.GetBytes(s)).encode();
            int      receivedBitCount = stripSpace(bits.ToString()).Length;

            Assert.AreEqual(expectedReceivedBits, receivedBitCount, "highLevelEncode() failed for input string: " + s);
            Assert.AreEqual(s, Internal.Decoder.highLevelDecode(toBooleanArray(bits)));
        }
Exemple #4
0
        private static void testHighLevelEncodeString(String s, String expectedBits)
        {
            BitArray bits         = new HighLevelEncoder(LATIN_1.GetBytes(s)).encode();
            String   receivedBits = bits.ToString().Replace(" ", "");

            Assert.AreEqual(expectedBits.Replace(" ", ""), receivedBits, "highLevelEncode() failed for input string: " + s);
            Assert.AreEqual(s, Internal.Decoder.highLevelDecode(toBooleanArray(bits)));
        }
        /// <summary>
        /// encodes the content to a BitMatrix
        /// </summary>
        /// <param name="contents"></param>
        /// <param name="format"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="hints"></param>
        /// <returns></returns>
        public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints)
        {
            if (String.IsNullOrEmpty(contents))
            {
                throw new ArgumentException("Found empty contents", contents);
            }

            if (format != BarcodeFormat.DATA_MATRIX)
            {
                throw new ArgumentException("Can only encode DATA_MATRIX, but got " + format);
            }

            if (width < 0 || height < 0)
            {
                throw new ArgumentException("Requested dimensions can't be negative: " + width + 'x' + height);
            }

            // Try to get force shape & min / max size
            var       shape             = SymbolShapeHint.FORCE_NONE;
            var       defaultEncodation = Encodation.ASCII;
            Dimension minSize           = null;
            Dimension maxSize           = null;

            if (hints != null)
            {
                if (hints.ContainsKey(EncodeHintType.DATA_MATRIX_SHAPE))
                {
                    var requestedShape = hints[EncodeHintType.DATA_MATRIX_SHAPE];
                    if (requestedShape is SymbolShapeHint)
                    {
                        shape = (SymbolShapeHint)requestedShape;
                    }
                    else
                    {
                        if (Enum.IsDefined(typeof(SymbolShapeHint), requestedShape.ToString()))
                        {
                            shape = (SymbolShapeHint)Enum.Parse(typeof(SymbolShapeHint), requestedShape.ToString(), true);
                        }
                    }
                }
                var requestedMinSize = hints.ContainsKey(EncodeHintType.MIN_SIZE) ? hints[EncodeHintType.MIN_SIZE] as Dimension : null;
                if (requestedMinSize != null)
                {
                    minSize = requestedMinSize;
                }
                var requestedMaxSize = hints.ContainsKey(EncodeHintType.MAX_SIZE) ? hints[EncodeHintType.MAX_SIZE] as Dimension : null;
                if (requestedMaxSize != null)
                {
                    maxSize = requestedMaxSize;
                }
                if (hints.ContainsKey(EncodeHintType.DATA_MATRIX_DEFAULT_ENCODATION))
                {
                    var requestedDefaultEncodation = hints[EncodeHintType.DATA_MATRIX_DEFAULT_ENCODATION];
                    if (requestedDefaultEncodation != null)
                    {
                        defaultEncodation = Convert.ToInt32(requestedDefaultEncodation.ToString());
                    }
                }
            }


            //1. step: Data encodation
            String encoded = HighLevelEncoder.encodeHighLevel(contents, shape, minSize, maxSize, defaultEncodation);

            SymbolInfo symbolInfo = SymbolInfo.lookup(encoded.Length, shape, minSize, maxSize, true);

            //2. step: ECC generation
            String codewords = ErrorCorrection.encodeECC200(encoded, symbolInfo);

            //3. step: Module placement in Matrix
            var placement = new DefaultPlacement(codewords, symbolInfo.getSymbolDataWidth(), symbolInfo.getSymbolDataHeight());

            placement.place();

            //4. step: low-level encoding
            return(encodeLowLevel(placement, symbolInfo, width, height));
        }