Beispiel #1
0
        void FillClassDefs(Glyph[] inputGlyphs)
        {
            //1. glyph def
            ClassDefTable classDef = GlyphClassDef;

            if (classDef == null)
            {
                return;
            }
            //-----------------------------------------

            switch (classDef.Format)
            {
            default:
                Utils.WarnUnimplemented("GDEF GlyphClassDef Format {0}", classDef.Format);
                break;

            case 1:
            {
                ushort   startGlyph  = classDef.startGlyph;
                ushort[] classValues = classDef.classValueArray;
                int      gIndex      = startGlyph;
                for (int i = 0; i < classValues.Length; ++i)
                {
#if DEBUG
                    ushort classV = classValues[i];
                    if (classV > (ushort)GlyphClassKind.Component)
                    {
                    }
#endif

                    inputGlyphs[gIndex].GlyphClass = (GlyphClassKind)classValues[i];
                    gIndex++;
                }
            }
            break;

            case 2:
            {
                ClassDefTable.ClassRangeRecord[] records = classDef.records;
                for (int n = 0; n < records.Length; ++n)
                {
                    ClassDefTable.ClassRangeRecord rec = records[n];

#if DEBUG
                    if (rec.classNo > (ushort)GlyphClassKind.Component)
                    {
                    }
#endif

                    GlyphClassKind glyphKind = (GlyphClassKind)rec.classNo;
                    for (int i = rec.startGlyphId; i <= rec.endGlyphId; ++i)
                    {
                        inputGlyphs[i].GlyphClass = glyphKind;
                    }
                }
            }
            break;
            }
        }
Beispiel #2
0
        void FillMarkAttachmentClassDefs(Glyph[] inputGlyphs)
        {
            //Mark Attachment Class Definition Table
            //A Mark Class Definition Table is used to assign mark glyphs into different classes
            //that can be used in lookup tables within the GSUB or GPOS table to control how mark glyphs within a glyph sequence are treated by lookups.
            //For more information on the use of mark attachment classes,
            //see the description of lookup flags in the “Lookup Table” section of the chapter, OpenType Layout Common Table Formats.
            ClassDefTable markAttachmentClassDef = this.MarkAttachmentClassDef;

            if (markAttachmentClassDef == null)
            {
                return;
            }
            //-----------------------------------------

            switch (markAttachmentClassDef.Format)
            {
            default:
                Utils.WarnUnimplemented("GDEF MarkAttachmentClassDef Table Format {0}", markAttachmentClassDef.Format);
                break;

            case 1:
            {
                ushort   startGlyph  = markAttachmentClassDef.startGlyph;
                ushort[] classValues = markAttachmentClassDef.classValueArray;

                int len    = classValues.Length;
                int gIndex = startGlyph;
                for (int i = 0; i < len; ++i)
                {
#if DEBUG
                    Glyph dbugTestGlyph = inputGlyphs[gIndex];
#endif
                    inputGlyphs[gIndex].MarkClassDef = classValues[i];
                    gIndex++;
                }
            }
            break;

            case 2:
            {
                ClassDefTable.ClassRangeRecord[] records = markAttachmentClassDef.records;
                int len = records.Length;
                for (int n = 0; n < len; ++n)
                {
                    ClassDefTable.ClassRangeRecord rec = records[n];
                    for (int i = rec.startGlyphId; i <= rec.endGlyphId; ++i)
                    {
#if DEBUG
                        Glyph dbugTestGlyph = inputGlyphs[i];
#endif
                        inputGlyphs[i].MarkClassDef = rec.classNo;
                    }
                }
            }
            break;
            }
        }
        public static ClassDefTable CreateFrom(BinaryReader reader, long beginAt)
        {
            reader.BaseStream.Seek(beginAt, SeekOrigin.Begin);

            //---------
            ClassDefTable classDefTable = new ClassDefTable();

            switch (classDefTable.Format = reader.ReadUInt16())
            {
            default: throw new NotSupportedException();

            case 1:
            {
                classDefTable.startGlyph = reader.ReadUInt16();
                ushort glyphCount = reader.ReadUInt16();
                classDefTable.classValueArray = Utils.ReadUInt16Array(reader, glyphCount);
            }
            break;

            case 2:
            {
                ushort             classRangeCount = reader.ReadUInt16();
                ClassRangeRecord[] records         = new ClassRangeRecord[classRangeCount];
                for (int i = 0; i < classRangeCount; ++i)
                {
                    records[i] = new ClassRangeRecord(
                        reader.ReadUInt16(),         //start glyph id
                        reader.ReadUInt16(),         //end glyph id
                        reader.ReadUInt16());        //classNo
                }
                classDefTable.records = records;
            }
            break;
            }
            return(classDefTable);
        }
Beispiel #4
0
        protected override void ReadContentFrom(BinaryReader reader)
        {
            _tableStartAt = reader.BaseStream.Position;
            //-----------------------------------------
            //GDEF 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  GlyphClassDef       Offset to class definition table for glyph type, from beginning of GDEF header (may be NULL)
            //Offset16  AttachList          Offset to list of glyphs with attachment points, from beginning of GDEF header (may be NULL)
            //Offset16  LigCaretList        Offset to list of positioning points for ligature carets, from beginning of GDEF header (may be NULL)
            //Offset16  MarkAttachClassDef  Offset to class definition table for mark attachment type, from beginning of GDEF header (may be NULL)
            //
            //GDEF Header, Version 1.2
            //Type  Name    Description
            //uint16    MajorVersion        Major version of the GDEF table, = 1
            //uint16    MinorVersion        Minor version of the GDEF table, = 2
            //Offset16  GlyphClassDef       Offset to class definition table for glyph type, from beginning of GDEF header (may be NULL)
            //Offset16  AttachList          Offset to list of glyphs with attachment points, from beginning of GDEF header (may be NULL)
            //Offset16  LigCaretList        Offset to list of positioning points for ligature carets, from beginning of GDEF header (may be NULL)
            //Offset16  MarkAttachClassDef  Offset to class definition table for mark attachment type, from beginning of GDEF header (may be NULL)
            //Offset16  MarkGlyphSetsDef    Offset to the table of mark set definitions, from beginning of GDEF header (may be NULL)
            //
            //GDEF Header, Version 1.3
            //Type  Name    Description
            //uint16    MajorVersion        Major version of the GDEF table, = 1
            //uint16    MinorVersion        Minor version of the GDEF table, = 3
            //Offset16  GlyphClassDef       Offset to class definition table for glyph type, from beginning of GDEF header (may be NULL)
            //Offset16  AttachList          Offset to list of glyphs with attachment points, from beginning of GDEF header (may be NULL)
            //Offset16  LigCaretList        Offset to list of positioning points for ligature carets, from beginning of GDEF header (may be NULL)
            //Offset16  MarkAttachClassDef  Offset to class definition table for mark attachment type, from beginning of GDEF header (may be NULL)
            //Offset16  MarkGlyphSetsDef    Offset to the table of mark set definitions, from beginning of GDEF header (may be NULL)
            //Offset32  ItemVarStore        Offset to the Item Variation Store table, from beginning of GDEF header (may be NULL)

            //common to 1.0, 1.2, 1.3...
            this.MajorVersion = reader.ReadUInt16();
            this.MinorVersion = reader.ReadUInt16();
            //
            ushort glyphClassDefOffset      = reader.ReadUInt16();
            ushort attachListOffset         = reader.ReadUInt16();
            ushort ligCaretListOffset       = reader.ReadUInt16();
            ushort markAttachClassDefOffset = reader.ReadUInt16();
            ushort markGlyphSetsDefOffset   = 0;
            uint   itemVarStoreOffset       = 0;

            //
            switch (MinorVersion)
            {
            default:
                Utils.WarnUnimplemented("GDEF Minor Version {0}", MinorVersion);
                return;

            case 0:
                break;

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

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


            this.GlyphClassDef       = (glyphClassDefOffset == 0) ? null : ClassDefTable.CreateFrom(reader, _tableStartAt + glyphClassDefOffset);
            this.AttachmentListTable = (attachListOffset == 0) ? null : AttachmentListTable.CreateFrom(reader, _tableStartAt + attachListOffset);
            this.LigCaretList        = (ligCaretListOffset == 0) ? null : LigCaretList.CreateFrom(reader, _tableStartAt + ligCaretListOffset);

            //A Mark Attachment Class Definition Table defines the class to which a mark glyph may belong.
            //This table uses the same format as the Class Definition table (for details, see the chapter, Common Table Formats ).


#if DEBUG
            if (markAttachClassDefOffset == 2)
            {
                //temp debug invalid font
                this.MarkAttachmentClassDef = (markAttachClassDefOffset == 0) ? null : ClassDefTable.CreateFrom(reader, reader.BaseStream.Position);
            }
            else
            {
                this.MarkAttachmentClassDef = (markAttachClassDefOffset == 0) ? null : ClassDefTable.CreateFrom(reader, _tableStartAt + markAttachClassDefOffset);
            }
#else
            this.MarkAttachmentClassDef = (markAttachClassDefOffset == 0) ? null : ClassDefTable.CreateFrom(reader, _tableStartAt + markAttachClassDefOffset);
#endif

            this.MarkGlyphSetsTable = (markGlyphSetsDefOffset == 0) ? null : MarkGlyphSetsTable.CreateFrom(reader, _tableStartAt + markGlyphSetsDefOffset);

            if (itemVarStoreOffset != 0)
            {
                //not supported
                Utils.WarnUnimplemented("GDEF ItemVarStore");
                reader.BaseStream.Seek(this.Header.Offset + itemVarStoreOffset, SeekOrigin.Begin);
            }
        }