コード例 #1
0
        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);
        }
コード例 #2
0
        public override ITypefaceFont ReadTypefaceAfterVersion(BigEndianReader reader, IFontInfo forReference, string source)
        {
            long startOffset = reader.BaseStream.Position - 4;

            TrueTypeHeader header;

            if (TrueTypeHeader.TryReadHeaderAfterVersion(reader, this, false, out header) == false)
            {
                throw new TypefaceReadException("Could not read the TrueType header for " + forReference.ToString() + " font");
            }

            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)); });

                return(ReadFile(header, dirs, reader, startOffset, forReference));
            }
            catch (Exception ex) { throw new TypefaceReadException("Could not read the TTF File", ex); }
        }
コード例 #3
0
        public override ITypefaceInfo ReadTypefaceInfoAfterVersion(BigEndianReader reader, string source)
        {
            ushort numtables = reader.ReadUInt16();
            ushort search    = reader.ReadUInt16();
            ushort entry     = reader.ReadUInt16();
            ushort range     = reader.ReadUInt16();

            TrueTypeTableEntryList list = new TrueTypeTableEntryList();
            bool hasOs2   = false;
            bool hasFHead = false;
            bool hasName  = false;

            for (int i = 0; i < numtables; i++)
            {
                TrueTypeTableEntry dir = new TrueTypeTableEntry();
                dir.Read(reader);
                list.Add(dir);
                if (dir.Tag == TrueTypeTableNames.WindowsMetrics)
                {
                    hasOs2 = true;
                }
                else if (dir.Tag == TrueTypeTableNames.FontHeader)
                {
                    hasFHead = true;
                }
                else if (dir.Tag == TrueTypeTableNames.NamingTable)
                {
                    hasName = true;
                }
            }

            if (!(hasOs2 || hasName) || !hasFHead)
            {
                return(new Utility.UnknownTypefaceInfo(source, "Not all the required tables (head with OS/2 or name) were found in the font file"));
            }
            else
            {
                return(ReadInfoFromTables(list, reader, source, hasOs2));
            }
        }
コード例 #4
0
        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); }
        }
コード例 #5
0
 public TrueTypeFontTable ReadTable(TrueTypeTableEntry directory, TrueTypeTableEntryList list, BigEndianReader reader)
 {
     reader.Position = directory.Offset;
     return(this.ReadTable(directory.Tag, directory.Length, list, reader));
 }
コード例 #6
0
        // public TrueTypeFontTable ReadTable(TrueTypeTableEntry entry, TTFFile file, BigEndianReader reader)
        // {
        //     return this.ReadTable(entry, file.Directories, reader);
        // }


        public TrueTypeFontTable ReadTable(TrueTypeTableEntry directory, TTF.TrueTypeFile file, BigEndianReader reader)
        {
            return(this.ReadTable(directory, file.Directories, reader));
        }
コード例 #7
0
        public TrueTypeFontTable ReadTable(string tname, TrueTypeTableEntryList list, BigEndianReader reader)
        {
            TrueTypeTableEntry dir = list[tname];

            return(ReadTable(dir, list, reader));
        }