public static LigatureCaretList Load(BigEndianBinaryReader reader, long offset)
        {
            // Ligature Caret list
            // Type      | Name                           | Description
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | coverageOffset                 | Offset to Coverage table - from beginning of LigCaretList table.
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | ligGlyphCount                  | Number of ligature glyphs.
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | ligGlyphOffsets[ligGlyphCount] | Array of offsets to LigGlyph tables, from beginning of LigCaretList table —in Coverage Index order.
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            reader.Seek(offset, SeekOrigin.Begin);

            ushort coverageOffset = reader.ReadUInt16();
            ushort ligGlyphCount  = reader.ReadUInt16();

            using Buffer <ushort> ligGlyphOffsetsBuffer = new(ligGlyphCount);
            Span <ushort> ligGlyphOffsets = ligGlyphOffsetsBuffer.GetSpan();

            reader.ReadUInt16Array(ligGlyphOffsets);

            var ligatureCaretList = new LigatureCaretList()
            {
                CoverageTable = CoverageTable.Load(reader, offset + coverageOffset)
            };

            ligatureCaretList.LigatureGlyphs = new LigatureGlyph[ligGlyphCount];
            for (int i = 0; i < ligatureCaretList.LigatureGlyphs.Length; i++)
            {
                ligatureCaretList.LigatureGlyphs[i] = LigatureGlyph.Load(reader, ligGlyphOffsets[i]);
            }

            return(ligatureCaretList);
        }
Esempio n. 2
0
        public static GlyphDefinitionTable Load(BigEndianBinaryReader reader)
        {
            // Header version 1.0
            // Type      | Name                     | Description
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | majorVersion             | Major version of the GDEF table, = 1
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | minorVersion             | Minor version of the GDEF table, = 0
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | glyphClassDefOffset      | Offset to class definition table for glyph type, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | attachListOffset         | Offset to attachment point list table, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | ligCaretListOffset       | Offset to ligature caret list table, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | markAttachClassDefOffset | Offset to class definition table for mark attachment type, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------

            // Header version 1.2
            // Type      | Name                     | Description
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | majorVersion             | Major version of the GDEF table, = 1
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | minorVersion             | Minor version of the GDEF table, = 0
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | glyphClassDefOffset      | Offset to class definition table for glyph type, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | attachListOffset         | Offset to attachment point list table, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | ligCaretListOffset       | Offset to ligature caret list table, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | markAttachClassDefOffset | Offset to class definition table for mark attachment type, from beginning of GDEF header (may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | markGlyphSetsDefOffset   | Offset to the table of mark glyph set definitions, from beginning of GDEF header (may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------

            // Header version 1.3
            // Type      | Name                     | Description
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | majorVersion             | Major version of the GDEF table, = 1
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | minorVersion             | Minor version of the GDEF table, = 0
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | glyphClassDefOffset      | Offset to class definition table for glyph type, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | attachListOffset         | Offset to attachment point list table, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | ligCaretListOffset       | Offset to ligature caret list table, from beginning of GDEF header(may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | markAttachClassDefOffset | Offset to class definition table for mark attachment type, from beginning of GDEF header (may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | markGlyphSetsDefOffset   | Offset to the table of mark glyph set definitions, from beginning of GDEF header (may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            // Offset32  | itemVarStoreOffset       | Offset to the Item Variation Store table, from beginning of GDEF header (may be NULL).
            // ----------|--------------------------|--------------------------------------------------------------------------------------------------------
            ushort majorVersion = reader.ReadUInt16();
            ushort minorVersion = reader.ReadUInt16();

            ushort glyphClassDefOffset      = reader.ReadUInt16();
            ushort attachListOffset         = reader.ReadUInt16();
            ushort ligatureCaretListOffset  = reader.ReadUInt16();
            ushort markAttachClassDefOffset = reader.ReadUInt16();
            ushort markGlyphSetsDefOffset   = 0;
            uint   itemVarStoreOffset       = 0;

            switch (minorVersion)
            {
            case 0:
                break;

            case 2:
                markGlyphSetsDefOffset = reader.ReadUInt16();
                break;

            case 3:
                markGlyphSetsDefOffset = reader.ReadUInt16();
                itemVarStoreOffset     = reader.ReadUInt32();
                break;

            default:
                throw new InvalidFontFileException($"Invalid value for 'minor version' {minorVersion} of GDEF table. Should be '0', '2' or '3'.");
            }

            ClassDefinitionTable?classDefinitionTable   = glyphClassDefOffset is 0 ? null : ClassDefinitionTable.Load(reader, glyphClassDefOffset);
            AttachmentListTable? attachmentListTable    = attachListOffset is 0 ? null : AttachmentListTable.Load(reader, attachListOffset);
            LigatureCaretList?   ligatureCaretList      = ligatureCaretListOffset is 0 ? null : LigatureCaretList.Load(reader, ligatureCaretListOffset);
            ClassDefinitionTable?markAttachmentClassDef = markAttachClassDefOffset is 0 ? null : ClassDefinitionTable.Load(reader, markAttachClassDefOffset);
            MarkGlyphSetsTable?  markGlyphSetsTable     = markGlyphSetsDefOffset is 0 ? null : MarkGlyphSetsTable.Load(reader, markGlyphSetsDefOffset);

            var glyphDefinitionTable = new GlyphDefinitionTable()
            {
                GlyphClassDefinition   = classDefinitionTable,
                AttachmentListTable    = attachmentListTable,
                LigatureCaretList      = ligatureCaretList,
                MarkAttachmentClassDef = markAttachmentClassDef,
                MarkGlyphSetsTable     = markGlyphSetsTable
            };

            // TODO: read itemVarStore.
            return(glyphDefinitionTable);
        }