Exemplo n.º 1
0
        public override int CharWidth(char ch)
        {
            FntGlyph g = ((FntFont)(font)).GetLoader().GetGlyph(ch);

            if (g != null)
            {
                return((int)((g.Width + 1) & ~1));
            }
            return(0);
        }
Exemplo n.º 2
0
        public FntGlyph GetGlyph(char c)
        {
            if (((int)c) > 255)
            {
                return(NotDefChar);
            }
            FntGlyph g = Glyphs[((int)c) - 1];

            if (g == null)
            {
                return(NotDefChar);
            }
            return(g);
        }
Exemplo n.º 3
0
        public override int[] CharsWidths(char[] chars, int start, int len)
        {
            int[] advances = new int[len];
            int   adv_idx  = 0;

            for (int i = start; i < start + len; i++)
            {
                FntGlyph glyph = ((FntFont)(font)).GetLoader().GetGlyph(chars[i]);
                if (adv_idx == 0)
                {
                    advances[adv_idx++] = glyph.Width;
                }
                else
                {
                    advances[adv_idx++] = advances[adv_idx - 1] + glyph.Width;
                }
            }

            return(advances);
        }
Exemplo n.º 4
0
        public void Load(Stream s)
        {
            BinaryReader br = new BinaryReader(s);

            byte[] buf;


            Version = br.ReadUInt16();
            if (Version != 0x0300 && Version != 0x0200)
            {
                throw new Exception("Unknown format version!");
            }

            FileSize = br.ReadUInt32();
            if (FileSize != s.Length)
            {
                throw new Exception("FileSize incorrect! Possible corrupt file?");
            }

            buf       = br.ReadBytes(60);
            Copyright = System.Text.ASCIIEncoding.ASCII.GetString(buf).Replace("\0", "");
            buf       = null;

            Type = br.ReadUInt16();
            if ((Type & 1) == 1)
            {
                throw new Exception("Can't handle Vector FNT files.");
            }
            PointSize       = br.ReadUInt16();
            VertDpi         = br.ReadUInt16();
            HorizDpi        = br.ReadUInt16();
            Ascent          = br.ReadUInt16();
            InternalLeading = br.ReadUInt16();
            ExternalLeading = br.ReadUInt16();

            if (br.ReadByte() != 0)
            {
                IsItalic = true;
            }
            else
            {
                IsItalic = false;
            }

            if (br.ReadByte() != 0)
            {
                IsUnderline = true;
            }
            else
            {
                IsUnderline = false;
            }

            if (br.ReadByte() != 0)
            {
                IsStrikeOut = true;
            }
            else
            {
                IsStrikeOut = false;
            }

            Weight         = br.ReadUInt16();
            CharSet        = br.ReadByte();
            PixWidth       = br.ReadUInt16();
            PixHeight      = br.ReadUInt16();
            PitchAndFamily = br.ReadByte();
            AvgWidth       = br.ReadUInt16();
            MaxWidth       = br.ReadUInt16();
            FirstChar      = br.ReadByte();
            LastChar       = br.ReadByte();
            DefaultChar    = br.ReadByte();
            BreakChar      = br.ReadByte();
            WidthBytes     = br.ReadUInt16();

            long   position;
            string deviceName = "";
            char   curChar    = ' ';

            #region Read Device Name
            Device   = br.ReadUInt32();
            position = br.BaseStream.Position;
            br.BaseStream.Position = Device;
            br.BaseStream.Flush();
            while (curChar != '\u0000')
            {
                deviceName += curChar;
                curChar     = (char)br.ReadByte();
            }
            br.BaseStream.Position = position;
            br.BaseStream.Flush();
            DeviceName = deviceName.Substring(1);
            #endregion

            #region Read Face Name
            Face                   = br.ReadUInt32();
            deviceName             = ""; // re-use the variable.
            curChar                = ' ';
            position               = br.BaseStream.Position;
            br.BaseStream.Position = Face;
            br.BaseStream.Flush();
            // loop while it's not the null terminator.
            while (curChar != '\u0000')
            {
                deviceName += curChar;
                curChar     = (char)br.ReadByte();
            }
            br.BaseStream.Position = position;
            br.BaseStream.Flush();
            // account for the extra char we added.
            FaceName = deviceName.Substring(1);
            #endregion

            BitsPointer = br.ReadUInt32();
            BitsOffset  = br.ReadUInt32();

            br.ReadByte(); // Not used.

            if (Version == 0x0300)
            {
                Flags        = br.ReadUInt32();
                ASpace       = br.ReadUInt16();
                BSpace       = br.ReadUInt16();
                CSpace       = br.ReadUInt16();
                ColorPointer = br.ReadUInt32();

                br.ReadBytes(16); // Not used.
            }

            // Next is the character table.
            List <FntGlyph> chars = new List <FntGlyph>();
            FntGlyph        g;
            uint            nChars = (uint)((LastChar - FirstChar) + 2);
            position = 0;
            long loc;
            int  bytesToRead;
            if (Version == 0x0200)
            {
                this.GlyphType = FntGlyphType.Version2;
                for (uint c = 0; c < nChars; c++)
                {
                    g        = new FntGlyph();
                    g.Width  = br.ReadUInt16();
                    g.Type   = FntGlyphType.Version2;
                    g.Height = PixHeight;
                    g.Font   = this;

                    #region Read Data
                    loc      = br.ReadUInt16();
                    position = br.BaseStream.Position;
                    br.BaseStream.Position = loc;
                    br.BaseStream.Flush();
                    bytesToRead            = (int)(((g.Width + 7) >> 3) * (PixHeight));
                    g.RawData              = br.ReadBytes(bytesToRead);
                    br.BaseStream.Position = position;
                    br.BaseStream.Flush();
                    #endregion

                    chars.Add(g);
                }
            }

            for (int i = 0; i < chars.Count; i++)
            {
                chars[i].Initialize();
            }
            Array.Copy(chars.ToArray(), 0, Glyphs, FirstChar - 1, chars.Count - 1);
            //Glyphs = chars;
            NotDefChar = chars[chars.Count - 1];
            //throw new Exception();

            //else // version == 0x0300
            //{
            //    if ((Flags & FixedFlagMask) == FixedFlagMask || (Flags & ProportionalFlagMask) == ProportionalFlagMask)
            //    {
            //        FntGlyphType t;
            //        if ((Flags & FixedFlagMask) == FixedFlagMask)
            //        {
            //            t = FntGlyphType.Fixed;
            //        }
            //        else
            //        {
            //            t = FntGlyphType.Proportional;
            //        }
            //        for (uint c = 0; c < nChars; c++)
            //        {
            //            g = new FntGlyph();
            //            g.Type = t;

            //        }
            //    }
            //    else if ((Flags & ABCFixedFlagMask) == ABCFixedFlagMask || (Flags & ABCProportionalFlagMask) == ABCProportionalFlagMask)
            //    {
            //        for (uint c = 0; c < nChars; c++)
            //        {

            //        }
            //    }
            //    else // A color flag.
            //    {
            //        for (uint c = 0; c < nChars; c++)
            //        {

            //        }
            //    }
            //}
        }
Exemplo n.º 5
0
        public void Load(Stream s)
        {
            BinaryReader br = new BinaryReader(s);
            byte[] buf;


            Version = br.ReadUInt16();
            if (Version != 0x0300 && Version != 0x0200)
            {
                throw new Exception("Unknown format version!");
            }

            FileSize = br.ReadUInt32();
            if (FileSize != s.Length)
            {
                throw new Exception("FileSize incorrect! Possible corrupt file?");
            }

            buf = br.ReadBytes(60);
            Copyright = System.Text.ASCIIEncoding.ASCII.GetString(buf).Replace("\0", "");
            buf = null;

            Type = br.ReadUInt16();
            if ((Type & 1) == 1)
            {
                throw new Exception("Can't handle Vector FNT files.");
            }
            PointSize = br.ReadUInt16();
            VertDpi = br.ReadUInt16();
            HorizDpi = br.ReadUInt16();
            Ascent = br.ReadUInt16();
            InternalLeading = br.ReadUInt16();
            ExternalLeading = br.ReadUInt16();

            if (br.ReadByte() != 0)
            {
                IsItalic = true;
            }
            else
            {
                IsItalic = false;
            }

            if (br.ReadByte() != 0)
            {
                IsUnderline = true;
            }
            else
            {
                IsUnderline = false;
            }

            if (br.ReadByte() != 0)
            {
                IsStrikeOut = true;
            }
            else
            {
                IsStrikeOut = false;
            }

            Weight = br.ReadUInt16();
            CharSet = br.ReadByte();
            PixWidth = br.ReadUInt16();
            PixHeight = br.ReadUInt16();
            PitchAndFamily = br.ReadByte();
            AvgWidth = br.ReadUInt16();
            MaxWidth = br.ReadUInt16();
            FirstChar = br.ReadByte();
            LastChar = br.ReadByte();
            DefaultChar = br.ReadByte();
            BreakChar = br.ReadByte();
            WidthBytes = br.ReadUInt16();
            
            long position;
            string deviceName = "";
            char curChar = ' ';
            
            #region Read Device Name
            Device = br.ReadUInt32();
            position = br.BaseStream.Position;
            br.BaseStream.Position = Device;
            br.BaseStream.Flush();
            while (curChar != '\u0000')
            {
            	deviceName += curChar;
            	curChar = (char)br.ReadByte();
            }
            br.BaseStream.Position = position;
            br.BaseStream.Flush();
            DeviceName = deviceName.Substring(1);
            #endregion
                    
            #region Read Face Name
            Face = br.ReadUInt32();
            deviceName = ""; // re-use the variable.
            curChar = ' ';
            position = br.BaseStream.Position;
            br.BaseStream.Position = Face;
            br.BaseStream.Flush();
            // loop while it's not the null terminator.
            while (curChar != '\u0000')
            {
            	deviceName += curChar;
            	curChar = (char)br.ReadByte();
            }
            br.BaseStream.Position = position;
            br.BaseStream.Flush();
            // account for the extra char we added.
            FaceName = deviceName.Substring(1);
            #endregion
            
            BitsPointer = br.ReadUInt32();
            BitsOffset = br.ReadUInt32();

            br.ReadByte(); // Not used.

            if (Version == 0x0300)
            {
                Flags = br.ReadUInt32();
                ASpace = br.ReadUInt16();
                BSpace = br.ReadUInt16();
                CSpace = br.ReadUInt16();
                ColorPointer = br.ReadUInt32();

                br.ReadBytes(16); // Not used.
            }

            // Next is the character table.
            List<FntGlyph> chars = new List<FntGlyph>();
            FntGlyph g;
            uint nChars = (uint)((LastChar - FirstChar) + 2);
            position = 0;
            long loc;
            int bytesToRead;
            if (Version == 0x0200)
            {
            	this.GlyphType = FntGlyphType.Version2;
                for (uint c = 0; c < nChars; c++)
                {
                    g = new FntGlyph();
                    g.Width = br.ReadUInt16();
                    g.Type = FntGlyphType.Version2;
                    g.Height = PixHeight;
                    g.Font = this;

                    #region Read Data
                    loc = br.ReadUInt16();
                    position = br.BaseStream.Position;
                    br.BaseStream.Position = loc;
                    br.BaseStream.Flush();
                    bytesToRead = (int)(((g.Width + 7) >> 3) * (PixHeight));
                    g.RawData = br.ReadBytes(bytesToRead);
                    br.BaseStream.Position = position;
                    br.BaseStream.Flush();
                    #endregion

                    chars.Add(g);

                }
            }

            for (int i = 0; i < chars.Count; i++)
            {
                chars[i].Initialize();
            }
            Array.Copy(chars.ToArray(), 0, Glyphs, FirstChar - 1, chars.Count - 1);
            //Glyphs = chars;
            NotDefChar = chars[chars.Count - 1];
            //throw new Exception();

            //else // version == 0x0300
            //{
            //    if ((Flags & FixedFlagMask) == FixedFlagMask || (Flags & ProportionalFlagMask) == ProportionalFlagMask)
            //    {
            //        FntGlyphType t;
            //        if ((Flags & FixedFlagMask) == FixedFlagMask)
            //        {
            //            t = FntGlyphType.Fixed;
            //        }
            //        else
            //        {
            //            t = FntGlyphType.Proportional;
            //        }
            //        for (uint c = 0; c < nChars; c++)
            //        {
            //            g = new FntGlyph();
            //            g.Type = t;

            //        }
            //    }
            //    else if ((Flags & ABCFixedFlagMask) == ABCFixedFlagMask || (Flags & ABCProportionalFlagMask) == ABCProportionalFlagMask)
            //    {
            //        for (uint c = 0; c < nChars; c++)
            //        {

            //        }
            //    }
            //    else // A color flag.
            //    {
            //        for (uint c = 0; c < nChars; c++)
            //        {

            //        }
            //    }
            //}

        }