Esempio n. 1
0
        public GFDv1(FileStream input)
        {
            _sourceFile = input.Name;

            if (_texAdapters == null || _texAdapters.Count == 0)
            {
                PluginLoader.ComposePlugins(this);
            }

            using (var br = new BinaryReaderX(input))
            {
                // Set endianess
                if (br.PeekString(4, Encoding.ASCII) == "\0DFG")
                {
                    br.ByteOrder = ByteOrder = ByteOrder.BigEndian;
                    br.BitOrder  = BitOrder = BitOrder.LSBFirst;
                }

                // Header
                Header  = br.ReadType <FileHeader>();
                HeaderF = br.ReadMultiple <float>(Header.FCount);

                // Name
                br.ReadInt32();
                Name = br.ReadCStringASCII();

                // Characters
                Characters = br.ReadMultiple <CharacterInfo>(Header.CharacterCount).Select(ci => new GFDv1Character
                {
                    Character = ci.Character,

                    GlyphX    = (int)ci.Block1.GlyphX,
                    GlyphY    = (int)ci.Block1.GlyphY,
                    TextureID = (int)ci.Block1.TextureIndex,

                    GlyphHeight = (int)ci.Block2.GlyphHeight,
                    GlyphWidth  = (int)ci.Block2.GlyphWidth,
                    XAdjust     = (int)ci.Block2.XAdjust,

                    IsSpace        = ci.Block3.IsSpace > 0 ? true : false,
                    Superscript    = ci.Block3.Superscript > 0 ? true : false,
                    CharacterWidth = (int)ci.Block3.CharacterWidth
                }).ToList();

                // Textures
                Textures = new List <Bitmap>();
                for (var i = 0; i < Header.FontTexCount; i++)
                {
                    //TODO
                    IMtFrameworkTextureAdapter texAdapter = null;//_texAdapters.Where(adapter => adapter is IIdentifyFiles).FirstOrDefault(adapter => ((IIdentifyFiles)adapter).Identify(GetTexName(_sourceFile, i)));
                    if (texAdapter == null)
                    {
                        continue;
                    }
                    //TODO
                    //((ILoadFiles)texAdapter).Load(GetTexName(_sourceFile, i));
                    Textures.Add(((IImageAdapter)texAdapter).BitmapInfos[0].Image);
                }
            }
        }
Esempio n. 2
0
        public GFDv1()
        {
            Header     = new FileHeader();
            HeaderF    = new List <float>();
            Name       = string.Empty;
            Characters = new List <GFDv1Character>();
            Textures   = new List <Bitmap>();

            if (_texAdapters == null || _texAdapters.Count == 0)
            {
                PluginLoader.ComposePlugins(this);
            }
        }
Esempio n. 3
0
        public GFDv1(StreamInfo input)
        {
            _sourceFile = input.FileName;

            if (_texAdapters == null || _texAdapters.Count == 0)
            {
                PluginLoader.ComposePlugins(this);
            }

            using (var br = new BinaryReaderX(input.FileData))
            {
                // Set endianess
                if (br.PeekString() == "\0DFG")
                {
                    br.ByteOrder = ByteOrder = ByteOrder.BigEndian;
                    br.BitOrder  = BitOrder = BitOrder.LSBFirst;
                }

                // Header
                Header  = br.ReadType <FileHeader>();
                HeaderF = br.ReadMultiple <float>(Header.FCount);

                // Name
                br.ReadInt32();
                Name = br.ReadCStringASCII();

                // Characters
                Characters = br.ReadMultiple <CharacterInfo>(Header.CharacterCount).Select(ci => new GFDv1Character
                {
                    Character = ci.Character,

                    WidthInfo = new CharWidthInfo
                    {
                        CharWidth  = (int)ci.Block2.GlyphWidth,
                        GlyphWidth = (int)ci.Block2.GlyphWidth,
                        Left       = (int)ci.Block2.XAdjust
                    },

                    GlyphX    = (int)ci.Block1.GlyphX,
                    GlyphY    = (int)ci.Block1.GlyphY,
                    TextureID = (int)ci.Block1.TextureIndex,

                    GlyphWidth  = (int)ci.Block2.GlyphWidth,
                    GlyphHeight = (int)ci.Block2.GlyphHeight,
                    XAdjust     = (int)ci.Block2.XAdjust,

                    IsSpace        = ci.Block3.IsSpace > 0,
                    Superscript    = ci.Block3.Superscript > 0,
                    CharacterWidth = (int)ci.Block3.CharacterWidth
                }).ToList();

                // Textures
                Textures = new List <Bitmap>();
                for (var i = 0; i < Header.FontTexCount; i++)
                {
                    var streamInfo = new StreamInfo {
                        FileData = File.OpenRead(GetTexName(_sourceFile, i)), FileName = GetTexName(_sourceFile, i)
                    };
                    var texAdapter = _texAdapters.Where(adapter => adapter is IIdentifyFiles).FirstOrDefault(adapter => ((IIdentifyFiles)adapter).Identify(streamInfo));
                    streamInfo.FileData.Position = 0;
                    if (texAdapter == null)
                    {
                        continue;
                    }
                    ((ILoadFiles)texAdapter).Load(streamInfo);
                    Textures.Add(((IImageAdapter)texAdapter).BitmapInfos[0].Image);
                }

                // Glyphs
                foreach (var c in Characters)
                {
                    var width  = c.WidthInfo.GlyphWidth;
                    var height = c.GlyphHeight;

                    var glyph = new Bitmap(Math.Max(width, 1), Math.Max(height, 1), PixelFormat.Format32bppArgb);
                    var gfx   = Graphics.FromImage(glyph);
                    gfx.DrawImage(Textures[c.TextureID],
                                  new[] {
                        new PointF(0, 0),
                        new PointF(width, 0),
                        new PointF(0, height)
                    },
                                  new RectangleF(c.GlyphX, c.GlyphY, width, height),
                                  GraphicsUnit.Pixel);
                    c.Glyph = glyph;
                }
            }
        }