示例#1
0
        private void EncodeTextCompleteString(string text)
        {
            TextMode textMode = new TextMode();

            text = PDF417.ValidateText(text);
            this.encodedRawData.AddRange((IEnumerable <long>)textMode.EncodeData(text, false));
        }
示例#2
0
 private static void DetermineNextMode(string text, ref bool shouldApplyNonLatchData)
 {
     if (PDF417.GetNumberOfCharsAtPosition(text, 0) >= 5 || PDF417.GetNumberOfBytesAtPosition(text, 0) == 1)
     {
         return;
     }
     shouldApplyNonLatchData = true;
 }
示例#3
0
        public void PopulateMatrix(
            string text,
            int errorCorrectionLevel,
            EncodingMode mode,
            int columns,
            int rows)
        {
            this.encodedRawData = new List <long>();
            this.xRatio         = this.GetValidValue(columns, 3, 30);
            this.yRatio         = this.GetValidValue(rows, 2, 90);
            this.eCLevel        = errorCorrectionLevel;
            this.eCCount        = SpecificationData.ErrorCorrectionLevels[this.eCLevel].Count;
            switch (mode)
            {
            case EncodingMode.Auto:
                text = PDF417.ValidateTextModeNone(text);
                int dataIndex = 0;
                while (dataIndex < text.Length)
                {
                    int digitsAtPosition = PDF417.GetNumberOfDigitsAtPosition(text, dataIndex);
                    if (digitsAtPosition >= 13)
                    {
                        this.EncodeNumeric(text, ref dataIndex, digitsAtPosition);
                    }
                    else if (digitsAtPosition < 13)
                    {
                        int ofCharsAtPosition = PDF417.GetNumberOfCharsAtPosition(text, dataIndex);
                        if (ofCharsAtPosition >= 5)
                        {
                            this.EncodeText(text, ref dataIndex, ofCharsAtPosition);
                        }
                        else if (ofCharsAtPosition < 5)
                        {
                            int ofBytesAtPosition = PDF417.GetNumberOfBytesAtPosition(text, dataIndex);
                            this.EncodeByte(text, ref dataIndex, ofBytesAtPosition);
                        }
                    }
                }
                break;

            case EncodingMode.Text:
                this.EncodeTextCompleteString(text);
                break;

            case EncodingMode.Numeric:
                this.EncodeNumericCompleteString(text);
                break;

            default:
                this.EncodeByteCompleteString(text);
                break;
            }
            this.SetSmallestSizeOfMatrix();
            this.VerifyDataLength();
            this.PadData();
            this.SetErrorCorrection();
            this.FillMatrixWithData();
        }
示例#4
0
        private static int GetNumberOfCharsAtPosition(string text, int currentPosition)
        {
            int num = 0;

            while (currentPosition <= text.Length - 1 && PDF417.GetNumberOfDigitsAtPosition(text, currentPosition) < 13 && TextMode.FindCharacterInTable((int)text[currentPosition]) != null)
            {
                ++currentPosition;
                ++num;
            }
            return(num);
        }
示例#5
0
        private static int GetNumberOfBytesAtPosition(string text, int currentPosition)
        {
            int num = 0;

            while (currentPosition <= text.Length - 1 && PDF417.GetNumberOfDigitsAtPosition(text, currentPosition) < 13 && (PDF417.GetNumberOfCharsAtPosition(text, currentPosition) < 5 && SpecificationData.ByteModeValues.Contains((int)text[currentPosition])))
            {
                ++currentPosition;
                ++num;
            }
            return(num);
        }
示例#6
0
        private static string ValidateTextModeNone(string text)
        {
            string empty = string.Empty;

            for (int index = 0; index < text.Length; ++index)
            {
                if (PDF417.IsCharValid(text[index]))
                {
                    empty += (string)(object)text[index];
                }
            }
            return(empty);
        }
示例#7
0
        private void EncodeText(string text, ref int dataIndex, int numberOfTexModeCharsAtPosition)
        {
            TextMode textMode   = new TextMode();
            int      startIndex = dataIndex + numberOfTexModeCharsAtPosition;
            bool     shouldApplyNonLatchData = false;

            if (startIndex < text.Length - 1)
            {
                PDF417.DetermineNextMode(text.Substring(startIndex), ref shouldApplyNonLatchData);
            }
            this.encodedRawData.Add(900L);
            this.encodedRawData.AddRange((IEnumerable <long>)textMode.EncodeData(text.Substring(dataIndex, numberOfTexModeCharsAtPosition), shouldApplyNonLatchData));
            dataIndex += numberOfTexModeCharsAtPosition;
        }
示例#8
0
        private void AddDataCluster(int rowIndex, int columnIndex, int dataPointer)
        {
            int    clusterIndex = PDF417.CalculateClusterIndex(rowIndex);
            string str          = SpecificationData.BarSpaceSequence[(int)this.encodedRawData[dataPointer]][clusterIndex].ToString();

            for (int index1 = 0; index1 < str.Length; ++index1)
            {
                bool flag = index1 % 2 == 0;
                for (int index2 = 0; index2 < int.Parse(str[index1].ToString()); ++index2)
                {
                    this.dataMatrix[rowIndex, columnIndex] = flag;
                    ++columnIndex;
                }
            }
        }
示例#9
0
        private void AddRightRowIndicatorCluster(int rowIndex, int columnIndex)
        {
            int    clusterIndex      = PDF417.CalculateClusterIndex(rowIndex);
            int    rightRowIndicator = PDF417.CalculateRightRowIndicator(clusterIndex, rowIndex, this.rows, this.columns, this.eCLevel);
            string str = SpecificationData.BarSpaceSequence[rightRowIndicator][clusterIndex].ToString();

            for (int index1 = 0; index1 < str.Length; ++index1)
            {
                bool flag = index1 % 2 == 0;
                for (int index2 = 0; index2 < int.Parse(str[index1].ToString()); ++index2)
                {
                    this.dataMatrix[rowIndex, columnIndex] = flag;
                    ++columnIndex;
                }
            }
        }
示例#10
0
 private void EncodeByteCompleteString(string text)
 {
     text = PDF417.ValidateByte(text);
     this.encodedRawData.AddRange((IEnumerable <long>)ByteMode.EncodeText(text));
 }
示例#11
0
 private void EncodeNumericCompleteString(string text)
 {
     text = PDF417.ValidateDigits(text);
     this.encodedRawData.Add(902L);
     this.encodedRawData.AddRange((IEnumerable <long>)NumericMode.EncodeData(text));
 }
示例#12
0
 private static bool IsCharValid(char character)
 {
     return(PDF417.GetNumberOfBytesAtPosition(character.ToString(), 0) + PDF417.GetNumberOfCharsAtPosition(character.ToString(), 0) + PDF417.GetNumberOfDigitsAtPosition(character.ToString(), 0) > 0);
 }