Example #1
0
        public void Encode_FixedNumberOfRows_ValidContent_ShouldEncodeDataMatrixCodeCorrectly()
        {
            // Arrange
            var content          = "1234567890";
            var expectedDataBits = ImageStringToBools(@"
                #.#.#.#.#.#.#.
                ##..#..#...###
                ##..##...###..
                ##...##....#.#
                ###.#......#..
                #.......##...#
                #...##.####...
                #..........#.#
                #.###..##.....
                ###.##.#.#####
                #.####...#..#.
                #.###..#.##.##
                #..##.######..
                ##############
            ");

            // Act
            var dataMatrix = DataMatrixEncoder.Encode(content, fixedNumberOfRows: 14) as DataMatrixCode;

            // Assert
            dataMatrix.Should().NotBeNull();
            dataMatrix.Bounds.X.Should().Be(14);
            dataMatrix.Bounds.Y.Should().Be(14);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % dataMatrix.Bounds.X;
                int y = i / dataMatrix.Bounds.X;
                dataMatrix.Get(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
Example #2
0
        public void Encode_Gs1ModeEnabled_ValidGs1Content_NonPreDefinedApplicationIdentifiers_ShouldEncodeDataMatrixGs1Correctly()
        {
            // Arrange
            var content          = "(10) 12 (22) 34";
            var expectedDataBits = ImageStringToBools(@"
                #.#.#.#.#.#.#.
                ##.##.#.##.###
                #..##....#.#..
                ##...##...#..#
                ###....#####..
                #.#..#.##.##.#
                #.#..#..###.#.
                #..#.#...#.###
                #.##.#######..
                #..#.#.#.#...#
                ###.###...#.#.
                #.#...##..##.#
                #..#.##..###..
                ##############
            ");

            // Act
            var dataMatrix = DataMatrixEncoder.Encode(content, gs1ModeEnabled: true) as DataMatrixCode;

            // Assert
            dataMatrix.Should().NotBeNull();
            (dataMatrix.Bounds.X * dataMatrix.Bounds.Y).Should().Be(expectedDataBits.Length);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % dataMatrix.Bounds.X;
                int y = i / dataMatrix.Bounds.X;
                dataMatrix.Get(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
Example #3
0
        private string GetDataMatrixStr()
        {
            DataMatrixEncoder encoder = new DataMatrixEncoder();

            encoder.targetSizeID           = this.datamatrixsize;
            encoder.m_nPreferredEncodation = this.encodationmode;
            return(encoder.Encode(this.texttoencode));
        }
Example #4
0
        private string GetDataMatrixStr(string str)
        {
            DataMatrixEncoder encoder = new DataMatrixEncoder();

            encoder.targetSizeID           = (int)this.datamatrixsize;
            encoder.m_nPreferredEncodation = (int)this.encodationmode;
            encoder.binaryEncode           = this.binaryEncode;
            return(encoder.Encode(str));
        }
Example #5
0
        private static void TestEncode_FixedSize(int rows, int columns, string content, bool[] expectedDataBits)
        {
            var dataMatrix = DataMatrixEncoder.Encode(content, fixedNumberOfRows: rows, fixedNumberOfColumns: columns) as DataMatrixCode;

            dataMatrix.Should().NotBeNull();
            dataMatrix.Bounds.X.Should().Be(columns);
            dataMatrix.Bounds.Y.Should().Be(rows);

            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % dataMatrix.Bounds.X;
                int y = i / dataMatrix.Bounds.X;
                dataMatrix.Get(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }
Example #6
0
    public static void Main()
    {
        // Read standard input
        string message = Console.In.ReadToEnd();

        // Encode
        DataMatrixEncoder encoder = new DataMatrixEncoder();
        encoder.Encode(message);

        // Print as ASCII Art
        for (int row = 0; row < encoder.GetRows(); row++) {
            for (int column = 0; column < encoder.GetColumns(); column++) {
                Console.Write(encoder.GetModule(column, row) == 0 ? ' ' : '#');
            }
            Console.WriteLine();
        }
    }
Example #7
0
        public void Encode_ValidContent_ShouldEncodeDataMatrixCodeCorrectly()
        {
            // Arrange
            var content          = "{\"po\":12,\"batchAction\":\"start_end\"}";
            var expectedDataBits = ImageStringToBools(@"
                #.#.#.#.#.#.#.#.#.#.#.#.
                #....###..#..#....#...##
                ##.......#...#.#.#....#.
                #.###...##..#...##.##..#
                ##...####..##..#.#.#.##.
                #.###.##.###..#######.##
                #..###...##.##..#.##.##.
                #.#.#.#.#.#.###....#.#.#
                ##.#...#.#.#..#...#####.
                #...####..#...##..#.#..#
                ##...#...##.###.#.....#.
                #.###.#.##.#.....###..##
                ##..#####...#..##...###.
                ###...#.####.##.#.#.#..#
                #..###..#.#.####.#.###..
                ###.#.#..#..#.###.#.##.#
                #####.##.###..#.####.#..
                #.##.#......#.#..#.#.###
                ###.#....######.#...##..
                ##...#..##.###..#...####
                #.######.###.##..#...##.
                #..#..#.##.#..####...#.#
                ###.###..#..##.#.##...#.
                ########################
            ");

            // Act
            var dataMatrix = DataMatrixEncoder.Encode(content) as DataMatrixCode;

            // Assert
            dataMatrix.Should().NotBeNull();
            (dataMatrix.Bounds.X * dataMatrix.Bounds.Y).Should().Be(expectedDataBits.Length);
            for (int i = 0; i < expectedDataBits.Length; i++)
            {
                int x = i % dataMatrix.Bounds.X;
                int y = i / dataMatrix.Bounds.X;
                dataMatrix.Get(x, y).Should().Be(expectedDataBits[i], $"of expected bit on index {i}");
            }
        }