コード例 #1
0
        /// <summary>
        /// Sets the stdio and display device callback handlers.
        /// </summary>
        /// <param name="stdIO">Stdio callback handler.</param>
        /// <param name="displayDevice">DisplayDevice callback handler.</param>
        public void Setup(GhostscriptStdIO stdIO, GhostscriptDisplayDeviceHandler displayDevice)
        {
            // check if we need to set stdio handler
            if (stdIO != null)
            {
                // check if stdio handler is not already set
                if (_stdIO == null)
                {
                    // GSAPI: set the stdio callback handlers
                    int rc_stdio = _gs.gsapi_set_stdio(_gs_instance,
                                                       stdIO != null ? stdIO._std_in : null,
                                                       stdIO != null ? stdIO._std_out : null,
                                                       stdIO != null ? stdIO._std_err : null);

                    // check if the stdio callback handlers are set correctly
                    if (ierrors.IsError(rc_stdio))
                    {
                        throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio);
                    }

                    // remember it
                    _stdIO = stdIO;
                }
                else
                {
                    throw new GhostscriptException("StdIO callback handler is already set.");
                }
            }

            // check if a custom display device needs to be used
            if (displayDevice != null)
            {
                // check if display device is already set
                if (_displayDevice == null)
                {
                    // allocate a memory for the display device callback handler
                    _displayDevice_callback_handle = Marshal.AllocCoTaskMem(displayDevice._callback.size);

                    // copy display device callback structure content to the pre-allocated block of memory
                    Marshal.StructureToPtr(displayDevice._callback, _displayDevice_callback_handle, true);

                    // GSAPI: set the display device callback handler
                    int rc_dev = _gs.gsapi_set_display_callback(_gs_instance, _displayDevice_callback_handle);

                    // check if the display callback handler is set correctly
                    if (ierrors.IsError(rc_dev))
                    {
                        throw new GhostscriptAPICallException("gsapi_set_display_callback", rc_dev);
                    }

                    // remember it
                    _displayDevice = displayDevice;
                }
                else
                {
                    throw new GhostscriptException("DisplayDevice callback is already set!");
                }
            }
        }
コード例 #2
0
        public void Setup(GhostscriptStdIO stdIO, GhostscriptDisplayDevice displayDevice)
        {
            if (stdIO != null)
            {
                if (_stdIO == null)
                {
                    int rc_stdio = _gs.gsapi_set_stdio(_gs_instance,
                                                       stdIO != null ? stdIO._std_in : null,
                                                       stdIO != null ? stdIO._std_out : null,
                                                       stdIO != null ? stdIO._std_err : null);

                    if (ierrors.IsError(rc_stdio))
                    {
                        throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio);
                    }

                    _stdIO = stdIO;
                }
                else
                {
                    throw new GhostscriptException("StdIO callback is already set!");
                }
            }

            if (displayDevice != null)
            {
                if (_displayDevice == null)
                {
                    _displayDevice_callback_handle = Marshal.AllocCoTaskMem(displayDevice._callback.size);

                    Marshal.StructureToPtr(displayDevice._callback, _displayDevice_callback_handle, true);

                    int rc_dev = _gs.gsapi_set_display_callback(_gs_instance, _displayDevice_callback_handle);

                    if (ierrors.IsError(rc_dev))
                    {
                        throw new GhostscriptAPICallException("gsapi_set_display_callback", rc_dev);
                    }

                    _displayDevice = displayDevice;
                }
                else
                {
                    throw new GhostscriptException("DisplayDevice callback is already set!");
                }
            }
        }