MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / parsePairPosSubTable

Function parsePairPosSubTable

libraries/p5.js:4742–4826  ·  view source on GitHub ↗
(data, start)

Source from the content-addressed store, hash-verified

4740// Parse a pair adjustment positioning subtable, format 1 or format 2
4741// The subtable is returned in the form of a lookup function.
4742function parsePairPosSubTable(data, start) {
4743 var p = new parse.Parser(data, start);
4744 // This part is common to format 1 and format 2 subtables
4745 var format = p.parseUShort();
4746 var coverageOffset = p.parseUShort();
4747 var coverage = parseCoverageTable(data, start + coverageOffset);
4748 // valueFormat 4: XAdvance only, 1: XPlacement only, 0: no ValueRecord for second glyph
4749 // Only valueFormat1=4 and valueFormat2=0 is supported.
4750 var valueFormat1 = p.parseUShort();
4751 var valueFormat2 = p.parseUShort();
4752 var value1;
4753 var value2;
4754 if (valueFormat1 !== 4 || valueFormat2 !== 0) return;
4755 var sharedPairSets = {};
4756 if (format === 1) {
4757 // Pair Positioning Adjustment: Format 1
4758 var pairSetCount = p.parseUShort();
4759 var pairSet = [];
4760 // Array of offsets to PairSet tables-from beginning of PairPos subtable-ordered by Coverage Index
4761 var pairSetOffsets = p.parseOffset16List(pairSetCount);
4762 for (var firstGlyph = 0; firstGlyph < pairSetCount; firstGlyph++) {
4763 var pairSetOffset = pairSetOffsets[firstGlyph];
4764 var sharedPairSet = sharedPairSets[pairSetOffset];
4765 if (!sharedPairSet) {
4766 // Parse a pairset table in a pair adjustment subtable format 1
4767 sharedPairSet = {};
4768 p.relativeOffset = pairSetOffset;
4769 var pairValueCount = p.parseUShort();
4770 for (; pairValueCount--;) {
4771 var secondGlyph = p.parseUShort();
4772 if (valueFormat1) value1 = p.parseShort();
4773 if (valueFormat2) value2 = p.parseShort();
4774 // We only support valueFormat1 = 4 and valueFormat2 = 0,
4775 // so value1 is the XAdvance and value2 is empty.
4776 sharedPairSet[secondGlyph] = value1;
4777 }
4778 }
4779
4780 pairSet[coverage[firstGlyph]] = sharedPairSet;
4781 }
4782
4783 return function(leftGlyph, rightGlyph) {
4784 var pairs = pairSet[leftGlyph];
4785 if (pairs) return pairs[rightGlyph];
4786 };
4787 }
4788 else if (format === 2) {
4789 // Pair Positioning Adjustment: Format 2
4790 var classDef1Offset = p.parseUShort();
4791 var classDef2Offset = p.parseUShort();
4792 var class1Count = p.parseUShort();
4793 var class2Count = p.parseUShort();
4794 var getClass1 = parseClassDefTable(data, start + classDef1Offset);
4795 var getClass2 = parseClassDefTable(data, start + classDef2Offset);
4796
4797 // Parse kerning values by class pair.
4798 var kerningMatrix = [];
4799 for (var i = 0; i < class1Count; i++) {

Callers 1

parseLookupTableFunction · 0.85

Calls 2

parseCoverageTableFunction · 0.85
parseClassDefTableFunction · 0.85

Tested by

no test coverage detected