Пример #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)
                    {
                        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;
                            }
                        }
                    }
                }
            }
        }