Implement meta table for font.
This commit is contained in:
@@ -77,6 +77,7 @@ namespace Cryville.Common.Font {
|
|||||||
public override object GetSubTable(TableRecord item) {
|
public override object GetSubTable(TableRecord item) {
|
||||||
switch (item.tableTag) {
|
switch (item.tableTag) {
|
||||||
case "name": return new NameTable(Reader, item.offset);
|
case "name": return new NameTable(Reader, item.offset);
|
||||||
|
case "meta": return new MetaTable(Reader, item.offset);
|
||||||
default: throw new NotImplementedException();
|
default: throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,6 +182,39 @@ namespace Cryville.Common.Font {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public sealed class MetaTable : FontTable<DataMap> {
|
||||||
|
readonly UInt32 version;
|
||||||
|
readonly UInt32 flags;
|
||||||
|
readonly UInt32 dataMapCount;
|
||||||
|
readonly List<DataMap> dataMaps = new List<DataMap>();
|
||||||
|
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
|
version = reader.ReadUInt32();
|
||||||
|
flags = reader.ReadUInt32();
|
||||||
|
reader.ReadUInt32();
|
||||||
|
dataMapCount = reader.ReadUInt32();
|
||||||
|
for (UInt32 i = 0; i < dataMapCount; i++)
|
||||||
|
dataMaps.Add(new DataMap {
|
||||||
|
tag = reader.ReadTag(),
|
||||||
|
dataOffset = reader.ReadUInt32(),
|
||||||
|
dataLength = reader.ReadUInt32(),
|
||||||
|
});
|
||||||
|
for (int i = 0; i < dataMaps.Count; i++) dataMaps[i] = dataMaps[i].Load(reader, offset);
|
||||||
|
}
|
||||||
|
public sealed override IReadOnlyList<DataMap> GetItems() {
|
||||||
|
return dataMaps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public struct DataMap {
|
||||||
|
public String tag;
|
||||||
|
public UInt32 dataOffset;
|
||||||
|
public UInt32 dataLength;
|
||||||
|
public String value { get; private set; }
|
||||||
|
public DataMap Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + dataOffset;
|
||||||
|
value = Encoding.ASCII.GetString(reader.ReadBytes((int)dataLength));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static class BinaryReaderExtensions {
|
public static class BinaryReaderExtensions {
|
||||||
public static string ReadTag(this BinaryReader reader) {
|
public static string ReadTag(this BinaryReader reader) {
|
||||||
return Encoding.ASCII.GetString(reader.ReadBytes(4));
|
return Encoding.ASCII.GetString(reader.ReadBytes(4));
|
||||||
|
|||||||
Reference in New Issue
Block a user