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}"); } }
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}"); } }
private string GetDataMatrixStr() { DataMatrixEncoder encoder = new DataMatrixEncoder(); encoder.targetSizeID = this.datamatrixsize; encoder.m_nPreferredEncodation = this.encodationmode; return(encoder.Encode(this.texttoencode)); }
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)); }
public void TextEncodingWithPadding() { // Arrange var content = "{\"po\":12,\"batchAction\":\"start_end\"}"; // Act var result = DataMatrixEncoder.AddPadding(DataMatrixEncoder.EncodeText(content), 36); // Assert result.Should().BeEquivalentTo(new byte[] { 124, 35, 113, 112, 35, 59, 142, 45, 35, 99, 98, 117, 100, 105, 66, 100, 117, 106, 112, 111, 35, 59, 35, 116, 117, 98, 115, 117, 96, 102, 111, 101, 35, 126, 129, 181 }); }
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}"); } }
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(); } }
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}"); } }