Example #1
0
 private static bool IsUnicodeEntry(NameEntry en)
 {
     if (en.PlatformId == (short)PlatformId.Unicode)
     {
         return true;
     }
     if (en.PlatformId == (short)PlatformId.Microsoft && (en.EncodingId == 1) ) // windows unicode
     {
         return true;
     }
     if (en.PlatformId == (short)PlatformId.Microsoft && (en.EncodingId == 1 || en.EncodingId == 10) &&
         ((en.LanguageId & 0x3FF) == 9))
     {
         return true;
     }
     return false;
 }
Example #2
0
 private void ReadNames(Stream stream)
 {
     TableDirectoryEntry table = Header.TableMap["name"];
     if (table == null)
     {
         throw new Exception("No name table found");
     }
     stream.Seek(table.Offset, SeekOrigin.Begin);
     byte[] buffer = new byte[256];
     stream.Read(buffer, 0, 6);
     if (IOUtils.GetShort(buffer,0)!=0)
     {
         throw new Exception("unknown cmap version");
     }
     int count = IOUtils.GetShort(buffer, 2) & 0xFFFF;
     int offset = (IOUtils.GetShort(buffer, 4) & 0xFFFF) + table.Offset;
     names.Clear();
     for (int i = 0; i < count; i++)
     {
         NameEntry entry = new NameEntry();
         names.Add(entry);
         stream.Read(buffer, 0, 12);
         entry.PlatformId = IOUtils.GetShort(buffer, 0);
         entry.EncodingId = IOUtils.GetShort(buffer, 2);
         entry.LanguageId = IOUtils.GetShort(buffer, 4);
         entry.NameId = IOUtils.GetShort(buffer, 6);
         entry.Length = IOUtils.GetShort(buffer, 8);
         entry.Offset = (IOUtils.GetShort(buffer, 10) & 0xFFFF) + offset;
     }
     foreach (var name in names)
     {
         if ((name.NameId == 1 || name.NameId == 16) && IsUnicodeEntry(name) )
         {
             stream.Seek(name.Offset, SeekOrigin.Begin);
             stream.Read(buffer, 0, name.Length);
             FamilyName = DecodeUnicode(buffer,0,name.Length);
             if (name.NameId == 16)
             {
                 break;
             }
         }
     }
 }