Example #1
0
        /// <summary>
        /// Creates the DataMatrix code.
        /// </summary>
        internal char[] DataMatrix()
        {
            int         matrixColumns = this.columns;
            int         matrixRows    = this.rows;
            Ecc200Block matrix        = new Ecc200Block(0, 0, 0, 0, 0, 0, 0);

            foreach (Ecc200Block eccmatrix in ecc200Sizes)
            {
                matrix = eccmatrix;
                if (matrix.Width != columns || matrix.Height != rows)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }

            char[] grid = new char[matrixColumns * matrixRows];
            Random rand = new Random();

            for (int ccol = 0; ccol < matrixColumns; ccol++)
            {
                grid[ccol] = (char)1;
            }

            for (int rrows = 1; rrows < matrixRows; rrows++)
            {
                grid[rrows * matrixRows] = (char)1;
                for (int ccol = 1; ccol < matrixColumns; ccol++)
                {
                    grid[rrows * matrixRows + ccol] = (char)rand.Next(2);
                }
            }

            if (grid == null || matrixColumns == 0)
            {
                return(null); //No barcode produced;
            }
            return(grid);
        }
    /// <summary>
    /// Creates the DataMatrix code.
    /// </summary>
    internal char[] DataMatrix()
    {
      int matrixColumns = this.columns;
      int matrixRows = this.rows;
      Ecc200Block matrix = new Ecc200Block(0, 0, 0, 0, 0, 0, 0);

      foreach (Ecc200Block eccmatrix in ecc200Sizes)
      {
        matrix = eccmatrix;
        if (matrix.Width != columns || matrix.Height != rows)
          continue;
        else
          break;
      }

      char[] grid = new char[matrixColumns * matrixRows];
      Random rand = new Random();

      for (int ccol = 0; ccol < matrixColumns; ccol++)
        grid[ccol] = (char)1;

      for (int rrows = 1; rrows < matrixRows; rrows++)
      {
        grid[rrows * matrixRows] = (char)1;
        for (int ccol = 1; ccol < matrixColumns; ccol++)
          grid[rrows * matrixRows + ccol] = (char)rand.Next(2);
      }

      if (grid == null || matrixColumns == 0)
        return null; //No barcode produced;
      return grid;
    }
Example #3
0
        /// <summary>
        /// Encodes the DataMatrix.
        /// </summary>
        internal char[] Iec16022Ecc200(int columns, int rows, string encoding, int barcodeLength, string barcode, int len, int max, int ecc)
        {
            char[] binary = new char[3000];  // encoded raw data and ecc to place in barcode
            Ecc200Block matrix = new Ecc200Block(0, 0, 0, 0, 0, 0, 0);
            for (int i = 0; i < 3000; i++)
                binary[i] = (char)0;

            foreach (Ecc200Block eccmatrix in ecc200Sizes)
            {
                matrix = eccmatrix;
                if (matrix.Width == columns && matrix.Height == rows)
                    break;
            }

            if (matrix.Width == 0)
                throw new ArgumentException(BcgSR.DataMatrixInvalid(columns, rows));

            if (!Ecc200Encode(ref binary, matrix.Bytes, barcode, barcodeLength, encoding, ref len))
                throw new ArgumentException(BcgSR.DataMatrixTooBig);

            // ecc code
            Ecc200(binary, matrix.Bytes, matrix.DataBlock, matrix.RSBlock);
            // placement
            int x;
            int y;
            int NR;
            int[] places;
            int NC = columns - 2 * (columns / matrix.CellWidth);
            NR = rows - 2 * (rows / matrix.CellHeight);
            places = new int[NC * NR];
            Ecc200Placement(ref places, NR, NC);
            char[] grid = new char[columns * rows];
            for (y = 0; y < rows; y += matrix.CellHeight)
            {
                for (x = 0; x < columns; x++)
                    grid[y * columns + x] = (char)1;
                for (x = 0; x < columns; x += 2)
                    grid[(y + matrix.CellHeight - 1) * columns + x] = (char)1;
            }

            for (x = 0; x < columns; x += matrix.CellWidth)
            {
                for (y = 0; y < rows; y++)
                    grid[y * columns + x] = (char)1;
                for (y = 0; y < rows; y += 2)
                    grid[y * columns + x + matrix.CellWidth - 1] = (char)1;
            }

            for (y = 0; y < NR; y++)
            {
                for (x = 0; x < NC; x++)
                {
                    int v = places[(NR - y - 1) * NC + x];
                    if (v == 1 || v > 7 && ((binary[(v >> 3) - 1] & (1 << (v & 7))) != 0))
                        grid[(1 + y + 2 * (y / (matrix.CellHeight - 2))) * columns + 1 + x + 2 * (x / (matrix.CellWidth - 2))] = (char)1;
                }
            }
            return grid;
        }
Example #4
0
        /// <summary>
        /// Encodes the DataMatrix.
        /// </summary>
        internal char[] Iec16022Ecc200(int columns, int rows, string encoding, int barcodeLength, string barcode, int len, int max, int ecc)
        {
            char[]      binary = new char[3000]; // encoded raw data and ecc to place in barcode
            Ecc200Block matrix = new Ecc200Block(0, 0, 0, 0, 0, 0, 0);

            for (int i = 0; i < 3000; i++)
            {
                binary[i] = (char)0;
            }

            foreach (Ecc200Block eccmatrix in ecc200Sizes)
            {
                matrix = eccmatrix;
                if (matrix.Width == columns && matrix.Height == rows)
                {
                    break;
                }
            }

            if (matrix.Width == 0)
            {
                throw new ArgumentException(BcgSR.DataMatrixInvalid(columns, rows));
            }

            if (!Ecc200Encode(ref binary, matrix.Bytes, barcode, barcodeLength, encoding, ref len))
            {
                throw new ArgumentException(BcgSR.DataMatrixTooBig);
            }

            // ecc code
            Ecc200(binary, matrix.Bytes, matrix.DataBlock, matrix.RSBlock);
            // placement
            int x;
            int y;
            int NR;

            int[] places;
            int   NC = columns - 2 * (columns / matrix.CellWidth);

            NR     = rows - 2 * (rows / matrix.CellHeight);
            places = new int[NC * NR];
            Ecc200Placement(ref places, NR, NC);
            char[] grid = new char[columns * rows];
            for (y = 0; y < rows; y += matrix.CellHeight)
            {
                for (x = 0; x < columns; x++)
                {
                    grid[y * columns + x] = (char)1;
                }
                for (x = 0; x < columns; x += 2)
                {
                    grid[(y + matrix.CellHeight - 1) * columns + x] = (char)1;
                }
            }

            for (x = 0; x < columns; x += matrix.CellWidth)
            {
                for (y = 0; y < rows; y++)
                {
                    grid[y * columns + x] = (char)1;
                }
                for (y = 0; y < rows; y += 2)
                {
                    grid[y * columns + x + matrix.CellWidth - 1] = (char)1;
                }
            }

            for (y = 0; y < NR; y++)
            {
                for (x = 0; x < NC; x++)
                {
                    int v = places[(NR - y - 1) * NC + x];
                    if (v == 1 || v > 7 && ((binary[(v >> 3) - 1] & (1 << (v & 7))) != 0))
                    {
                        grid[(1 + y + 2 * (y / (matrix.CellHeight - 2))) * columns + 1 + x + 2 * (x / (matrix.CellWidth - 2))] = (char)1;
                    }
                }
            }
            return(grid);
        }