Example #1
0
        private static AxisRecord CreateAxisRecord(short axisType)
        {
            AxisRecord r = new AxisRecord();

            r.AxisType = (axisType);
            return(r);
        }
Example #2
0
        public IVAxisAggregate(RecordStream rs, ChartRecordAggregate container, AxisRecord axis)
            : base(RuleName_IVAXIS, container)
        {
            this.axis = axis;

            if (rs.PeekNextChartSid() == CatSerRangeRecord.sid)
            {
                catSerRange = (CatSerRangeRecord)rs.GetNext();
            }

            Debug.Assert(rs.PeekNextChartSid() == AxcExtRecord.sid);
            axcExt = (AxcExtRecord)rs.GetNext();

            if (rs.PeekNextChartSid() == CatLabRecord.sid)
            {
                catLab = (CatLabRecord)rs.GetNext();
            }

            axs = new AXSAggregate(rs, this);
            while (rs.PeekNextChartSid() == CrtMlFrtRecord.sid)
            {
                crtmlfrtList.Add(new CrtMlFrtAggregate(rs, this));
            }

            Record r = rs.GetNext();//EndRecord

            Debug.Assert(r.GetType() == typeof(EndRecord));
        }
Example #3
0
        public DVAxisAggregate(RecordStream rs, ChartRecordAggregate container, AxisRecord axis)
            : base(RuleName_DVAXIS, container)
        {
            if (axis == null)
            {
                this.axis = (AxisRecord)rs.GetNext();
                rs.GetNext();
            }
            else
            {
                this.axis = axis;
            }

            if (rs.PeekNextChartSid() == ValueRangeRecord.sid)
            {
                valueRange = (ValueRangeRecord)rs.GetNext();
            }

            if (rs.PeekNextChartSid() == YMultRecord.sid)
            {
                axm = new AXMAggregate(rs, this);
            }

            axs = new AXSAggregate(rs, this);
            if (rs.PeekNextChartSid() == CrtMlFrtRecord.sid)
            {
                crtmlfrt = new CrtMlFrtAggregate(rs, this);
            }

            Record r = rs.GetNext();//EndRecord

            Debug.Assert(r.GetType() == typeof(EndRecord));
        }
Example #4
0
        public void TestLoad()
        {
            AxisRecord record = new AxisRecord(TestcaseRecordInputStream.Create((short)0x101d, data));

            Assert.AreEqual(AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS, record.AxisType);
            Assert.AreEqual(0, record.Reserved1);
            Assert.AreEqual(0, record.Reserved2);
            Assert.AreEqual(0, record.Reserved3);
            Assert.AreEqual(0, record.Reserved4);


            Assert.AreEqual(4 + 18, record.RecordSize);
        }
Example #5
0
        public void TestLoad()
        {

            AxisRecord record = new AxisRecord(TestcaseRecordInputStream.Create((short)0x101d, data));
            Assert.AreEqual(AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS, record.AxisType);
            Assert.AreEqual(0, record.Reserved1);
            Assert.AreEqual(0, record.Reserved2);
            Assert.AreEqual(0, record.Reserved3);
            Assert.AreEqual(0, record.Reserved4);


            Assert.AreEqual(4 + 18, record.RecordSize);
        }
Example #6
0
        public void TestStore()
        {
            AxisRecord record = new AxisRecord();
            record.AxisType = (AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS);
            record.Reserved1 = (0);
            record.Reserved2 = (0);
            record.Reserved3 = (0);
            record.Reserved4 = (0);


            byte[] recordBytes = record.Serialize();
            Assert.AreEqual(recordBytes.Length - 4, data.Length);
            for (int i = 0; i < data.Length; i++)
                Assert.AreEqual(data[i], recordBytes[i + 4], "At offset " + i);
        }
Example #7
0
        public void TestStore()
        {
            AxisRecord record = new AxisRecord();

            record.AxisType  = (AxisRecord.AXIS_TYPE_CATEGORY_OR_X_AXIS);
            record.Reserved1 = (0);
            record.Reserved2 = (0);
            record.Reserved3 = (0);
            record.Reserved4 = (0);


            byte[] recordBytes = record.Serialize();
            Assert.AreEqual(recordBytes.Length - 4, data.Length);
            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], recordBytes[i + 4], "At offset " + i);
            }
        }
Example #8
0
        public AxesAggregate(RecordStream rs, ChartRecordAggregate container)
            : base(RuleName_AXES, container)
        {
            if (rs.PeekNextChartSid() == AxisRecord.sid)
            {
                AxisRecord axis = (AxisRecord)rs.GetNext();
                rs.GetNext();
                int sid = rs.PeekNextChartSid();
                if (sid == CatSerRangeRecord.sid)
                {
                    ivaxis = new IVAxisAggregate(rs, this, axis);
                }
                else if (sid == ValueRangeRecord.sid)
                {
                    dvaxis = new DVAxisAggregate(rs, this, axis);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Invalid record sid=0x{0:X}. Shoud be CatSerRangeRecord or ValueRangeRecord", sid));
                }

                Debug.Assert(rs.PeekNextChartSid() == AxisRecord.sid);
                dvaxisSecond = new DVAxisAggregate(rs, this, null);
                if (rs.PeekNextChartSid() == AxisRecord.sid)
                {
                    seriesAxis = new SeriesAxisAggregate(rs, this);
                }

                while (rs.PeekNextChartSid() == TextRecord.sid)
                {
                    attachedLabelList.Add(new AttachedLabelAggregate(rs, this));
                }
                if (rs.PeekNextChartSid() == PlotAreaRecord.sid)
                {
                    plotArea = (PlotAreaRecord)rs.GetNext();
                    if (rs.PeekNextChartSid() == FrameRecord.sid)
                    {
                        frame = new FrameAggregate(rs, this);
                    }
                }
            }
        }
Example #9
0
        public SeriesAxisAggregate(RecordStream rs, ChartRecordAggregate container)
            : base("SERIESAXIS", container)
        {
            axis = (AxisRecord)rs.GetNext();
            rs.GetNext();

            if (rs.PeekNextChartSid() == CatSerRangeRecord.sid)
            {
                catSerRange = (CatSerRangeRecord)rs.GetNext();
            }

            axs = new AXSAggregate(rs, this);
            if (rs.PeekNextChartSid() == CrtMlFrtRecord.sid)
            {
                crtmlfrt = new CrtMlFrtAggregate(rs, this);
            }

            Record r = rs.GetNext();//EndRecord

            Debug.Assert(r.GetType() == typeof(EndRecord));
        }
Example #10
0
 private AxisRecord CreateAxisRecord(short axisType)
 {
     AxisRecord r = new AxisRecord();
     r.AxisType = (axisType);
     return r;
 }
Example #11
0
        //
        protected override void ReadContentFrom(BinaryReader reader)
        {
            //Style Attributes Header
            //The style attributes table, version 1.2, is organized as follows:
            //Style attributes header:
            //Type      Name                Description
            //uint16    majorVersion        Major version number of the style attributes table — set to 1.
            //uint16    minorVersion        Minor version number of the style attributes table — set to 2.
            //uint16    designAxisSize      The size in bytes of each axis record.
            //uint16    designAxisCount     The number of design axis records.
            //                              In a font with an 'fvar' table, this value must be greater than or equal to the axisCount value in the 'fvar' table.
            //                              In all fonts, must be greater than zero if axisValueCount is greater than zero.
            //Offset32  designAxesOffset    Offset in bytes from the beginning of the STAT table to the start of the design axes array.
            //                              If designAxisCount is zero, set to zero;
            //                              if designAxisCount is greater than zero, must be greater than zero.
            //uint16    axisValueCount      The number of axis value tables.
            //Offset32  offsetToAxisValueOffsets    Offset in bytes from the beginning of the STAT table to the start of the design axes value offsets array.
            //                                      If axisValueCount is zero, set to zero;
            //                                      if axisValueCount is greater than zero, must be greater than zero.
            //uint16    elidedFallbackNameID    Name ID used as fallback when projection of names into a particular font model produces a subfamily name containing only elidable elements.

            long beginPos = reader.BaseStream.Position;
            //
            ushort majorVersion    = reader.ReadUInt16();
            ushort minorVersion    = reader.ReadUInt16();
            ushort designAxisSize  = reader.ReadUInt16();
            ushort designAxisCount = reader.ReadUInt16();
            //
            uint   designAxesOffset         = reader.ReadUInt32();
            ushort axisValueCount           = reader.ReadUInt16();
            uint   offsetToAxisValueOffsets = reader.ReadUInt32();
            //
            ushort elidedFallbackNameID = (minorVersion != 0) ? reader.ReadUInt16() : (ushort)0;

            //(elidedFallbackNameIDk, In version 1.0 of the style attributes table, the elidedFallbackNameId field was not included. Use of version 1.0 is deprecated)



            //The header is followed by the design axes and axis value offsets arrays, the location of which are provided by offset fields.
            //Type          Name                                Description
            //AxisRecord    designAxes[designAxisCount]         The design-axes array.
            //Offset16      axisValueOffsets[axisValueCount]    Array of offsets to axis value tables,
            //                                                  in bytes from the start of the axis value offsets array.

            //The designAxisSize field indicates the size of each axis record.
            //Future minor-version updates of the STAT table may define compatible extensions
            //to the axis record format with additional fields.
            //**Implementations must use the designAxisSize designAxisSize field to determine the start of each record.**


            //Axis Records
            //The axis record provides information about a single design axis.
            //AxisRecord:
            //Type      Name            Description
            //Tag       axisTag         A tag identifying the axis of design variation.
            //uint16    axisNameID      The name ID for entries in the 'name' table that provide a display string for this axis.
            //uint16    axisOrdering    A value that applications can use to determine primary sorting of face names, or for ordering of descriptors when composing family or face names.

            AxisRecord[] axisRecords = new AxisRecord[designAxisCount];
            for (int i = 0; i < designAxisCount; ++i)
            {
                var axisRecord = new AxisRecord();
                axisRecords[i]          = axisRecord;
                axisRecord.axisTagName  = Utils.TagToString(reader.ReadUInt32()); //4
                axisRecord.axisNameId   = reader.ReadUInt16();                    //2
                axisRecord.axisOrdering = reader.ReadUInt16();                    //2


                //***
                if (designAxisSize > 8)
                {
                    //**Implementations must use the designAxisSize designAxisSize field to determine the start of each record.**
                    //Future minor-version updates of the STAT table may define compatible extensions
                    //to the axis record format with additional fields.


                    // so skip more ...
                    //
                    //at least there are 8 bytes
                    reader.BaseStream.Position += (designAxisSize - 8);
                }
            }


            long axisValueOffsets_beginPos = reader.BaseStream.Position = beginPos + offsetToAxisValueOffsets;

            ushort[] axisValueOffsets = Utils.ReadUInt16Array(reader, axisValueCount); // Array of offsets to axis value tables,in bytes from the start of the axis value offsets array.


            //move to axis value record

            AxisValueTableBase[] axisValueTables = new AxisValueTableBase[axisValueCount];
            for (int i = 0; i < axisValueCount; ++i)
            {
                //Axis Value Tables
                //Axis value tables provide details regarding a specific style - attribute value on some specific axis of design variation,
                //or a combination of design-variation axis values, and the relationship of those values to name elements.
                //This information can be useful for presenting fonts in application user interfaces.

                //
                //read each axis table
                ushort offset = axisValueOffsets[i];
                reader.BaseStream.Position = axisValueOffsets_beginPos + offset;

                ushort             format       = reader.ReadUInt16();//common field of all axis value table
                AxisValueTableBase axisValueTbl = null;
                switch (format)
                {
                default: throw new NotSupportedException();

                case 1: axisValueTbl = new AxisValueTableFmt1(); break;

                case 2: axisValueTbl = new AxisValueTableFmt2(); break;

                case 3: axisValueTbl = new AxisValueTableFmt3(); break;

                case 4: axisValueTbl = new AxisValueTableFmt4(); break;
                }
                axisValueTbl.ReadContent(reader);
                axisValueTables[i] = axisValueTbl;
            }


            //Each AxisValue record must have a different axisIndex value.
            //The records can be in any order.

            //Flags
            //The following axis value table flags are defined:
            //Mask    Name                            Description
            //0x0001  OLDER_SIBLING_FONT_ATTRIBUTE    If set, this axis value table provides axis value information that is applicable to other fonts within the same font family.This is used if the other fonts were released earlier and did not include information about values for some axis. If newer versions of the other fonts include the information themselves and are present, then this record is ignored.
            //0x0002  ELIDABLE_AXIS_VALUE_NAME        If set, it indicates that the axis value represents the “normal” value for the axis and may be omitted when composing name strings.
            //0xFFFC  Reserved                        Reserved for future use — set to zero.


            //When the OlderSiblingFontAttribute flag is used, implementations may use the information provided to determine behaviour associated with a different font in the same family.
            //If a previously - released family is extended with fonts for style variations from a new axis of design variation,
            //then all of them should include a OlderSiblingFontAttribute table for the “normal” value of earlier fonts.

            //The values in the different fonts should match; if they do not, application behavior may be unpredictable.

            // Note: When the OlderSiblingFontAttribute flag is set, that axis value table is intended to provide default information about other fonts in the same family,
            //but not about the font in which that axis value table is contained.
            //The font should contain different axis value tables that do not use this flag to make declarations about itself.

            //The ElidableAxisValueName flag can be used to designate a “normal” value for an axis that should not normally appear in a face name.
            //For example, the designer may prefer that face names not include “Normal” width or “Regular” weight.
            //If this flag is set, applications are permitted to omit these descriptors from face names, though they may also include them in certain scenarios.

            //Note: Fonts should provide axis value tables for “normal” axis values even if they should not normally be reflected in face names.

            //Note: If a font or a variable-font instance is selected for which all axis values have the ElidableAxisValueName flag set,
            //then applications may keep the name for the weight axis, if present, to use as a constructed subfamily name, with names for all other axis values omitted.

            //When the OlderSiblingFontAttribute flag is set, this will typically be providing information regarding the “normal” value on some newly-introduced axis.
            //In this case, the ElidableAxisValueName flag may also be set, as desired.When applied to the earlier fonts,
            //those likely would not have included any descriptors for the new axis, and so the effects of the ElidableAxisValueName flag are implicitly assumed.

            //If multiple axis value tables have the same axis index, then one of the following should be true:

            //    The font is a variable font, and the axis is defined in the font variations table as a variation.
            //    The OlderSiblingFontAttribute flag is set in one of the records.

            //Two different fonts within a family may share certain style attributes in common.
            //For example, Bold Condensed and Bold Semi Condensed fonts both have the same weight attribute, Bold.
            //Axis value tables for particular values should be implemented consistently across a family.
            //If they are not consistent, applications may exhibit unpredictable behaviors.
        }