private TrueTypeFontTable ReadHorizontalMetrics(uint length, TrueTypeTableEntryList list, BigEndianReader reader)
        {
            var pos = reader.Position;
            //Get the number of entries for the hMetrics list from the horizontal header table.
            TrueTypeTableEntry hhead = list["hhea"];

            if (hhead == null)
            {
                throw new ArgumentNullException("No horizontal header (hhea) has been specified in the font file, this is needed to load the hroizontal metrics");
            }

            if (hhead.Table == null)
            {
                TrueTypeFontTable tbl = this.ReadTable(hhead, list, reader);
                if (tbl == null)
                {
                    throw new ArgumentNullException("No horizontal header (hhea) has been specified in the font file, this is needed to load the hroizontal metrics");
                }
                hhead.SetTable(tbl);
            }

            TrueTypeTableEntry os2 = list["OS/2"];

            if (os2 == null)
            {
                throw new ArgumentNullException("No OS2 table has been specified in the font file, this is a required table and needed to load the horizontal metrics");
            }

            if (os2.Table == null)
            {
                TrueTypeFontTable tbl = this.ReadTable(os2, list, reader);
                if (tbl == null)
                {
                    throw new ArgumentNullException("No OS/2 has been specified in the font file, this is needed to load the hroizontal metrics");
                }
                os2.SetTable(tbl);
            }

            if (reader.Position != pos)
            {
                reader.Position = pos;
            }

            int firstcharindex   = (os2.Table as OS2Table).FirstCharIndex;
            HorizontalMetrics hm = new HorizontalMetrics(reader.Position);

            ushort count = (hhead.Table as SubTables.HorizontalHeader).NumberOfHMetrics;

            List <HMetric> metrics = new List <HMetric>();

            for (int i = 0; i < count; i++)
            {
                SubTables.HMetric metric = new HMetric(reader.ReadUInt16(), reader.ReadInt16(), (char)(i + firstcharindex));
                metrics.Add(metric);
            }

            hm.HMetrics = metrics;

            return(hm);
        }
Esempio n. 2
0
        protected virtual ITypefaceFont ReadFile(TrueTypeHeader header, IEnumerable <TrueTypeTableEntry> dirs, BigEndianReader reader, long startOffset, IFontInfo reference)
        {
            var entries = new TrueTypeTableEntryList(dirs);

            TrueTypeFile file = new TrueTypeFile(header, entries);

            TrueTypeTableFactory factory = this.GetTableFactory();

            foreach (TrueTypeTableEntry dir in dirs)
            {
                TrueTypeFontTable tbl = factory.ReadTable(dir, entries, reader);
                if (tbl != null)
                {
                    dir.SetTable(tbl);
                }
            }

            file.EnsureReferenceMatched(reference);


            byte[] data = CopyStreamData(reader.BaseStream, startOffset);
            file.SetFileData(data, this.DataFormat);

            return(file);
        }
 public bool TryGetTable(string name, out TrueTypeFontTable table)
 {
     if (null == this.Tables)
     {
         table = null;
         return(false);
     }
     else
     {
         return(this.Tables.TryGetTable(name, out table));
     }
 }
Esempio n. 4
0
 public bool TryGetTable(string name, out TrueTypeFontTable table)
 {
     if (this._directories.Contains(name))
     {
         table = _directories[name].Table;
     }
     else
     {
         table = null;
     }
     return(null != table);
 }
        protected void Read(BigEndianReader reader)
        {
            TrueTypeHeader header;

            if (TrueTypeHeader.TryReadHeader(reader, out header) == false)
            {
                throw new NotSupportedException("The current stream is not a supported OpenType or TrueType font file");
            }

            List <TrueTypeTableEntry> dirs;

            try
            {
                dirs = new List <TrueTypeTableEntry>();

                for (int i = 0; i < header.NumberOfTables; i++)
                {
                    TrueTypeTableEntry dir = new TrueTypeTableEntry();
                    dir.Read(reader);
                    dirs.Add(dir);
                }

                dirs.Sort(delegate(TrueTypeTableEntry one, TrueTypeTableEntry two) { return(one.Offset.CompareTo(two.Offset)); });
                this._dirs = new TrueTypeTableEntryList(dirs);
                this._head = header;

                TrueTypeTableFactory factory = this.GetFactory(header);
                foreach (TrueTypeTableEntry dir in dirs)
                {
                    TrueTypeFontTable tbl = factory.ReadTable(dir, this, reader);
                    if (tbl != null)
                    {
                        dir.SetTable(tbl);
                    }
                }
            }
            catch (Exception ex) { throw new TypefaceReadException("Could not read the TTF File", ex); }
        }
Esempio n. 6
0
 internal void SetTable(TrueTypeFontTable tbl)
 {
     this._tbl = tbl;
 }