public static Format4CMapTable Load(TrueTypeDataBytes data, int platformId, int encodingId) { // Length in bytes. var length = data.ReadUnsignedShort(); // Used for sub-tables with a Macintosh platform ID. var version = data.ReadUnsignedShort(); var doubleSegmentCount = data.ReadUnsignedShort(); // Defines the number of contiguous segments. var segmentCount = doubleSegmentCount / 2; // Some crazy sum. var searchRange = data.ReadUnsignedShort(); var entrySelector = data.ReadUnsignedShort(); var rangeShift = data.ReadUnsignedShort(); // End character codes for each segment. var endCounts = data.ReadUnsignedShortArray(segmentCount); // Should be zero. var reservedPad = data.ReadUnsignedShort(); // Start character codes for each segment. var startCounts = data.ReadUnsignedShortArray(segmentCount); // Delta for all character codes in the segment. Contrary to the spec this is actually a short[]. var idDeltas = data.ReadShortArray(segmentCount); var idRangeOffsets = data.ReadUnsignedShortArray(segmentCount); const int singleIntsRead = 8; const int intArraysRead = 8; // ReSharper disable once ArrangeRedundantParentheses var remainingBytes = length - ((singleIntsRead * 2) + intArraysRead * segmentCount); var remainingInts = remainingBytes / 2; var glyphIndices = data.ReadUnsignedShortArray(remainingInts); var segments = new Segment[endCounts.Length]; for (int i = 0; i < endCounts.Length; i++) { var start = startCounts[i]; var end = endCounts[i]; var delta = idDeltas[i]; var offsets = idRangeOffsets[i]; segments[i] = new Segment(start, end, delta, offsets); } return(new Format4CMapTable(platformId, encodingId, version, segments, glyphIndices)); }