Пример #1
0
        public static PatternTable PatternTable(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (index) pattern table index
            // P2: (integer) nx, the dimension of colour array in the direction of the PATTERN SIZE width vector
            // P3: (integer) ny, the dimension of colour array in the direction of the PATTERN SIZE height vector
            // P4: (integer) local colour precision: valid values are as for the local colour precision parameter of CELL ARRAY.
            // P5: (colour array) pattern definition
            int index = reader.ReadIndex();
            int nx    = reader.ReadInteger();
            int ny    = reader.ReadInteger();
            int localColorPrecision = reader.ReadInteger();

            if (localColorPrecision == 0)
            {
                if (reader.Descriptor.ColorSelectionMode == ColorModeType.Direct)
                {
                    localColorPrecision = reader.Descriptor.ColorPrecision;
                }
                else
                {
                    localColorPrecision = reader.Descriptor.ColorIndexPrecision;
                }
            }
            // might be either 1/2/4 or 8/16/32 here; but we want byte-sizes in ReadColor
            if (localColorPrecision >= 8)
            {
                localColorPrecision /= 8;
            }

            var colors = new List <MetafileColor>();
            int count  = nx * ny;

            while (reader.HasMoreData() && count-- > 0)
            {
                colors.Add(reader.ReadColor(localColorPrecision));
            }

            return(new PatternTable(index, nx, ny, colors.ToArray()));
        }
Пример #2
0
 public static MarkerColor MarkerColor(MetafileReader reader, CommandHeader commandHeader)
 {
     // P1: (colour) marker colour
     return(new MarkerColor(reader.ReadColor()));
 }
Пример #3
0
        public static InterpolatedInterior InterpolatedInterior(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (index) style: valid values are
            //      1 parallel
            //      2 elliptical
            //      3 triangular
            //      >3 reserved for registered values
            // P2: (2n(size specification)) reference geometry: see part 1, subclause 7.1 for its form.
            // P3: (integer) number of stages (=m)
            // P4: (real) array of m stage designators
            // P5: (colour) array of k colour specifiers: k=3 for triangular, m+1 otherwise.

            int style             = reader.ReadIndex();
            var referenceGeometry = new List <PointF>();
            var stageDesignators  = new List <double>();
            var colorSpecifiers   = new List <MetafileColor>();

            // Legal values of the style parameter are positive integers. [ISO/IEC 8632-1 7.7.43]
            // Values greater than 3 are reserved for future standardization and registration.
            if (style >= 1 && style <= 3)
            {
                // parallel: the number of scalars shall be 2. The FILL REFERENCE POINT is one defining
                //      point of a reference line. A second defining point of the reference line is defined by
                //      the 2 scalars, which are respectively the x and y offset of the second point from the
                //      FILL REFERENCE POINT.
                // elliptical: the number of scalars shall be 4. The FILL REFERENCE POINT is the centre of a
                //      reference ellipse. The first pair of scalars are respectively the x and y offset from
                //      the FILL REFERENCE POINT to the first CDP of ellipse and the second pair are
                //      respectively the x and y offset from the FILL REFERENCE POINT to the second
                //      CDP of ellipse.
                // triangular: the number of scalars shall be 4. The first pair of scalars are respectively the x and
                //      y offset from the FILL REFERENCE POINT to the second corner of a reference
                //      triangle and the second pair are respectively the x and y offset from the FILL
                //      REFERENCE POINT to the third corner of the reference triangle. The number of
                //      stages shall be 0 and the list of stage designators shall be empty.
                int geoCount;
                if (style == 1)
                {
                    geoCount = 2;
                }
                else
                {
                    geoCount = 4;
                }
                for (int i = 0; i < geoCount / 2; i++)
                {
                    double rgX = reader.ReadSizeSpecification(reader.Descriptor.InteriorStyleSpecificationMode);
                    double rgY = reader.ReadSizeSpecification(reader.Descriptor.InteriorStyleSpecificationMode);
                    referenceGeometry.Add(new PointF((float)rgX, (float)rgY));
                }

                int numberOfStages = reader.ReadInteger();
                for (int i = 0; i < numberOfStages; i++)
                {
                    stageDesignators.Add(reader.ReadReal());
                }

                int numberOfColors = style == 3 ? 3 : numberOfStages + 1;
                for (int i = 0; i < numberOfColors; i++)
                {
                    colorSpecifiers.Add(reader.ReadColor());
                }
            }
            return(new InterpolatedInterior(style, referenceGeometry.ToArray(), stageDesignators.ToArray(), colorSpecifiers.ToArray()));
        }
Пример #4
0
 public static LineColor LineColor(MetafileReader reader, CommandHeader commandHeader)
 {
     // P1: (colour) line colour
     return(new LineColor(reader.ReadColor()));
 }
Пример #5
0
 public static EdgeColor EdgeColor(MetafileReader reader, CommandHeader commandHeader)
 {
     // P1: (colour) edge colour
     return(new EdgeColor(reader.ReadColor()));
 }
Пример #6
0
 public static FillColor FillColor(MetafileReader reader, CommandHeader commandHeader)
 {
     // P1: (colour) fill colour
     return(new FillColor(reader.ReadColor()));
 }
Пример #7
0
 public static TextColor TextColor(MetafileReader reader, CommandHeader commandHeader)
 {
     // P1: (colour) text colour
     return(new TextColor(reader.ReadColor()));
 }
Пример #8
0
 public static AuxiliaryColor AuxiliaryColor(MetafileReader reader, CommandHeader commandHeader)
 {
     // P1: (colour) auxiliary colour
     return(new AuxiliaryColor(reader.ReadColor()));
 }
Пример #9
0
        public static CellArray CellArray(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (point) corner point P
            // P2: (point) corner point Q
            // P3: (point) corner point R
            // P4: (integer) nx
            // P5: (integer) ny
            // P6: (integer) local colour precision: valid values are 0, 1, 2, 4, 8, 16, 24, and 32. If the value is zero (the
            //      'default colour precision indicator' value), the COLOUR (INDEX) PRECISION for the picture indicates the
            //      precision with which the colour list is encoded. If the value is non-zero, the precision with which the colour
            //      data is encoded is given by the value.
            // P7: (enumerated) cell representation mode: valid values are
            //      0 run length list mode
            //      1 packed list mode
            // P8: (colour list) array of cell colour values.
            //      If the COLOUR SELECTION MODE is 'direct', the values will be direct colour values. If the COLOUR
            //      SELECTION MODE is 'indexed', the values will be indexes into the COLOUR TABLE.
            //      If the cell representation mode is 'packed list', the colour values are represented by rows of values, each
            //      row starting on a word boundary. If the cell representation mode is 'run length', the colour list values are
            //      represented by rows broken into runs of constant colour; each row starts on a word boundary. Each list
            //      item consists of a cell count (integer) followed by a colour value. With the exception of the first run of a
            //      row, the integer count of each run immediately follows the colour specifier of the preceding run with no
            //      intervening padding.
            var p = reader.ReadPoint();
            var q = reader.ReadPoint();
            var r = reader.ReadPoint();

            int nx = reader.ReadInteger();
            int ny = reader.ReadInteger();

            int localColorPrecision = reader.ReadInteger();

            if (localColorPrecision == 0)
            {
                if (reader.Descriptor.ColorSelectionMode == ColorModeType.Direct)
                {
                    localColorPrecision = reader.Descriptor.ColorPrecision;
                }
                else
                {
                    localColorPrecision = reader.Descriptor.ColorIndexPrecision;
                }
            }
            // might be either 1/2/4 or 8/16/32 here; but we want byte-sizes in ReadColor
            if (localColorPrecision >= 8)
            {
                localColorPrecision /= 8;
            }

            var cellRepresentationMode = reader.ReadEnum <CellRepresentationMode>();

            int totalCount = nx * ny;
            var colors     = new List <MetafileColor>();

            while (colors.Count < totalCount)
            {
                // chunks are split into rows; each row is word-aligned
                // word-align the next read if necessary
                if (reader.Position % 2 == 1 && reader.HasMoreData())
                {
                    reader.ReadByte();
                }

                int rowCount = nx;
                while (rowCount > 0)
                {
                    if (cellRepresentationMode == CellRepresentationMode.RunLengthList)
                    {
                        int cellCount = reader.ReadInteger();
                        rowCount -= cellCount;
                        var cellColor = reader.ReadColor(localColorPrecision);
                        colors.AddRange(Enumerable.Range(0, cellCount).Select(i => cellColor));
                    }
                    else
                    {
                        rowCount--;
                        colors.Add(reader.ReadColor(localColorPrecision));
                    }
                }
            }
            return(new CellArray(p, q, r, nx, ny, colors.ToArray()));
        }