예제 #1
0
        private static void AddCharacterSet(int value, String[] encodingNames, Dictionary <String, CharacterSetECI> n)
        {
            CharacterSetECI eci = new CharacterSetECI(value, encodingNames[0]);

            for (int i = 0; i < encodingNames.Length; i++)
            {
                n[encodingNames[i]] = eci;
            }
        }
예제 #2
0
파일: Encoder.cs 프로젝트: arsalan0312/Eco
 private static void AppendECI(CharacterSetECI eci, BitVector bits)
 {
     bits.AppendBits(Mode.ECI.GetBits(), 4);
     // This is correct for values up to 127, which is all we need now.
     bits.AppendBits(eci.GetValue(), 8);
 }
예제 #3
0
파일: Encoder.cs 프로젝트: arsalan0312/Eco
        public static void Encode(String content, ErrorCorrectionLevel ecLevel, IDictionary <EncodeHintType, Object> hints,
                                  QRCode qrCode)
        {
            String encoding = null;

            if (hints != null && hints.ContainsKey(EncodeHintType.CHARACTER_SET))
            {
                encoding = (string)hints[EncodeHintType.CHARACTER_SET];
            }
            if (encoding == null)
            {
                encoding = DEFAULT_BYTE_MODE_ENCODING;
            }

            // Step 1: Choose the mode (encoding).
            Mode mode = ChooseMode(content, encoding);

            // Step 2: Append "bytes" into "dataBits" in appropriate encoding.
            BitVector dataBits = new BitVector();

            AppendBytes(content, mode, dataBits, encoding);
            // Step 3: Initialize QR code that can contain "dataBits".
            int numInputBytes = dataBits.SizeInBytes();

            InitQRCode(numInputBytes, ecLevel, mode, qrCode);

            // Step 4: Build another bit vector that contains header and data.
            BitVector headerAndDataBits = new BitVector();

            // Step 4.5: Append ECI message if applicable
            if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.Equals(encoding))
            {
                CharacterSetECI eci = CharacterSetECI.GetCharacterSetECIByName(encoding);
                if (eci != null)
                {
                    AppendECI(eci, headerAndDataBits);
                }
            }

            AppendModeInfo(mode, headerAndDataBits);

            int numLetters = mode.Equals(Mode.BYTE) ? dataBits.SizeInBytes() : content.Length;

            AppendLengthInfo(numLetters, qrCode.GetVersion(), mode, headerAndDataBits);
            headerAndDataBits.AppendBitVector(dataBits);

            // Step 5: Terminate the bits properly.
            TerminateBits(qrCode.GetNumDataBytes(), headerAndDataBits);

            // Step 6: Interleave data bits with error correction code.
            BitVector finalBits = new BitVector();

            InterleaveWithECBytes(headerAndDataBits, qrCode.GetNumTotalBytes(), qrCode.GetNumDataBytes(),
                                  qrCode.GetNumRSBlocks(), finalBits);

            // Step 7: Choose the mask pattern and set to "qrCode".
            ByteMatrix matrix = new ByteMatrix(qrCode.GetMatrixWidth(), qrCode.GetMatrixWidth());

            qrCode.SetMaskPattern(ChooseMaskPattern(finalBits, qrCode.GetECLevel(), qrCode.GetVersion(),
                                                    matrix));

            // Step 8.  Build the matrix and set it to "qrCode".
            MatrixUtil.BuildMatrix(finalBits, qrCode.GetECLevel(), qrCode.GetVersion(),
                                   qrCode.GetMaskPattern(), matrix);
            qrCode.SetMatrix(matrix);
            // Step 9.  Make sure we have a valid QR Code.
            if (!qrCode.IsValid())
            {
                throw new WriterException("Invalid QR code: " + qrCode.ToString());
            }
        }
예제 #4
0
        private static void AddCharacterSet(int value, String encodingName, Dictionary <String, CharacterSetECI> n)
        {
            CharacterSetECI eci = new CharacterSetECI(value, encodingName);

            n[encodingName] = eci;
        }