Exemplo n.º 1
0
        /// <summary>
        /// Send the print job to Meteor.  When the method returns, all print data has been
        /// sent to Meteor - however, it has not necessarily all been sent to the hardware.
        /// </summary>
        /// <returns>Success / failure</returns>
        public eRET Start()
        {
            eRET rVal;

            // Meteor command to start a print job
            int[] StartJobCmd = new int[] {
                (int)CtrlCmdIds.PCMD_STARTJOB,  // Command ID
                4,                              // Number of DWORD parameters
                jobid,                          // Job ID
                (int)eJOBTYPE.JT_PRELOAD,       // This job uses the preload data path
                (int)eRES.RES_HIGH,             // Print at full resolution
                image.GetDocWidth() + 2         // Needed for Left-To-Right printing only
            };

            // A start job command can fail if there is an existing print job
            // ready or printing in Meteor, or if a previous print job is still
            // aborting.  The sequencing of the main form's control enables should
            // guarantee that thie never happens in this application.
            if ((rVal = PrinterInterfaceCLS.PiSendCommand(StartJobCmd)) != eRET.RVAL_OK)
            {
                return(rVal);
            }
            // The start document command specifies the number of discrete copies
            // of the image which are required
            //
            int[] StartDocCmd = new int[] {
                (int)CtrlCmdIds.PCMD_STARTPDOC, // Command ID
                1,                              // DWORD parameter count
                repeatmode == (REPEAT_MODE.DISCRETE) ? copies : 1
            };
            if ((rVal = PrinterInterfaceCLS.PiSendCommand(StartDocCmd)) != eRET.RVAL_OK)
            {
                return(rVal);
            }
            // For seamless image repeats using the prelod data path, PCMD_REPEAT
            // must be sent after PCMD_STARTPDOC and before the image data.
            //
            if (copies > 1 && repeatmode == REPEAT_MODE.SEAMLESS)
            {
                int[] RepeatCmd = new int[] {
                    (int)CtrlCmdIds.PCMD_REPEAT,    // Command ID
                    1,                              // DWORD parameter cound
                    copies
                };
                if ((rVal = PrinterInterfaceCLS.PiSendCommand(RepeatCmd)) != eRET.RVAL_OK)
                {
                    return(rVal);
                }
            }
            // PCMD_BIGIMAGE must be used if the application needs to pass images
            // which exceed 60MB in size to Meteor as one buffer.  (An alternative
            // is for the application to split up the data into smaller images,
            // each of which can used PCMD_IMAGE).
            //
            // The image data is sent through the Printer Interface to the Meteor
            // Print Engine in chunks.  The application must continually call
            // PiSendCommand with the same buffer while the Print Engine
            // returns RVAL_FULL.
            //
            // Note that it is necessary to fix the location of the image command
            // in memory while carrying out this sequence, to prevent the garbage
            // collector from relocating the buffer (theoretically possible, but
            // highly unlikely) between successive PiSendCommand calls.
            //
            int[] ImageCmd = image.GetBigImageCommand(ytop, bpp);
            unsafe
            {
                fixed(int *pImageCmd = ImageCmd)
                {
                    do
                    {
                        rVal = PrinterInterfaceCLS.PiSendCommand(ImageCmd);
                    } while (rVal == eRET.RVAL_FULL);
                    if (rVal != eRET.RVAL_OK)
                    {
                        return(rVal);
                    }
                }
            }
            int[] EndDocCmd = new int[] { (int)CtrlCmdIds.PCMD_ENDDOC, 0 };
            if ((rVal = PrinterInterfaceCLS.PiSendCommand(EndDocCmd)) != eRET.RVAL_OK)
            {
                return(rVal);
            }
            int[] EndJobCmd = new int[] { (int)CtrlCmdIds.PCMD_ENDJOB, 0 };
            if ((rVal = PrinterInterfaceCLS.PiSendCommand(EndJobCmd)) != eRET.RVAL_OK)
            {
                return(rVal);
            }
            return(eRET.RVAL_OK);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the data for a new print image
        /// </summary>
        private void LoadImage()
        {
            // Attempt to avoid memory allocation problems with large images by
            // cleaning up the currently loading image.  For very large images
            // the 64 bit build of the application should be used.
            if (image != null)
            {
                pictureBoxPrintData.Image = null;
                image.Dispose();
                image = null;
                pictureBoxPrintData.Refresh();
            }
            GC.Collect();
            // Load the new image
            Cursor.Current = Cursors.WaitCursor;
            string FileName = openFileDialogLoadImage.FileName;

            image = ImageDataFactory.Create(FileName);

            if (image != null)
            {
                pictureBoxPrintData.Image           = image.GetPreviewBitmap();
                Cursor.Current                      = Cursors.Default;
                toolStripStatusFilename.Text        = image.GetBaseName();
                toolStripStatusFilename.ToolTipText = FileName;
                toolStripStatusImageDimensions.Text = string.Format("{0} x {1} pixels", image.GetDocWidth(), image.GetDocHeight());
            }
            else
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show("Failed to load image " + openFileDialogLoadImage.FileName,
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                openFileDialogLoadImage.FileName    = "";
                toolStripStatusFilename.Text        = "No image loaded";
                toolStripStatusFilename.ToolTipText = "";
                toolStripStatusImageDimensions.Text = "";
            }
            EnableControls();
        }