public TTCHeader(TTCollectionVersionReader version, int numFonts, uint[] offsets)
 {
     if (offsets.Length != numFonts)
     {
         throw new ArgumentOutOfRangeException("The number of fonts and their offsets do not match");
     }
     NumFonts    = numFonts;
     FontOffsets = offsets;
 }
예제 #2
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 TTCHeader ReadHeader(BigEndianReader reader, TTCollectionVersionReader version)
        {
            ushort versMajor = reader.ReadUInt16();
            ushort versMinor = reader.ReadUInt16();

            int numtables = (int)reader.ReadUInt32();

            uint[] offsets = new uint[numtables];

            for (var i = 0; i < numtables; i++)
            {
                offsets[i] = reader.ReadUInt32();
            }

            return(new TTCHeader(version, numtables, offsets));
        }