示例#1
0
        public static AspectSourceFlags AspectSourceFlags(MetafileReader reader, CommandHeader commandHeader)
        {
            // ASPECT SOURCE FLAGS: has up to 18 parameter-pairs, corresponding to each attribute that may be
            // bundled; each parameter-pair contains the ASF type and the ASF value:
            // (enumerated) ASF type; valid values are
            //      0 line type ASF
            //      1 line width ASF
            //      2 line colour ASF
            //      3 marker type ASF
            //      4 markersizeASF
            //      5 marker colour ASF
            //      6 text font index ASF
            //      7 text precision ASF
            //      8 character expansion factor ASF
            //      9 character spacing ASF
            //      10 text colour ASF
            //      11 interior style ASF
            //      12 fill colour ASF
            //      13 hatch index ASF
            //      14 pattern index ASF
            //      15 edge type ASF
            //      16 edge width ASF
            //      17 edge colour ASF
            // (enumerated) ASF value; valid values are
            //      0 individual
            //      1 bundled
            var asf = new Dictionary <AspectSourceFlagsType, AspectSourceFlagsValue>();

            while (reader.HasMoreData(2))
            {
                asf[reader.ReadEnum <AspectSourceFlagsType>()] = reader.ReadEnum <AspectSourceFlagsValue>();
            }
            return(new AspectSourceFlags(asf));
        }
        public static FontProperties FontProperties(MetafileReader reader, CommandHeader commandHeader)
        {
            // FONT PROPERTIES: has a variable number of parameter 3-tuples (P1,P2,P3); each parameter 3-tuple contains
            // P1: (index) property indicator, valid values are
            //      1 font index
            //      2 standard version
            //      3 design source
            //      4 font family
            //      5 posture
            //      6 weight
            //      7 proportionate width
            //      8 included glyph collections
            //      9 included glyphs
            //      10 design size
            //      11 minimum size
            //      12 maximum size
            //      13 design group
            //      14 structure
            //      >14 reserved for registered values
            // P2: (integer) priority, valid values are non-negative integers.
            // P3: (structured data record) property value record, each record contains a single member and is comprised of
            // [data type indicator, data element count, data element(s)].
            var properties = new List <FontProperty>();

            while (reader.HasMoreData((reader.Descriptor.IndexPrecision + reader.Descriptor.IntegerPrecision) / 8))
            {
                int propertyIndicator = reader.ReadIndex();
                int priority          = reader.ReadInteger();
                // The SDR for each of the standardized properties contains only one member (typed sequence) [ISO/IEC 8632-1 7.3.21]
                var record = ApplicationStructureDescriptorReader.ReadStructuredDataRecord(reader);
                properties.Add(new FontProperty(propertyIndicator, priority, record.Elements.First()));
            }
            return(new FontProperties(properties.ToArray()));
        }
        public static FontList FontList(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1-Pn: (string fixed) n font names
            var fonts = new List <string>();

            while (reader.HasMoreData())
            {
                fonts.Add(reader.ReadString());
            }
            return(new FontList(fonts));
        }
示例#4
0
        public static ColorTable ColorTable(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (colour index) starting colour table index
            // P2: (direct colour list) list of direct colour values (>3-tuples or 4-tuples of direct colour components (CCO))
            int startIndex = reader.ReadColorIndex();
            var colors     = new List <MetafileColor>();

            while (reader.HasMoreData(3)) // at least 3 color components with at least 1 byte each
            {
                colors.Add(reader.ReadDirectColor());
            }
            return(new ColorTable(startIndex, colors.ToArray()));
        }
示例#5
0
        public static Polygon Polygon(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1-Pn: (point) n (X,Y) polygon vertices
            var points = new List <PointF>();

            // TODO: point is 2 VDCs, but that may range from 8 bits each until up to 64 bits for a single coordinate
            //       this should probably check for 2x VDC size instead of simply 2x minimum-possible VDC size
            while (reader.HasMoreData(2))
            {
                points.Add(reader.ReadPoint());
            }
            return(new Polygon(points.ToArray()));
        }
示例#6
0
        private static List <PointF> ReadPointList(MetafileReader reader)
        {
            var points = new List <PointF>();

            // TODO: point is 2 VDCs, but that may range from 8 bits each until up to 64 bits for a single coordinate
            //       this should probably check for 2x VDC size instead of simply 2x minimum-possible VDC size
            while (reader.HasMoreData(2))
            {
                points.Add(reader.ReadPoint());
            }

            return(points);
        }
示例#7
0
        public static InheritanceFilter InheritanceFilter(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (enumerated list) list of one or more of: (list omitted)
            // P2: (enumerated) setting: valid values are
            //      0 state list
            //      1 segment
            var items = new List <InheritanceFilterItem>();

            while (reader.HasMoreData(4)) // 2 per enum
            {
                items.Add(new InheritanceFilterItem(
                              reader.ReadEnum <InheritanceFilterDesignator>(),
                              reader.ReadEnum <InheritanceFilterSetting>()));
            }
            return(new InheritanceFilter(items.ToArray()));
        }
示例#8
0
        public static LineAndEdgeTypeDefinition LineAndEdgeTypeDefinition(MetafileReader reader, CommandHeader header)
        {
            // P1: (index) line type, valid values are negative.
            // P2: (size specification) dash cycle repeat length: see Part 1, subclause 7.1 for its form.
            //      dash cycle repeat length is affected by LINE WIDTH SPECIFICATION MODE
            // P3-P(n+2): (integer) list of n dash elements
            int    lineType = reader.ReadIndex();
            double dashCycleRepeatLength = reader.ReadSizeSpecification(reader.Descriptor.LineWidthSpecificationMode);
            var    dashElements          = new List <int>();

            while (reader.HasMoreData())
            {
                dashElements.Add(reader.ReadInteger());
            }
            return(new LineAndEdgeTypeDefinition(lineType, dashCycleRepeatLength, dashElements.ToArray()));
        }
        public static CharacterSetList CharacterSetList(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (enumerated) CHARACTER SET TYPE: valid codes are
            //      0 94 - character G - set
            //      1 96 - character G - set
            //      2 94 - character multibyte G-set
            //      3 96 - character multibyte G-set
            //      4 complete code
            // P2: (string fixed) Designation sequence tail; see Part 1, subclause 7.3.14.
            var entries = new List <CharacterSetListEntry>();

            while (reader.HasMoreData(3)) // enums take up 2 bytes, strings at least 1 byte
            {
                entries.Add(new CharacterSetListEntry(reader.ReadEnum <CharacterSetType>(), reader.ReadString()));
            }
            return(new CharacterSetList(entries));
        }
        public static MetafileElementsList MetafileElementsList(MetafileReader reader, CommandHeader commandHeader)
        {
            // P1: (integer) number of elements specified
            // P2: (index-pair array) List of metafile elements in this metafile. Each element is represented by two values:
            //      the first is its element class code (as in Table 2)
            //      the second is its element id code (as in Table 3 to Table 10).
            int numberOfElements = reader.ReadInteger(); // unused
            var elements         = new List <string>();

            while (reader.HasMoreData())
            {
                int elementClass = reader.ReadIndex();
                int elementId    = reader.ReadIndex();
                elements.Add(GetMetafileElementsListName(elementClass, elementId));
            }
            return(new MetafileElementsList(elements));
        }
示例#11
0
        public static PolygonSet PolygonSet(MetafileReader reader, CommandHeader commandHeader)
        {
            // P(i): (point) (X,Y) polygon vertex
            // P(i+1): (enumerated) edge out flag, indicating closures and edge visibility: valid values are
            //      0 invisible
            //      1 visible
            //      2 close, invisible
            //      3 close, visible
            var points = new List <PointF>();
            var flags  = new List <EdgeOutFlags>();

            // TODO: point is 2 VDCs, but that may range from 8 bits each until up to 64 bits for a single coordinate
            //       this should probably check for 2x VDC size instead of simply 2x minimum-possible VDC size
            while (reader.HasMoreData(3))
            {
                points.Add(reader.ReadPoint());
                flags.Add(reader.ReadEnum <EdgeOutFlags>());
            }
            return(new PolygonSet(points.ToArray(), flags.ToArray()));
        }
示例#12
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()));
        }
        public static StructuredDataRecord ReadStructuredDataRecord(MetafileReader reader)
        {
            // overall length seems to be encoded similar to the string length [ISO/IEC 8632-3 7, Table 1, Note 12]
            // (ie. one byte, followed by one word if its 255).
            int length = reader.ReadByte();

            if (length == 255)
            {
                // FIXME: does an SDR also have a long form similar to a string?
                length = reader.ReadWord();
            }

            var  elements      = new List <StructuredDataElement>();
            long startPosition = reader.Position;

            // require at least the number of bytes for the enum and the count; which depends on integer/index precision:
            // > The integer of the "data count" and the index of the "data type index" are represented respectively at the current
            // > Integer Precision and the current Index Precision of the metafile. [ISO/IEC 8632-1 H.2.2]
            // some files seem to include padding or similar, which throws this off by having an extra byte available at the end
            while (reader.HasMoreData((reader.Descriptor.IndexPrecision + reader.Descriptor.IntegerPrecision) / 8))
            {
                // enum is an index at the current index precision for SDR [ISO/IEC 8632-1 H.2.2]
                DataTypeIndex type = (DataTypeIndex)Enum.ToObject(typeof(DataTypeIndex), reader.ReadIndex());
                // count is an interger at the current integer precision for SDR [ISO/IEC 8632-1 H.2.2]
                int      count  = reader.ReadInteger();
                object[] values = new object[count];
                for (int i = 0; i < count; i++)
                {
                    values[i] = ReadValue(reader, type);
                }
                elements.Add(new StructuredDataElement(type, values));
                // only read as much as specified by length
                if (reader.Position - startPosition >= length)
                {
                    break;
                }
            }
            return(new StructuredDataRecord(elements));
        }
示例#14
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()));
        }