예제 #1
0
        /// <summary>
        /// Loads a printer's paper sizes. Returns the default PaperSize, and fills a list of paper_names for use in dialogues
        /// </summary>
        /// <param name="ppd_handle">PPD printer file handle</param>
        /// <param name="settings">PrinterSettings object to fill</param>
        /// <param name="def_size">Default paper size, from the global options of the printer</param>
        /// <param name="paper_names">List of available paper sizes that gets filled</param>
        private PaperSize LoadPrinterPaperSizes(IntPtr ppd_handle, PrinterSettings settings,
                                                string def_size, NameValueCollection paper_names)
        {
            IntPtr    ptr;
            string    real_name;
            PPD_FILE  ppd;
            PPD_SIZE  size;
            PaperSize ps;

            PaperSize defsize = new PaperSize("A4", 827, 1169, GetPaperKind(827, 1169), true);

            ppd = (PPD_FILE)Marshal.PtrToStructure(ppd_handle, typeof(PPD_FILE));
            ptr = ppd.sizes;
            float w, h;

            for (int i = 0; i < ppd.num_sizes; i++)
            {
                size      = (PPD_SIZE)Marshal.PtrToStructure(ptr, typeof(PPD_SIZE));
                real_name = paper_names[size.name];
                w         = size.width * 100 / 72;
                h         = size.length * 100 / 72;
                PaperKind kind = GetPaperKind((int)w, (int)h);
                ps = new PaperSize(real_name, (int)w, (int)h, kind, def_size == kind.ToString());
                ps.SetKind(kind);
                if (def_size == ps.Kind.ToString())
                {
                    defsize = ps;
                }
                settings.paper_sizes.Add(ps);
                ptr = (IntPtr)((long)ptr + Marshal.SizeOf(size));
            }

            return(defsize);
        }
예제 #2
0
        public object Clone()
        {
            // We do a deep copy
            PrinterResolution pres    = new PrinterResolution(this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
            PaperSource       psource = new PaperSource(this.paperSource.SourceName, this.paperSource.Kind);
            PaperSize         psize   = new PaperSize(this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);

            psize.SetKind(this.paperSize.Kind);

            PageSettings ps = new PageSettings(this.printerSettings, this.color, this.landscape,
                                               psize, psource, pres);

            ps.Margins = (Margins)this.margins.Clone();
            return(ps);
        }
        void LoadPrinterPaperSizes(string printer, PrinterSettings settings)
        {
            int    items, ret;
            IntPtr ptr_names, buff_names = IntPtr.Zero;
            IntPtr ptr_sizes, buff_sizes = IntPtr.Zero;
            IntPtr ptr_sizes_enum, buff_sizes_enum = IntPtr.Zero;
            string name;

            if (settings.PaperSizes == null)
            {
                settings.PaperSizes = new PrinterSettings.PaperSizeCollection(new PaperSize [0]);
            }
            else
            {
                settings.PaperSizes.Clear();
            }

            items = Win32DeviceCapabilities(printer, null, DCCapabilities.DC_PAPERSIZE, IntPtr.Zero, IntPtr.Zero);

            if (items == -1)
            {
                return;
            }

            try {
                ptr_sizes      = buff_sizes = Marshal.AllocHGlobal(items * 2 * 4);
                ptr_names      = buff_names = Marshal.AllocHGlobal(items * 64 * 2);
                ptr_sizes_enum = buff_sizes_enum = Marshal.AllocHGlobal(items * 2);
                ret            = Win32DeviceCapabilities(printer, null, DCCapabilities.DC_PAPERSIZE, buff_sizes, IntPtr.Zero);

                if (ret == -1)
                {
                    // the finally clause will free the unmanaged memory before returning
                    return;
                }

                ret = Win32DeviceCapabilities(printer, null, DCCapabilities.DC_PAPERS, buff_sizes_enum, IntPtr.Zero);
                ret = Win32DeviceCapabilities(printer, null, DCCapabilities.DC_PAPERNAMES, buff_names, IntPtr.Zero);

                int       x, y;
                PaperSize ps;
                PaperKind kind;
                for (int i = 0; i < ret; i++)
                {
                    x = Marshal.ReadInt32(ptr_sizes, i * 8);
                    y = Marshal.ReadInt32(ptr_sizes, (i * 8) + 4);

                    x = PrinterUnitConvert.Convert(x, PrinterUnit.TenthsOfAMillimeter,
                                                   PrinterUnit.Display);

                    y = PrinterUnitConvert.Convert(y, PrinterUnit.TenthsOfAMillimeter,
                                                   PrinterUnit.Display);

                    name      = Marshal.PtrToStringUni(ptr_names);
                    ptr_names = new IntPtr(ptr_names.ToInt64() + 64 * 2);

                    kind           = (PaperKind)Marshal.ReadInt16(ptr_sizes_enum);
                    ptr_sizes_enum = new IntPtr(ptr_sizes_enum.ToInt64() + 2);

                    ps = new PaperSize(name, x, y);
                    ps.SetKind(kind);
                    settings.PaperSizes.Add(ps);
                }
            }
            finally {
                if (buff_names != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buff_names);
                }
                if (buff_sizes != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buff_sizes);
                }
                if (buff_sizes_enum != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buff_sizes_enum);
                }
            }
        }
예제 #4
0
		public object Clone ()
		{
			// We do a deep copy
			PrinterResolution pres = new PrinterResolution (this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
			PaperSource psource = new PaperSource (this.paperSource.SourceName, this.paperSource.Kind);
			PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);
			psize.SetKind (this.paperSize.Kind);

			PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape,
					psize, psource, pres);
			ps.Margins = (Margins) this.margins.Clone ();
			return ps;
		}
예제 #5
0
		/// <summary>
		/// Loads a printer's paper sizes. Returns the default PaperSize, and fills a list of paper_names for use in dialogues
		/// </summary>
		/// <param name="ppd_handle">PPD printer file handle</param>
		/// <param name="settings">PrinterSettings object to fill</param>
		/// <param name="def_size">Default paper size, from the global options of the printer</param>
		/// <param name="paper_names">List of available paper sizes that gets filled</param>
		private PaperSize LoadPrinterPaperSizes(IntPtr ppd_handle, PrinterSettings settings, 
												string def_size, NameValueCollection paper_names)
		{
			IntPtr ptr;
			string real_name;
			PPD_FILE ppd;
			PPD_SIZE size;
			PaperSize ps;

			PaperSize defsize = new PaperSize ("A4", 827, 1169, GetPaperKind (827, 1169), true);
			ppd = (PPD_FILE) Marshal.PtrToStructure (ppd_handle, typeof (PPD_FILE));
			ptr = ppd.sizes;
			float w, h;
			for (int i = 0; i < ppd.num_sizes; i++) {
				size = (PPD_SIZE) Marshal.PtrToStructure (ptr, typeof (PPD_SIZE));
				real_name = paper_names[size.name];
				w = size.width * 100 / 72;
				h = size.length * 100 / 72;
				PaperKind kind = GetPaperKind ((int) w, (int) h);
				ps = new PaperSize (real_name, (int) w, (int) h, kind, def_size == kind.ToString ());
				ps.SetKind (kind);
				if (def_size == ps.Kind.ToString ())
					defsize = ps;
				settings.paper_sizes.Add (ps);
				ptr = (IntPtr) ((long)ptr + Marshal.SizeOf (size));
			}
			
			return defsize;

		}
예제 #6
0
		void LoadPrinterPaperSizes (string printer, PrinterSettings settings)
		{
			int items, ret;
			IntPtr ptr_names, buff_names = IntPtr.Zero;
			IntPtr ptr_sizes, buff_sizes = IntPtr.Zero;
			IntPtr ptr_sizes_enum, buff_sizes_enum = IntPtr.Zero;
			string name;

			if (settings.PaperSizes == null)
				settings.paper_sizes = new PrinterSettings.PaperSizeCollection (new PaperSize [0]);
			else
				settings.PaperSizes.Clear ();

			items = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, IntPtr.Zero, IntPtr.Zero);

			if (items == -1)
				return;

			try {
				ptr_sizes = buff_sizes = Marshal.AllocHGlobal (items * 2 * 4);
				ptr_names = buff_names = Marshal.AllocHGlobal (items * 64 * 2);
				ptr_sizes_enum = buff_sizes_enum = Marshal.AllocHGlobal (items * 2);
				ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, buff_sizes, IntPtr.Zero);

				if (ret == -1) {
					// the finally clause will free the unmanaged memory before returning
					return;
				}

				ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERS, buff_sizes_enum, IntPtr.Zero);
				ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERNAMES, buff_names, IntPtr.Zero);

				int x, y;
				PaperSize ps;
				PaperKind kind;
				for (int i = 0; i < ret; i++) {
					x = Marshal.ReadInt32 (ptr_sizes, i * 8);
					y = Marshal.ReadInt32 (ptr_sizes, (i * 8) + 4);

					x = PrinterUnitConvert.Convert (x, PrinterUnit.TenthsOfAMillimeter,
					      PrinterUnit.Display);

					y = PrinterUnitConvert.Convert (y, PrinterUnit.TenthsOfAMillimeter,
					      PrinterUnit.Display);

					name  = Marshal.PtrToStringUni (ptr_names);
					ptr_names = new IntPtr (ptr_names.ToInt64 () + 64 * 2);

					kind = (PaperKind) Marshal.ReadInt16 (ptr_sizes_enum);
					ptr_sizes_enum = new IntPtr (ptr_sizes_enum.ToInt64 () + 2);

					ps = new PaperSize (name, x,y);
					ps.SetKind (kind);
					settings.PaperSizes.Add (ps);
				}
			}
			finally {
				if (buff_names != IntPtr.Zero)
					Marshal.FreeHGlobal (buff_names);
				if (buff_sizes != IntPtr.Zero)
					Marshal.FreeHGlobal (buff_sizes);
				if (buff_sizes_enum != IntPtr.Zero)
					Marshal.FreeHGlobal (buff_sizes_enum);
			}
		}