コード例 #1
0
        private static async Task <IList <string> > GetTableNameAsync(FontReader reader, uint offset)
        {
            await reader.SeekAsync(offset);

            await reader.SkipAsync(2); //version

            var nameRecordCount = await reader.ReadUInt16BEAsync();

            ushort storageOffset = await reader.ReadUInt16BEAsync();

            var items = new List <string>();

            for (int i = 0; i < nameRecordCount; i++)
            {
                var platformID = await reader.ReadUInt16BEAsync();

                var encodingID = await reader.ReadUInt16BEAsync();

                var languageID = await reader.ReadUInt16BEAsync();

                var nameID = await reader.ReadUInt16BEAsync();

                var length = await reader.ReadUInt16BEAsync();

                var stringOffset   = (ushort)(await reader.ReadUInt16BEAsync() + storageOffset);
                var actualPosition = reader.BaseStream.Position;
                if (nameID != NameID.Family)
                {
                    continue;
                }
                var data = await ExtractStringFromNameRecordAsync(reader,
                                                                  offset,
                                                                  stringOffset,
                                                                  length,
                                                                  platformID,
                                                                  encodingID);

                reader.BaseStream.Seek(actualPosition, SeekOrigin.Begin);
                items.Add(data);
            }
            return(items);
        }
コード例 #2
0
        private static async Task <string> ExtractStringFromNameRecordAsync(FontReader reader,
                                                                            uint offset, ushort stringOffset, ushort length, ushort platformID,
                                                                            ushort encodingID)
        {
            await reader.SeekAsync(offset + stringOffset);

            var data = await reader.ReadBytesAsync(length);

            if (platformID == PlatformID.Windows)
            {
                return(Encoding.BigEndianUnicode.GetString(data));
            }
            if (platformID == PlatformID.Unicode)
            {
                return(Encoding.BigEndianUnicode.GetString(data));
            }
            if (platformID == PlatformID.Macintosh)
            {
                return(Encoding.ASCII.GetString(data));
            }
            return(Encoding.UTF8.GetString(data));
        }
コード例 #3
0
        public static async Task <List <string> > GetFontFamilyAsync(FontReader reader)
        {
            var sfntVersion = await reader.ReadUInt32BEAsync();

            FontCheck.ValidateSfntVersion(sfntVersion);
            var tableCount = await reader.ReadUInt16BEAsync();

            await reader.SkipAsync(6);

            var offsetItems = new List <uint>();

            for (var i = 0; i < tableCount; i++)
            {
                var tagByte = await reader.ReadBytesAsync(4);

                var checksum = await reader.ReadUInt32BEAsync();

                var offset = await reader.ReadUInt32BEAsync();

                var length = await reader.ReadUInt32BEAsync();

                var tag = FontCheck.ConvertToTagName(tagByte);
                if (tag != Tables.NAME)
                {
                    continue;
                }
                offsetItems.Add(offset);
            }
            var items = new List <string>();

            foreach (var item in offsetItems)
            {
                items.AddRange(await GetTableNameAsync(reader, item));
            }

            return(items);
        }
コード例 #4
0
 public static async Task <List <string> > GetFontFamilyAsync(Stream fs)
 {
     using var reader = new FontReader(fs);
     return(await GetFontFamilyAsync(reader));
 }