예제 #1
0
        /// <include file='doc\Metafile.uex' path='docs/doc[@for="Metafile.Metafile27"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Imaging.Metafile'/> class with the
        ///       specified filename.
        ///    </para>
        /// </devdoc>
        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            IntSecurity.DemandReadFileIO(fileName);
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty)
            {
                status = SafeNativeMethods.GdipRecordMetafileFileName(fileName, new HandleRef(null, referenceHdc), (int)type, NativeMethods.NullHandleRef, (int)frameUnit,
                                                                      description, out metafile);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.GdipRecordMetafileFileNameI(fileName, new HandleRef(null, referenceHdc), (int)type,
                                                                       ref gprect, (int)frameUnit,
                                                                       description, out metafile);
            }

            if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            SetNativeImage(metafile);
        }
예제 #2
0
        /// <include file='doc\PrivateFontCollection.uex' path='docs/doc[@for="PrivateFontCollection.AddFontFile"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Adds a font from the specified file to
        ///       this <see cref='System.Drawing.Text.PrivateFontCollection'/>.
        ///    </para>
        /// </devdoc>
        public void AddFontFile(string filename)
        {
            IntSecurity.DemandReadFileIO(filename);
            int status = SafeNativeMethods.GdipPrivateAddFontFile(new HandleRef(this, nativeFontCollection), filename);

            if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }
        }
        public void SetOutputChannelColorProfile(string colorProfileFilename, ColorAdjustType type)
        {
            IntSecurity.DemandReadFileIO(colorProfileFilename);
            int status = SafeNativeMethods.Gdip.GdipSetImageAttributesOutputChannelColorProfile(new HandleRef(this, this.nativeImageAttributes), type, true, colorProfileFilename);

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
        }
        /// <include file='doc\PrivateFontCollection.uex' path='docs/doc[@for="PrivateFontCollection.AddFontFile"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Adds a font from the specified file to
        ///       this <see cref='System.Drawing.Text.PrivateFontCollection'/>.
        ///    </para>
        /// </devdoc>
        public void AddFontFile(string filename)
        {
            IntSecurity.DemandReadFileIO(filename);
            int status = SafeNativeMethods.Gdip.GdipPrivateAddFontFile(new HandleRef(this, nativeFontCollection), filename);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            // Register private font with GDI as well so pure GDI-based controls (TextBox, Button for instance) can access it.
            SafeNativeMethods.AddFontFile(filename);
        }
예제 #5
0
        public Metafile(string filename)
        {
            IntSecurity.DemandReadFileIO(filename);

            IntPtr metafile = IntPtr.Zero;

            int status = SafeNativeMethods.Gdip.GdipCreateMetafileFromFile(filename, out metafile);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            SetNativeImage(metafile);
        }
예제 #6
0
        /// <include file='doc\Metafile.uex' path='docs/doc[@for="Metafile.Metafile17"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Imaging.Metafile'/> class with the specified filename.
        ///    </para>
        /// </devdoc>
        public Metafile(string fileName, IntPtr referenceHdc, EmfType type, String description)
        {
            IntSecurity.DemandReadFileIO(fileName);
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            int status = SafeNativeMethods.GdipRecordMetafileFileName(fileName, new HandleRef(null, referenceHdc), (int)type, NativeMethods.NullHandleRef,
                                                                      (int)MetafileFrameUnit.GdiCompatible, description,
                                                                      out metafile);

            if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            SetNativeImage(metafile);
        }
예제 #7
0
        public static MetafileHeader GetMetafileHeader(string fileName)
        {
            IntSecurity.DemandReadFileIO(fileName);

            MetafileHeader header = new MetafileHeader();

            IntPtr memory = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MetafileHeaderEmf)));

            try {
                int status = SafeNativeMethods.Gdip.GdipGetMetafileHeaderFromFile(fileName, memory);

                if (status != SafeNativeMethods.Gdip.Ok)
                {
                    throw SafeNativeMethods.Gdip.StatusException(status);
                }

                int[] type = new int[] { 0 };

                Marshal.Copy(memory, type, 0, 1);

                MetafileType metafileType = (MetafileType)type[0];

                if (metafileType == MetafileType.Wmf ||
                    metafileType == MetafileType.WmfPlaceable)
                {
                    // WMF header
                    header.wmf = (MetafileHeaderWmf)UnsafeNativeMethods.PtrToStructure(memory, typeof(MetafileHeaderWmf));
                    header.emf = null;
                }
                else
                {
                    // EMF header
                    header.wmf = null;
                    header.emf = (MetafileHeaderEmf)UnsafeNativeMethods.PtrToStructure(memory, typeof(MetafileHeaderEmf));
                }
            }
            finally {
                Marshal.FreeHGlobal(memory);
            }

            return(header);
        }
예제 #8
0
        // WARNING: if you have nested PrintControllers, this method won't get called on the inner one.
        // Add initialization code to StartPrint or StartPage instead.
        internal void Print(PrintDocument document)
        {
            IntSecurity.SafePrinting.Demand();
            // Most of the printing security is left to the individual print controller

            // Check that user has permission to print to this particular printer
            PrintEventArgs printEvent = new PrintEventArgs();

            document._OnBeginPrint(printEvent);
            if (printEvent.Cancel)
            {
                return;
            }

            OnStartPrint(document, printEvent);
            bool canceled = true;

            try {
                canceled = PrintLoop(document);
            }
            finally {
                try {
                    try {
                        document._OnEndPrint(printEvent);
                        printEvent.Cancel = canceled | printEvent.Cancel;
                    }
                    finally {
                        OnEndPrint(document, printEvent);
                    }
                }
                finally {
                    if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                    {
                        // Ensure programs with SafePrinting only get to print once for each time they
                        // throw up the PrintDialog.
                        IntSecurity.AllPrinting.Assert();
                        document.PrinterSettings.PrintDialogDisplayed = false;
                    }
                }
            }
        }
예제 #9
0
        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect,
                        MetafileFrameUnit frameUnit, EmfType type, String description)
        {
            IntSecurity.DemandReadFileIO(fileName);
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            GPRECTF rectf  = new GPRECTF(frameRect);
            int     status = SafeNativeMethods.Gdip.GdipRecordMetafileFileName(fileName,
                                                                               new HandleRef(null, referenceHdc),
                                                                               unchecked ((int)type),
                                                                               ref rectf,
                                                                               unchecked ((int)frameUnit),
                                                                               description,
                                                                               out metafile);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            SetNativeImage(metafile);
        }
        internal void Print(PrintDocument document)
        {
            PrintAction printToPreview;

            IntSecurity.SafePrinting.Demand();
            if (this.IsPreview)
            {
                printToPreview = PrintAction.PrintToPreview;
            }
            else
            {
                printToPreview = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
            }
            PrintEventArgs e = new PrintEventArgs(printToPreview);

            document._OnBeginPrint(e);
            if (e.Cancel)
            {
                document._OnEndPrint(e);
            }
            else
            {
                this.OnStartPrint(document, e);
                if (e.Cancel)
                {
                    document._OnEndPrint(e);
                    this.OnEndPrint(document, e);
                }
                else
                {
                    bool flag = true;
                    try
                    {
                        flag = this.PrintLoop(document);
                    }
                    finally
                    {
                        try
                        {
                            try
                            {
                                document._OnEndPrint(e);
                                e.Cancel = flag | e.Cancel;
                            }
                            finally
                            {
                                this.OnEndPrint(document, e);
                            }
                        }
                        finally
                        {
                            if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                            {
                                IntSecurity.AllPrinting.Assert();
                                document.PrinterSettings.PrintDialogDisplayed = false;
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
        internal void Print(PrintDocument document)
        {
            IntSecurity.SafePrinting.Demand();
            // Most of the printing security is left to the individual print controller

            //
            // Get the PrintAction for this event
            PrintAction printAction;

            if (IsPreview)
            {
                printAction = PrintAction.PrintToPreview;
            }
            else
            {
                printAction = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
            }

            // Check that user has permission to print to this particular printer
            PrintEventArgs printEvent = new PrintEventArgs(printAction);

            document._OnBeginPrint(printEvent);
            if (printEvent.Cancel)
            {
                document._OnEndPrint(printEvent);
                return;
            }

            OnStartPrint(document, printEvent);
            if (printEvent.Cancel)
            {
                document._OnEndPrint(printEvent);
                OnEndPrint(document, printEvent);
                return;
            }

            bool canceled = true;

            try {
                // To enable optimization of the preview dialog, add the following to the config file:
                // <runtime >
                //     <!-- AppContextSwitchOverrides values are in the form of 'key1=true|false;key2=true|false  -->
                //     <AppContextSwitchOverrides value = "Switch.System.Drawing.Printing.OptimizePrintPreview=true" />
                // </runtime >
                canceled = LocalAppContextSwitches.OptimizePrintPreview ? PrintLoopOptimized(document) : PrintLoop(document);
            }
            finally {
                try {
                    try {
                        document._OnEndPrint(printEvent);
                        printEvent.Cancel = canceled | printEvent.Cancel;
                    }
                    finally {
                        OnEndPrint(document, printEvent);
                    }
                }
                finally {
                    if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                    {
                        // Ensure programs with SafePrinting only get to print once for each time they
                        // throw up the PrintDialog.
                        IntSecurity.AllPrinting.Assert();
                        document.PrinterSettings.PrintDialogDisplayed = false;
                    }
                }
            }
        }