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