Esempio n. 1
0
            public unsafe bool Apply(
                IOpenTypeFont           Font,           // Font access interface 
                OpenTypeTags            TableTag,       // Layout table tag (GSUB or GPOS) 
                FontTable               Table,          // Layout table (GSUB or GPOS)
                LayoutMetrics           Metrics,        // LayoutMetrics 
                ClassDefTable           inputClassDef,
                ClassDefTable           backtrackClassDef,
                ClassDefTable           lookaheadClassDef,
                int                     CharCount,      // Characters count (i.e. Charmap.Length); 
                UshortList              Charmap,        // Char to glyph mapping
                GlyphInfoList           GlyphInfo,      // List of GlyphInfo structs 
                int*                    Advances,       // Glyph adv.widths 
                LayoutOffset*           Offsets,        // Glyph offsets
                ushort                  LookupFlags,    // Lookup table flags 
                int                     FirstGlyph,     // where to apply it
                int                     AfterLastGlyph, // how long is a context we can use
                uint                    Parameter,      // lookup parameter
                int                     nestingLevel,   // Contextual lookup nesting level 
                out int                 NextGlyph       // out: next glyph index
                ) 
            { 
                bool match = true;
                NextGlyph = FirstGlyph + 1; //In case we don't match 

                //We are moving through table. We can pick glyph count or glyph class id.
                int curOffset = offset;
                int glyphIndex; 

                // 
                //Check backtrack sequence 
                //
                int backtrackGlyphCount = GlyphCount(Table,curOffset); 
                curOffset += sizeCount;

                glyphIndex = FirstGlyph;
                for(ushort backtrackIndex = 0; 
                    backtrackIndex < backtrackGlyphCount && match;
                    backtrackIndex++) 
                { 
                    glyphIndex = LayoutEngine.GetNextGlyphInLookup(Font, GlyphInfo,
                        glyphIndex-1, 
                        LookupFlags,
                        LayoutEngine.LookBackward
                        );
 
                    if (glyphIndex<0)
                    { 
                        match = false; 
                    }
                    else 
                    {
                        ushort classId = ClassId(Table,curOffset);
                        curOffset+=sizeClassId;
 
                        ushort glyphClass = backtrackClassDef.
                                        GetClass(Table,GlyphInfo.Glyphs[glyphIndex]); 
 
                        match = (glyphClass == classId);
                    } 
                }

                if (!match) return false;
 
                //
                // Check input sequence 
                // 
                int inputGlyphCount = GlyphCount(Table,curOffset);
                curOffset += sizeCount; 

                glyphIndex = FirstGlyph;
                for(ushort inputIndex = 1; //go from second glyph in the input
                    inputIndex < inputGlyphCount && match; 
                    inputIndex++)
                { 
                    glyphIndex = LayoutEngine.GetNextGlyphInLookup(Font, GlyphInfo, 
                        glyphIndex+1,
                        LookupFlags, 
                        LayoutEngine.LookForward
                        );

                    if (glyphIndex >= AfterLastGlyph) 
                    {
                        match = false; 
                    } 
                    else
                    { 
                        ushort classId = ClassId(Table,curOffset);
                        curOffset+=sizeClassId;

                        ushort glyphClass = inputClassDef. 
                            GetClass(Table,GlyphInfo.Glyphs[glyphIndex]);
 
                        match = (glyphClass == classId); 
                    }
                } 

                if (!match) return false;

                int afterInputGlyph = glyphIndex + 1; // remember where we were after input seqence 

                // 
                // Check lookahead sequence 
                //
                int lookaheadGlyphCount = GlyphCount(Table,curOffset); 
                curOffset += sizeCount;

                // Lokahead sequence starting right after input,
                // no need to change current glyphIndex 
                for(ushort lookaheadIndex = 0;
                    lookaheadIndex < lookaheadGlyphCount && match; 
                    lookaheadIndex++) 
                {
                    glyphIndex = LayoutEngine.GetNextGlyphInLookup(Font, GlyphInfo, 
                        glyphIndex+1,
                        LookupFlags,
                        LayoutEngine.LookForward
                        ); 

                    if (glyphIndex >= GlyphInfo.Length) 
                    { 
                        match = false;
                    } 
                    else
                    {
                        ushort classId = ClassId(Table,curOffset);
                        curOffset+=sizeClassId; 

                        ushort glyphClass = lookaheadClassDef. 
                            GetClass(Table,GlyphInfo.Glyphs[glyphIndex]); 

                        match = (glyphClass == classId); 
                    }
                }

                if (match) 
                {
                    ContextualLookups(Table,curOffset).ApplyContextualLookups( 
                        Font, 
                        TableTag,
                        Table, 
                        Metrics,
                        CharCount,
                        Charmap,
                        GlyphInfo, 
                        Advances,
                        Offsets, 
                        LookupFlags, 
                        FirstGlyph,
                        afterInputGlyph, //As AfterLastGlyph 
                        Parameter,
                        nestingLevel,
                        out NextGlyph
                    ); 
                }
 
                return match; 
            }
Esempio n. 2
0
            public unsafe bool Apply(
                IOpenTypeFont           Font,           // Font access interface 
                OpenTypeTags            TableTag,       // Layout table tag (GSUB or GPOS) 
                FontTable               Table,          // Layout table (GSUB or GPOS)
                LayoutMetrics           Metrics,        // LayoutMetrics 
                ClassDefTable           ClassDef,
                int                     CharCount,      // Characters count (i.e. Charmap.Length);
                UshortList              Charmap,        // Char to glyph mapping
                GlyphInfoList           GlyphInfo,      // List of GlyphInfo structs 
                int*                    Advances,       // Glyph adv.widths
                LayoutOffset*           Offsets,        // Glyph offsets 
                ushort                  LookupFlags,    // Lookup table flags 
                int                     FirstGlyph,     // where to apply it
                int                     AfterLastGlyph, // how long is a context we can use 
                uint                    Parameter,      // lookup parameter
                int                     nestingLevel,   // Contextual lookup nesting level
                out int                 NextGlyph       // out: next glyph index
                ) 
            {
                NextGlyph = FirstGlyph + 1; //In case we don't match 
 
                //
                // Check input sequence 
                //
                bool match = true;
                int glyphIndex = FirstGlyph;
 
                int inputGlyphCount = GlyphCount(Table);
                for(ushort inputIndex = 1; // go from second glyph in the input 
                    inputIndex < inputGlyphCount && match; 
                    inputIndex++)
                { 
                    glyphIndex = LayoutEngine.GetNextGlyphInLookup(Font, GlyphInfo,
                        glyphIndex+1,
                        LookupFlags,
                        LayoutEngine.LookForward 
                        );
 
                    if (glyphIndex>=AfterLastGlyph) 
                    {
                        match = false; 
                    }
                    else
                    {
                        ushort classId = ClassId(Table,inputIndex); 

                        ushort glyphClass = 
                                  ClassDef.GetClass(Table,GlyphInfo.Glyphs[glyphIndex]); 

                        match = (glyphClass == classId); 
                    }
                }

                if (match) 
                {
                    ContextualLookups(Table).ApplyContextualLookups( 
                        Font, 
                        TableTag,
                        Table, 
                        Metrics,
                        CharCount,
                        Charmap,
                        GlyphInfo, 
                        Advances,
                        Offsets, 
                        LookupFlags, 
                        FirstGlyph,
                        glyphIndex + 1, //As AfterLastGlyph 
                        Parameter,
                        nestingLevel,
                        out NextGlyph
                    ); 
                }
 
                return match; 
            }