Example #1
0
        /// <summary>
        /// Gets a version reader for a typeface from the reader at the current position
        /// </summary>
        /// <param name="reader">The bigendian reader to read the version from</param>
        /// <param name="vers">Set to the version reader if known</param>
        /// <returns>True if the version is known, otherwise false</returns>
        /// <remarks>This will check the current reader for a known version and move the position on 4 bytes</remarks>
        public static bool TryGetVersion(BigEndianReader reader, out TypefaceVersionReader vers, bool thrownOnUnsupported = false)
        {
            vers = null;
            byte[] data  = reader.Read(4);
            char[] chars = ConvertToChars(data, 4);

            if (chars[0] == 'O' && chars[1] == 'T' && chars[2] == 'T' && chars[3] == 'O')        //OTTO
            {
                vers = new OTTO.CCFOpenTypeVersionReader(new string(chars), data);
            }
            else if (chars[0] == 't' && chars[1] == 'r' && chars[2] == 'u' && chars[3] == 'e')   //true
            {
                vers = new TTF.TrueTypeVersionReader(new string(chars), data);
            }

            else if (chars[0] == 't' && chars[1] == 'y' && chars[2] == 'p' && chars[3] == '1')   //typ1
            {
                vers = new TTF.TrueTypeVersionReader(new string(chars), data);
            }

            else if (chars[0] == 't' && chars[1] == 't' && chars[2] == 'c' && chars[3] == 'f')   //ttcf
            {
                vers = new TTC.TTCollectionVersionReader(new string(chars), data);
            }

            else if (chars[0] == 'w' && chars[1] == 'O' && chars[2] == 'F' && chars[3] == 'F')   //wOFF
            {
                vers = new Woff.WoffVersionReader(new string(chars), data);
            }

            else if (chars[0] == 'w' && chars[1] == 'O' && chars[2] == 'F' && chars[3] == '2') //wOF2
            {
                vers = null;                                                                   // new Woff2.Woff2VersionReader(new string(chars), data);
            }
            //throw new NotSupportedException("The Woff2 format is not currently supported.");
            else                                                                                 //1.0
            {
                BigEnd16 wrd1 = new BigEnd16(data, 0);
                BigEnd16 wrd2 = new BigEnd16(data, 2);

                if (((int)wrd1.UnsignedValue) == 1 && ((int)wrd2.UnsignedValue) == 0)
                {
                    vers = new OTTO.OpenType1VersionReader(wrd1.UnsignedValue, wrd2.UnsignedValue, data);
                }
            }

            return(vers != null);
        }
        internal static bool TryReadHeader(BigEndianReader reader, out TrueTypeHeader header)
        {
            header = null;

            TypefaceVersionReader vers;

            if (TypefaceVersionReader.TryGetVersion(reader, out vers) == false)
            {
                return(false);
            }
            else if (vers is TrueTypeVersionReader ttv)
            {
                return(TryReadHeaderAfterVersion(reader, ttv, false, out header));
            }
            else
            {
                return(false);
            }
        }
Example #3
0
 public TypefaceHeader(TypefaceVersionReader version, int numTables)
 {
     this.Version        = version;
     this.NumberOfTables = numTables;
 }