public static AttachmentListTable Load(BigEndianBinaryReader reader, long offset)
        {
            // Attachment Point List Table
            // Type      | Name                           | Description
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | coverageOffset                 | Offset to Coverage table -from beginning of AttachList table.
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            // uint16    | glyphCount                     | Number of glyphs with attachment points.
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            // Offset16  | attachPointOffsets[glyphCount] | Array of offsets to AttachPoint tables-from beginning of AttachList table-in Coverage Index order.
            // ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
            reader.Seek(offset, SeekOrigin.Begin);

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

            using Buffer <ushort> attachPointOffsetsBuffer = new(glyphCount);
            Span <ushort> attachPointOffsets = attachPointOffsetsBuffer.GetSpan();

            reader.ReadUInt16Array(attachPointOffsets);

            var attachmentListTable = new AttachmentListTable
            {
                CoverageTable = CoverageTable.Load(reader, offset + coverageOffset),
                AttachPoints  = new AttachPoint[glyphCount]
            };

            for (int i = 0; i < glyphCount; ++i)
            {
                reader.Seek(offset + attachPointOffsets[i], SeekOrigin.Begin);
                ushort pointCount = reader.ReadUInt16();
                attachmentListTable.AttachPoints[i] = new AttachPoint()
                {
                    PointIndices = reader.ReadUInt16Array(pointCount)
                };
            }

            return(attachmentListTable);
        }
Ejemplo 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);
        }