예제 #1
0
        /// <summary>
        /// Encode the given symbol info to a bit matrix.
        /// </summary>
        /// <param name="placement">The DataMatrix placement.</param>
        /// <param name="symbolInfo">The symbol info to encode.</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns>The bit matrix generated.</returns>
        private static BitMatrix encodeLowLevel(DefaultPlacement placement, SymbolInfo symbolInfo, int width, int height)
        {
            int symbolWidth  = symbolInfo.getSymbolDataWidth();
            int symbolHeight = symbolInfo.getSymbolDataHeight();

            var matrix = new ByteMatrix(symbolInfo.getSymbolWidth(), symbolInfo.getSymbolHeight());

            int matrixY = 0;

            for (int y = 0; y < symbolHeight; y++)
            {
                // Fill the top edge with alternate 0 / 1
                int matrixX;
                if ((y % symbolInfo.matrixHeight) == 0)
                {
                    matrixX = 0;
                    for (int x = 0; x < symbolInfo.getSymbolWidth(); x++)
                    {
                        matrix.set(matrixX, matrixY, (x % 2) == 0);
                        matrixX++;
                    }
                    matrixY++;
                }
                matrixX = 0;
                for (int x = 0; x < symbolWidth; x++)
                {
                    // Fill the right edge with full 1
                    if ((x % symbolInfo.matrixWidth) == 0)
                    {
                        matrix.set(matrixX, matrixY, true);
                        matrixX++;
                    }
                    matrix.set(matrixX, matrixY, placement.getBit(x, y));
                    matrixX++;
                    // Fill the right edge with alternate 0 / 1
                    if ((x % symbolInfo.matrixWidth) == symbolInfo.matrixWidth - 1)
                    {
                        matrix.set(matrixX, matrixY, (y % 2) == 0);
                        matrixX++;
                    }
                }
                matrixY++;
                // Fill the bottom edge with full 1
                if ((y % symbolInfo.matrixHeight) == symbolInfo.matrixHeight - 1)
                {
                    matrixX = 0;
                    for (int x = 0; x < symbolInfo.getSymbolWidth(); x++)
                    {
                        matrix.set(matrixX, matrixY, true);
                        matrixX++;
                    }
                    matrixY++;
                }
            }

            return(convertByteMatrixToBitMatrix(matrix, width, height));
        }
예제 #2
0
        public void testSymbolInfo()
        {
            SymbolInfo info = SymbolInfo.lookup(3);

            Assert.AreEqual(5, info.errorCodewords);
            Assert.AreEqual(8, info.matrixWidth);
            Assert.AreEqual(8, info.matrixHeight);
            Assert.AreEqual(10, info.getSymbolWidth());
            Assert.AreEqual(10, info.getSymbolHeight());

            info = SymbolInfo.lookup(3, SymbolShapeHint.FORCE_RECTANGLE);
            Assert.AreEqual(7, info.errorCodewords);
            Assert.AreEqual(16, info.matrixWidth);
            Assert.AreEqual(6, info.matrixHeight);
            Assert.AreEqual(18, info.getSymbolWidth());
            Assert.AreEqual(8, info.getSymbolHeight());

            info = SymbolInfo.lookup(9);
            Assert.AreEqual(11, info.errorCodewords);
            Assert.AreEqual(14, info.matrixWidth);
            Assert.AreEqual(6, info.matrixHeight);
            Assert.AreEqual(32, info.getSymbolWidth());
            Assert.AreEqual(8, info.getSymbolHeight());

            info = SymbolInfo.lookup(9, SymbolShapeHint.FORCE_SQUARE);
            Assert.AreEqual(12, info.errorCodewords);
            Assert.AreEqual(14, info.matrixWidth);
            Assert.AreEqual(14, info.matrixHeight);
            Assert.AreEqual(16, info.getSymbolWidth());
            Assert.AreEqual(16, info.getSymbolHeight());

            try
            {
                SymbolInfo.lookup(1559);
                throw new AssertionException("There's no rectangular symbol for more than 1558 data codewords");
            }
            catch (ArgumentException)
            {
                //expected
            }
            try
            {
                SymbolInfo.lookup(50, SymbolShapeHint.FORCE_RECTANGLE);
                throw new AssertionException("There's no rectangular symbol for 50 data codewords");
            }
            catch (ArgumentException)
            {
                //expected
            }

            info = SymbolInfo.lookup(35);
            Assert.AreEqual(24, info.getSymbolWidth());
            Assert.AreEqual(24, info.getSymbolHeight());

            Dimension fixedSize = new Dimension(26, 26);

            info = SymbolInfo.lookup(35,
                                     SymbolShapeHint.FORCE_NONE, fixedSize, fixedSize, false);
            Assert.AreEqual(26, info.getSymbolWidth());
            Assert.AreEqual(26, info.getSymbolHeight());

            info = SymbolInfo.lookup(45,
                                     SymbolShapeHint.FORCE_NONE, fixedSize, fixedSize, false);
            Assert.IsNull(info);

            Dimension minSize = fixedSize;
            Dimension maxSize = new Dimension(32, 32);

            info = SymbolInfo.lookup(35,
                                     SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
            Assert.AreEqual(26, info.getSymbolWidth());
            Assert.AreEqual(26, info.getSymbolHeight());

            info = SymbolInfo.lookup(40,
                                     SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
            Assert.AreEqual(26, info.getSymbolWidth());
            Assert.AreEqual(26, info.getSymbolHeight());

            info = SymbolInfo.lookup(45,
                                     SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
            Assert.AreEqual(32, info.getSymbolWidth());
            Assert.AreEqual(32, info.getSymbolHeight());

            info = SymbolInfo.lookup(63,
                                     SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
            Assert.IsNull(info);
        }