Exemplo n.º 1
0
        public float DrawCharacter(BGICanvas bgi, float x, float y, BGICanvas.Direction dir, int size, byte character, IList <Rectangle> updates)
        {
            BGICharacter ch = this[character];

            if (ch != null)
            {
                var drawUpdates = updates ?? new List <Rectangle>();
                ch.Draw(bgi, x, y, dir, size, updates);
                if (updates == null)
                {
                    bgi.UpdateRegion(drawUpdates);
                }
                return(ch.GetWidth(size));
            }
            return(0);
        }
Exemplo n.º 2
0
        public Size GetTextSize(string str, BGICanvas.Direction dir, int size)
        {
            float width = 0;

            foreach (byte c in BGICanvas.Encoding.GetBytes(str))
            {
                BGICharacter ch = this[c];
                if (ch != null)
                {
                    width += ch.Width;
                }
            }
            if (dir == BGICanvas.Direction.Horizontal)
            {
                return(new Size(BGICanvas.Trunc(width * BGICharacter.scaleup[size] / BGICharacter.scaledown[size]), (int)((Height + Math.Abs(OriginToDescender) + 1) * BGICharacter.scaleup[size] / BGICharacter.scaledown[size])));
            }
            else
            {
                return(new Size((int)((Height + Math.Abs(OriginToDescender) + 1) * BGICharacter.scaleup[size] / BGICharacter.scaledown[size]), BGICanvas.Trunc(width * BGICharacter.scaleup[size] / BGICharacter.scaledown[size])));
            }
        }
Exemplo n.º 3
0
        public void Load(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);
            byte         b;

            do
            {
                b = br.ReadByte();
            } while (b != 0x1a);

            // fheader
            headerSize = br.ReadUInt16();
            byte[] name = br.ReadBytes(4);
            fontName  = Encoding.ASCII.GetString(name);
            fontSize  = br.ReadUInt16();
            fontMajor = br.ReadByte();
            fontMinor = br.ReadByte();
            minMajor  = br.ReadByte();
            minMinor  = br.ReadByte();

            stream.Position = headerSize;

            // header
            sig            = br.ReadByte();
            characterCount = br.ReadInt16();
            br.ReadByte();             // unused byte
            first           = br.ReadByte();
            characterOffset = br.ReadInt16();
            scanFlag        = br.ReadByte();
            org_to_cap      = br.ReadSByte();
            org_to_base     = br.ReadSByte();
            org_to_dec      = br.ReadSByte();
            byte[] shortName = br.ReadBytes(4);
            shortFontName = Encoding.ASCII.GetString(shortName);
            br.ReadByte();             // unused byte

            // read offset table
            Int16[] fontOffsets = new Int16[256];
            for (int i = first; i < first + characterCount; i++)
            {
                fontOffsets[i] = br.ReadInt16();
            }

            // read character width table
            byte[] charWidths = new byte[256];
            for (int i = first; i < first + characterCount; i++)
            {
                charWidths[i] = br.ReadByte();
            }

            characters = new BGICharacter[256];

            long start = stream.Position;

            for (int i = first; i < first + characterCount; i++)
            {
                stream.Seek(start + fontOffsets[i], SeekOrigin.Begin);
                characters[i] = new BGICharacter(this, stream, charWidths[i]);
            }

            capitalHeight   = 40;
            baseHeight      = 0;
            descenderHeight = -7;
            BGICharacter bc;

            bc = characters[(int)'E'];
            if (bc == null)
            {
                bc = characters[(int)'M'];
            }
            if (bc != null)
            {
                bool isFirst = true;
                int  min     = 0;
                int  max     = 0;
                foreach (BGICharacter.Stroke s in bc.Strokes)
                {
                    if (isFirst || max < s.y)
                    {
                        max = s.y;
                    }
                    if (isFirst || min > s.y)
                    {
                        min = s.y;
                    }
                    isFirst = false;
                }
                capitalHeight = Math.Abs(max);
                baseHeight    = Math.Abs(min);
            }
            lowerCaseHeight = capitalHeight / 2;

            bc = characters[(int)'q'];
            if (bc != null)
            {
                bool isFirst = true;
                int  min     = 0;
                int  max     = 0;
                foreach (BGICharacter.Stroke s in bc.Strokes)
                {
                    if (isFirst || max < s.y)
                    {
                        max = s.y;
                    }
                    if (isFirst || min > s.y)
                    {
                        min = s.y;
                    }
                    isFirst = false;
                }
                descenderHeight = Math.Abs(min);
            }

            bc = characters[(int)'x'];
            if (bc != null)
            {
                bool isFirst = true;
                int  min     = 0;
                int  max     = 0;
                foreach (BGICharacter.Stroke s in bc.Strokes)
                {
                    if (isFirst || max < s.y)
                    {
                        max = s.y;
                    }
                    if (isFirst || min > s.y)
                    {
                        min = s.y;
                    }
                    isFirst = false;
                }
                lowerCaseHeight = Math.Abs(max);
            }

            //Console.WriteLine("Font {0}", this);
            loaded = true;
        }