Exemple #1
0
        public virtual void Refresh()
        {
            if (!this.m_Invalidated)
            {
                return;
            }
            UnicodeFont unicodeFont = this.m_Font as UnicodeFont;
            bool        flag        = unicodeFont != null && unicodeFont.Underline;
            int         num         = unicodeFont == null ? 0 : unicodeFont.SpaceWidth;

            if (unicodeFont != null)
            {
                unicodeFont.Underline = this.m_Underline;
            }
            if (unicodeFont != null && this.m_SpaceWidth > 0)
            {
                unicodeFont.SpaceWidth = this.m_SpaceWidth;
            }
            this.m_Image = this.m_Font.GetString(this.m_Text, this.m_Hue);
            if (this.m_Image != null && !this.m_Image.IsEmpty())
            {
                this.m_Width  = this.m_Image.Width;
                this.m_Height = this.m_Image.Height;
                this.m_Draw   = true;
            }
            else
            {
                this.m_Draw = false;
            }
            this.m_Invalidated = false;
            if (this.m_vCache != null)
            {
                this.m_vCache.Invalidate();
            }
            if (unicodeFont != null)
            {
                unicodeFont.Underline = flag;
            }
            if (unicodeFont == null)
            {
                return;
            }
            unicodeFont.SpaceWidth = num;
        }
        public override void Initialize()
        {
            base.Initialize();

            var install = Install;

            var fonts = new List <UnicodeFont>();

            var i    = 0;
            var path = install.GetPath(FILE_NAME_FORMAT, string.Empty);

            while (File.Exists(path))
            {
                var font = new UnicodeFont();

                var maxHeight = 0;

                using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var length = (int)fs.Length;
                    var buffer = new byte[length];

                    fs.Read(buffer, 0, buffer.Length);

                    using (var stream = new MemoryStream(buffer))
                    {
                        using (var bin = new BinaryReader(stream))
                        {
                            for (var c = 0; c < 0x10000; ++c)
                            {
                                font.Chars[c] = new UnicodeChar();
                                stream.Seek(((c) * 4), SeekOrigin.Begin);

                                var index = bin.ReadInt32();

                                if ((index >= fs.Length) || (index <= 0))
                                {
                                    continue;
                                }

                                stream.Seek(index, SeekOrigin.Begin);

                                var xOffset = bin.ReadSByte();
                                var yOffset = bin.ReadSByte();

                                int width  = bin.ReadByte();
                                int height = bin.ReadByte();

                                maxHeight = Math.Max(height, maxHeight);

                                font.Chars[c].XOffset = xOffset;
                                font.Chars[c].YOffset = yOffset;
                                font.Chars[c].Width   = width;
                                font.Chars[c].Height  = height;

                                if (!((width == 0) || (height == 0)))
                                {
                                    font.Chars[c].Bytes = bin.ReadBytes(height * (((width - 1) / 8) + 1));
                                }
                            }
                        }
                    }
                }

                font.Height = maxHeight;
                fonts.Add(font);
                path = install.GetPath(FILE_NAME_FORMAT, ++i);
            }

            _fonts = fonts.ToArray();
        }
Exemple #3
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 #4
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 #5
0
 public FontInfo(UnicodeFont font, int color)
 {
     this.m_Font  = font;
     this.m_Color = color;
     this.m_Hue   = (IHue) new Hues.ColorFillHue(color);
 }
Exemple #6
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);
        }