Exemple #1
0
        public unsafe Bitmap GetText(int fontId, string text, short hueId)
        {
            UnicodeFont font = _fonts[fontId];

            int width  = font.GetWidth(text);
            int height = font.GetHeight(text);

            Bitmap     bmp = new Bitmap(width, height, PixelFormat.Format16bppArgb1555);
            BitmapData bd  = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);

            ushort *line  = (ushort *)bd.Scan0;
            int     delta = bd.Stride >> 1;

            int dx = 2;

            for (int i = 0; i < text.Length; ++i)
            {
                int         c  = (int)text[i] % 0x10000;
                UnicodeChar ch = font.Chars[c];

                int charWidth  = ch.Width;
                int charHeight = ch.Height;

                byte[] data = ch.Bytes;

                if (c == 32)
                {
                    dx += 5;
                    continue;
                }
                else
                {
                    dx += ch.XOffset;
                }

                for (int dy = 0; dy < charHeight; ++dy)
                {
                    ushort *dest = (line + (delta * (dy + (height - charHeight)))) + (dx);

                    for (int k = 0; k < charWidth; ++k)
                    {
                        int offset = k / 8 + dy * ((charWidth + 7) / 8);

                        if (offset > data.Length)
                        {
                            continue;
                        }

                        if ((data[offset] & (1 << (7 - (k % 8)))) != 0)
                        {
                            *dest++ = 0x8000;
                        }
                        else
                        {
                            *dest++ = 0x0000;
                        }
                    }
                }

                dx += ch.Width;
            }

            bmp.UnlockBits(bd);

            return(bmp);
        }
Exemple #2
0
        public unsafe ImageSource GetText(int fontId, string text, short hueId)
        {
            UnicodeFont font = _fonts[fontId];

            int width  = font.GetWidth(text);
            int height = font.GetHeight(text);

            WriteableBitmap bmp = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr555, null);

            bmp.Lock();

            ushort *line  = (ushort *)bmp.BackBuffer;
            int     delta = bmp.BackBufferStride >> 1;

            int dx = 2;

            for (int i = 0; i < text.Length; ++i)
            {
                int         c  = (int)text[i] % 0x10000;
                UnicodeChar ch = font.Chars[c];

                int charWidth  = ch.Width;
                int charHeight = ch.Height;

                byte[] data = ch.Bytes;

                if (c == 32)
                {
                    dx += 5;
                    continue;
                }
                else
                {
                    dx += ch.XOffset;
                }

                for (int dy = 0; dy < charHeight; ++dy)
                {
                    ushort *dest = (line + (delta * (dy + (height - charHeight)))) + (dx);

                    for (int k = 0; k < charWidth; ++k)
                    {
                        int offset = k / 8 + dy * ((charWidth + 7) / 8);

                        if (offset > data.Length)
                        {
                            continue;
                        }

                        if ((data[offset] & (1 << (7 - (k % 8)))) != 0)
                        {
                            *dest++ = 0x8000;
                        }
                        else
                        {
                            *dest++ = 0x0000;
                        }
                    }
                }

                dx += ch.Width;
            }

            bmp.AddDirtyRect(new Int32Rect(0, 0, width, height));
            bmp.Unlock();

            return(bmp);
        }
Exemple #3
0
        public unsafe Texture GetText(int fontId, string text, short hueId)
        {
            UnicodeFont font = _fonts[fontId];

            int width  = font.GetWidth(text);
            int height = font.GetHeight(text);

            Texture       texture = new Texture(_device, width, height, 0, Usage.None, Format.A1R5G5B5, Pool.Managed);
            DataRectangle rect    = texture.LockRectangle(0, LockFlags.None);

            ushort *line  = (ushort *)rect.DataPointer;
            int     delta = rect.Pitch >> 1;

            int dx = 2;

            for (int i = 0; i < text.Length; ++i)
            {
                int         c  = (int)text[i] % 0x10000;
                UnicodeChar ch = font.Chars[c];

                int charWidth  = ch.Width;
                int charHeight = ch.Height;

                byte[] data = ch.Bytes;

                if (c == 32)
                {
                    dx += 5;
                    continue;
                }
                else
                {
                    dx += ch.XOffset;
                }

                for (int dy = 0; dy < charHeight; ++dy)
                {
                    ushort *dest = (line + (delta * (dy + (height - charHeight)))) + (dx);

                    for (int k = 0; k < charWidth; ++k)
                    {
                        int offset = k / 8 + dy * ((charWidth + 7) / 8);

                        if (offset > data.Length)
                        {
                            continue;
                        }

                        if ((data[offset] & (1 << (7 - (k % 8)))) != 0)
                        {
                            *dest++ = 0x8000;
                        }
                        else
                        {
                            *dest++ = 0x0000;
                        }
                    }
                }

                dx += ch.Width;
            }

            texture.UnlockRectangle(0);

            return(texture);
        }