Ejemplo n.º 1
0
        public static MetafileHeader GetMetafileHeader(String fileName)
        {
            Metafile       file   = new Metafile(fileName);
            MetafileHeader header = file.GetMetafileHeader();

            file.Detach();
            return(header);
        }
Ejemplo n.º 2
0
        // Convenience wrappers for "GetMetafileHeader".
        public static MetafileHeader GetMetafileHeader(IntPtr henhmetafile)
        {
            Metafile       file   = new Metafile(henhmetafile, false);
            MetafileHeader header = file.GetMetafileHeader();

            file.Detach();
            return(header);
        }
Ejemplo n.º 3
0
        public static MetafileHeader GetMetafileHeader(Stream stream)
        {
            Metafile       file   = new Metafile(stream);
            MetafileHeader header = file.GetMetafileHeader();

            file.Detach();
            return(header);
        }
Ejemplo n.º 4
0
        public static MetafileHeader GetMetafileHeader
            (IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader)
        {
            Metafile       file   = new Metafile(hmetafile, wmfHeader);
            MetafileHeader header = file.GetMetafileHeader();

            file.Detach();
            return(header);
        }
Ejemplo n.º 5
0
	public static MetafileHeader GetMetafileHeader(Stream stream)
			{
				Metafile file = new Metafile(stream);
				MetafileHeader header = file.GetMetafileHeader();
				file.Detach();
				return header;
			}
Ejemplo n.º 6
0
	// Convenience wrappers for "GetMetafileHeader".
	public static MetafileHeader GetMetafileHeader(IntPtr henhmetafile)
			{
				Metafile file = new Metafile(henhmetafile, false);
				MetafileHeader header = file.GetMetafileHeader();
				file.Detach();
				return header;
			}
Ejemplo n.º 7
0
		private void CheckEmptyHeader (Metafile mf, EmfType type)
		{
			MetafileHeader mh = mf.GetMetafileHeader ();
			Assert.AreEqual (0, mh.Bounds.X, "Bounds.X");
			Assert.AreEqual (0, mh.Bounds.Y, "Bounds.Y");
			Assert.AreEqual (0, mh.Bounds.Width, "Bounds.Width");
			Assert.AreEqual (0, mh.Bounds.Height, "Bounds.Height");
			Assert.AreEqual (0, mh.MetafileSize, "MetafileSize");
			switch (type) {
			case EmfType.EmfOnly:
				Assert.AreEqual (MetafileType.Emf, mh.Type, "Type");
				break;
			case EmfType.EmfPlusDual:
				Assert.AreEqual (MetafileType.EmfPlusDual, mh.Type, "Type");
				break;
			case EmfType.EmfPlusOnly:
				Assert.AreEqual (MetafileType.EmfPlusOnly, mh.Type, "Type");
				break;
			default:
				Assert.Fail ("Unknown EmfType '{0}'", type);
				break;
			}
		}
Ejemplo n.º 8
0
		public void GetMetafileHeader_WmfPlaceable ()
		{
			using (Metafile mf = new Metafile (getInFile (WmfPlaceable))) {
				MetafileHeader header1 = mf.GetMetafileHeader ();
				Check_MetafileHeader_WmfPlaceable (header1);

				MetafileHeader header2 = mf.GetMetafileHeader ();
				Assert.IsFalse (Object.ReferenceEquals (header1, header2), "Same object");
			}
		}
Ejemplo n.º 9
0
		public void GetMetafileHeader_FromFileStream_Emf ()
		{
			using (FileStream fs = File.OpenRead (getInFile (Emf))) {
				using (Metafile mf = new Metafile (fs)) {
					MetafileHeader header1 = mf.GetMetafileHeader ();
					Check_MetafileHeader_Emf (header1);
				}
			}
		}
Ejemplo n.º 10
0
		public void GetMetafileHeader_FromMemoryStream_Emf ()
		{
			MemoryStream ms;
			string filename = getInFile (Emf);
			using (FileStream fs = File.OpenRead (filename)) {
				byte[] data = new byte[fs.Length];
				fs.Read (data, 0, data.Length);
				ms = new MemoryStream (data);
			}
			using (Metafile mf = new Metafile (ms)) {
				MetafileHeader header1 = mf.GetMetafileHeader ();
				Check_MetafileHeader_Emf (header1);
			}
			ms.Close ();
		}
Ejemplo n.º 11
0
		public void GetMetafileHeader_FromFile_Emf ()
		{
			using (Metafile mf = new Metafile (getInFile (Emf))) {
				MetafileHeader header1 = mf.GetMetafileHeader ();
				Check_MetafileHeader_Emf (header1);
			}
		}
Ejemplo n.º 12
0
		public void GetMetafileHeader_FromMemoryStream_WmfPlaceable ()
		{
			MemoryStream ms;
			string filename = getInFile (WmfPlaceable);
			using (FileStream fs = File.OpenRead (filename)) {
				byte[] data = new byte[fs.Length];
				fs.Read (data, 0, data.Length);
				ms = new MemoryStream (data);
			}
			using (Metafile mf = new Metafile (ms)) {
				MetafileHeader header1 = mf.GetMetafileHeader ();
				Check_MetafileHeader_WmfPlaceable (header1);

				MetaHeader mh1 = header1.WmfHeader;
				Check_MetaHeader_WmfPlaceable (mh1);

				MetaHeader mh2 = mf.GetMetafileHeader ().WmfHeader;
				Assert.IsFalse (Object.ReferenceEquals (mh1, mh2), "Same object");
			}
			ms.Close ();
		}
Ejemplo n.º 13
0
		public void GetMetafileHeader_FromFileStream_WmfPlaceable ()
		{
			using (FileStream fs = File.OpenRead (getInFile (WmfPlaceable))) {
				using (Metafile mf = new Metafile (fs)) {
					MetafileHeader header1 = mf.GetMetafileHeader ();
					Check_MetafileHeader_WmfPlaceable (header1);

					MetaHeader mh1 = header1.WmfHeader;
					Check_MetaHeader_WmfPlaceable (mh1);

					MetaHeader mh2 = mf.GetMetafileHeader ().WmfHeader;
					Assert.IsFalse (Object.ReferenceEquals (mh1, mh2), "Same object");
				}
			}
		}
Ejemplo n.º 14
0
	public static MetafileHeader GetMetafileHeader(String fileName)
			{
				Metafile file = new Metafile(fileName);
				MetafileHeader header = file.GetMetafileHeader();
				file.Detach();
				return header;
			}
        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            //1. Avoid unintended rounding issues
            //   by specifying units directly as 100ths of a mm (GDI)
            //   This can be done by reading directly as a stream with no HDC
            var mf = new Metafile(_PrintingStreams[_PrintingIndex]);

            //2. Apply scaling to correct for dpi differences
            //   E.g. the mf.Width needs the PrintDpiX in order
            //        to be translated to a real width (in mm)
            var mfh = mf.GetMetafileHeader();
            e.Graphics.ScaleTransform(mfh.DpiX / _PrintingDPI.X,
                       mfh.DpiY / _PrintingDPI.Y, MatrixOrder.Prepend);

            //3. Apply scaling to fit to current page by shortest difference
            //   by comparing real page size with available printable area in 100ths of an inch
            var size = new PointF((float)mf.Size.Width / _PrintingDPI.X * 100.0f,
                                  (float)mf.Size.Height / _PrintingDPI.Y * 100.0f);
            size.X = (float)Math.Floor(e.PageSettings.PrintableArea.Width) / size.X;
            size.Y = (float)Math.Floor(e.PageSettings.PrintableArea.Height) / size.Y;
            var scale = Math.Min(size.X, size.Y);
            e.Graphics.ScaleTransform(scale, scale, MatrixOrder.Append);

            //4. Draw the image at the adjusted coordinates
            //   i.e. these are real coordinates so need to reverse the transform that is about
            //        to be applied so that when it is, these real coordinates will be the result.
            var points = new[] { new Point(e.PageSettings.Margins.Left, e.PageSettings.Margins.Top) };
            var matrix = e.Graphics.Transform;
            matrix.Invert();
            matrix.TransformPoints(points);
            //
            e.Graphics.DrawImageUnscaled(mf, points[0]);

            _PrintingIndex++;
            e.HasMorePages = (_PrintingIndex < _PrintingStreams.Count);
        }
Ejemplo n.º 16
0
	public static MetafileHeader GetMetafileHeader
				(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader)
			{
				Metafile file = new Metafile(hmetafile, wmfHeader);
				MetafileHeader header = file.GetMetafileHeader();
				file.Detach();
				return header;
			}
Ejemplo n.º 17
0
        private void send_metafile_to_printer(Metafile metafile, PrintPageEventArgs e)
        {

            // constants
            const float unit_factor = 100.0f;

            // prefs
            var desired_printing_dpi = new System.Drawing.SizeF(300.0f, 300.0f);

            // Retrieve metadfile information
            var metafile_header = metafile.GetMetafileHeader();
            var metafile_dpi = new System.Drawing.SizeF(metafile_header.DpiX, metafile_header.DpiY);

            // Based on the orientation command, adjust the printer orientation
            var orient_command = SSRSCommon.PageOrientationCommand.UseDefaultPrinterSetting;

            if (orient_command == SSRSCommon.PageOrientationCommand.ForceLandscape)
            {
                e.PageSettings.Landscape = true;
            }
            else if (orient_command == SSRSCommon.PageOrientationCommand.ForcePortrait)
            {
                e.PageSettings.Landscape = false;
            }
            else if (orient_command == SSRSCommon.PageOrientationCommand.UseDefaultPrinterSetting)
            {
                // do nothing
            }
            else if (orient_command == SSRSCommon.PageOrientationCommand.UseReportDesign)
            {
                bool design_landscape = metafile.Width > metafile.Height;
                e.PageSettings.Landscape = design_landscape;
            }

            // Retrieve information about the printer
            var papersize = new SD.SizeF(e.PageSettings.PaperSize.Width, e.PageSettings.PaperSize.Height);
            //var printable_size = new SD.SizeF(e.PageSettings.PrintableArea.Width, e.PageSettings.PrintableArea.Height);

            // ------------------------------------------------------------------
            // find the metafile size in printer units
            var dpi_factor = metafile_dpi.DivideBy(desired_printing_dpi);
            e.Graphics.ScaleTransform(dpi_factor.Width, dpi_factor.Height, System.Drawing.Drawing2D.MatrixOrder.Prepend);
            var metafile_size_normalized = metafile.Size.ToSizeF().DivideBy(desired_printing_dpi).MultiplyBy(unit_factor);
            var metafile_size_oriented = e.PageSettings.Landscape ? metafile_size_normalized.FlipSides() : metafile_size_normalized;

            // ----------------------------------------------------
            // Calculate the scaling factor to use on the metafile - do we need to shrink it down to fit the page or not.
            
            float scale_to_fit_factor = 1.0f; // 1.0 = don't scale the metafile at all
            if (!metafile_size_normalized.FitsInside(papersize))
            {
                scale_to_fit_factor = papersize.DivideBy(metafile_size_oriented).GetSmallestSide();
            }

            // we now have all the information we need to scale
            e.Graphics.ScaleTransform(scale_to_fit_factor, scale_to_fit_factor, System.Drawing.Drawing2D.MatrixOrder.Append);

            // shift the metafile by hard margin size to aling to the top left side of the paper
            int hm_offset_x = (int) e.PageSettings.HardMarginX*-1;
            int hm_offset_y = (int) e.PageSettings.HardMarginY * -1;
            var hm_offset = new SD.Point(hm_offset_x, hm_offset_y);
            var points = new[] { hm_offset };
            var matrix = e.Graphics.Transform;
            matrix.Invert();
            matrix.TransformPoints(points);

            // --------------------------------------------------------------------
            // Draw the image
            
            e.Graphics.DrawImageUnscaled(metafile, points[0]);
        }