Example #1
0
        public static TupleVariationHeader Read(BinaryReader reader, int axisCount)
        {
            TupleVariationHeader header = new TupleVariationHeader();

            header.variableDataSize = reader.ReadUInt16();
            ushort tupleIndex = reader.ReadUInt16();
            int    flags      = (tupleIndex >> 12) & 0xF;                      //The high 4 bits are flags(see below).

            header.flags = flags;                                              //The high 4 bits are flags(see below).
            header.indexToSharedTupleRecArray = (ushort)(tupleIndex & 0x0FFF); // The low 12 bits are an index into a shared tuple records array.


            if ((flags & ((int)TupleIndexFormat.EMBEDDED_PEAK_TUPLE >> 12)) == ((int)TupleIndexFormat.EMBEDDED_PEAK_TUPLE >> 12))
            {
                //TODO:...
                header.peakTuple = TupleRecord.ReadTupleRecord(reader, axisCount);
            }
            if ((flags & ((int)TupleIndexFormat.INTERMEDIATE_REGION >> 12)) == ((int)TupleIndexFormat.INTERMEDIATE_REGION >> 12))
            {
                //TODO:...
                header.intermediateStartTuple = TupleRecord.ReadTupleRecord(reader, axisCount);
                header.intermediateEndTuple   = TupleRecord.ReadTupleRecord(reader, axisCount);
            }

            return(header);
        }
Example #2
0
        void ReadShareTupleArray(BinaryReader reader, ushort sharedTupleCount)
        {
            //-------------
            //Shared tuples array
            //-------------
            //The shared tuples array provides a set of variation-space positions
            //that can be referenced by variation data for any glyph.
            //The shared tuples array follows the GlyphVariationData offsets array
            //at the end of the 'gvar' header.
            //This data is simply an array of tuple records, each representing a position in the font’s variation space.

            //Shared tuples array:
            //Type            Name                            Description
            //TupleRecord     sharedTuples[sharedTupleCount]  Array of tuple records shared across all glyph variation data tables.

            //Tuple records that are in the shared array or
            //that are contained directly within a given glyph variation data table
            //use 2.14 values to represent normalized coordinate values.
            //See the Common Table Formats chapter for details.

            //

            //Tuple Records
            //https://docs.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats
            //The tuple variation store formats make reference to regions within the font’s variation space using tuple records.
            //These references identify positions in terms of normalized coordinates, which use F2DOT14 values.
            //Tuple record(F2DOT14):
            //Type Name    Description
            //F2DOT14     coordinates[axisCount]  Coordinate array specifying a position within the font’s variation space.
            //                                    The number of elements must match the axisCount specified in the 'fvar' table.


            TupleRecord[] tubleRecords = new TupleRecord[sharedTupleCount];
            for (int i = 0; i < sharedTupleCount; ++i)
            {
                TupleRecord rec    = new TupleRecord();
                float[]     coords = new float[axisCount];
                rec.coords = coords;
                for (int n = 0; n < axisCount; ++n)
                {
                    coords[n] = reader.ReadF2Dot14();
                }
                tubleRecords[i] = rec;
            }
        }
Example #3
0
            public ushort postScriptNameID;//point to name table, will be resolved later

            public void ReadContent(BinaryReader reader, int axisCount, int instanceRecordSize)
            {
                long expectedEndPos = reader.BaseStream.Position + instanceRecordSize;

                subfamilyNameID = reader.ReadUInt16();
                flags           = reader.ReadUInt16();
                float[] coords = new float[axisCount];
                for (int i = 0; i < axisCount; ++i)
                {
                    coords[i] = reader.ReadFixed();
                }
                coordinates = new TupleRecord(coords);

                if (reader.BaseStream.Position < expectedEndPos)
                {
                    //optional field
                    postScriptNameID = reader.ReadUInt16();
                }
            }