Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Text;
- using iTextSharp.text.pdf.codec;
- namespace iTextSharp.text.pdf
- {
- public class MyBarcodeDatamatrix
- {
- private static readonly iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams[] dmSizes = new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams[30]
- {
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(10, 10, 10, 10, 3, 3, 5),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(12, 12, 12, 12, 5, 5, 7),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(8, 18, 8, 18, 5, 5, 7),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(14, 14, 14, 14, 8, 8, 10),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(8, 32, 8, 16, 10, 10, 11),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(16, 16, 16, 16, 12, 12, 12),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(12, 26, 12, 26, 16, 16, 14),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(18, 18, 18, 18, 18, 18, 14),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(20, 20, 20, 20, 22, 22, 18),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(12, 36, 12, 18, 22, 22, 18),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(22, 22, 22, 22, 30, 30, 20),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(16, 36, 16, 18, 32, 32, 24),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(24, 24, 24, 24, 36, 36, 24),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(26, 26, 26, 26, 44, 44, 28),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(16, 48, 16, 24, 49, 49, 28),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(32, 32, 16, 16, 62, 62, 36),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(36, 36, 18, 18, 86, 86, 42),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(40, 40, 20, 20, 114, 114, 48),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(44, 44, 22, 22, 144, 144, 56),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(48, 48, 24, 24, 174, 174, 68),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(52, 52, 26, 26, 204, 102, 42),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(64, 64, 16, 16, 280, 140, 56),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(72, 72, 18, 18, 368, 92, 36),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(80, 80, 20, 20, 456, 114, 48),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(88, 88, 22, 22, 576, 144, 56),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(96, 96, 24, 24, 696, 174, 68),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(104, 104, 26, 26, 816, 136, 56),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(120, 120, 20, 20, 1050, 175, 68),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(132, 132, 22, 22, 1304, 163, 62),
- new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(144, 144, 24, 24, 1558, 156, 62)
- };
- /// No error.
- public const int DM_NO_ERROR = 0;
- /// The text is too big for the symbology capabilities.
- public const int DM_ERROR_TEXT_TOO_BIG = 1;
- /// The dimensions given for the symbol are illegal.
- public const int DM_ERROR_INVALID_SQUARE = 3;
- /// An error while parsing an extension.
- public const int DM_ERROR_EXTENSION = 5;
- /// The best encodation will be used.
- public const int DM_AUTO = 0;
- /// ASCII encodation.
- public const int DM_ASCII = 1;
- /// C40 encodation.
- public const int DM_C40 = 2;
- /// TEXT encodation.
- public const int DM_TEXT = 3;
- /// Binary encodation.
- public const int DM_B256 = 4;
- /// X21 encodation.
- public const int DM_X12 = 5;
- /// X12 encodation.
- ///
- /// @deprecated Use {@link BarcodeDataMatrix#DM_X12} instead.
- public const int DM_X21 = 5;
- /// EDIFACT encodation.
- public const int DM_EDIFACT = 6;
- /// No encodation needed. The bytes provided are already encoded.
- public const int DM_RAW = 7;
- /// Allows extensions to be embedded at the start of the text.
- public const int DM_EXTENSION = 32;
- /// Doesn't generate the image but returns all the other information.
- public const int DM_TEST = 64;
- private const byte LATCH_B256 = 231;
- private const byte LATCH_EDIFACT = 240;
- private const byte LATCH_X12 = 238;
- private const byte LATCH_TEXT = 239;
- private const byte LATCH_C40 = 230;
- private const byte UNLATCH = 254;
- private const byte EXTENDED_ASCII = 235;
- private const byte PADDING = 129;
- public const string DEFAULT_DATA_MATRIX_ENCODING = "iso-8859-1";
- private const string X12 = "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- private string encoding;
- private int extOut;
- private short[] place;
- private byte[] image;
- private int height;
- private int width;
- private int ws;
- private int options;
- private bool forceSquareSize;
- //private static int[][] f;
- //private static int[][] switchMode;
- private int[][] f;
- private int[][] switchMode;
- /// Creates an instance of this class.
- public MyBarcodeDatamatrix()
- {
- this.encoding = "iso-8859-1";
- }
- public MyBarcodeDatamatrix(string code)
- {
- this.encoding = "iso-8859-1";
- this.Generate(code);
- }
- public MyBarcodeDatamatrix(string code, string encoding)
- {
- this.encoding = encoding;
- this.Generate(code);
- }
- private void SetBit(int x, int y, int xByte)
- {
- this.image[y * xByte + x / 8] |= (byte)(128 >> (x & 7));
- }
- private void Draw(byte[] data, int dataSize, iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams dm)
- {
- int xByte = (dm.width + this.ws * 2 + 7) / 8;
- for (int index = 0; index < this.image.Length; ++index)
- this.image[index] = (byte)0;
- for (int ws1 = this.ws; ws1 < dm.height + this.ws; ws1 += dm.heightSection)
- {
- for (int ws2 = this.ws; ws2 < dm.width + this.ws; ws2 += 2)
- this.SetBit(ws2, ws1, xByte);
- }
- for (int y = dm.heightSection - 1 + this.ws; y < dm.height + this.ws; y += dm.heightSection)
- {
- for (int ws = this.ws; ws < dm.width + this.ws; ++ws)
- this.SetBit(ws, y, xByte);
- }
- for (int ws1 = this.ws; ws1 < dm.width + this.ws; ws1 += dm.widthSection)
- {
- for (int ws2 = this.ws; ws2 < dm.height + this.ws; ++ws2)
- this.SetBit(ws1, ws2, xByte);
- }
- for (int x = dm.widthSection - 1 + this.ws; x < dm.width + this.ws; x += dm.widthSection)
- {
- for (int y = 1 + this.ws; y < dm.height + this.ws; y += 2)
- this.SetBit(x, y, xByte);
- }
- int num1 = 0;
- for (int index1 = 0; index1 < dm.height; index1 += dm.heightSection)
- {
- for (int index2 = 1; index2 < dm.heightSection - 1; ++index2)
- {
- for (int index3 = 0; index3 < dm.width; index3 += dm.widthSection)
- {
- for (int index4 = 1; index4 < dm.widthSection - 1; ++index4)
- {
- int num2 = (int)this.place[num1++];
- if (num2 == 1 || num2 > 1 && ((int)data[num2 / 8 - 1] & (int)byte.MaxValue & 128 >> num2 % 8) != 0)
- this.SetBit(index4 + index3 + this.ws, index2 + index1 + this.ws, xByte);
- }
- }
- }
- }
- }
- private static void MakePadding(byte[] data, int position, int count)
- {
- if (count <= 0)
- return;
- data[position++] = (byte)129;
- while (--count > 0)
- {
- int num = 129 + (position + 1) * 149 % 253 + 1;
- if (num > 254)
- num -= 254;
- data[position++] = (byte)num;
- }
- }
- private static bool IsDigit(int c)
- {
- if (c >= 48)
- return c <= 57;
- return false;
- }
- private static int AsciiEncodation(
- byte[] text,
- int textOffset,
- int textLength,
- byte[] data,
- int dataOffset,
- int dataLength,
- int symbolIndex,
- int prevEnc,
- int origDataOffset)
- {
- int index1 = textOffset;
- int num1 = dataOffset;
- textLength += textOffset;
- dataLength += dataOffset;
- while (index1 < textLength)
- {
- int c = (int)text[index1++] & (int)byte.MaxValue;
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && symbolIndex > 0 && (prevEnc == 1 && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[index1 - 2] & (int)byte.MaxValue)) && (data[dataOffset - 1] > (byte)48 && data[dataOffset - 1] < (byte)59))
- {
- data[num1 - 1] = (byte)((((int)text[index1 - 2] & (int)byte.MaxValue) - 48) * 10 + c - 48 + 130);
- return num1 - origDataOffset;
- }
- if (num1 >= dataLength)
- return -1;
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && symbolIndex < 0 && (index1 < textLength && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[index1] & (int)byte.MaxValue)))
- data[num1++] = (byte)((c - 48) * 10 + ((int)text[index1++] & (int)byte.MaxValue) - 48 + 130);
- else if (c > (int)sbyte.MaxValue)
- {
- if (num1 + 1 >= dataLength)
- return -1;
- byte[] numArray1 = data;
- int index2 = num1;
- int num2 = index2 + 1;
- numArray1[index2] = (byte)235;
- byte[] numArray2 = data;
- int index3 = num2;
- num1 = index3 + 1;
- int num3 = (int)(byte)(c - 128 + 1);
- numArray2[index3] = (byte)num3;
- }
- else
- data[num1++] = (byte)(c + 1);
- }
- return num1 - origDataOffset;
- }
- private int B256Encodation(
- byte[] text,
- int textOffset,
- int textLength,
- byte[] data,
- int dataOffset,
- int dataLength,
- int symbolIndex,
- int prevEnc,
- int origDataOffset)
- {
- if (textLength == 0)
- return 0;
- int num1 = dataOffset;
- if (prevEnc != 4)
- {
- if (textLength < 250 && textLength + 2 > dataLength || textLength >= 250 && textLength + 3 > dataLength)
- return -1;
- data[dataOffset] = (byte)231;
- }
- else
- {
- int index = symbolIndex - 1;
- while (index > 0 && switchMode[3][index] == 4)
- --index;
- textLength = symbolIndex - index + 1;
- if (textLength != 250 && 1 > dataLength || textLength == 250 && 2 > dataLength)
- return -1;
- num1 -= textLength - 1 + (textLength < 250 ? 2 : 3);
- }
- int num2;
- if (textLength < 250)
- {
- data[num1 + 1] = (byte)textLength;
- num2 = prevEnc != 4 ? 2 : 0;
- }
- else if (textLength == 250 && prevEnc == 4)
- {
- data[num1 + 1] = (byte)(textLength / 250 + 249);
- for (int index = dataOffset + 1; index > num1 + 2; --index)
- data[index] = data[index - 1];
- data[num1 + 2] = (byte)(textLength % 250);
- num2 = 1;
- }
- else
- {
- data[num1 + 1] = (byte)(textLength / 250 + 249);
- data[num1 + 2] = (byte)(textLength % 250);
- num2 = prevEnc != 4 ? 3 : 0;
- }
- if (prevEnc == 4)
- textLength = 1;
- Array.Copy((Array)text, textOffset, (Array)data, num2 + dataOffset, textLength);
- for (int j = prevEnc != 4 ? dataOffset + 1 : dataOffset; j < num2 + textLength + dataOffset; ++j)
- RandomizationAlgorithm255(data, j);
- if (prevEnc == 4)
- RandomizationAlgorithm255(data, num1 + 1);
- return textLength + dataOffset + num2 - origDataOffset;
- }
- private void RandomizationAlgorithm255(byte[] data, int j)
- {
- int num = ((int)data[j] & (int)byte.MaxValue) + (149 * (j + 1) % (int)byte.MaxValue + 1);
- if (num > (int)byte.MaxValue)
- num -= 256;
- data[j] = (byte)num;
- }
- private int X12Encodation(
- byte[] text,
- int textOffset,
- int textLength,
- byte[] data,
- int dataOffset,
- int dataLength,
- int symbolIndex,
- int prevEnc,
- int origDataOffset)
- {
- bool flag1 = true;
- if (textLength == 0)
- return 0;
- int index1 = 0;
- int num1 = 0;
- byte[] numArray1 = new byte[textLength];
- int num2 = 0;
- for (; index1 < textLength; ++index1)
- {
- int num3 = "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[index1 + textOffset]);
- if (num3 >= 0)
- {
- numArray1[index1] = (byte)num3;
- ++num2;
- }
- else
- {
- numArray1[index1] = (byte)100;
- if (num2 >= 6)
- num2 -= num2 / 3 * 3;
- for (int index2 = 0; index2 < num2; ++index2)
- numArray1[index1 - index2 - 1] = (byte)100;
- num2 = 0;
- }
- }
- if (num2 >= 6)
- num2 -= num2 / 3 * 3;
- for (int index2 = 0; index2 < num2; ++index2)
- numArray1[index1 - index2 - 1] = (byte)100;
- int index3 = 0;
- for (; index3 < textLength; ++index3)
- {
- byte num3 = numArray1[index3];
- if (num1 <= dataLength)
- {
- if (num3 < (byte)40)
- {
- if (index3 == 0 && flag1 || index3 > 0 && numArray1[index3 - 1] > (byte)40)
- data[dataOffset + num1++] = (byte)238;
- if (num1 + 2 <= dataLength)
- {
- int num4 = 1600 * (int)numArray1[index3] + 40 * (int)numArray1[index3 + 1] + (int)numArray1[index3 + 2] + 1;
- byte[] numArray2 = data;
- int num5 = dataOffset;
- int num6 = num1;
- int num7 = num6 + 1;
- int index2 = num5 + num6;
- int num8 = (int)(byte)(num4 / 256);
- numArray2[index2] = (byte)num8;
- byte[] numArray3 = data;
- int num9 = dataOffset;
- int num10 = num7;
- num1 = num10 + 1;
- int index4 = num9 + num10;
- int num11 = (int)(byte)num4;
- numArray3[index4] = (byte)num11;
- index3 += 2;
- }
- else
- break;
- }
- else
- {
- bool flag2 = true;
- if (symbolIndex <= 0)
- {
- if (index3 > 0 && numArray1[index3 - 1] < (byte)40)
- data[dataOffset + num1++] = (byte)254;
- }
- else if (symbolIndex > 4 && prevEnc == 5 && ("\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset]) >= 0 && "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset - 1]) >= 0))
- {
- int index2 = symbolIndex - 1;
- while (index2 > 0 && switchMode[4][index2] == 5 && "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset - (symbolIndex - index2 + 1)]) >= 0)
- --index2;
- int num4 = -1;
- if (symbolIndex - index2 >= 5)
- {
- for (int index4 = 1; index4 <= symbolIndex - index2; ++index4)
- {
- if (data[dataOffset - index4] == (byte)254)
- {
- num4 = dataOffset - index4;
- break;
- }
- }
- int num5 = num4 >= 0 ? dataOffset - num4 - 1 : symbolIndex - index2;
- if (num5 % 3 == 2)
- {
- flag2 = false;
- textLength = num5 + 1;
- textOffset -= num5;
- dataLength += num4 < 0 ? num5 : num5 + 1;
- dataOffset -= num4 < 0 ? num5 : num5 + 1;
- index3 = -1;
- flag1 = num4 != dataOffset;
- numArray1 = new byte[num5 + 1];
- for (int index4 = 0; index4 <= num5; ++index4)
- numArray1[index4] = (byte)"\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset + index4]);
- }
- else
- numArray1 = new byte[1] { (byte)100 };
- }
- }
- if (flag2)
- {
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + index3, 1, data, dataOffset + num1, dataLength, -1, -1, origDataOffset) < 0)
- return -1;
- if (data[dataOffset + num1] == (byte)235)
- ++num1;
- ++num1;
- }
- }
- }
- else
- break;
- }
- byte num12 = 100;
- if (textLength > 0)
- num12 = numArray1[textLength - 1];
- if (index3 != textLength)
- return -1;
- if (num12 < (byte)40)
- data[dataOffset + num1++] = (byte)254;
- if (num1 > dataLength)
- return -1;
- return num1 + dataOffset - origDataOffset;
- }
- private int EdifactEncodation(
- byte[] text,
- int textOffset,
- int textLength,
- byte[] data,
- int dataOffset,
- int dataLength,
- int symbolIndex,
- int prevEnc,
- int origDataOffset,
- bool sizeFixed)
- {
- if (textLength == 0)
- return 0;
- int num1 = 0;
- int num2 = 0;
- int num3 = 0;
- int num4 = 18;
- bool flag1 = true;
- int index1 = -1;
- int index2 = -1;
- int num5 = -1;
- if (prevEnc == 6 && (((int)text[textOffset] & (int)byte.MaxValue & 224) == 64 || ((int)text[textOffset] & (int)byte.MaxValue & 224) == 32) && (((int)text[textOffset] & (int)byte.MaxValue) != 95 && (((int)text[textOffset - 1] & (int)byte.MaxValue & 224) == 64 || ((int)text[textOffset - 1] & (int)byte.MaxValue & 224) == 32)) && ((int)text[textOffset - 1] & (int)byte.MaxValue) != 95)
- {
- for (index1 = symbolIndex - 1; index1 > 0 && switchMode[5][index1] == 6; --index1)
- {
- int num6 = (int)text[textOffset - (symbolIndex - index1 + 1)] & (int)byte.MaxValue;
- if ((num6 & 224) != 64 && (num6 & 224) != 32 || num6 == 95)
- break;
- }
- num5 = switchMode[5][index1] == 2 || switchMode[5][index1] == 5 ? switchMode[5][index1] : -1;
- if (num5 > 0)
- index2 = index1;
- for (; num5 > 0 && index2 > 0 && switchMode[num5 - 1][index2] == num5; --index2)
- {
- int num6 = (int)text[textOffset - (symbolIndex - index2 + 1)] & (int)byte.MaxValue;
- if (((num6 & 224) == 64 || (num6 & 224) == 32) && num6 != 95)
- continue;
- index2 = -1;
- break;
- }
- }
- int num7 = dataOffset + dataLength;
- bool flag2 = false;
- if (symbolIndex != -1)
- flag2 = true;
- int num8 = 0;
- int num9 = 0;
- if (index2 >= 0 && symbolIndex - index2 + 1 > 9)
- {
- textLength = symbolIndex - index2 + 1;
- int num6 = 0;
- int num10 = 0 + (1 + textLength / 4 * 3);
- if (!sizeFixed && (symbolIndex == text.Length - 1 || symbolIndex < 0) && textLength % 4 < 3)
- {
- num7 = int.MaxValue;
- for (int index3 = 0; index3 < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length; ++index3)
- {
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize >= num10 + textLength % 4)
- {
- num7 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize;
- break;
- }
- }
- }
- int num11;
- if (num7 - dataOffset - num10 <= 2 && textLength % 4 <= 2)
- {
- num11 = num10 + textLength % 4;
- }
- else
- {
- num11 = num10 + (textLength % 4 + 1);
- if (textLength % 4 == 3)
- --num11;
- }
- for (int index3 = dataOffset - 1; index3 >= 0; --index3)
- {
- ++num6;
- if ((int)data[index3] == (num5 == 2 ? 230 : 238))
- break;
- }
- if (num11 <= num6)
- {
- flag2 = false;
- textOffset -= textLength - 1;
- dataOffset -= num6;
- dataLength += num6;
- }
- }
- else if (index1 >= 0 && symbolIndex - index1 + 1 > 9)
- {
- textLength = symbolIndex - index1 + 1;
- int num6 = num9 + (1 + textLength / 4 * 3);
- int num10;
- if (num7 - dataOffset - num6 <= 2 && textLength % 4 <= 2)
- {
- num10 = num6 + textLength % 4;
- }
- else
- {
- num10 = num6 + (textLength % 4 + 1);
- if (textLength % 4 == 3)
- --num10;
- }
- int num11 = 0;
- int num12 = -1;
- for (int index3 = origDataOffset; index3 < dataOffset; ++index3)
- {
- if (data[index3] == (byte)240 && dataOffset - index3 <= num10)
- {
- num12 = index3;
- break;
- }
- }
- if (num12 != -1)
- {
- int num13 = num8 + (dataOffset - num12);
- if (((int)text[textOffset] & (int)byte.MaxValue) > (int)sbyte.MaxValue)
- {
- num8 = num13 + 2;
- }
- else
- {
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset] & (int)byte.MaxValue) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - 1] & (int)byte.MaxValue) && (data[dataOffset - 1] >= (byte)49 && data[dataOffset - 1] <= (byte)58))
- --num13;
- num8 = num13 + 1;
- }
- num11 = dataOffset - num12;
- }
- else
- {
- for (int index3 = symbolIndex - index1; index3 >= 0; --index3)
- {
- if (((int)text[textOffset - index3] & (int)byte.MaxValue) > (int)sbyte.MaxValue)
- {
- num8 += 2;
- }
- else
- {
- if (index3 > 0 && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index3] & (int)byte.MaxValue) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index3 + 1] & (int)byte.MaxValue))
- {
- if (index3 == 1)
- num11 = num8;
- --index3;
- }
- ++num8;
- }
- if (index3 == 1)
- num11 = num8;
- }
- }
- if (num10 <= num8)
- {
- flag2 = false;
- textOffset -= textLength - 1;
- dataOffset -= num11;
- dataLength += num11;
- }
- }
- if (flag2)
- {
- int c = (int)text[textOffset] & (int)byte.MaxValue;
- if (!iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) || textOffset + num1 <= 0 || (!iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - 1] & (int)byte.MaxValue) || prevEnc != 6) || (data[dataOffset - 1] < (byte)49 || data[dataOffset - 1] > (byte)58))
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + num1, 1, data, dataOffset + num2, dataLength, -1, -1, origDataOffset);
- data[dataOffset + num2 - 1] = (byte)((((int)text[textOffset - 1] & (int)byte.MaxValue) - 48) * 10 + c - 48 + 130);
- return dataOffset - origDataOffset;
- }
- for (; num1 < textLength; ++num1)
- {
- int c = (int)text[num1 + textOffset] & (int)byte.MaxValue;
- if (((c & 224) == 64 || (c & 224) == 32) && c != 95)
- {
- if (flag1)
- {
- if (num2 + 1 <= dataLength)
- {
- data[dataOffset + num2++] = (byte)240;
- flag1 = false;
- }
- else
- break;
- }
- int num6 = c & 63;
- num3 |= num6 << num4;
- if (num4 == 0)
- {
- if (num2 + 3 <= dataLength)
- {
- byte[] numArray1 = data;
- int num10 = dataOffset;
- int num11 = num2;
- int num12 = num11 + 1;
- int index3 = num10 + num11;
- int num13 = (int)(byte)(num3 >> 16);
- numArray1[index3] = (byte)num13;
- byte[] numArray2 = data;
- int num14 = dataOffset;
- int num15 = num12;
- int num16 = num15 + 1;
- int index4 = num14 + num15;
- int num17 = (int)(byte)(num3 >> 8);
- numArray2[index4] = (byte)num17;
- byte[] numArray3 = data;
- int num18 = dataOffset;
- int num19 = num16;
- num2 = num19 + 1;
- int index5 = num18 + num19;
- int num20 = (int)(byte)num3;
- numArray3[index5] = (byte)num20;
- num3 = 0;
- num4 = 18;
- }
- else
- break;
- }
- else
- num4 -= 6;
- }
- else
- {
- if (!flag1)
- {
- num3 |= 31 << num4;
- if (num2 + 3 - num4 / 8 <= dataLength)
- {
- data[dataOffset + num2++] = (byte)(num3 >> 16);
- if (num4 <= 12)
- data[dataOffset + num2++] = (byte)(num3 >> 8);
- if (num4 <= 6)
- data[dataOffset + num2++] = (byte)num3;
- flag1 = true;
- num4 = 18;
- num3 = 0;
- }
- else
- break;
- }
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && textOffset + num1 > 0 && (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset + num1 - 1] & (int)byte.MaxValue) && prevEnc == 6) && (data[dataOffset - 1] >= (byte)49 && data[dataOffset - 1] <= (byte)58))
- {
- data[dataOffset + num2 - 1] = (byte)((((int)text[textOffset - 1] & (int)byte.MaxValue) - 48) * 10 + c - 48 + 130);
- --num2;
- }
- else
- {
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + num1, 1, data, dataOffset + num2, dataLength, -1, -1, origDataOffset) < 0)
- return -1;
- if (data[dataOffset + num2] == (byte)235)
- ++num2;
- ++num2;
- }
- }
- }
- if (num1 != textLength)
- return -1;
- if (!sizeFixed && (symbolIndex == text.Length - 1 || symbolIndex < 0))
- {
- num7 = int.MaxValue;
- for (int index3 = 0; index3 < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length; ++index3)
- {
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize >= dataOffset + num2 + (3 - num4 / 6))
- {
- num7 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize;
- break;
- }
- }
- }
- if (num7 - dataOffset - num2 <= 2 && num4 >= 6)
- {
- if (num4 != 18 && num2 + 2 - num4 / 8 > dataLength)
- return -1;
- if (num4 <= 12)
- {
- byte num6 = (byte)(num3 >> 18 & 63);
- if (((int)num6 & 32) == 0)
- num6 |= (byte)64;
- data[dataOffset + num2++] = (byte)((uint)num6 + 1U);
- }
- if (num4 <= 6)
- {
- byte num6 = (byte)(num3 >> 12 & 63);
- if (((int)num6 & 32) == 0)
- num6 |= (byte)64;
- data[dataOffset + num2++] = (byte)((uint)num6 + 1U);
- }
- }
- else if (!flag1)
- {
- int num6 = num3 | 31 << num4;
- if (num2 + 3 - num4 / 8 > dataLength)
- return -1;
- data[dataOffset + num2++] = (byte)(num6 >> 16);
- if (num4 <= 12)
- data[dataOffset + num2++] = (byte)(num6 >> 8);
- if (num4 <= 6)
- data[dataOffset + num2++] = (byte)num6;
- }
- return num2 + dataOffset - origDataOffset;
- }
- private int C40OrTextEncodation(
- byte[] text,
- int textOffset,
- int textLength,
- byte[] data,
- int dataOffset,
- int dataLength,
- bool c40,
- int symbolIndex,
- int prevEnc,
- int origDataOffset)
- {
- if (textLength == 0)
- return 0;
- int num1 = 0;
- int num2 = 0;
- string str1 = "!\"#$%&'()*+,-./:;<=>?@[\\]^_";
- string str2;
- string str3;
- if (c40)
- {
- str2 = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- str3 = "`abcdefghijklmnopqrstuvwxyz{|}~\\177";
- }
- else
- {
- str2 = " 0123456789abcdefghijklmnopqrstuvwxyz";
- str3 = "`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\\177";
- }
- bool flag1 = true;
- bool flag2 = false;
- int num3 = c40 ? 2 : 3;
- if (prevEnc == num3)
- {
- flag2 = true;
- int index1 = symbolIndex - 1;
- while (index1 > 0 && switchMode[num3 - 1][index1] == num3)
- --index1;
- int num4 = -1;
- int num5 = 0;
- if (symbolIndex - index1 >= 5)
- {
- for (int index2 = symbolIndex - index1; index2 > 0; --index2)
- {
- if (((int)text[textOffset - index2] & (int)byte.MaxValue) > (int)sbyte.MaxValue)
- num5 += 2;
- else
- ++num5;
- }
- for (int index2 = 1; index2 <= num5 && index2 <= dataOffset; ++index2)
- {
- if (data[dataOffset - index2] == (byte)254)
- {
- num4 = dataOffset - index2;
- break;
- }
- }
- int num6 = 0;
- if (num4 >= 0)
- {
- for (int index2 = num4 + 1; index2 < dataOffset; ++index2)
- {
- if (data[index2] == (byte)235)
- ++index2;
- if (data[index2] >= (byte)129 && data[index2] <= (byte)229)
- ++num6;
- ++num6;
- }
- }
- else
- num6 = symbolIndex - index1;
- int num7 = 0;
- for (int index2 = num6; index2 > 0; --index2)
- {
- int num8 = 0;
- int num9 = 0;
- for (int index3 = index2; index3 >= 0; --index3)
- {
- int c = (int)text[textOffset - index3] & (int)byte.MaxValue;
- if (c > (int)sbyte.MaxValue)
- {
- c -= 128;
- num9 += 2;
- }
- num9 += str2.IndexOf((char)c) >= 0 ? 1 : 2;
- if (c > (int)sbyte.MaxValue)
- {
- num8 += 2;
- }
- else
- {
- if (index3 > 0 && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index3 + 1] & (int)byte.MaxValue))
- {
- num9 += str2.IndexOf((char)text[textOffset - index3 + 1]) >= 0 ? 1 : 2;
- --index3;
- num7 = num8 + 1;
- }
- ++num8;
- }
- if (index3 == 1)
- num7 = num8;
- }
- flag1 = num4 < 0 || dataOffset - num8 != num4;
- if (num9 % 3 == 0 && num9 / 3 * 2 + (flag1 ? 2 : 0) < num8)
- {
- flag2 = false;
- textLength = index2 + 1;
- textOffset -= index2;
- dataOffset -= flag1 ? num7 : num7 + 1;
- dataLength += flag1 ? num7 : num7 + 1;
- break;
- }
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index2] & (int)byte.MaxValue) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index2 + 1] & (int)byte.MaxValue))
- --index2;
- }
- }
- }
- else if (symbolIndex != -1)
- flag2 = true;
- if (flag2)
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset, 1, data, dataOffset, dataLength, prevEnc == num3 ? 1 : -1, 1, origDataOffset);
- if (flag1)
- data[dataOffset + num2++] = !c40 ? (byte)239 : (byte)230;
- int[] numArray1 = new int[textLength * 4 + 10];
- int num10 = 0;
- int num11 = 0;
- int num12 = 0;
- while (num1 < textLength)
- {
- if (num10 % 3 == 0)
- {
- num11 = num1;
- num12 = num10;
- }
- int num4 = (int)text[textOffset + num1++] & (int)byte.MaxValue;
- if (num4 > (int)sbyte.MaxValue)
- {
- num4 -= 128;
- int[] numArray2 = numArray1;
- int index1 = num10;
- int num5 = index1 + 1;
- numArray2[index1] = 1;
- int[] numArray3 = numArray1;
- int index2 = num5;
- num10 = index2 + 1;
- numArray3[index2] = 30;
- }
- int num6 = str2.IndexOf((char)num4);
- if (num6 >= 0)
- numArray1[num10++] = num6 + 3;
- else if (num4 < 32)
- {
- int[] numArray2 = numArray1;
- int index1 = num10;
- int num5 = index1 + 1;
- numArray2[index1] = 0;
- int[] numArray3 = numArray1;
- int index2 = num5;
- num10 = index2 + 1;
- int num7 = num4;
- numArray3[index2] = num7;
- }
- else
- {
- int num5;
- if ((num5 = str1.IndexOf((char)num4)) >= 0)
- {
- int[] numArray2 = numArray1;
- int index1 = num10;
- int num7 = index1 + 1;
- numArray2[index1] = 1;
- int[] numArray3 = numArray1;
- int index2 = num7;
- num10 = index2 + 1;
- int num8 = num5;
- numArray3[index2] = num8;
- }
- else
- {
- int num7;
- if ((num7 = str3.IndexOf((char)num4)) >= 0)
- {
- int[] numArray2 = numArray1;
- int index1 = num10;
- int num8 = index1 + 1;
- numArray2[index1] = 2;
- int[] numArray3 = numArray1;
- int index2 = num8;
- num10 = index2 + 1;
- int num9 = num7;
- numArray3[index2] = num9;
- }
- }
- }
- }
- if (num10 % 3 != 0)
- {
- num1 = num11;
- num10 = num12;
- }
- if (num10 / 3 * 2 > dataLength - 2)
- return -1;
- for (int index1 = 0; index1 < num10; index1 += 3)
- {
- int num4 = 1600 * numArray1[index1] + 40 * numArray1[index1 + 1] + numArray1[index1 + 2] + 1;
- byte[] numArray2 = data;
- int num5 = dataOffset;
- int num6 = num2;
- int num7 = num6 + 1;
- int index2 = num5 + num6;
- int num8 = (int)(byte)(num4 / 256);
- numArray2[index2] = (byte)num8;
- byte[] numArray3 = data;
- int num9 = dataOffset;
- int num13 = num7;
- num2 = num13 + 1;
- int index3 = num9 + num13;
- int num14 = (int)(byte)num4;
- numArray3[index3] = (byte)num14;
- }
- if (dataLength - num2 > 2)
- data[dataOffset + num2++] = (byte)254;
- if (symbolIndex < 0 && textLength > num1)
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + num1, textLength - num1, data, dataOffset + num2, dataLength - num2, -1, -1, origDataOffset);
- return num2 + dataOffset - origDataOffset;
- }
- private static int MinValueInColumn(int[][] array, int column)
- {
- int maxValue = int.MaxValue;
- for (int index = 0; index < 6; ++index)
- {
- if (array[index][column] < maxValue && array[index][column] >= 0)
- maxValue = array[index][column];
- }
- if (maxValue == int.MaxValue)
- return -1;
- return maxValue;
- }
- private static int ValuePositionInColumn(int[][] array, int column, int value)
- {
- for (int index = 0; index < 6; ++index)
- {
- if (array[index][column] == value)
- return index;
- }
- return -1;
- }
- private void SolveFAndSwitchMode(int[] forMin, int mode, int currIndex)
- {
- if (forMin[mode] >= 0 && f[mode][currIndex - 1] >= 0)
- {
- f[mode][currIndex] = forMin[mode];
- switchMode[mode][currIndex] = mode + 1;
- }
- else
- f[mode][currIndex] = int.MaxValue;
- for (int index = 0; index < 6; ++index)
- {
- if (forMin[index] < f[mode][currIndex] && forMin[index] >= 0 && f[index][currIndex - 1] >= 0)
- {
- f[mode][currIndex] = forMin[index];
- switchMode[mode][currIndex] = index + 1;
- }
- }
- if (f[mode][currIndex] != int.MaxValue)
- return;
- f[mode][currIndex] = -1;
- }
- private int GetEncodation(
- byte[] text,
- int textOffset,
- int textSize,
- byte[] data,
- int dataOffset,
- int dataSize,
- int options,
- bool sizeFixed)
- {
- if (dataSize < 0)
- return -1;
- options &= 7;
- switch (options)
- {
- case 0:
- if (textSize == 0)
- return 0;
- int length = data.Length;
- byte[][] numArray1 = new byte[6][];
- for (int index = 0; index < numArray1.Length; ++index)
- numArray1[index] = new byte[length];
- for (int index = 0; index < 6; ++index)
- {
- Array.Copy((Array)data, 0, (Array)numArray1[index], 0, data.Length);
- switchMode[index][0] = index + 1;
- }
- f[0][0] = AsciiEncodation(text, textOffset, 1, numArray1[0], dataOffset, dataSize, 0, -1, dataOffset);
- f[1][0] = C40OrTextEncodation(text, textOffset, 1, numArray1[1], dataOffset, dataSize, true, 0, -1, dataOffset);
- f[2][0] = C40OrTextEncodation(text, textOffset, 1, numArray1[2], dataOffset, dataSize, false, 0, -1, dataOffset);
- f[3][0] = B256Encodation(text, textOffset, 1, numArray1[3], dataOffset, dataSize, 0, -1, dataOffset);
- f[4][0] = X12Encodation(text, textOffset, 1, numArray1[4], dataOffset, dataSize, 0, -1, dataOffset);
- f[5][0] = EdifactEncodation(text, textOffset, 1, numArray1[5], dataOffset, dataSize, 0, -1, dataOffset, sizeFixed);
- int[] numArray2 = new int[6];
- for (int index1 = 1; index1 < textSize; ++index1)
- {
- int[] forMin = new int[6];
- for (int index2 = 0; index2 < 6; ++index2)
- numArray2[index2] = f[index2][index1 - 1] >= 0 ? f[index2][index1 - 1] : int.MaxValue;
- for (int mode = 0; mode < 6; ++mode)
- {
- byte[][] numArray3 = new byte[6][];
- for (int index2 = 0; index2 < numArray3.Length; ++index2)
- numArray3[index2] = new byte[length];
- for (int index2 = 0; index2 < 6; ++index2)
- {
- Array.Copy((Array)numArray1[index2], 0, (Array)numArray3[index2], 0, data.Length);
- if (mode == 0)
- forMin[index2] = AsciiEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset);
- if (mode == 1)
- forMin[index2] = C40OrTextEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], true, index1, index2 + 1, dataOffset);
- if (mode == 2)
- forMin[index2] = C40OrTextEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], false, index1, index2 + 1, dataOffset);
- if (mode == 3)
- forMin[index2] = B256Encodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset);
- if (mode == 4)
- forMin[index2] = X12Encodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset);
- if (mode == 5)
- forMin[index2] = EdifactEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset, sizeFixed);
- }
- SolveFAndSwitchMode(forMin, mode, index1);
- if (switchMode[mode][index1] != 0)
- Array.Copy((Array)numArray3[switchMode[mode][index1] - 1], 0, (Array)numArray1[mode], 0, data.Length);
- }
- }
- int num = iTextSharp.text.pdf.MyBarcodeDatamatrix.MinValueInColumn(f, textSize - 1);
- if (num > dataSize || num < 0)
- return -1;
- int index3 = iTextSharp.text.pdf.MyBarcodeDatamatrix.ValuePositionInColumn(f, textSize - 1, num);
- Array.Copy((Array)numArray1[index3], 0, (Array)data, 0, data.Length);
- return num;
- case 1:
- return AsciiEncodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset);
- case 2:
- return C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, true, -1, -1, dataOffset);
- case 3:
- return C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, false, -1, -1, dataOffset);
- case 4:
- return B256Encodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset);
- case 5:
- return X12Encodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset);
- case 6:
- return EdifactEncodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset, sizeFixed);
- case 7:
- if (textSize > dataSize)
- return -1;
- Array.Copy((Array)text, textOffset, (Array)data, dataOffset, textSize);
- return textSize;
- default:
- return -1;
- }
- }
- private static int GetNumber(byte[] text, int ptrIn, int n)
- {
- int num1 = 0;
- for (int index = 0; index < n; ++index)
- {
- int num2 = (int)text[ptrIn++] & (int)byte.MaxValue;
- if (num2 < 48 || num2 > 57)
- return -1;
- num1 = num1 * 10 + num2 - 48;
- }
- return num1;
- }
- private int ProcessExtensions(byte[] text, int textOffset, int textSize, byte[] data)
- {
- if ((this.options & 32) == 0)
- return 0;
- int num1 = 0;
- int num2 = 0;
- int num3 = 0;
- while (num2 < textSize && num1 <= 20)
- {
- int num4 = (int)text[textOffset + num2++] & (int)byte.MaxValue;
- ++num1;
- switch (num4)
- {
- case 46:
- this.extOut = num2;
- return num3;
- case 101:
- if (num2 + 6 > textSize)
- return -1;
- int number1 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num2, 6);
- if (number1 < 0)
- return -1;
- num2 += 6;
- byte[] numArray1 = data;
- int index1 = num3;
- int num5 = index1 + 1;
- numArray1[index1] = (byte)241;
- if (number1 < (int)sbyte.MaxValue)
- {
- byte[] numArray2 = data;
- int index2 = num5;
- num3 = index2 + 1;
- int num6 = (int)(byte)(number1 + 1);
- numArray2[index2] = (byte)num6;
- continue;
- }
- if (number1 < 16383)
- {
- byte[] numArray2 = data;
- int index2 = num5;
- int num6 = index2 + 1;
- int num7 = (int)(byte)((number1 - (int)sbyte.MaxValue) / 254 + 128);
- numArray2[index2] = (byte)num7;
- byte[] numArray3 = data;
- int index3 = num6;
- num3 = index3 + 1;
- int num8 = (int)(byte)((number1 - (int)sbyte.MaxValue) % 254 + 1);
- numArray3[index3] = (byte)num8;
- continue;
- }
- byte[] numArray4 = data;
- int index4 = num5;
- int num9 = index4 + 1;
- int num10 = (int)(byte)((number1 - 16383) / 64516 + 192);
- numArray4[index4] = (byte)num10;
- byte[] numArray5 = data;
- int index5 = num9;
- int num11 = index5 + 1;
- int num12 = (int)(byte)((number1 - 16383) / 254 % 254 + 1);
- numArray5[index5] = (byte)num12;
- byte[] numArray6 = data;
- int index6 = num11;
- num3 = index6 + 1;
- int num13 = (int)(byte)((number1 - 16383) % 254 + 1);
- numArray6[index6] = (byte)num13;
- continue;
- case 102:
- switch (num1)
- {
- case 1:
- data[num3++] = (byte)232;
- continue;
- case 2:
- if (text[textOffset] == (byte)115 || text[textOffset] == (byte)109)
- goto case 1;
- else
- break;
- }
- return -1;
- case 109:
- if (num1 != 1 || num2 + 1 > textSize)
- return -1;
- int num14 = (int)text[textOffset + num2++] & (int)byte.MaxValue;
- if (num14 != 53 && num14 != 53)
- return -1;
- byte[] numArray7 = data;
- int index7 = num3;
- int num15 = index7 + 1;
- numArray7[index7] = (byte)234;
- byte[] numArray8 = data;
- int index8 = num15;
- num3 = index8 + 1;
- int num16 = num14 == 53 ? 236 : 237;
- numArray8[index8] = (byte)num16;
- continue;
- case 112:
- if (num1 != 1)
- return -1;
- data[num3++] = (byte)234;
- continue;
- case 115:
- if (num1 != 1 || num2 + 9 > textSize)
- return -1;
- int number2 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num2, 2);
- if (number2 <= 0 || number2 > 16)
- return -1;
- int num17 = num2 + 2;
- int number3 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num17, 2);
- if (number3 <= 1 || number3 > 16)
- return -1;
- int num18 = num17 + 2;
- int number4 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num18, 5);
- if (number4 < 0 || number2 >= 64516)
- return -1;
- num2 = num18 + 5;
- byte[] numArray9 = data;
- int index9 = num3;
- int num19 = index9 + 1;
- numArray9[index9] = (byte)233;
- byte[] numArray10 = data;
- int index10 = num19;
- int num20 = index10 + 1;
- int num21 = (int)(byte)(number2 - 1 << 4 | 17 - number3);
- numArray10[index10] = (byte)num21;
- byte[] numArray11 = data;
- int index11 = num20;
- int num22 = index11 + 1;
- int num23 = (int)(byte)(number4 / 254 + 1);
- numArray11[index11] = (byte)num23;
- byte[] numArray12 = data;
- int index12 = num22;
- num3 = index12 + 1;
- int num24 = (int)(byte)(number4 % 254 + 1);
- numArray12[index12] = (byte)num24;
- continue;
- default:
- continue;
- }
- }
- return -1;
- }
- public virtual int Generate(string text)
- {
- byte[] bytes = Encoding.GetEncoding(this.encoding).GetBytes(text);
- return this.Generate(bytes, 0, bytes.Length);
- }
- public virtual int Generate(string text, string encoding)
- {
- byte[] bytes = Encoding.GetEncoding(encoding).GetBytes(text);
- return this.Generate(bytes, 0, bytes.Length);
- }
- public virtual int Generate(byte[] text, int textOffset, int textSize)
- {
- byte[] numArray = new byte[2500];
- this.extOut = 0;
- int dataOffset = this.ProcessExtensions(text, textOffset, textSize, numArray);
- if (dataOffset < 0)
- return 5;
- int length = textSize - this.extOut;
- f = new int[6][];
- switchMode = new int[6][];
- for (int index = 0; index < f.Length; ++index)
- {
- f[index] = new int[length];
- switchMode[index] = new int[length];
- }
- int position;
- iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams dmSize1;
- if (this.height == 0 || this.width == 0)
- {
- iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams dmSize2 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length - 1];
- int encodation = GetEncodation(text, textOffset + this.extOut, textSize - this.extOut, numArray, dataOffset, dmSize2.dataSize - dataOffset, this.options, false);
- if (encodation < 0)
- return 1;
- position = encodation + dataOffset;
- int index = 0;
- while (index < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length && iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index].dataSize < position)
- ++index;
- dmSize1 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index];
- this.height = dmSize1.height;
- this.width = dmSize1.width;
- }
- else
- {
- int index = 0;
- while (index < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length && (this.height != iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index].height || this.width != iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index].width))
- ++index;
- if (index == iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length)
- return 3;
- dmSize1 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index];
- int encodation = GetEncodation(text, textOffset + this.extOut, textSize - this.extOut, numArray, dataOffset, dmSize1.dataSize - dataOffset, this.options, true);
- if (encodation < 0)
- return 1;
- position = encodation + dataOffset;
- }
- if ((this.options & 64) != 0)
- return 0;
- this.image = new byte[(dmSize1.width + 2 * this.ws + 7) / 8 * (dmSize1.height + 2 * this.ws)];
- iTextSharp.text.pdf.MyBarcodeDatamatrix.MakePadding(numArray, position, dmSize1.dataSize - position);
- this.place = iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.DoPlacement(dmSize1.height - dmSize1.height / dmSize1.heightSection * 2, dmSize1.width - dmSize1.width / dmSize1.widthSection * 2);
- int dataSize = dmSize1.dataSize + (dmSize1.dataSize + 2) / dmSize1.dataBlock * dmSize1.errorBlock;
- iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.GenerateECC(numArray, dmSize1.dataSize, dmSize1.dataBlock, dmSize1.errorBlock);
- this.Draw(numArray, dataSize, dmSize1);
- return 0;
- }
- public virtual void PlaceBarcode(
- PdfContentByte cb,
- BaseColor foreground,
- float moduleHeight,
- float moduleWidth)
- {
- int num1 = this.width + 2 * this.ws;
- int num2 = this.height + 2 * this.ws;
- int num3 = (num1 + 7) / 8;
- cb.SetColorFill(foreground);
- for (int index1 = 0; index1 < num2; ++index1)
- {
- int num4 = index1 * num3;
- for (int index2 = 0; index2 < num1; ++index2)
- {
- if ((((int)this.image[num4 + index2 / 8] & (int)byte.MaxValue) << index2 % 8 & 128) != 0)
- cb.Rectangle((float)index2 * moduleWidth, (float)(num2 - index1 - 1) * moduleHeight, moduleWidth, moduleHeight);
- }
- }
- cb.Fill();
- }
- /// Gets an <CODE>Image</CODE>
- /// with the barcode. A successful call to the method <CODE>generate()</CODE>
- ///
- /// before calling this method is required.
- /// @return the barcode <CODE>Image</CODE>
- ///
- /// @throws BadElementException on error
- public virtual iTextSharp.text.Image CreateImage()
- {
- if (this.image == null)
- return (iTextSharp.text.Image)null;
- return iTextSharp.text.Image.GetInstance(this.width + 2 * this.ws, this.height + 2 * this.ws, false, 256, 0, CCITTG4Encoder.Compress(this.image, this.width + 2 * this.ws, this.height + 2 * this.ws), (int[])null);
- }
- /// Creates a <CODE>java.awt.Image</CODE>
- /// . A successful call to the method <CODE>generate()</CODE>
- ///
- /// before calling this method is required.
- /// @param foreground the color of the bars
- /// @param background the color of the background
- /// @return the image
- public virtual System.Drawing.Image CreateDrawingImage(Color foreground, Color background)
- {
- if (this.image == null)
- return (System.Drawing.Image)null;
- int height = this.height + 2 * this.ws;
- int width = this.width + 2 * this.ws;
- int num1 = (width + 7) / 8;
- Bitmap bitmap = new Bitmap(width, height);
- for (int y = 0; y < height; ++y)
- {
- int num2 = y * num1;
- for (int x = 0; x < width; ++x)
- {
- int num3 = ((int)this.image[num2 + x / 8] & (int)byte.MaxValue) << x % 8;
- bitmap.SetPixel(x, y, (num3 & 128) == 0 ? background : foreground);
- }
- }
- return (System.Drawing.Image)bitmap;
- }
- /// Gets the generated image. The image is represented as a stream of bytes, each byte representing
- /// 8 pixels, 0 for white and 1 for black, with the high-order bit of each byte first. Each row
- /// is aligned at byte boundaries. The dimensions of the image are defined by height and width
- /// plus 2 * ws.
- /// @return the generated image
- public virtual byte[] BitImage
- {
- get
- {
- return this.image;
- }
- }
- public virtual int Height
- {
- get
- {
- return this.height;
- }
- set
- {
- this.height = value;
- }
- }
- public virtual int Width
- {
- get
- {
- return this.width;
- }
- set
- {
- this.width = value;
- }
- }
- /// Gets/sets the whitespace border around the barcode.
- /// @param ws the whitespace border around the barcode
- public virtual int Ws
- {
- get
- {
- return this.ws;
- }
- set
- {
- this.ws = value;
- }
- }
- public virtual int Options
- {
- get
- {
- return this.options;
- }
- set
- {
- this.options = value;
- }
- }
- public virtual bool ForceSquareSize
- {
- set
- {
- this.forceSquareSize = value;
- }
- }
- private class DmParams
- {
- internal int height;
- internal int width;
- internal int heightSection;
- internal int widthSection;
- internal int dataSize;
- internal int dataBlock;
- internal int errorBlock;
- internal DmParams(
- int height,
- int width,
- int heightSection,
- int widthSection,
- int dataSize,
- int dataBlock,
- int errorBlock)
- {
- this.height = height;
- this.width = width;
- this.heightSection = heightSection;
- this.widthSection = widthSection;
- this.dataSize = dataSize;
- this.dataBlock = dataBlock;
- this.errorBlock = errorBlock;
- }
- }
- internal class Placement
- {
- private static Dictionary<int, short[]> cache = new Dictionary<int, short[]>();
- private int nrow;
- private int ncol;
- private short[] array;
- private Placement()
- {
- }
- internal static short[] DoPlacement(int nrow, int ncol)
- {
- int key = nrow * 1000 + ncol;
- lock (iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache)
- {
- short[] numArray;
- if (iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache.TryGetValue(key, out numArray))
- return numArray;
- }
- iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement placement = new iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement();
- placement.nrow = nrow;
- placement.ncol = ncol;
- placement.array = new short[nrow * ncol];
- placement.Ecc200();
- lock (iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache)
- iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache[key] = placement.array;
- return placement.array;
- }
- private void Module(int row, int col, int chr, int bit)
- {
- if (row < 0)
- {
- row += this.nrow;
- col += 4 - (this.nrow + 4) % 8;
- }
- if (col < 0)
- {
- col += this.ncol;
- row += 4 - (this.ncol + 4) % 8;
- }
- this.array[row * this.ncol + col] = (short)(8 * chr + bit);
- }
- private void Utah(int row, int col, int chr)
- {
- this.Module(row - 2, col - 2, chr, 0);
- this.Module(row - 2, col - 1, chr, 1);
- this.Module(row - 1, col - 2, chr, 2);
- this.Module(row - 1, col - 1, chr, 3);
- this.Module(row - 1, col, chr, 4);
- this.Module(row, col - 2, chr, 5);
- this.Module(row, col - 1, chr, 6);
- this.Module(row, col, chr, 7);
- }
- private void Corner1(int chr)
- {
- this.Module(this.nrow - 1, 0, chr, 0);
- this.Module(this.nrow - 1, 1, chr, 1);
- this.Module(this.nrow - 1, 2, chr, 2);
- this.Module(0, this.ncol - 2, chr, 3);
- this.Module(0, this.ncol - 1, chr, 4);
- this.Module(1, this.ncol - 1, chr, 5);
- this.Module(2, this.ncol - 1, chr, 6);
- this.Module(3, this.ncol - 1, chr, 7);
- }
- private void Corner2(int chr)
- {
- this.Module(this.nrow - 3, 0, chr, 0);
- this.Module(this.nrow - 2, 0, chr, 1);
- this.Module(this.nrow - 1, 0, chr, 2);
- this.Module(0, this.ncol - 4, chr, 3);
- this.Module(0, this.ncol - 3, chr, 4);
- this.Module(0, this.ncol - 2, chr, 5);
- this.Module(0, this.ncol - 1, chr, 6);
- this.Module(1, this.ncol - 1, chr, 7);
- }
- private void Corner3(int chr)
- {
- this.Module(this.nrow - 3, 0, chr, 0);
- this.Module(this.nrow - 2, 0, chr, 1);
- this.Module(this.nrow - 1, 0, chr, 2);
- this.Module(0, this.ncol - 2, chr, 3);
- this.Module(0, this.ncol - 1, chr, 4);
- this.Module(1, this.ncol - 1, chr, 5);
- this.Module(2, this.ncol - 1, chr, 6);
- this.Module(3, this.ncol - 1, chr, 7);
- }
- private void Corner4(int chr)
- {
- this.Module(this.nrow - 1, 0, chr, 0);
- this.Module(this.nrow - 1, this.ncol - 1, chr, 1);
- this.Module(0, this.ncol - 3, chr, 2);
- this.Module(0, this.ncol - 2, chr, 3);
- this.Module(0, this.ncol - 1, chr, 4);
- this.Module(1, this.ncol - 3, chr, 5);
- this.Module(1, this.ncol - 2, chr, 6);
- this.Module(1, this.ncol - 1, chr, 7);
- }
- private void Ecc200()
- {
- for (int index = 0; index < this.array.Length; ++index)
- this.array[index] = (short)0;
- int num = 1;
- int row1 = 4;
- int col1 = 0;
- do
- {
- if (row1 == this.nrow && col1 == 0)
- this.Corner1(num++);
- if (row1 == this.nrow - 2 && col1 == 0 && this.ncol % 4 != 0)
- this.Corner2(num++);
- if (row1 == this.nrow - 2 && col1 == 0 && this.ncol % 8 == 4)
- this.Corner3(num++);
- if (row1 == this.nrow + 4 && col1 == 2 && this.ncol % 8 == 0)
- this.Corner4(num++);
- do
- {
- if (row1 < this.nrow && col1 >= 0 && this.array[row1 * this.ncol + col1] == (short)0)
- this.Utah(row1, col1, num++);
- row1 -= 2;
- col1 += 2;
- }
- while (row1 >= 0 && col1 < this.ncol);
- int row2 = row1 + 1;
- int col2 = col1 + 3;
- do
- {
- if (row2 >= 0 && col2 < this.ncol && this.array[row2 * this.ncol + col2] == (short)0)
- this.Utah(row2, col2, num++);
- row2 += 2;
- col2 -= 2;
- }
- while (row2 < this.nrow && col2 >= 0);
- row1 = row2 + 3;
- col1 = col2 + 1;
- }
- while (row1 < this.nrow || col1 < this.ncol);
- if (this.array[this.nrow * this.ncol - 1] != (short)0)
- return;
- this.array[this.nrow * this.ncol - 1] = this.array[this.nrow * this.ncol - this.ncol - 2] = (short)1;
- }
- }
- internal class ReedSolomon
- {
- private static readonly int[] log = new int[256]
- {
- 0,
- (int) byte.MaxValue,
- 1,
- 240,
- 2,
- 225,
- 241,
- 53,
- 3,
- 38,
- 226,
- 133,
- 242,
- 43,
- 54,
- 210,
- 4,
- 195,
- 39,
- 114,
- 227,
- 106,
- 134,
- 28,
- 243,
- 140,
- 44,
- 23,
- 55,
- 118,
- 211,
- 234,
- 5,
- 219,
- 196,
- 96,
- 40,
- 222,
- 115,
- 103,
- 228,
- 78,
- 107,
- 125,
- 135,
- 8,
- 29,
- 162,
- 244,
- 186,
- 141,
- 180,
- 45,
- 99,
- 24,
- 49,
- 56,
- 13,
- 119,
- 153,
- 212,
- 199,
- 235,
- 91,
- 6,
- 76,
- 220,
- 217,
- 197,
- 11,
- 97,
- 184,
- 41,
- 36,
- 223,
- 253,
- 116,
- 138,
- 104,
- 193,
- 229,
- 86,
- 79,
- 171,
- 108,
- 165,
- 126,
- 145,
- 136,
- 34,
- 9,
- 74,
- 30,
- 32,
- 163,
- 84,
- 245,
- 173,
- 187,
- 204,
- 142,
- 81,
- 181,
- 190,
- 46,
- 88,
- 100,
- 159,
- 25,
- 231,
- 50,
- 207,
- 57,
- 147,
- 14,
- 67,
- 120,
- 128,
- 154,
- 248,
- 213,
- 167,
- 200,
- 63,
- 236,
- 110,
- 92,
- 176,
- 7,
- 161,
- 77,
- 124,
- 221,
- 102,
- 218,
- 95,
- 198,
- 90,
- 12,
- 152,
- 98,
- 48,
- 185,
- 179,
- 42,
- 209,
- 37,
- 132,
- 224,
- 52,
- 254,
- 239,
- 117,
- 233,
- 139,
- 22,
- 105,
- 27,
- 194,
- 113,
- 230,
- 206,
- 87,
- 158,
- 80,
- 189,
- 172,
- 203,
- 109,
- 175,
- 166,
- 62,
- (int) sbyte.MaxValue,
- 247,
- 146,
- 66,
- 137,
- 192,
- 35,
- 252,
- 10,
- 183,
- 75,
- 216,
- 31,
- 83,
- 33,
- 73,
- 164,
- 144,
- 85,
- 170,
- 246,
- 65,
- 174,
- 61,
- 188,
- 202,
- 205,
- 157,
- 143,
- 169,
- 82,
- 72,
- 182,
- 215,
- 191,
- 251,
- 47,
- 178,
- 89,
- 151,
- 101,
- 94,
- 160,
- 123,
- 26,
- 112,
- 232,
- 21,
- 51,
- 238,
- 208,
- 131,
- 58,
- 69,
- 148,
- 18,
- 15,
- 16,
- 68,
- 17,
- 121,
- 149,
- 129,
- 19,
- 155,
- 59,
- 249,
- 70,
- 214,
- 250,
- 168,
- 71,
- 201,
- 156,
- 64,
- 60,
- 237,
- 130,
- 111,
- 20,
- 93,
- 122,
- 177,
- 150
- };
- private static readonly int[] alog = new int[256]
- {
- 1,
- 2,
- 4,
- 8,
- 16,
- 32,
- 64,
- 128,
- 45,
- 90,
- 180,
- 69,
- 138,
- 57,
- 114,
- 228,
- 229,
- 231,
- 227,
- 235,
- 251,
- 219,
- 155,
- 27,
- 54,
- 108,
- 216,
- 157,
- 23,
- 46,
- 92,
- 184,
- 93,
- 186,
- 89,
- 178,
- 73,
- 146,
- 9,
- 18,
- 36,
- 72,
- 144,
- 13,
- 26,
- 52,
- 104,
- 208,
- 141,
- 55,
- 110,
- 220,
- 149,
- 7,
- 14,
- 28,
- 56,
- 112,
- 224,
- 237,
- 247,
- 195,
- 171,
- 123,
- 246,
- 193,
- 175,
- 115,
- 230,
- 225,
- 239,
- 243,
- 203,
- 187,
- 91,
- 182,
- 65,
- 130,
- 41,
- 82,
- 164,
- 101,
- 202,
- 185,
- 95,
- 190,
- 81,
- 162,
- 105,
- 210,
- 137,
- 63,
- 126,
- 252,
- 213,
- 135,
- 35,
- 70,
- 140,
- 53,
- 106,
- 212,
- 133,
- 39,
- 78,
- 156,
- 21,
- 42,
- 84,
- 168,
- 125,
- 250,
- 217,
- 159,
- 19,
- 38,
- 76,
- 152,
- 29,
- 58,
- 116,
- 232,
- 253,
- 215,
- 131,
- 43,
- 86,
- 172,
- 117,
- 234,
- 249,
- 223,
- 147,
- 11,
- 22,
- 44,
- 88,
- 176,
- 77,
- 154,
- 25,
- 50,
- 100,
- 200,
- 189,
- 87,
- 174,
- 113,
- 226,
- 233,
- (int) byte.MaxValue,
- 211,
- 139,
- 59,
- 118,
- 236,
- 245,
- 199,
- 163,
- 107,
- 214,
- 129,
- 47,
- 94,
- 188,
- 85,
- 170,
- 121,
- 242,
- 201,
- 191,
- 83,
- 166,
- 97,
- 194,
- 169,
- (int) sbyte.MaxValue,
- 254,
- 209,
- 143,
- 51,
- 102,
- 204,
- 181,
- 71,
- 142,
- 49,
- 98,
- 196,
- 165,
- 103,
- 206,
- 177,
- 79,
- 158,
- 17,
- 34,
- 68,
- 136,
- 61,
- 122,
- 244,
- 197,
- 167,
- 99,
- 198,
- 161,
- 111,
- 222,
- 145,
- 15,
- 30,
- 60,
- 120,
- 240,
- 205,
- 183,
- 67,
- 134,
- 33,
- 66,
- 132,
- 37,
- 74,
- 148,
- 5,
- 10,
- 20,
- 40,
- 80,
- 160,
- 109,
- 218,
- 153,
- 31,
- 62,
- 124,
- 248,
- 221,
- 151,
- 3,
- 6,
- 12,
- 24,
- 48,
- 96,
- 192,
- 173,
- 119,
- 238,
- 241,
- 207,
- 179,
- 75,
- 150,
- 1
- };
- private static readonly int[] poly5 = new int[5]
- {
- 228,
- 48,
- 15,
- 111,
- 62
- };
- private static readonly int[] poly7 = new int[7]
- {
- 23,
- 68,
- 144,
- 134,
- 240,
- 92,
- 254
- };
- private static readonly int[] poly10 = new int[10]
- {
- 28,
- 24,
- 185,
- 166,
- 223,
- 248,
- 116,
- (int) byte.MaxValue,
- 110,
- 61
- };
- private static readonly int[] poly11 = new int[11]
- {
- 175,
- 138,
- 205,
- 12,
- 194,
- 168,
- 39,
- 245,
- 60,
- 97,
- 120
- };
- private static readonly int[] poly12 = new int[12]
- {
- 41,
- 153,
- 158,
- 91,
- 61,
- 42,
- 142,
- 213,
- 97,
- 178,
- 100,
- 242
- };
- private static readonly int[] poly14 = new int[14]
- {
- 156,
- 97,
- 192,
- 252,
- 95,
- 9,
- 157,
- 119,
- 138,
- 45,
- 18,
- 186,
- 83,
- 185
- };
- private static readonly int[] poly18 = new int[18]
- {
- 83,
- 195,
- 100,
- 39,
- 188,
- 75,
- 66,
- 61,
- 241,
- 213,
- 109,
- 129,
- 94,
- 254,
- 225,
- 48,
- 90,
- 188
- };
- private static readonly int[] poly20 = new int[20]
- {
- 15,
- 195,
- 244,
- 9,
- 233,
- 71,
- 168,
- 2,
- 188,
- 160,
- 153,
- 145,
- 253,
- 79,
- 108,
- 82,
- 27,
- 174,
- 186,
- 172
- };
- private static readonly int[] poly24 = new int[24]
- {
- 52,
- 190,
- 88,
- 205,
- 109,
- 39,
- 176,
- 21,
- 155,
- 197,
- 251,
- 223,
- 155,
- 21,
- 5,
- 172,
- 254,
- 124,
- 12,
- 181,
- 184,
- 96,
- 50,
- 193
- };
- private static readonly int[] poly28 = new int[28]
- {
- 211,
- 231,
- 43,
- 97,
- 71,
- 96,
- 103,
- 174,
- 37,
- 151,
- 170,
- 53,
- 75,
- 34,
- 249,
- 121,
- 17,
- 138,
- 110,
- 213,
- 141,
- 136,
- 120,
- 151,
- 233,
- 168,
- 93,
- (int) byte.MaxValue
- };
- private static readonly int[] poly36 = new int[36]
- {
- 245,
- (int) sbyte.MaxValue,
- 242,
- 218,
- 130,
- 250,
- 162,
- 181,
- 102,
- 120,
- 84,
- 179,
- 220,
- 251,
- 80,
- 182,
- 229,
- 18,
- 2,
- 4,
- 68,
- 33,
- 101,
- 137,
- 95,
- 119,
- 115,
- 44,
- 175,
- 184,
- 59,
- 25,
- 225,
- 98,
- 81,
- 112
- };
- private static readonly int[] poly42 = new int[42]
- {
- 77,
- 193,
- 137,
- 31,
- 19,
- 38,
- 22,
- 153,
- 247,
- 105,
- 122,
- 2,
- 245,
- 133,
- 242,
- 8,
- 175,
- 95,
- 100,
- 9,
- 167,
- 105,
- 214,
- 111,
- 57,
- 121,
- 21,
- 1,
- 253,
- 57,
- 54,
- 101,
- 248,
- 202,
- 69,
- 50,
- 150,
- 177,
- 226,
- 5,
- 9,
- 5
- };
- private static readonly int[] poly48 = new int[48]
- {
- 245,
- 132,
- 172,
- 223,
- 96,
- 32,
- 117,
- 22,
- 238,
- 133,
- 238,
- 231,
- 205,
- 188,
- 237,
- 87,
- 191,
- 106,
- 16,
- 147,
- 118,
- 23,
- 37,
- 90,
- 170,
- 205,
- 131,
- 88,
- 120,
- 100,
- 66,
- 138,
- 186,
- 240,
- 82,
- 44,
- 176,
- 87,
- 187,
- 147,
- 160,
- 175,
- 69,
- 213,
- 92,
- 253,
- 225,
- 19
- };
- private static readonly int[] poly56 = new int[56]
- {
- 175,
- 9,
- 223,
- 238,
- 12,
- 17,
- 220,
- 208,
- 100,
- 29,
- 175,
- 170,
- 230,
- 192,
- 215,
- 235,
- 150,
- 159,
- 36,
- 223,
- 38,
- 200,
- 132,
- 54,
- 228,
- 146,
- 218,
- 234,
- 117,
- 203,
- 29,
- 232,
- 144,
- 238,
- 22,
- 150,
- 201,
- 117,
- 62,
- 207,
- 164,
- 13,
- 137,
- 245,
- (int) sbyte.MaxValue,
- 67,
- 247,
- 28,
- 155,
- 43,
- 203,
- 107,
- 233,
- 53,
- 143,
- 46
- };
- private static readonly int[] poly62 = new int[62]
- {
- 242,
- 93,
- 169,
- 50,
- 144,
- 210,
- 39,
- 118,
- 202,
- 188,
- 201,
- 189,
- 143,
- 108,
- 196,
- 37,
- 185,
- 112,
- 134,
- 230,
- 245,
- 63,
- 197,
- 190,
- 250,
- 106,
- 185,
- 221,
- 175,
- 64,
- 114,
- 71,
- 161,
- 44,
- 147,
- 6,
- 27,
- 218,
- 51,
- 63,
- 87,
- 10,
- 40,
- 130,
- 188,
- 17,
- 163,
- 31,
- 176,
- 170,
- 4,
- 107,
- 232,
- 7,
- 94,
- 166,
- 224,
- 124,
- 86,
- 47,
- 11,
- 204
- };
- private static readonly int[] poly68 = new int[68]
- {
- 220,
- 228,
- 173,
- 89,
- 251,
- 149,
- 159,
- 56,
- 89,
- 33,
- 147,
- 244,
- 154,
- 36,
- 73,
- (int) sbyte.MaxValue,
- 213,
- 136,
- 248,
- 180,
- 234,
- 197,
- 158,
- 177,
- 68,
- 122,
- 93,
- 213,
- 15,
- 160,
- 227,
- 236,
- 66,
- 139,
- 153,
- 185,
- 202,
- 167,
- 179,
- 25,
- 220,
- 232,
- 96,
- 210,
- 231,
- 136,
- 223,
- 239,
- 181,
- 241,
- 59,
- 52,
- 172,
- 25,
- 49,
- 232,
- 211,
- 189,
- 64,
- 54,
- 108,
- 153,
- 132,
- 63,
- 96,
- 103,
- 82,
- 186
- };
- private static int[] GetPoly(int nc)
- {
- switch (nc)
- {
- case 5:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly5;
- case 7:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly7;
- case 10:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly10;
- case 11:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly11;
- case 12:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly12;
- case 14:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly14;
- case 18:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly18;
- case 20:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly20;
- case 24:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly24;
- case 28:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly28;
- case 36:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly36;
- case 42:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly42;
- case 48:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly48;
- case 56:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly56;
- case 62:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly62;
- case 68:
- return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly68;
- default:
- return (int[])null;
- }
- }
- private static void ReedSolomonBlock(byte[] wd, int nd, byte[] ncout, int nc, int[] c)
- {
- for (int index = 0; index <= nc; ++index)
- ncout[index] = (byte)0;
- for (int index1 = 0; index1 < nd; ++index1)
- {
- int index2 = ((int)ncout[0] ^ (int)wd[index1]) & (int)byte.MaxValue;
- for (int index3 = 0; index3 < nc; ++index3)
- ncout[index3] = (byte)((int)ncout[index3 + 1] ^ (index2 == 0 ? 0 : (int)(byte)iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.alog[(iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.log[index2] + iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.log[c[nc - index3 - 1]]) % (int)byte.MaxValue]));
- }
- }
- internal static void GenerateECC(byte[] wd, int nd, int datablock, int nc)
- {
- int num1 = (nd + 2) / datablock;
- byte[] wd1 = new byte[256];
- byte[] ncout = new byte[256];
- int[] poly = iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.GetPoly(nc);
- for (int index1 = 0; index1 < num1; ++index1)
- {
- int nd1 = 0;
- for (int index2 = index1; index2 < nd; index2 += num1)
- wd1[nd1++] = wd[index2];
- iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.ReedSolomonBlock(wd1, nd1, ncout, nc, poly);
- int num2 = 0;
- for (int index2 = index1; index2 < nc * num1; index2 += num1)
- wd[nd + index2] = ncout[num2++];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement