示例#1
0
        public unsafe static Bitmap DrawText(int fontId, string text, short hueId)
        {
            ASCIIFont font = ASCIIFont.GetFixed(fontId);

            Bitmap result =
                new Bitmap(font.GetWidth(text), font.Height);
            BitmapData surface =
                result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            int dx = 0;

            for (int i = 0; i < text.Length; ++i)
            {
                Bitmap bmp =
                    font.GetBitmap(text[i]);
                BitmapData chr =
                    bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                for (int dy = 0; dy < chr.Height; ++dy)
                {
                    byte *src =
                        ((byte *)chr.Scan0) + (chr.Stride * dy);
                    byte *dest =
                        (((byte *)surface.Scan0) + (surface.Stride * (dy + (font.Height - chr.Height)))) + (dx << 2);

                    for (int k = 0; k < chr.Width; ++k)
                    {
                        *dest++ = *src++;
                        *dest++ = *src++;
                        *dest++ = *src++;
                        *dest++ = *src++;
                    }
                }

                dx += chr.Width;
                bmp.UnlockBits(chr);
            }

            result.UnlockBits(surface);

            hueId = (short)((hueId & 0x3FFF) - 1);
            if (hueId >= 0 && hueId < Hues.List.Length)
            {
                Hue hueObject = Hues.List[hueId];

                if (hueObject != null)
                {
                    hueObject.ApplyTo(result, ((hueId & 0x8000) == 0));
                }
            }

            return(result);
        }
示例#2
0
        static ASCIIText()
        {
            string path = Client.GetFilePath("fonts.mul");

            if (path != null)
            {
                using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open)))
                {
                    for (int i = 0; i < 10; ++i)
                    {
                        Fonts[i] = new ASCIIFont();

                        byte header = reader.ReadByte();

                        for (int k = 0; k < 224; ++k)
                        {
                            byte width  = reader.ReadByte();
                            byte height = reader.ReadByte();
                            reader.ReadByte();                             // delimeter?

                            if (width > 0 && height > 0)
                            {
                                if (height > Fonts[i].Height && k < 96)
                                {
                                    Fonts[i].Height = height;
                                }

                                Bitmap bmp = new Bitmap(width, height);

                                for (int y = 0; y < height; ++y)
                                {
                                    for (int x = 0; x < width; ++x)
                                    {
                                        short pixel = (short)(reader.ReadByte() | (reader.ReadByte() << 8));

                                        if (pixel != 0)
                                        {
                                            bmp.SetPixel(x, y, Color.FromArgb((pixel & 0x7C00) >> 7, (pixel & 0x3E0) >> 2, (pixel & 0x1F) << 3));
                                        }
                                    }
                                }

                                Fonts[i].Characters[k] = bmp;
                            }
                        }
                    }
                }
            }
        }
示例#3
0
		static ASCIIText()
		{
			string path = Client.GetFilePath( "fonts.mul" );

			if( path != null )
			{
				using( BinaryReader reader = new BinaryReader( new FileStream( path, FileMode.Open ) ) )
				{
					for( int i = 0; i < 10; ++i )
					{
						m_Fonts[ i ] = new ASCIIFont();

						byte header = reader.ReadByte();

						for( int k = 0; k < 224; ++k )
						{
							byte width = reader.ReadByte();
							byte height = reader.ReadByte();
							reader.ReadByte(); // delimeter?

							if( width > 0 && height > 0 )
							{
								if( height > m_Fonts[ i ].Height && k < 96 )
								{
									m_Fonts[ i ].Height = height;
								}

								Bitmap bmp = new Bitmap( width, height );

								for( int y = 0; y < height; ++y )
								{
									for( int x = 0; x < width; ++x )
									{
										short pixel = (short)( reader.ReadByte() | ( reader.ReadByte() << 8 ) );

										if( pixel != 0 )
										{
											bmp.SetPixel( x, y, Color.FromArgb( ( pixel & 0x7C00 ) >> 7, ( pixel & 0x3E0 ) >> 2, ( pixel & 0x1F ) << 3 ) );
										}
									}
								}

								m_Fonts[ i ].Characters[ k ] = bmp;
							}
						}
					}
				}
			}
		}
示例#4
0
        /// <summary>
        /// Draws Text with font in Bitmap and returns
        /// </summary>
        /// <param name="fontId"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static Bitmap DrawText(int fontId, string text)
        {
            ASCIIFont font   = ASCIIFont.GetFixed(fontId);
            Bitmap    result = new Bitmap(font.GetWidth(text) + 2, font.Height + 2);

            int dx = 2;
            int dy = font.Height + 2;

            using (Graphics graph = Graphics.FromImage(result))
            {
                for (int i = 0; i < text.Length; ++i)
                {
                    Bitmap bmp = font.GetBitmap(text[i]);
                    graph.DrawImage(bmp, dx, dy - bmp.Height);
                    dx += bmp.Width;
                }
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// Draws Text with font in Bitmap and returns
        /// </summary>
        /// <param name="fontId"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static Bitmap DrawText(int fontId, string text)
        {
            ASCIIFont font   = ASCIIFont.GetFixed(fontId);
            var       result = new Bitmap(font.GetWidth(text) + 2, font.Height + 2);

            int dx = 2;
            int dy = font.Height + 2;

            using (Graphics graph = Graphics.FromImage(result))
            {
                foreach (var character in text)
                {
                    Bitmap bmp = font.GetBitmap(character);
                    graph.DrawImage(bmp, dx, dy - bmp.Height);
                    dx += bmp.Width;
                }
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Reads fonts.mul
        /// </summary>
        public static unsafe void Initialize()
        {
            string path = Files.GetFilePath("fonts.mul");

            if (path != null)
            {
                using (FileStream reader = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    byte[] buffer = new byte[(int)reader.Length];
                    reader.Read(buffer, 0, (int)reader.Length);
                    fixed(byte *bin = buffer)
                    {
                        byte *read = bin;

                        for (int i = 0; i < 10; ++i)
                        {
                            byte header = *read++;
                            Fonts[i] = new ASCIIFont(header);

                            for (int k = 0; k < 224; ++k)
                            {
                                byte width  = *read++;
                                byte height = *read++;
                                byte unk    = *read++; // delimeter?

                                if (width > 0 && height > 0)
                                {
                                    if (height > Fonts[i].Height && k < 96)
                                    {
                                        Fonts[i].Height = height;
                                    }

                                    Bitmap     bmp = new Bitmap(width, height);
                                    BitmapData bd  = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                                                  ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
                                    ushort *line  = (ushort *)bd.Scan0;
                                    int     delta = bd.Stride >> 1;

                                    for (int y = 0; y < height; ++y, line += delta)
                                    {
                                        ushort *cur = line;
                                        for (int x = 0; x < width; ++x)
                                        {
                                            ushort pixel = (ushort)(*read++ | (*read++ << 8));
                                            if (pixel == 0)
                                            {
                                                cur[x] = pixel;
                                            }
                                            else
                                            {
                                                cur[x] = (ushort)(pixel ^ 0x8000);
                                            }
                                        }
                                    }

                                    bmp.UnlockBits(bd);
                                    Fonts[i].Characters[k] = bmp;
                                    Fonts[i].Unk[k]        = unk;
                                }
                            }
                        }
                    }
                }
            }
        }
		/// <summary>
		///     Reads fonts.mul
		/// </summary>
		public static unsafe void Initialize()
		{
			string path = Files.GetFilePath("fonts.mul");

			if (path != null)
			{
				using (var reader = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					var buffer = new byte[(int)reader.Length];
					reader.Read(buffer, 0, (int)reader.Length);
					fixed (byte* bin = buffer)
					{
						byte* read = bin;
						for (int i = 0; i < 10; ++i)
						{
							byte header = *read++;
							Fonts[i] = new ASCIIFont(header);

							for (int k = 0; k < 224; ++k)
							{
								byte width = *read++;
								byte height = *read++;
								byte unk = *read++; // delimeter?

								if (width > 0 && height > 0)
								{
									if (height > Fonts[i].Height && k < 96)
									{
										Fonts[i].Height = height;
									}

									var bmp = new Bitmap(width, height);
									BitmapData bd = bmp.LockBits(
										new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
									var line = (ushort*)bd.Scan0;
									int delta = bd.Stride >> 1;

									for (int y = 0; y < height; ++y, line += delta)
									{
										ushort* cur = line;
										for (int x = 0; x < width; ++x)
										{
											var pixel = (ushort)(*read++ | (*read++ << 8));
											if (pixel == 0)
											{
												cur[x] = pixel;
											}
											else
											{
												cur[x] = (ushort)(pixel ^ 0x8000);
											}
										}
									}
									bmp.UnlockBits(bd);
									Fonts[i].Characters[k] = bmp;
									Fonts[i].Unk[k] = unk;
								}
							}
						}
					}
				}
			}
		}