예제 #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
        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;
            }
        }
예제 #3
0
        private static void AddCharacterSet(int value, String encodingName, Dictionary <String, CharacterSetECI> n)
        {
            CharacterSetECI eci = new CharacterSetECI(value, encodingName);

            n[encodingName] = eci;
        }
예제 #4
0
        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).
            var mode = ChooseMode(content, encoding);

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

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

            InitQRCode(numInputBytes, ecLevel, mode, qrCode);

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

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

            AppendModeInfo(mode, headerAndDataBits);

            var 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.
            var finalBits = new BitVector();

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

            // Step 7: Choose the mask pattern and set to "qrCode".
            var 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());
            }
        }
예제 #5
0
 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);
 }
예제 #6
0
 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);
 }
예제 #7
0
 private static void AddCharacterSet(int value, String encodingName, Dictionary<String, CharacterSetECI> n)
 {
     CharacterSetECI eci = new CharacterSetECI(value, encodingName);
     n[encodingName] = eci;
 }