Exemple #1
0
        /**
         * <summary>Gets the internal representation of the given text.</summary>
         * <param name="text">Text to encode.</param>
         */
        public byte[] Encode(
            string text
            )
        {
            io::MemoryStream encodedStream = new io::MemoryStream();

            for (int index = 0, length = text.Length; index < length; index++)
            {
                int    textCode = text[index];
                byte[] charCode = codes.GetKey(textCode).Data;
                encodedStream.Write(charCode, 0, charCode.Length);
                usedCodes.Add(textCode);
            }
            encodedStream.Close();
            return(encodedStream.ToArray());
        }
Exemple #2
0
        /**
         * <summary>Gets the internal representation of the given text.</summary>
         * <param name="text">Text to encode.</param>
         */
        public byte[] Encode(
            string text
            )
        {
            io::MemoryStream encodedStream = new io::MemoryStream();

            try
            {
                foreach (char textChar in text)
                {
                    byte[] charCode = codes.GetKey((int)textChar).Data;
                    encodedStream.Write(charCode, 0, charCode.Length);
                }
                encodedStream.Close();
            }
            catch (Exception exception)
            { throw new Exception("Failed to encode text.", exception); }

            return(encodedStream.ToArray());
        }
Exemple #3
0
        /**
         * <summary>Gets the internal representation of the given text.</summary>
         * <param name="text">Text to encode.</param>
         * <exception cref="EncodeException"/>
         */
        public byte[] Encode(
            string text
            )
        {
            io::MemoryStream encodedStream = new io::MemoryStream();

            for (int index = 0, length = text.Length; index < length; index++)
            {
                int textCode = text[index];
                if (textCode < 32) // NOTE: Control characters are ignored [FIX:7].
                {
                    continue;
                }

                ByteArray code = codes.GetKey(textCode);
                if (code == null) // Missing glyph.
                {
                    switch (Document.Configuration.EncodingFallback)
                    {
                    case EncodingFallbackEnum.Exclusion:
                        continue;

                    case EncodingFallbackEnum.Substitution:
                        code = codes.GetKey(defaultCode);
                        break;

                    case EncodingFallbackEnum.Exception:
                        throw new EncodeException(text, index);

                    default:
                        throw new NotImplementedException();
                    }
                }

                byte[] charCode = code.Data;
                encodedStream.Write(charCode, 0, charCode.Length);
                usedCodes.Add(textCode);
            }
            encodedStream.Close();
            return(encodedStream.ToArray());
        }