Ejemplo n.º 1
0
        private void WritePolyPolygon(byte[] parameters, EmfContext context, XmlWriter output)
        {
            int count = ReadInt16(parameters, 0);
            int position = count * 2 + 2;
            for (int i = 0; i < count; i++) {
                int pointsCount = ReadInt16(parameters, (i * 2) + 2);
                string points = ReadPoints(parameters, position, pointsCount, context);

                position += 4 * pointsCount;

                WritePolygon(points, context, output);
            }
        }
Ejemplo n.º 2
0
        private void WriteRectangle(byte[] parameters, EmfContext context, XmlWriter output)
        {
            Point rightBottom = ReadPoint(parameters, 0, false, context);
            Point leftTop = ReadPoint(parameters, 4, false, context);

            WriteStartElement(output, "Rectangle");
            WriteAttribute(output, "Canvas.Left", leftTop.X);
            WriteAttribute(output, "Canvas.Top", leftTop.Y);
            WriteAttribute(output, "Width", rightBottom.X - leftTop.X);
            WriteAttribute(output, "Height", rightBottom.Y - leftTop.Y);
            WriteStroke(context.Pen, output);
            WriteFill(context.Brush, output);
            WriteEndElement(output);
        }
Ejemplo n.º 3
0
 private void WritePolygon(string points, EmfContext context, XmlWriter output)
 {
     WriteStartElement(output, "Polygon");
     WriteStroke(context.Pen, output);
     WriteFill(context.Brush, output);
     WriteAttribute(output, "Points", points);
     WriteEndElement(output);
 }
Ejemplo n.º 4
0
        private void WritePolyline(byte[] parameters, EmfContext context, XmlWriter output)
        {
            int count = ReadInt16(parameters, 0);
            string points = ReadPoints(parameters, 2, count, context);

            WriteStartElement(output, "Polyline");
            WriteStroke(context.Pen, output);
            WriteAttribute(output, "Points", points);
            WriteEndElement(output);
        }
Ejemplo n.º 5
0
        private void WriteLine(byte[] parameters, EmfContext context, XmlWriter output)
        {
            Point to = ReadPoint(parameters, 0, false, context);

            WriteStartElement(output, "Line");
            WriteAttribute(output, "X1", context.CurrentPosition.X);
            WriteAttribute(output, "Y1", context.CurrentPosition.Y);
            WriteAttribute(output, "X2", to.X);
            WriteAttribute(output, "Y2", to.Y);
            WriteStroke(context.Pen, output);
            WriteEndElement(output);
        }
Ejemplo n.º 6
0
        private void WritePolygon(byte[] parameters, EmfContext context, XmlWriter output)
        {
            int count = ReadInt16(parameters, 0);
            string points = ReadPoints(parameters, 2, count, context);

            WritePolygon(points, context, output);
        }
Ejemplo n.º 7
0
        private void WriteArc(byte[] parameters, EmfContext context, XmlWriter output)
        {
            Point end = ReadPoint(parameters, 0, false, context);
            Point start = ReadPoint(parameters, 4, false, context);
            Point rightBottom = ReadPoint(parameters, 8, false, context);
            Point leftTop = ReadPoint(parameters, 12, false, context);

            WriteStartElement(output, "Path");
            WriteStroke(context.Pen, output);
            //WriteFill(context.Brush, output);
            WriteStartElement(output, "Path.Data");
            WriteStartElement(output, "PathGeometry");
            WriteStartElement(output, "PathGeometry.Figures");
            WriteStartElement(output, "PathFigure");
            WriteAttribute(output, "StartPoint", start);
            WriteStartElement(output, "PathFigure.Segments");
            WriteStartElement(output, "ArcSegment");
            WriteAttribute(output, "Size", new Size(rightBottom.X - leftTop.X, rightBottom.Y - leftTop.Y));
            WriteAttribute(output, "Point", end);
            WriteEndElement(output);
            WriteEndElement(output);
            WriteEndElement(output);
            WriteEndElement(output);
            WriteEndElement(output);
            WriteEndElement(output);
            WriteEndElement(output);
        }
Ejemplo n.º 8
0
        private bool ReadRecord(Stream stream, EmfContext context, XmlWriter output)
        {
            byte[] header = ByteUtility.Read(stream, 6);
            int size = ReadInt32(header, 0);
            short function = ReadInt16(header, 4);

            if (function == 0) {
                return false;
            }

            byte[] parameters = ByteUtility.Read(stream, (int)((size - 3) * 2));

            if (function == META_SETBKCOLOR) {
                context.BackgroundColor = ReadColor(parameters, 0);
            }
            else if (function == META_SETBKMODE) {
                context.BackgroundMode = ReadInt16(parameters, 0);
            }
            else if (function == META_SETMAPMODE) {
                context.MappingMode = ReadInt16(parameters, 0);
            }
            else if (function == META_SETROP2) {
                HandleNotImplemented("META_SETROP2", parameters);
            }
            else if (function == META_SETPOLYFILLMODE) {
                context.PolyFillMode = ReadInt16(parameters, 0);
            }
            else if (function == META_SETSTRETCHBLTMODE) {
                HandleNotImplemented("META_SETSTRETCHBLTMODE", parameters);
            }
            else if (function == META_SETTEXTCOLOR) {
                context.TextColor = ReadColor(parameters, 0);
            }
            else if (function == META_SETTEXTCHAREXTRA) {
                HandleNotImplemented("META_SETTEXTCHAREXTRA", parameters);
            }
            else if (function == META_SETWINDOWORG) {
                context.WindowOrg = ReadPoint(parameters, 0, false, null);
            }
            else if (function == META_SETWINDOWEXT) {
                context.WindowExt = ReadPoint(parameters, 0, false, null);
            }
            else if (function == META_SETVIEWPORTORG) {
                context.ViewPortOrg = ReadPoint(parameters, 0, false, null);
            }
            else if (function == META_SETVIEWPORTEXT) {
                context.ViewPortExt = ReadPoint(parameters, 0, false, null);
            }
            else if (function == META_OFFSETWINDOWORG) {
                context.OffsetWindowOrg = ReadPoint(parameters, 0, false, null);
            }
            else if (function == META_SCALEWINDOWEXT) {
                //context.ScaleWindowExt = new Scale(parameters);
                HandleNotImplemented("META_EXCLUDECLIPRECT", parameters);
            }
            else if (function == META_OFFSETVIEWPORTORG) {
                context.OffsetViewPortOrg = ReadPoint(parameters, 0, false, null);
            }
            else if (function == META_SCALEVIEWPORTEXT) {
                //context.ScaleViewPortExt = new Scale(parameters);
                HandleNotImplemented("META_EXCLUDECLIPRECT", parameters);
            }
            else if (function == META_LINETO) {
                WriteLine(parameters, context, output);
            }
            else if (function == META_MOVETO) {
                context.CurrentPosition = ReadPoint(parameters, 0, false, context);
            }
            else if (function == META_EXCLUDECLIPRECT) {
                HandleNotImplemented("META_EXCLUDECLIPRECT", parameters);
            }
            else if (function == META_INTERSECTCLIPRECT) {
                HandleNotImplemented("META_INTERSECTCLIPRECT", parameters);
            }
            else if (function == META_ARC){
                WriteArc(parameters, context, output);
            }
            else if (function == META_ELLIPSE) {
                WriteEllipse(parameters, context, output);
            }
            else if (function == META_FLOODFILL) {
                HandleNotImplemented("META_FLOODFILL", parameters);
            }
            else if (function == META_PIE) {
                HandleNotImplemented("META_PIE", parameters);
            }
            else if (function == META_RECTANGLE) {
                WriteRectangle(parameters, context, output);
            }
            else if (function == META_ROUNDRECT) {
                HandleNotImplemented("META_ROUNDRECT", parameters);
            }
            else if (function == META_PATBLT) {
                HandleNotImplemented("META_PATBLT", parameters);
            }
            else if (function == META_SAVEDC) {
                HandleNotImplemented("META_SAVEDC", parameters);
            }
            else if (function == META_SETPIXEL) {
                HandleNotImplemented("META_SETPIXEL", parameters);
            }
            else if (function == META_OFFSETCLIPRGN) {
                HandleNotImplemented("META_OFFSETCLIPRGN", parameters);
            }
            else if (function == META_POLYGON) {
                WritePolygon(parameters, context, output);
            }
            else if (function == META_POLYLINE) {
                WritePolyline(parameters, context, output);
            }
            else if (function == META_ESCAPE) {
                HandleNotImplemented("META_ESCAPE", parameters);
            }
            else if (function == META_RESTOREDC) {
                HandleNotImplemented("META_RESTOREDC", parameters);
            }
            else if (function == META_FILLREGION) {
                HandleNotImplemented("META_FILLREGION", parameters);
            }
            else if (function == META_FRAMEREGION) {
                HandleNotImplemented("META_FRAMEREGION", parameters);
            }
            else if (function == META_INVERTREGION) {
                HandleNotImplemented("META_INVERTREGION", parameters);
            }
            else if (function == META_PAINTREGION) {
                HandleNotImplemented("META_PAINTREGION", parameters);
            }
            else if (function == META_SELECTCLIPREGION) {
                short index = ReadInt16(parameters, 0);
                context.SelectObject(index);
            }
            else if (function == META_SELECTOBJECT) {
                short index = ReadInt16(parameters, 0);
                context.SelectObject(index);
            }
            else if (function == META_SETTEXTALIGN) {
                HandleNotImplemented("META_SETTEXTALIGN", parameters);
            }
            else if (function == META_CHORD) {
                HandleNotImplemented("META_CHORD", parameters);
            }
            else if (function == META_SETMAPPERFLAGS) {
                HandleNotImplemented("META_SETMAPPERFLAGS", parameters);
            }
            else if (function == META_TEXTOUT) {
                HandleNotImplemented("META_TEXTOUT", parameters);
            }
            else if (function == META_EXTTEXTOUT) {
                HandleNotImplemented("META_EXTTEXTOUT", parameters);
            }
            else if (function == META_SETDIBTODEV) {
                HandleNotImplemented("META_SETDIBTODEV", parameters);
            }
            else if (function == META_POLYPOLYGON) {
                WritePolyPolygon(parameters, context, output);
            }
            else if (function == META_DIBBITBLT) {
                HandleNotImplemented("META_DIBBITBLT", parameters);
            }
            else if (function == META_DIBSTRETCHBLT) {
                HandleNotImplemented("META_DIBSTRETCHBLT", parameters);
            }
            else if (function == META_EXTFLOODFILL) {
                HandleNotImplemented("META_EXTFLOODFILL", parameters);
            }
            else if (function == META_DELETEOBJECT) {
                short index = ReadInt16(parameters, 0);
                context.RemoveObject(index);
            }
            else if (function == META_CREATEPENINDIRECT) {
                context.AddObject(new Pen(parameters));
            }
            else if (function == META_CREATEFONTINDIRECT) {
                context.AddObject(new object());

                HandleNotImplemented("META_CREATEFONTINDIRECT", parameters);
            }
            else if (function == META_CREATEBRUSHINDIRECT) {
                context.AddObject(new Brush(parameters));
            }
            else if (function == META_CREATEREGION) {
                context.AddObject(new object());

                HandleNotImplemented("META_CREATEREGION", parameters);
            }
            else if (function == META_STRETCHDIB) {
                HandleNotImplemented("META_STRETCHDIB", parameters);
            }
            else if (function == META_SETTEXTJUSTIFICATION) {
                HandleNotImplemented("META_SETTEXTJUSTIFICATION", parameters);
            }
            else if (function == META_BITBLT) {
                HandleNotImplemented("META_BITBLT", parameters);
            }
            else if (function == META_STRETCHBLT) {
                HandleNotImplemented("META_STRETCHBLT", parameters);
            }
            else if (function == META_CREATEPATTERNBRUSH) {
                context.AddObject(new object());

                HandleNotImplemented("META_CREATEPATTERNBRUSH", parameters);
            }
            else if (function == META_SELECTPALETTE) {
                short index = ReadInt16(parameters, 0);
                context.SelectObject(index);
            }
            else if (function == META_REALIZEPALETTE) {
                HandleNotImplemented("META_REALIZEPALETTE", parameters);
            }
            else if (function == META_ANIMATEPALETTE) {
                HandleNotImplemented("META_ANIMATEPALETTE", parameters);
            }
            else if (function == META_SETPALENTRIES) {
                HandleNotImplemented("META_SETPALENTRIES", parameters);
            }
            else if (function == META_RESIZEPALETTE) {
                HandleNotImplemented("META_RESIZEPALETTE", parameters);
            }
            else if (function == META_CREATEPALETTE) {
                context.AddObject(new object());

                HandleNotImplemented("META_CREATEPALETTE", parameters);
            }
            else if (function == META_SETRELABS) {
                HandleNotImplemented("META_SETRELABS", parameters);
            }
            else {
                OnWarning(Resource.MessageEmfFunctionUnknown, function);
            }

            return true;
        }
Ejemplo n.º 9
0
        internal static string ReadPoints(byte[] parameters, int index, int count, EmfContext context)
        {
            StringBuilder points = new StringBuilder();
            for (int i = index; i < parameters.Length; i += 4) {
                if (i > index) {
                    points.Append(' ');
                }

                Point p = ReadPoint(parameters, i, true, context);

                points.Append(p.Format());
            }

            return points.ToString();
        }
Ejemplo n.º 10
0
        internal static Point ReadPoint(byte[] parameters, int index, bool xy, EmfContext context)
        {
            int x = ReadInt16(parameters, index);
            int y = ReadInt16(parameters, index + 2);

            if (!xy) {
                int c = x;
                x = y;
                y = c;
            }

            if (context != null) {
                return context.Translate(x, y);
            }

            return new Point(x, y);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Writes the XAML from specified EMF input stream.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="output">The output.</param>
        public override void ToXaml(Stream input, XmlWriter output)
        {
            if (input == null) {
                throw new ArgumentNullException("input");
            }

            byte[] header;

            if (!ByteUtility.TryRead(input, 40, out header) || ReadUInt32(header, 0) != 0x9ac6cdd7) {
                throw new ConverterException(Resource.ExceptionNoEmfStream);
            }

            // EMF special header
            short handle = ReadInt16(header, 4);
            short left = ReadInt16(header, 6);
            short top = ReadInt16(header, 8);
            short right = ReadInt16(header, 10);
            short bottom = ReadInt16(header, 12);
            short twipsPerInch = ReadInt16(header, 14);
            int reserved = ReadInt32(header, 16);
            short checksum = ReadInt16(header, 20);

            // EMF meta header
            short fileType = ReadInt16(header, 22);
            short headerSize = ReadInt16(header, 24);
            short version = ReadInt16(header, 26);
            int fileSize = ReadInt32(header, 28);
            short numberOfObjects = ReadInt16(header, 32);
            int maxRecordSize = ReadInt32(header, 34);
            short noParameters = ReadInt16(header, 38);

            EmfContext context = new EmfContext();

            double width = right - left;
            double height = bottom - top;

            context.ViewPortExt = new Point(width, height);
            context.Scale = 1D / 15D * 1440 / twipsPerInch;     // converts twips to pixels

            WriteStartElement(output, "Canvas");
            WriteAttribute(output, "Width", width * context.Scale);
            WriteAttribute(output, "Height", height * context.Scale);

            while (ReadRecord(input, context, output)) ;

            WriteEndElement(output);
        }