Example #1
0
OSStatus  OpenPrinterAndValidate(void)
{
	OSStatus			err = noErr;

	#if TARGET_API_MAC_CARBON
	/////////////////////////////////////////////////
		err =  PMCreateSession(&gPrintSession);
		if(err) return err;

		// get and validate the page formatting
		if (gPageFormat == kPMNoPageFormat) {   // Set up a valid PageFormat object
			err = PMCreatePageFormat(&gPageFormat);
			//  Note that PMPageFormat is not session-specific, but calling
			//  PMSessionDefaultPageFormat assigns values specific to the printer
			//  associated with the current printing session.
			if ((err == noErr) && (gPageFormat != kPMNoPageFormat))
				err = PMSessionDefaultPageFormat(gPrintSession, gPageFormat);
		}
		else{
			err = PMSessionValidatePageFormat(gPrintSession, gPageFormat, kPMDontWantBoolean);
		}
		if(err) return err;
		/////////////////////////////////////////////////
		// let's also get and validate the print settings
		if (gPrintSettings == kPMNoPrintSettings)
		{
			err = PMCreatePrintSettings(&gPrintSettings);	
			// Note that PMPrintSettings is not session-specific, but calling
			// PMSessionDefaultPrintSettings assigns values specific to the printer
			// associated with the current printing session.
			if ((err == noErr) && (gPrintSettings != kPMNoPrintSettings))
				err = PMSessionDefaultPrintSettings(gPrintSession, gPrintSettings);
		}
		else {
			err = PMSessionValidatePrintSettings(gPrintSession, gPrintSettings, kPMDontWantBoolean);
		}

		return err;
	
	#else //// MACB4CARBON ////////////////////////////////////////
	/////////////////////////////////////////////////
		PrOpen();
		err = PrError();
		if(err) return err;		
	   
		// always use the global
		if(gPrRecHdl == nil){
			gPrRecHdl  = (THPrint)_NewHandleClear(sizeof(TPrint));
			if(!gPrRecHdl)return memFullErr; 
			PrintDefault(gPrRecHdl);
		}
	
		PrValidate(gPrRecHdl); 	
		// We ignore the returned value  
		
		return(noErr);
	#endif
} 
Example #2
0
//-----------------------------------------------------------------------------------------------------------------------
// (Borrowed from /Developer/Examples/Printing/App/)
static OSStatus DoPrintDialog(PMPrintSession printSession, PMPageFormat pageFormat, PMPrintSettings* printSettings)
{
    OSStatus	status = noErr;
    Boolean     accepted;
    UInt32      realNumberOfPagesinDoc;
    
    //	In this sample code the caller provides a valid PageFormat reference but in
    //	your application you may want to load and unflatten the PageFormat object
    //	that was saved at PageSetup time.  See LoadAndUnflattenPageFormat below.
    
    //	Set up a valid PrintSettings object.
    if (*printSettings == kPMNoPrintSettings)
    {
        status = PMCreatePrintSettings(printSettings);	
        check(status == noErr);
        // Note that PMPrintSettings is not session-specific, but calling
        // PMSessionDefaultPrintSettings assigns values specific to the printer
        // associated with the current printing session.
        if ((status == noErr) && (*printSettings != kPMNoPrintSettings))
            status = PMSessionDefaultPrintSettings(printSession, *printSettings);
        check(status == noErr);
    }
    else
    {
        status = PMSessionValidatePrintSettings(printSession, *printSettings, kPMDontWantBoolean);
        check(status == noErr);
    }
    
    // Before displaying the Print dialog, we calculate the number of pages in the
    // document.  On Mac OS X this is useful because we can prime the Print dialog
    // with the actual page range of the document and prevent the user from entering
    // out-of-range numbers.  This is not possible on Mac OS 8 and 9 because the driver,
    // not the printing manager, controls the page range fields in the Print dialog.

    // Calculate the number of pages required to print the entire document.
    if (status == noErr)
        status = DetermineNumberOfPagesInDoc(pageFormat, &realNumberOfPagesinDoc);

    // Set a valid page range before displaying the Print dialog
    if (status == noErr)
        status = PMSetPageRange(*printSettings, 1, realNumberOfPagesinDoc);
    check(status == noErr);

    //	Display the Print dialog.
    if (status == noErr)
    {
        status = PMSessionPrintDialog(printSession, *printSettings, pageFormat, &accepted);
        check(status == noErr);
        if (status == noErr && !accepted)
            status = kPMCancel;		// user clicked Cancel button
    }

    return status;
	
}   // DoPrintDialog
Example #3
0
bool QPrinter::cmd(int c, QPainter *, QPDevCmdParam *)
{
  if (!psession && PMCreateSession(&psession) != noErr)
    return FALSE;

  if (c ==  PdcBegin) {                     // begin; start printing
    if (state != PST_IDLE) {
      qDebug("Qt: internal: printer: two PdcBegin(s).");
      return FALSE;
    }

    //just to be sure they've been setup
    prepare(&pformat);
    prepare(&psettings);

    //validate the settings
    if (PMSessionValidatePrintSettings(psession, psettings, kPMDontWantBoolean) != noErr)
      return FALSE;
    if (PMSessionValidatePageFormat(psession, pformat, kPMDontWantBoolean) != noErr)
      return FALSE;

    if (PMSessionBeginDocument(psession, psettings, pformat) != noErr) //begin the document
      return FALSE;


    if (PMSessionBeginPage(psession, pformat, 0) != noErr) //begin the page
      return FALSE;
    if (PMSessionGetGraphicsContext(psession, kPMGraphicsContextQuickdraw,
                                    &hd) != noErr) //get the gworld
      return FALSE;
    state = PST_ACTIVE;
    if (fullPage()) {
      uint top, left, bottom, right;
      qt_get_margins(pformat, &top, &left, &bottom, &right);
      QMacSavedPortInfo mp(this);
      SetOrigin(top, left);
    } else {
      QMacSavedPortInfo mp(this);
      SetOrigin(0, 0);
    }
  } else if (c == PdcEnd) {
    if (hd && state != PST_IDLE) {
      PMSessionEndPage(psession);
      PMSessionEndDocument(psession);
      hd = NULL;
    }
    state  = PST_IDLE;
  } else {                                    // all other commands...
    if (state == PST_ABORTED || ((state == PST_ACTIVE || state == PST_ERROR) && PMSessionError(psession) != noErr))
      return FALSE;
  }
  return TRUE;
}
Example #4
0
void wxMacCarbonPrintData::ValidateOrCreate()
{
    OSStatus err = noErr ;
    if ( m_macPrintSession == kPMNoReference )
    {
        err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
    }
    //  Set up a valid PageFormat object.
    if ( m_macPageFormat == kPMNoPageFormat)
    {
        err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat);

        //  Note that PMPageFormat is not session-specific, but calling
        //  PMSessionDefaultPageFormat assigns values specific to the printer
        //  associated with the current printing session.
        if ((err == noErr) &&
            ( m_macPageFormat != kPMNoPageFormat))
        {
            err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession,
                (PMPageFormat) m_macPageFormat);
        }
    }
    else
    {
        err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
            (PMPageFormat) m_macPageFormat,
            kPMDontWantBoolean);
    }

    //  Set up a valid PrintSettings object.
    if ( m_macPrintSettings == kPMNoPrintSettings)
    {
        err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);

        //  Note that PMPrintSettings is not session-specific, but calling
        //  PMSessionDefaultPrintSettings assigns values specific to the printer
        //  associated with the current printing session.
        if ((err == noErr) &&
            ( m_macPrintSettings != kPMNoPrintSettings))
        {
            err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
                (PMPrintSettings) m_macPrintSettings);
        }
    }
    else
    {
        err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
            (PMPrintSettings) m_macPrintSettings,
            kPMDontWantBoolean);
    }
}
Example #5
0
bool QMacPrintEngine::begin(QPaintDevice *dev)
{
    Q_D(QMacPrintEngine);

    if (d->state == QPrinter::Idle && d->session == 0) // Need to reinitialize
        d->initialize();

    d->paintEngine->state = state;
    d->paintEngine->begin(dev);
    Q_ASSERT_X(d->state == QPrinter::Idle, "QMacPrintEngine", "printer already active");

    if (PMSessionValidatePrintSettings(d->session, d->settings, kPMDontWantBoolean) != noErr
        || PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean) != noErr) {
        d->state = QPrinter::Error;
        return false;
    }

    if (!d->outputFilename.isEmpty()) {
        QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault,
                                                                  QCFString(d->outputFilename),
                                                                  kCFURLPOSIXPathStyle,
                                                                  false);
        if (PMSessionSetDestination(d->session, d->settings, kPMDestinationFile,
                                    kPMDocumentFormatPDF, outFile) != noErr) {
            qWarning("QMacPrintEngine::begin: Problem setting file [%s]", d->outputFilename.toUtf8().constData());
            return false;
        }
    }
    OSStatus status = noErr;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
        status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format)
                                           : PMSessionBeginCGDocument(d->session, d->settings, d->format);
    } else
#endif
    {
#ifndef Q_OS_MAC64
        status = d->shouldSuppressStatus() ? PMSessionBeginDocumentNoDialog(d->session, d->settings, d->format)
                                           : PMSessionBeginDocument(d->session, d->settings, d->format);
#endif
    }
    if (status != noErr) {
        d->state = QPrinter::Error;
        return false;
    }

    d->state = QPrinter::Active;
    setActive(true);
    d->newPage_helper();
    return true;
}
Example #6
0
static boolean
carbonSessionDefaultPageAndSettingValidate(void)
{
#if TARGET_API_MAC_CARBON == 1
	OSStatus	theErr;
	Boolean		f;
	
	
	theErr = PMSessionDefaultPageFormat(
										shellprintinfo.printhandle,
										shellprintinfo.pageformat);
	if(theErr != noErr)
		goto error;
	
	theErr = PMSessionValidatePageFormat(
										 shellprintinfo.printhandle,
										 shellprintinfo.pageformat, &f);
	if(theErr != noErr)
		goto error;
	
	theErr = PMSessionDefaultPrintSettings(
										   shellprintinfo.printhandle,
										   shellprintinfo.printsettings);
	if(theErr != noErr)
		goto error;
	
	theErr = PMSessionValidatePrintSettings(
											shellprintinfo.printhandle,
											shellprintinfo.printsettings, &f);
	if(theErr != noErr)
		goto error;

	
	return (true);
	
error:
		carbonKillPrintVars();

#endif
	
	return false;
	
}
Example #7
0
bool wxOSXPrintData::TransferFrom( const wxPrintData &data )
{
    TransferPrinterNameFrom(data);
    TransferPaperInfoFrom(data);
    TransferResolutionFrom(data);

    // after setting the new resolution the format has to be updated, otherwise the page rect remains
    // at the 'old' scaling

    PMSessionValidatePageFormat(m_macPrintSession,
                                m_macPageFormat, kPMDontWantBoolean);
    PMSessionValidatePrintSettings(m_macPrintSession,
                                   m_macPrintSettings, kPMDontWantBoolean);

#if wxOSX_USE_COCOA
    UpdateFromPMState();
#endif

    return true ;
}
Example #8
0
	static void initPrinter () {
		Boolean result;
		PMResolution res300 = { 300, 300 }, res600 = { 600, 600 };
		if (! theMacPrintSettings) {   // once
			PMCreateSession (& theMacPrintSession);   // initialize the Printing Manager
			PMCreatePageFormat (& theMacPageFormat);
			PMCreatePrintSettings (& theMacPrintSettings);
			PMSessionDefaultPageFormat (theMacPrintSession, theMacPageFormat);
			PMSessionDefaultPrintSettings (theMacPrintSession, theMacPrintSettings);
		}
		PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result);
		PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result);
		/*
		 * BUG.
		 * If we now ask for the available printer resolutions,
		 * we may get the answer that there's only 300 dpi (perhaps PostScript drivers say so?).
		 * So we don't rely on that and have a buggy assumption instead.
		 */
		PMSetResolution (theMacPageFormat, & res300);   // perhaps all printers have this...
		PMSetResolution (theMacPageFormat, & res600);   // ... but this is preferred
	}
Example #9
0
bool
QPrinter::prepare(PMPrintSettings *s)
{
  if (!psession && PMCreateSession(&psession) != noErr)
    return FALSE;
  if (*s == kPMNoPrintSettings) {
    if (PMCreatePrintSettings(s) != noErr)
      return FALSE;
    if (PMSessionDefaultPrintSettings(psession, *s) != noErr)
      return FALSE;
  } else {
    if (PMSessionValidatePrintSettings(psession, *s, kPMDontWantBoolean) != noErr)
      return FALSE;
  }
  if (minPage() != 0 || maxPage() != 0)
    PMSetPageRange(*s, minPage(), maxPage());
  if (d->printRange != AllPages) {
    PMSetFirstPage(*s, fromPage(), TRUE);
    PMSetLastPage(*s, toPage(), TRUE);
  }
  PMSetColorMode(*s, colorMode() == GrayScale ? kPMGray : kPMColor);
  PMSetCopies(*s, numCopies(), TRUE);
  if (outputToFile()) {
    CFStringRef cfstring = qstring2cfstring(outputFileName());
    CFURLRef outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, cfstring,
                                                     kCFURLPOSIXPathStyle, false);
    PMSessionSetDestination(psession, *s, kPMDestinationFile, kPMDocumentFormatPDF, outFile);
    CFRelease(outFile);
    CFRelease(cfstring);
  }

  QString printName = printerName();
  if (!printName.isEmpty()) {
    CFStringRef pname = qstring2cfstring(printName);
    PMSessionSetCurrentPrinter(psession, pname);
    CFRelease(pname);
  }
  return TRUE;
}
Example #10
0
/*------------------------------------------------------------------------------
	Function:	DoPrintDialog
		
	Parameters:
			
	Description:
		If the caller passes an empty PrintSettings object, DoPrintDialog creates
		a new one, otherwise it validates the one provided by the caller.
		It then invokes the Print dialog and checks for Cancel.
		Note that the PrintSettings object is modified by this function.
		
------------------------------------------------------------------------------*/
OSStatus 	DoPrintDialog(PrintingLogicPtr printJob)
{
	OSStatus	status = noErr;
	Boolean		accepted;
	UInt32		realNumberOfPagesinDoc;
	
	//	In this sample code the caller provides a valid PageFormat reference but in
	//	your application you may want to load and unflatten the PageFormat object
	//	that was saved at PageSetup time.  See LoadAndUnflattenPageFormat below.
	
	//	Set up a valid PrintSettings object.
	if (printJob->printSettings == kPMNoPrintSettings)
            {
            status = PMCreatePrintSettings(&printJob->printSettings);	

            //	Note that PMPrintSettings is not session-specific, but calling
            //	PMSessionDefaultPrintSettings assigns values specific to the printer
            //	associated with the current printing session.
            if ((status == noErr) && (printJob->printSettings != kPMNoPrintSettings))
                status = PMSessionDefaultPrintSettings(printJob->printSession, printJob->printSettings);
            }
	else
            status = PMSessionValidatePrintSettings(printJob->printSession, printJob->printSettings, kPMDontWantBoolean);
	
	//	Before displaying the Print dialog, we calculate the number of pages in the
	//	document.  On Mac OS X this is useful because we can prime the Print dialog
	//	with the actual page range of the document and prevent the user from entering
	//	out-of-range numbers.  This is not possible on Mac OS 8 and 9 because the driver,
	//	not the printing manager, controls the page range fields in the Print dialog.

	//	Calculate the number of pages required to print the entire document.
	if (status == noErr)
            status = DetermineNumberOfPagesInDoc(&realNumberOfPagesinDoc,printJob);

	//	Set a valid page range before displaying the Print dialog
	if (status == noErr)
            status = PMSetPageRange(printJob->printSettings, 1, realNumberOfPagesinDoc);

	//	Display the Print dialog.
	if (status == noErr)
            {
            void * giLocker;
            giLocker = interpreterProxy->ioLoadFunctionFrom("getUIToLock", "");
            if (giLocker != 0) {
                long *foo;
                foo = malloc(sizeof(long)*7);
                foo[0] = 4;
                foo[1] =  (long)PMSessionPrintDialog;
                foo[2] =  (long)printJob->printSession;
                foo[3] =  (long)printJob->printSettings;
                foo[4] =  (long)printJob->pageFormat;
                foo[5] =  (long)&accepted;
                foo[6] = 0;
                ((int (*) (void *)) giLocker)(foo);
                status = foo[6];
                free(foo);
            } else
                status = PMSessionPrintDialog(printJob->printSession, printJob->printSettings,
                        printJob->pageFormat, &accepted);
            if (status == noErr && !accepted)
                status = kPMCancel;		// user clicked Cancel button
            }
		
	return status;
	
}	//	DoPrintDialog
Example #11
0
bool wxOSXPrintData::TransferFrom( const wxPrintData &data )
{
    PMPrinter printer;
    PMSessionGetCurrentPrinter(m_macPrintSession, &printer);

    wxSize papersize = wxDefaultSize;
    const wxPaperSize paperId = data.GetPaperId();
    if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
    {
        papersize = wxThePrintPaperDatabase->GetSize(paperId);
        if ( papersize != wxDefaultSize )
        {
            papersize.x /= 10;
            papersize.y /= 10;
        }
    }
    else
    {
        papersize = data.GetPaperSize();
    }
    
    if ( papersize != wxDefaultSize )
    {
        papersize.x = (wxInt32) (papersize.x * mm2pt);
        papersize.y = (wxInt32) (papersize.y * mm2pt);
        
        double height, width;
        PMPaperGetHeight(m_macPaper, &height);
        PMPaperGetWidth(m_macPaper, &width);
        
        if ( fabs( width - papersize.x ) >= 5 || 
            fabs( height - papersize.y ) >= 5 )
        {
            // we have to change the current paper
            CFArrayRef paperlist = 0 ;
            if ( PMPrinterGetPaperList( printer, &paperlist ) == noErr )
            {
                PMPaper bestPaper = kPMNoData ;
                CFIndex top = CFArrayGetCount(paperlist);
                for ( CFIndex i = 0 ; i < top ; ++ i )
                {
                    PMPaper paper = (PMPaper) CFArrayGetValueAtIndex( paperlist, i );
                    PMPaperGetHeight(paper, &height);
                    PMPaperGetWidth(paper, &width);
                    if ( fabs( width - papersize.x ) < 5 && 
                        fabs( height - papersize.y ) < 5 )
                    {
                        // TODO test for duplicate hits and use additional
                        // criteria for best match
                        bestPaper = paper;
                    }
                }
                PMPaper paper = kPMNoData;
                if ( bestPaper == kPMNoData )
                {
                    const PMPaperMargins margins = { 0.0, 0.0, 0.0, 0.0 };
                    wxString id, name(_T("Custom paper"));                    
                    id.Printf(_T("wxPaperCustom%dx%d"), papersize.x, papersize.y);

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
                    if ( PMPaperCreateCustom != NULL)
                    {
                        PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
                            papersize.x, papersize.y, &margins, &paper);
                    }
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 
                    if ( paper == kPMNoData )
                    {
                        PMPaperCreate(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), 
                            papersize.x, papersize.y, &margins, &paper);
                    }
#endif
                }
                if ( bestPaper != kPMNoData )
                {
                    PMPageFormat pageFormat;
                    PMCreatePageFormatWithPMPaper(&pageFormat, bestPaper);
                    PMCopyPageFormat( pageFormat, m_macPageFormat );
                    PMRelease(pageFormat);
                    PMGetPageFormatPaper(m_macPageFormat, &m_macPaper);
                }
                PMRelease(paper);
            }
        }
    }

    CFArrayRef printerList;
    CFIndex index, count;
    CFStringRef name;
    
    if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr)
    {
        count = CFArrayGetCount(printerList);
        for (index = 0; index < count; index++)
        {
            printer = (PMPrinter)CFArrayGetValueAtIndex(printerList, index);
            if ((data.GetPrinterName().empty()) && (PMPrinterIsDefault(printer)))
                break;
            else
            {
                name = PMPrinterGetName(printer);
                CFRetain(name);
                if (data.GetPrinterName() == wxCFStringRef(name).AsString())
                    break;
            }
        }
        if (index < count)
            PMSessionSetCurrentPMPrinter(m_macPrintSession, printer);
        CFRelease(printerList);
    }
    
    PMSetCopies( m_macPrintSettings , data.GetNoCopies() , false ) ;
    PMSetCollate(m_macPrintSettings, data.GetCollate());
    if ( data.IsOrientationReversed() )
        PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
            kPMReverseLandscape : kPMReversePortrait , false ) ;
    else
        PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
            kPMLandscape : kPMPortrait , false ) ;
    
    PMDuplexMode mode = 0 ;
    switch( data.GetDuplex() )
    {
        case wxDUPLEX_HORIZONTAL :
            mode = kPMDuplexNoTumble ;
            break ;
        case wxDUPLEX_VERTICAL :
            mode = kPMDuplexTumble ;
            break ;
        case wxDUPLEX_SIMPLEX :
        default :
            mode = kPMDuplexNone ;
            break ;
    }
    PMSetDuplex(  m_macPrintSettings, mode ) ;

    // PMQualityMode not yet accessible via API
    
    
    if ( data.IsOrientationReversed() )
        PMSetOrientation(  m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
            kPMReverseLandscape : kPMReversePortrait , false ) ;
    else
        PMSetOrientation(  m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
            kPMLandscape : kPMPortrait , false ) ;
    
#ifndef __LP64__
    // PMQualityMode not accessible via API
    // TODO: use our quality property to determine optimal resolution
    PMResolution res;
    PMTag tag = kPMMaxSquareResolution;
    PMPrinterGetPrinterResolution(printer, tag, &res);
    PMSetResolution( m_macPageFormat, &res);
#endif

    // after setting the new resolution the format has to be updated, otherwise the page rect remains 
    // at the 'old' scaling
    
    PMSessionValidatePageFormat(m_macPrintSession,
        m_macPageFormat, kPMDontWantBoolean);
    PMSessionValidatePrintSettings(m_macPrintSession,
        m_macPrintSettings, kPMDontWantBoolean);
#if wxOSX_USE_COCOA
    UpdateFromPMState();
#endif

    return true ;
}
Example #12
0
int Printer_print (void (*draw) (void *boss, Graphics g), void *boss) {
	#if defined (UNIX)
		structMelderFile tempFile = { 0 };
		char tempPath_utf8 [] = "/tmp/picXXXXXX";
		close (mkstemp (tempPath_utf8));
		Melder_pathToFile (Melder_peekUtf8ToWcs (tempPath_utf8), & tempFile);
		thePrinter. graphics = Graphics_create_postscriptjob (& tempFile, thePrinter. resolution,
			thePrinter. spots, thePrinter. paperSize, thePrinter. orientation, thePrinter. magnification);
		if (! thePrinter. graphics) return Melder_error1 (L"Cannot create temporary PostScript file for printing.");
		draw (boss, thePrinter. graphics);
		forget (thePrinter. graphics);
		char command [500];
		sprintf (command, Melder_peekWcsToUtf8 (Site_getPrintCommand ()), tempPath_utf8);
		system (command);
		MelderFile_delete (& tempFile);
	#elif defined (_WIN32)
		int postScriptCode = POSTSCRIPT_PASSTHROUGH;
		DOCINFO docInfo;
		DEVMODE *devMode;
		initPrinter ();
		if (! theWinPrint. hDevMode) {
			memset (& theWinPrint, 0, sizeof (PRINTDLG));
			theWinPrint. lStructSize = sizeof (PRINTDLG);
			theWinPrint. Flags = PD_RETURNDEFAULT;
			if (! PrintDlg (& theWinPrint)) return Melder_error1 (L"Cannot initialize printer.");
		}
		if (Melder_backgrounding) {
			theWinPrint. Flags = PD_RETURNDEFAULT | PD_RETURNDC;
			if (! PrintDlg (& theWinPrint) || theWinPrint. hDC == NULL) {
				return Melder_error1 (L"Cannot print from a script on this computer.");
			}
		} else {
			theWinPrint. Flags &= ~ PD_RETURNDEFAULT;
			theWinPrint. Flags |= PD_RETURNDC;
			if (! PrintDlg (& theWinPrint)) return 1;
		}
		theWinDC = theWinPrint. hDC;
		thePrinter. postScript = thePrinter. allowDirectPostScript &&
			Escape (theWinDC, QUERYESCSUPPORT, sizeof (int), (LPSTR) & postScriptCode, NULL);
		/*
		 * The HP colour inkjet printer returns in dmFields:
		 * 0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 23, 24, 25, 26 = DM_ORIENTATION |
		 *    DM_PAPERSIZE | DM_COPIES | DM_DEFAULTSOURCE | DM_PRINTQUALITY |
		 *    DM_COLOR | DM_DUPLEX | DM_YRESOLUTION | DM_TTOPTION | DM_COLLATE |
		 *    DM_ICMMETHOD | DM_ICMINTENT | DM_MEDIATYPE | DM_DITHERTYPE
		 */
		devMode = * (DEVMODE **) theWinPrint. hDevMode;
		thePrinter. resolution = devMode -> dmFields & DM_YRESOLUTION ? devMode -> dmYResolution :
			devMode -> dmFields & DM_PRINTQUALITY ?
			( devMode -> dmPrintQuality > 0 ? devMode -> dmPrintQuality : 300 ) : 300;
		if (devMode -> dmFields & DM_PAPERWIDTH) {
			thePrinter. paperWidth = devMode -> dmPaperWidth * thePrinter. resolution / 254;
			thePrinter. paperHeight = devMode -> dmPaperLength * thePrinter. resolution / 254;
		} else if (devMode -> dmFields & DM_PAPERSIZE) {
			static struct { float width, height; } sizes [] = { { 0, 0 }, { 8.5, 11 }, { 8.5, 11 }, { 11, 17 },
				{ 17, 11 }, { 8.5, 14 }, { 5.5, 8.5 }, { 7.25, 10.5 }, { 297/25.4, 420/25.4 },
				{ 210/25.4, 297/25.4 }, { 210/25.4, 297/25.4 }, { 148.5/25.4, 210/25.4 },
				{ 250/25.4, 354/25.4 }, { 182/25.4, 257/25.4 }, { 8.5, 13 },
				{ 215/25.4, 275/25.4 }, { 10, 14 }, { 11, 17 }, { 8.5, 11 }, { 3.875, 8.875 },
				{ 4.125, 9.5 }, { 4.5, 10.375 } };
			int paperSize = devMode -> dmPaperSize;
			if (paperSize <= 0 || paperSize > 21) paperSize = 1;
			thePrinter. paperWidth = sizes [paperSize]. width * thePrinter. resolution;
			thePrinter. paperHeight = sizes [paperSize]. height * thePrinter. resolution;
			if (devMode -> dmOrientation == DMORIENT_LANDSCAPE) {
				long dummy = thePrinter. paperWidth;
				thePrinter. paperWidth = thePrinter. paperHeight;
				thePrinter. paperHeight = dummy;
			}
		} else {
			thePrinter. paperWidth = 1000;
			thePrinter. paperHeight = 1000;
		}
		EnableWindow ((HWND) XtWindow (theCurrentPraatApplication -> topShell), FALSE);
		SetAbortProc (theWinDC, AbortFunc);
		memset (& docInfo, 0, sizeof (DOCINFO));
		docInfo. cbSize = sizeof (DOCINFO);
		docInfo. lpszDocName = L"Praatjes";
		docInfo. lpszOutput = NULL;
		if (thePrinter. postScript) {
			StartDoc (theWinDC, & docInfo);
			StartPage (theWinDC);
			initPostScriptPage ();
			thePrinter. graphics = Graphics_create_postscriptprinter ();
			if (! thePrinter. graphics) return Melder_error1 (L"Cannot open printer.");
			draw (boss, thePrinter. graphics);
			forget (thePrinter. graphics);
			exitPostScriptPage ();
			EndPage (theWinDC);
			EndDoc (theWinDC);
		} else {
			StartDoc (theWinDC, & docInfo);
			StartPage (theWinDC);
			thePrinter. graphics = Graphics_create_screenPrinter (NULL, (unsigned long) theWinDC);
			if (! thePrinter. graphics) return Melder_error1 (L"Cannot open printer.");
			draw (boss, thePrinter. graphics);
			forget (thePrinter. graphics);
			if (EndPage (theWinDC) < 0) {
				Melder_error1 (L"Cannot print page.");
			} else {
				EndDoc (theWinDC);
			}
		}
		EnableWindow ((HWND) XtWindow (theCurrentPraatApplication -> topShell), TRUE);
		DeleteDC (theWinDC), theWinDC = NULL;
	#elif defined (macintosh)
		Boolean result;
		initPrinter ();
		if (Melder_backgrounding) {
			PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result);
			PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result);
		} else {
			Boolean accepted;
			PMSessionPrintDialog (theMacPrintSession, theMacPrintSettings, theMacPageFormat, & accepted);
			if (! accepted) return 1;   /* Normal cancelled return. */
		}
		PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result);
		PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result);
		PMResolution res;
		PMGetResolution (theMacPageFormat, & res);
		thePrinter. resolution = res. hRes;
		PMGetAdjustedPaperRect (theMacPageFormat, & paperSize);
		thePrinter. paperWidth = paperSize. right - paperSize. left;
		thePrinter. paperHeight = paperSize. bottom - paperSize. top;
		Boolean isPostScriptDriver = FALSE;
		//PMSessionIsDocumentFormatSupported (theMacPrintSession,
		//	kPMDocumentFormatPICTPS, & isPostScriptDriver);
		CFArrayRef supportedFormats;
		PMSessionGetDocumentFormatGeneration (theMacPrintSession, & supportedFormats);
		CFIndex numberOfSupportedFormats = CFArrayGetCount (supportedFormats);
		if (Melder_debug == 21) {
			MelderInfo_open ();
			MelderInfo_writeLine1 (L"Supported document formats:");
		}
		for (CFIndex i = 0; i < numberOfSupportedFormats; i ++) {
			CFStringRef supportedFormat = CFArrayGetValueAtIndex (supportedFormats, i);
			if (CFStringCompare (supportedFormat, kPMDocumentFormatPICTPS, 0) == 0) {
				isPostScriptDriver = TRUE;
			}
			if (Melder_debug == 21) {
				MelderInfo_writeLine3 (Melder_integer (i), L": ",
					Melder_peekUtf8ToWcs (CFStringGetCStringPtr (supportedFormat, kCFStringEncodingUTF8)));
			}
		}
		if (Melder_debug == 21) {
			MelderInfo_close ();
		}
		CFRelease (supportedFormats);
		isPostScriptDriver = FALSE;   // OVERRIDE, because from 10.4 on we have something better: we'll be sending PDF
		thePrinter. postScript = thePrinter. allowDirectPostScript && isPostScriptDriver;
		if (thePrinter. postScript) {
			CFStringRef strings [1];
			strings [0] = kPMGraphicsContextQuickdraw;
			CFArrayRef array = CFArrayCreate (kCFAllocatorDefault, (const void **) strings, 1, & kCFTypeArrayCallBacks);
			OSStatus err = PMSessionSetDocumentFormatGeneration (theMacPrintSession, kPMDocumentFormatPICTPS, array, NULL);
			CFRelease (array);
			if (err != 0) {
				return Melder_error2 (L"PMSessionSetDocumentFormatGeneration: error ", Melder_integer (err));
			}
		}
		PMOrientation orientation;
		PMGetOrientation (theMacPageFormat, & orientation);
		thePrinter. orientation = orientation == kPMLandscape ||
			orientation == kPMReverseLandscape ? kGraphicsPostscript_orientation_LANDSCAPE : kGraphicsPostscript_orientation_PORTRAIT;
		PMSessionBeginDocument (theMacPrintSession, theMacPrintSettings, theMacPageFormat);
		PMSessionBeginPage (theMacPrintSession, theMacPageFormat, NULL);
		PMSessionGetGraphicsContext (theMacPrintSession, kPMGraphicsContextQuickdraw, (void **) & theMacPort);
		/*
		 * On PostScript, the point (0, 0) is the bottom left corner of the paper, which is fine.
		 * On the screen, however, the point (0, 0) is the top left corner of the writable page.
		 * Since we want paper-related margins, not writable-page-related margins,
		 * we require that this point gets the coordinates (250, 258) or so,
		 * so that the top left corner of the paper gets coordinates (0, 0).
		 * The "left" and "top" attributes of rPaper are negative values (e.g. -250 and -258),
		 * so multiply them by -1.
		 *
		 * Under Carbon, the port has to be set inside the page.
		 */
		SetPort (theMacPort);
		if (! thePrinter. postScript) SetOrigin (- paperSize. left, - paperSize. top);
		if (thePrinter. postScript) {
			if (! openPostScript ()) error1 (L"Cannot print PostScript.")
			thePrinter. graphics = Graphics_create_postscriptprinter ();
			if (! thePrinter. graphics) goto end;
			draw (boss, thePrinter. graphics);
			forget (thePrinter. graphics);
			closePostScript ();
		} else {
			thePrinter. graphics = Graphics_create_screenPrinter (NULL, (unsigned long) theMacPort);
			draw (boss, thePrinter. graphics);
			forget (thePrinter. graphics);
		}
	end:
		if (theMacPort) {
			PMSessionEndPage (theMacPrintSession);
			PMSessionEndDocument (theMacPrintSession);
			theMacPort = NULL;
		}
	#endif
	iferror return 0;
	return 1;
}