Esempio n. 1
0
        /// <summary>
        /// Returns the bit representation of input data.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        internal override BitList GetDataBits(string content)
        {
            var eciSet = new ECISet(ECISet.AppendOption.NameToValue);

            if (!eciSet.ContainsECIName(Encoding))
            {
                throw new ArgumentOutOfRangeException("Encoding",
                                                      Encoding,
                                                      "Current ECI table does not support this encoding. Please check ECISet class for more info");
            }

            byte[] contentBytes = EncodeContent(content, Encoding);

            return(GetDataBitsByByteArray(contentBytes, Encoding));
        }
Esempio n. 2
0
        /// <summary>
        /// Determine which version to use
        /// </summary>
        /// <param name="dataBitsLength">Number of bits for encoded content</param>
        /// <param name="mode">The mode.</param>
        /// <param name="level">The level.</param>
        /// <param name="encodingName">Encoding name for EightBitByte</param>
        /// <returns>VersionDetail and ECI</returns>
        /// <remarks></remarks>
        internal static VersionControlStruct InitialSetup(int dataBitsLength, Mode mode, ErrorCorrectionLevel level,
                                                          string encodingName)
        {
            int totalDataBits = dataBitsLength;

            bool containECI = false;

            var eciHeader = new BitList();


            //Check ECI header
            if (mode == Mode.EightBitByte)
            {
                if (encodingName != DEFAULT_ENCODING && encodingName != QRCodeConstantVariable.UTF8Encoding)
                {
                    var eciSet = new ECISet(ECISet.AppendOption.NameToValue);
                    int eciValue = eciSet.GetECIValueByName(encodingName);

                    totalDataBits += ECISet.NumOfECIHeaderBits(eciValue);
                    eciHeader = eciSet.GetECIHeader(encodingName);
                    containECI = true;
                }
            }
            //Determine which version group it belong to
            int searchGroup = DynamicSearchIndicator(totalDataBits, level, mode);

            int[] charCountIndicator = CharCountIndicatorTable.GetCharCountIndicatorSet(mode);

            totalDataBits += (NUM_BITS_MODE_INDICATOR + charCountIndicator[searchGroup]);

            int lowerSearchBoundary = searchGroup == 0 ? 1 : (VERSION_GROUP[searchGroup - 1] + 1);
            int higherSearchBoundary = VERSION_GROUP[searchGroup];

            //Binary search to find proper version
            int versionNum = BinarySearch(totalDataBits, level, lowerSearchBoundary, higherSearchBoundary);

            VersionControlStruct vcStruct = FillVCStruct(versionNum, level, encodingName);

            vcStruct.isContainECI = containECI;

            vcStruct.ECIHeader = eciHeader;

            return vcStruct;
        }
        /// <summary>
        /// Returns the bit representation of input data.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        internal override BitList GetDataBits(string content)
        {
            var eciSet = new ECISet(ECISet.AppendOption.NameToValue);
            if (!eciSet.ContainsECIName(Encoding))
            {
                throw new ArgumentOutOfRangeException("Encoding",
                                                      Encoding,
                                                      "Current ECI table does not support this encoding. Please check ECISet class for more info");
            }

            byte[] contentBytes = EncodeContent(content, Encoding);

            return GetDataBitsByByteArray(contentBytes, Encoding);
        }