예제 #1
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(Resources.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);
            WriteAttribute(output, "HorizontalAlignment", "Left");
            WriteAttribute(output, "VerticalAlignment", "Top");

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

            WriteEndElement(output);
        }