GetChars() private method

private GetChars ( byte bytes, int byteCount, char chars, int charCount ) : int
bytes byte
byteCount int
chars char
charCount int
return int
 private static EMFFont Process(byte[] RecordData)
 {
     //put the Data into a stream and use a binary reader to read the data
     MemoryStream _ms = null;
     BinaryReader _br = null;
     try
     {
         _ms = new MemoryStream(RecordData);
         _br = new BinaryReader(_ms);
         UInt32 Version = _br.ReadUInt32();
         Single EmSize = _br.ReadSingle();
         UInt32 SizeUnit = _br.ReadUInt32();
         Int32 FontStyleFlags = _br.ReadInt32();
         _br.ReadUInt32();
         UInt32 NameLength = _br.ReadUInt32();
         char[] FontFamily = new char[NameLength]; 
         System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
         d.GetChars(_br.ReadBytes((int)NameLength * 2),0,(int)NameLength * 2,FontFamily,0);                
         Font aFont = new Font(new String(FontFamily), EmSize, (FontStyle)FontStyleFlags, (GraphicsUnit)SizeUnit);
         EMFFont ThisFont = new EMFFont();
         ThisFont.myFont = aFont;
         return ThisFont;
     }
     finally
     {
         if (_br != null)
             _br.Close();               
         if (_ms != null)
             _ms.Dispose();            
     }
 }
Example #2
0
 public void PosTest3()
 {
     Char[] srcChars = GetCharArray(10);
     Char[] desChars = new Char[10];
     Byte[] bytes = new Byte[20];
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
     int actualValue;
     actualValue = uEncoding.GetChars(bytes, 0, 0, desChars, 10);
     Assert.Equal(0, actualValue);
 }
 public void TestEncodingDecodingGetBytes1()
 {
         //pi and sigma in unicode
         string Unicode = "\u03a0\u03a3";
         UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian 
         //Encode the unicode string.
         byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);
         //Decode the bytes to a unicode char array.
         char[] UniChars = UnicodeEnc.GetChars (UniBytes);
         string Result = new string(UniChars);
         
         Assertion.AssertEquals ("Uni #1", Unicode, Result);
 }
Example #4
0
        public void PosTest2()
        {
            int expectedValue = _generator.GetInt16(-55) % 10 + 1;
            int actualValue;

            Char[] srcChars = GetCharArray(10);
            Char[] desChars = new Char[10];
            Byte[] bytes = new Byte[20];
            UnicodeEncoding uEncoding = new UnicodeEncoding();
            int byteCount = uEncoding.GetBytes(srcChars, 0, expectedValue, bytes, 0);

            actualValue = uEncoding.GetChars(bytes, 0, expectedValue * 2, desChars, 0);
            Assert.Equal(expectedValue, actualValue);
        }
 static public int GetChars__A_Byte(IntPtr l)
 {
     try {
         System.Text.UnicodeEncoding self = (System.Text.UnicodeEncoding)checkSelf(l);
         System.Byte[] a1;
         checkArray(l, 2, out a1);
         var ret = self.GetChars(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int GetChars__A_Byte__Int32__Int32__A_Char__Int32(IntPtr l)
 {
     try {
         System.Text.UnicodeEncoding self = (System.Text.UnicodeEncoding)checkSelf(l);
         System.Byte[] a1;
         checkArray(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         System.Int32 a3;
         checkType(l, 4, out a3);
         System.Char[] a4;
         checkArray(l, 5, out a4);
         System.Int32 a5;
         checkType(l, 6, out a5);
         var ret = self.GetChars(a1, a2, a3, a4, a5);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #7
0
        private static EMFFont Process(byte[] RecordData)
        {
            //put the Data into a stream and use a binary reader to read the data
            MemoryStream _ms = null;
            BinaryReader _br = null;

            try
            {
                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);
                UInt32 Version        = _br.ReadUInt32();
                Single EmSize         = _br.ReadSingle();
                UInt32 SizeUnit       = _br.ReadUInt32();
                Int32  FontStyleFlags = _br.ReadInt32();
                _br.ReadUInt32();
                UInt32 NameLength             = _br.ReadUInt32();
                char[] FontFamily             = new char[NameLength];
                System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
                d.GetChars(_br.ReadBytes((int)NameLength * 2), 0, (int)NameLength * 2, FontFamily, 0);
                Font    aFont    = new Font(new String(FontFamily), EmSize, (FontStyle)FontStyleFlags, (GraphicsUnit)SizeUnit);
                EMFFont ThisFont = new EMFFont();
                ThisFont.myFont = aFont;
                return(ThisFont);
            }
            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
            }
        }
Example #8
0
        public List<PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;
            MemoryStream _fs = null;
            BinaryReader _fr = null;
            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(Flags));
                _fr = new BinaryReader(_fs);
                //Byte 1 will be ObjectID - a font in the object table
                byte ObjectID = _fr.ReadByte();
                //Byte 2 is the real flags
                byte RealFlags = _fr.ReadByte();
                // 0 1 2 3 4 5 6 7
                // X X X X X X X S
                // if S = type of brush - if S then ARGB, else a brush object in object table

                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);
                bool BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
                Brush b;
                if (BrushIsARGB)
                {
                    byte A, R, G, B;
                    B = _br.ReadByte();
                    G = _br.ReadByte();
                    R = _br.ReadByte();
                    A = _br.ReadByte();
                    b = new SolidBrush(Color.FromArgb(A, R, G, B));
                }
                else
                {
                    UInt32 BrushID = _br.ReadUInt32();
                    EMFBrush EMFb = (EMFBrush)ObjectTable[(byte)BrushID];
                    b = EMFb.myBrush;
                }

                UInt32 FormatID = _br.ReadUInt32(); // Index of Optional stringFormatobject in Object Table...
                UInt32 StringLength = _br.ReadUInt32();
                //bounding of string...
                Single recX = _br.ReadSingle();
                Single recY = _br.ReadSingle();
                Single recWidth = _br.ReadSingle();
                Single recHeight = _br.ReadSingle();
                //Array of Chars...
                char[] StringData = new char[StringLength];
                System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
                d.GetChars(_br.ReadBytes((int)StringLength * 2), 0, (int)StringLength * 2, StringData, 0);
                EMFFont EF = (EMFFont)ObjectTable[(byte)ObjectID];
                Font f = EF.myFont;
                StringFormat sf;
                if (ObjectTable.Contains((byte)FormatID))
                {
                    EMFStringFormat ESF = (EMFStringFormat)ObjectTable[(byte)FormatID];
                    sf = ESF.myStringFormat;
                }
                else
                {
                    sf = new StringFormat();
                }

                DoInstructions(f, sf, b, recX, recY, recWidth, recHeight, new String(StringData));
                return items;
            }
            finally
            {
                if (_br != null)
                    _br.Close();
                if (_ms != null)
                    _ms.Dispose();
                if (_fr != null)
                    _fr.Close();
                if (_fs != null)
                    _fs.Dispose();
            }
        }
Example #9
0
        public List <PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;
            MemoryStream _fs = null;
            BinaryReader _fr = null;

            try
            {
                _fs = new MemoryStream(BitConverter.GetBytes(Flags));
                _fr = new BinaryReader(_fs);
                //Byte 1 will be ObjectID - a font in the object table
                byte ObjectID = _fr.ReadByte();
                //Byte 2 is the real flags
                byte RealFlags = _fr.ReadByte();
                // 0 1 2 3 4 5 6 7
                // X X X X X X X S
                // if S = type of brush - if S then ARGB, else a brush object in object table

                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);
                bool  BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
                Brush b;
                if (BrushIsARGB)
                {
                    byte A, R, G, B;
                    B = _br.ReadByte();
                    G = _br.ReadByte();
                    R = _br.ReadByte();
                    A = _br.ReadByte();
                    b = new SolidBrush(Color.FromArgb(A, R, G, B));
                }
                else
                {
                    UInt32   BrushID = _br.ReadUInt32();
                    EMFBrush EMFb    = (EMFBrush)ObjectTable[(byte)BrushID];
                    b = EMFb.myBrush;
                }

                UInt32 FormatID     = _br.ReadUInt32(); // Index of Optional stringFormatobject in Object Table...
                UInt32 StringLength = _br.ReadUInt32();
                //bounding of string...
                Single recX      = _br.ReadSingle();
                Single recY      = _br.ReadSingle();
                Single recWidth  = _br.ReadSingle();
                Single recHeight = _br.ReadSingle();
                //Array of Chars...
                char[] StringData             = new char[StringLength];
                System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
                d.GetChars(_br.ReadBytes((int)StringLength * 2), 0, (int)StringLength * 2, StringData, 0);
                EMFFont      EF = (EMFFont)ObjectTable[(byte)ObjectID];
                Font         f  = EF.myFont;
                StringFormat sf;
                if (ObjectTable.Contains((byte)FormatID))
                {
                    EMFStringFormat ESF = (EMFStringFormat)ObjectTable[(byte)FormatID];
                    sf = ESF.myStringFormat;
                }
                else
                {
                    sf = new StringFormat();
                }

                DoInstructions(f, sf, b, recX, recY, recWidth, recHeight, new String(StringData));
                return(items);
            }
            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
                if (_fr != null)
                {
                    _fr.Close();
                }
                if (_fs != null)
                {
                    _fs.Dispose();
                }
            }
        }
Example #10
0
        public void NegTest2()
        {
            Char[] srcChars = GetCharArray(10);
            Char[] desChars = new Char[10];
            Byte[] bytes = null;
            UnicodeEncoding uEncoding = new UnicodeEncoding();
            int actualValue;

            Assert.Throws<ArgumentNullException>(() =>
            {
                actualValue = uEncoding.GetChars(bytes, 0, 0, desChars, 0);
            });
        }
Example #11
0
 public static string DecryptPassword(string password)
 {
     UnicodeEncoding ByteConverter = new UnicodeEncoding();
     StringBuilder sb = new StringBuilder();
     byte[] encryptedPassword = Convert.FromBase64String(password);
     sb.Append(ByteConverter.GetChars(ProtectedData.Unprotect(encryptedPassword, SmanConstants.ProtectionKey, DataProtectionScope.CurrentUser)));
     return sb.ToString();
 }
Example #12
0
 public void TestEncodingDecodingGetBytes2()
 {
         //pi and sigma in unicode
         string Unicode = "\u03a0\u03a3";
         UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); //big-endian 
         //Encode the unicode string.
         byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);
         //Decode the bytes to a unicode char array.
         char[] UniChars = UnicodeEnc.GetChars (UniBytes);
         string Result = new string(UniChars);
         
         Assert.AreEqual (Unicode, Result, "Uni #1");
 }
Example #13
0
        public void NegTest10()
        {
            Char[] srcChars = GetCharArray(10);
            Char[] desChars = new Char[10];
            Byte[] bytes = new Byte[20];
            UnicodeEncoding uEncoding = new UnicodeEncoding();
            int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
            int actualValue;

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                actualValue = uEncoding.GetChars(bytes, 0, 0, desChars, 11);
            });
        }
Example #14
0
 //
 // Returns null if property is not set.
 //
 protected string GetStringW(
     uint dwPropertyId)
 {
     UnicodeEncoding ue = new UnicodeEncoding();
     byte[] rgb;
     rgb = GetProperty(dwPropertyId);
     if((rgb == null) || (rgb.Length < 2))
         return null;
     // -2 to remove null term for wide character.
     else return new string(ue.GetChars( rgb, 0, rgb.Length - 2 ));
 }
Example #15
0
        private void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            if (!Directory.Exists("./Replays"))
            {
                Directory.CreateDirectory("./Replays");
            }
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.InitialDirectory = Directory.GetCurrentDirectory() + "\\Replays";
            dlg.DefaultExt = ".sgs"; // Default file extension
            dlg.Filter = "Replay File (.sgs)|*.sgs|Crash Report File (.rpt)|*.rpt|All Files (*.*)|*.*"; // Filter files by extension
            bool? result = dlg.ShowDialog();
            if (result != true) return;

            string fileName = dlg.FileName;

            Client client;
            MainGame game = null;
            try
            {
                client = new Client();
                game = new MainGame();
                game.OnNavigateBack += game_OnNavigateBack;
                Stream stream = File.Open(fileName, FileMode.Open);
                byte[] seed = new byte[8];
                stream.Seek(-16, SeekOrigin.End);
                stream.Read(seed, 0, 8);
                if (System.Text.Encoding.Default.GetString(seed).Equals(Misc.MagicAnimal.ToString("X8")))
                {
                    stream.Read(seed, 0, 8);
                    game.HasSeed = Convert.ToInt32(System.Text.Encoding.Default.GetString(seed), 16);
                }
                stream.Seek(0, SeekOrigin.Begin);

                byte[] bytes = new byte[4];
                stream.Read(bytes, 0, 4);
                int length = BitConverter.ToInt32(bytes, 0);
                if (length != 0)
                {
                    byte[] msg = new byte[length];
                    stream.Read(msg, 0, length);
                    UnicodeEncoding uniEncoding = new UnicodeEncoding();
                    MessageBox.Show(new String(uniEncoding.GetChars(msg)));
                }
                client.StartReplay(stream);
                game.NetworkClient = client;
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to open replay file.");
                return;
            }
            if (game != null)
            {
                MainGame.BackwardNavigationService = this.NavigationService;
                game.Start();
                // this.NavigationService.Navigate(game);
            }
        }
Example #16
0
		public void ZeroLengthArrays ()
		{
			UnicodeEncoding encoding = new UnicodeEncoding ();
			encoding.GetCharCount (new byte [0]);
			encoding.GetChars (new byte [0]);
			encoding.GetCharCount (new byte [0], 0, 0);
			encoding.GetChars (new byte [0], 0, 0);
			encoding.GetChars (new byte [0], 0, 0, new char [0], 0);
			encoding.GetByteCount (new char [0]);
			encoding.GetBytes (new char [0]);
			encoding.GetByteCount (new char [0], 0, 0);
			encoding.GetBytes (new char [0], 0, 0);
			encoding.GetBytes (new char [0], 0, 0, new byte [0], 0);
			encoding.GetByteCount ("");
			encoding.GetBytes ("");
		}
Example #17
0
        private static char[] ExtractUTF16_BigEndian(byte[] content, bool abortAfterTermination)
        {
            var data = new List<char>();

            // Create a Big Endian UTF 16 Encoder
            var encoder = new UnicodeEncoding(true, true);
            var chars = encoder.GetChars(content, 0, content.Length);
            foreach (var curChar in chars)
            {
                if (abortAfterTermination && curChar == '\u0000')
                {
                    break;
                }

                data.Add(curChar);
            }

            return data.ToArray();
        }
Example #18
0
        private static char[] ExtractUTF16(byte[] content, bool abortAfterTermination)
        {
            var data = new List<char>();

            if (content.Length > 4)
            {
                var bomBytes = new byte[2];
                Array.Copy(content, 0, bomBytes, 0, 2);
                var bigEndianEnabled = false;

                //
                //  See Byte Order Mask (BOM) UTF 16 for details
                //
                if (bomBytes[0] == 0xFE && bomBytes[1] == 0xFF)
                {
                    bigEndianEnabled = true;
                }

                var encoder = new UnicodeEncoding(bigEndianEnabled, true);
                var inputBytes = new byte[content.Length - 2];
                Array.Copy(content, 2, inputBytes, 0, inputBytes.Length);

                var chars = encoder.GetChars(inputBytes, 0, inputBytes.Length);
                foreach (var curChar in chars)
                {
                    if (abortAfterTermination && curChar == '\u0000')
                    {
                        break;
                    }

                    data.Add(curChar);
                }
            }

            return data.ToArray();
        }