コード例 #1
0
        private IGlyphTransformationTable ParsePairPositioningTable(int subTableOffset, dynamic fontTable, LookupFlags lookupFlags)
        {
            var     type   = typeof(GlyphTypeface).Assembly.GetType("MS.Internal.Shaping.PairPositioningSubtable");
            dynamic table  = new AccessPrivateWrapper(type.Instantiate(subTableOffset));
            ushort  format = table.Format(fontTable.Wrapped);

            var coverage          = (ICoverageTable)this.ParseCoverageTable(fontTable, new AccessPrivateWrapper(table.Coverage(fontTable.Wrapped)));
            var coveredGlyphCount = coverage.CoveredGlyphIds.Count();

            switch (format)
            {
            case 1:
                var pairSetTables = this.GetEnumerableFromInternalList(
                    () => (ushort)coveredGlyphCount,
                    i => (dynamic) new AccessPrivateWrapper(table.Format1PairSet(fontTable.Wrapped, i))).ToList();

                return(new GlyphPairPositioningTable
                {
                    Coverage = coverage,
                    PairSets =
                        pairSetTables.Select(pairSet => this.GetEnumerableFromInternalList(
                                                 () => (ushort)pairSet.PairValueCount(fontTable.Wrapped),
                                                 i => new PositioningPair
                    {
                        SecondGlyphID = (ushort)pairSet.PairValueGlyph(fontTable.Wrapped, i),
                        FirstGlyphPositionChange = this.ParseValueRecord(fontTable, new AccessPrivateWrapper(pairSet.FirstValueRecord(fontTable.Wrapped, i, table.FirstValueFormat(fontTable.Wrapped)))),
                        SecondGlyphPositionChange = this.ParseValueRecord(fontTable, new AccessPrivateWrapper(pairSet.SecondValueRecord(fontTable.Wrapped, i, table.SecondValueFormat(fontTable.Wrapped)))),
                    }).ToList()).ToList(),
                    LookupFlags = lookupFlags
                });

            case 2:
                var class2Count = (ushort)table.Format2Class2Count(fontTable.Wrapped);

                return(new ClassPairPositioningTable
                {
                    Coverage = coverage,
                    FirstClassDef = this.ParseClassDef(fontTable, new AccessPrivateWrapper(table.Format2Class1Table(fontTable.Wrapped))),
                    SecondClassDef = this.ParseClassDef(fontTable, new AccessPrivateWrapper(table.Format2Class2Table(fontTable.Wrapped))),
                    PairSets =
                        (from i in Enumerable.Range(0, (ushort)table.Format2Class1Count(fontTable.Wrapped))
                         select
                             (from j in Enumerable.Range(0, class2Count)
                             select Tuple.Create(
                                 (GlyphPositionChange)this.ParseValueRecord(fontTable, new AccessPrivateWrapper(table.Format2FirstValueRecord(fontTable.Wrapped, class2Count, (ushort)i, (ushort)j))),
                                 (GlyphPositionChange)this.ParseValueRecord(fontTable, new AccessPrivateWrapper(table.Format2SecondValueRecord(fontTable.Wrapped, class2Count, (ushort)i, (ushort)j)))
                                 )).ToList()).ToList(),
                    LookupFlags = lookupFlags
                });

            default:
                throw new UnknownTableFormatException(type, format);
            }
        }