(data, start)
| 4693 | // Parse a Class Definition Table in a GSUB, GPOS or GDEF table. |
| 4694 | // Returns a function that gets a class value from a glyph ID. |
| 4695 | function parseClassDefTable(data, start) { |
| 4696 | var p = new parse.Parser(data, start); |
| 4697 | var format = p.parseUShort(); |
| 4698 | if (format === 1) { |
| 4699 | // Format 1 specifies a range of consecutive glyph indices, one class per glyph ID. |
| 4700 | var startGlyph = p.parseUShort(); |
| 4701 | var glyphCount = p.parseUShort(); |
| 4702 | var classes = p.parseUShortList(glyphCount); |
| 4703 | return function(glyphID) { |
| 4704 | return classes[glyphID - startGlyph] || 0; |
| 4705 | }; |
| 4706 | } |
| 4707 | else if (format === 2) { |
| 4708 | // Format 2 defines multiple groups of glyph indices that belong to the same class. |
| 4709 | var rangeCount = p.parseUShort(); |
| 4710 | var startGlyphs = []; |
| 4711 | var endGlyphs = []; |
| 4712 | var classValues = []; |
| 4713 | for (var i = 0; i < rangeCount; i++) { |
| 4714 | startGlyphs[i] = p.parseUShort(); |
| 4715 | endGlyphs[i] = p.parseUShort(); |
| 4716 | classValues[i] = p.parseUShort(); |
| 4717 | } |
| 4718 | |
| 4719 | return function(glyphID) { |
| 4720 | var l = 0; |
| 4721 | var r = startGlyphs.length - 1; |
| 4722 | while (l < r) { |
| 4723 | var c = (l + r + 1) >> 1; |
| 4724 | if (glyphID < startGlyphs[c]) { |
| 4725 | r = c - 1; |
| 4726 | } else { |
| 4727 | l = c; |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | if (startGlyphs[l] <= glyphID && glyphID <= endGlyphs[l]) { |
| 4732 | return classValues[l] || 0; |
| 4733 | } |
| 4734 | |
| 4735 | return 0; |
| 4736 | }; |
| 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | // Parse a pair adjustment positioning subtable, format 1 or format 2 |
| 4741 | // The subtable is returned in the form of a lookup function. |
no outgoing calls
no test coverage detected