Exemple #1
0
        private FontHeader ReadHeadTable()
        {
            if (!_tables.ContainsKey("head"))
            {
                throw new Exception("Bad font: Header table missing");
            }
            _file.Seek(_tables["head"].Offset);

            var h = new FontHeader();

            // DO NOT REARRANGE CALLS!
            h.Version            = _file.GetFixed();
            h.Revision           = _file.GetFixed();
            h.ChecksumAdjustment = _file.GetUint32();
            h.MagicNumber        = _file.GetUint32();

            if (h.MagicNumber != HeaderMagic)
            {
                throw new Exception("Bad font: incorrect identifier in header table");
            }

            h.Flags      = _file.GetUint16();
            h.UnitsPerEm = _file.GetUint16();
            h.Created    = _file.GetDate();
            h.Modified   = _file.GetDate();

            h.xMin = _file.GetFWord();
            h.yMin = _file.GetFWord();
            h.xMax = _file.GetFWord();
            h.yMax = _file.GetFWord();

            h.MacStyle          = _file.GetUint16();
            h.LowestRecPPEM     = _file.GetUint16();
            h.FontDirectionHint = _file.GetInt16();
            h.IndexToLocFormat  = _file.GetInt16();
            h.GlyphDataFormat   = _file.GetInt16();

            return(h);
        }
Exemple #2
0
        public TrueTypeFont(string filename)
        {
            _filename       = filename;
            _file           = new BinaryReader(filename);
            _unicodeIndexes = new Dictionary <char, int>();
            _glyphCache     = new Dictionary <int, Glyph>();

            // The order that things are read below is important
            // DO NOT REARRANGE CALLS!
            _tables = ReadOffsetTables();
            _header = ReadHeadTable();
            _length = GlyphCount();

            if (!_tables.ContainsKey("glyf"))
            {
                throw new Exception("Bad font: glyf table missing");
            }
            if (!_tables.ContainsKey("loca"))
            {
                throw new Exception("Bad font: loca table missing");
            }
        }