void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) { if ( m_err ) return ; wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().GetNativeData() ; m_err = PMSessionBeginPage(native->m_macPrintSession, native->m_macPageFormat, nil); #if wxMAC_USE_CORE_GRAPHICS CGContextRef pageContext; #endif if ( m_err == noErr ) { #if wxMAC_USE_CORE_GRAPHICS m_err = PMSessionGetGraphicsContext(native->m_macPrintSession, kPMGraphicsContextCoreGraphics, (void**) &pageContext ); dc->MacSetCGContext(pageContext) ; #else m_err = PMSessionGetGraphicsContext(native->m_macPrintSession, kPMGraphicsContextQuickdraw, (void**) &dc->m_macPort ); #endif } if ( m_err != noErr ) { PMSessionEndPage(native->m_macPrintSession); PMSessionEndDocument(native->m_macPrintSession); } else { PMRect rPage; m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage); if ( !m_err ) { #if wxMAC_USE_CORE_GRAPHICS PMRect paperRect ; PMGetAdjustedPaperRect( native->m_macPageFormat , &paperRect ) ; CGContextTranslateCTM( pageContext , -paperRect.left , -paperRect.top + ( rPage.bottom - rPage.top ) ) ; CGContextScaleCTM( pageContext , 1 , -1 ) ; CGContextSaveGState( pageContext ) ; #else dc->m_macLocalOrigin.x = (int) rPage.left; dc->m_macLocalOrigin.y = (int) rPage.top; #endif } // since this is a non-critical error, we set the flag back m_err = noErr ; } }
wxRect wxPrinterDC::GetPaperRect() { wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) m_printData.GetNativeData() ; OSStatus err = noErr ; PMRect rPaper; err = PMGetAdjustedPaperRect(native->m_macPageFormat, &rPaper); if ( err != noErr ) return pageRect; return wxRect(wxCoord(rPaper.left), wxCoord(rPaper.top), wxCoord(rPaper.right - rPaper.left), wxCoord(rPaper.bottom - rPaper.top)); }
static inline int qt_get_PDMHeight(PMPageFormat pformat, bool fullPage) { int val = 0; PMRect r; if (fullPage) { if (PMGetAdjustedPaperRect(pformat, &r) == noErr) val = (int)(r.bottom - r.top); } else { if (PMGetAdjustedPageRect(pformat, &r) == noErr) val = (int)(r.bottom - r.top); } return val; }
static inline int qt_get_PDMWidth(PMPageFormat pformat, bool fullPage) { int val = 0; PMRect r; if (fullPage) { if (PMGetAdjustedPaperRect(pformat, &r) == noErr) val = (int)(r.right - r.left); } else { if (PMGetAdjustedPageRect(pformat, &r) == noErr) val = (int)(r.right - r.left); } return val; }
static inline int qt_get_PDMHeight(PMPageFormat pformat, bool fullPage, const PMResolution &resolution) { int val = 0; PMRect r; qreal vRatio = resolution.vRes / 72; if (fullPage) { if (PMGetAdjustedPaperRect(pformat, &r) == noErr) val = qRound((r.bottom - r.top) * vRatio); } else { if (PMGetAdjustedPageRect(pformat, &r) == noErr) val = qRound((r.bottom - r.top) * vRatio); } return val; }
static inline int qt_get_PDMWidth(PMPageFormat pformat, bool fullPage, const PMResolution &resolution) { int val = 0; PMRect r; qreal hRatio = resolution.hRes / 72; if (fullPage) { if (PMGetAdjustedPaperRect(pformat, &r) == noErr) val = qRound((r.right - r.left) * hRatio); } else { if (PMGetAdjustedPageRect(pformat, &r) == noErr) val = qRound((r.right - r.left) * hRatio); } return val; }
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) { if ( m_err ) return ; wxPrinterDCImpl *impl = (wxPrinterDCImpl*) dc->GetImpl(); wxOSXPrintData *native = (wxOSXPrintData*) impl->GetPrintData().GetNativeData() ; m_err = PMSessionBeginPageNoDialog(native->GetPrintSession(), native->GetPageFormat(), NULL); CGContextRef pageContext; if ( m_err == noErr ) { m_err = PMSessionGetCGGraphicsContext(native->GetPrintSession(), &pageContext ); } if ( m_err != noErr ) { PMSessionEndPageNoDialog(native->GetPrintSession()); PMSessionEndDocumentNoDialog(native->GetPrintSession()); } else { PMRect paperRect ; m_err = PMGetAdjustedPaperRect( native->GetPageFormat() , &paperRect ) ; // make sure (0,0) is at the upper left of the printable area (wx conventions) // Core Graphics initially has the lower left of the paper as 0,0 if ( !m_err ) CGContextTranslateCTM( pageContext , (CGFloat) -paperRect.left , (CGFloat) paperRect.bottom ) ; // since this is a non-critical error, we set the flag back m_err = noErr ; // Leopard deprecated PMSetResolution() which will not be available in 64 bit mode, so we avoid using it. // To set the proper drawing resolution, the docs suggest the use of CGContextScaleCTM(), so here we go; as a // consequence though, PMGetAdjustedPaperRect() and PMGetAdjustedPageRect() return unscaled rects, so we // have to manually scale them later. CGContextScaleCTM( pageContext, 72.0 / (double)m_ppi.x, -72.0 / (double)m_ppi.y); impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) ); } }
/*------------------------------------------------------------------------------ Function: DetermineNumberOfPagesInDoc Parameters: pageFormat - a PageFormat object addr numPages - on return, the size of the document in pages Description: Calculates the number of pages needed to print the entire document. ------------------------------------------------------------------------------*/ OSStatus DetermineNumberOfPagesInDoc(UInt32 *numPages,PrintingLogicPtr printJob) { OSStatus status; // PMGetAdjustedPageRect returns the page size taking into account rotation, // resolution and scaling settings. status = PMGetAdjustedPageRect(printJob->pageFormat, &printJob->pageRect); status = PMGetAdjustedPaperRect(printJob->pageFormat, &printJob->paperRect); // In this sample code we simply return a hard coded number. In your application, // you will need to figure out how many page rects are needed to image the // current document. *numPages = printJob->numberOfPages; return status; } // DetermineNumberOfPagesinDoc
static inline void qt_get_margins(PMPageFormat pformat, uint *top, uint *left, uint *bottom, uint *right) { PMRect paperr, pager; if (PMGetAdjustedPaperRect(pformat, &paperr) != noErr) { qWarning("Qt: QPrinter: Unexpected condition reached %s:%d", __FILE__, __LINE__); return; } if (PMGetAdjustedPageRect(pformat, &pager) != noErr) { qWarning("Qt: QPrinter: Unexpected condition reached %s:%d", __FILE__, __LINE__); return; } if (top) *top = (uint)(pager.top - paperr.top); if (left) *left = (uint)(pager.left - paperr.left); if (bottom) *bottom = (uint)(paperr.bottom - pager.bottom); if (right) *right = (uint)(paperr.right - pager.right); }
wxRect wxPrinterDCImpl::GetPaperRect() const { wxCoord w, h; GetOwner()->GetSize(&w, &h); wxRect pageRect(0, 0, w, h); wxOSXPrintData *native = (wxOSXPrintData*) m_printData.GetNativeData() ; OSStatus err = noErr ; PMRect rPaper; err = PMGetAdjustedPaperRect(native->GetPageFormat(), &rPaper); if ( err != noErr ) return pageRect; wxSize ppi = GetOwner()->GetPPI(); rPaper.right *= (ppi.x / 72.0); rPaper.bottom *= (ppi.y / 72.0); rPaper.left *= (ppi.x / 72.0); rPaper.top *= (ppi.y / 72.0); return wxRect(wxCoord(rPaper.left), wxCoord(rPaper.top), wxCoord(rPaper.right - rPaper.left), wxCoord(rPaper.bottom - rPaper.top)); }
static void shellcopyprintinfo (void) { /* set up our printing rect according to the print manager's rects. we'll use the smaller of the printable area (rPage) and the physical paper (rPaper) with 1/2 inch margins 5.0.1 dmb: measure in pixels (1/72 inch) for Win */ Rect rpage, rpaper; //typrintinfo *dbgprintinfo = &shellprintinfo; #ifdef MACVERSION # if TARGET_API_MAC_CARBON == 1 static int firstTime = 1; OSErr theErr; boolean fl; PMRect dRect; if (1 == firstTime) { carbonSessionPrintSession(); carbonCreateFormatAndSetting(); carbonSessionDefaultPageAndSettingValidate(); } theErr = PMSessionValidatePageFormat( shellprintinfo.printhandle, shellprintinfo.pageformat, &fl); if(theErr != noErr) // || !fl) // why should i kill this if nothing has changed??? oserror(theErr); theErr = PMGetAdjustedPageRect(shellprintinfo.pageformat, &dRect); shellprintinfo.pagerect = dRect; theErr = PMGetAdjustedPaperRect(shellprintinfo.pageformat, &dRect); rect2rect(dRect, shellprintinfo.paperrect); rect2rect(shellprintinfo.pagerect, rpage); rpaper = shellprintinfo.paperrect; # else rpage = (**shellprintinfo.printhandle).prInfo.rPage; rpaper = (**shellprintinfo.printhandle).rPaper; # endif #endif #ifdef WIN95VERSION long res = 72L; pushport (hwndMDIClient); res = GetDeviceCaps(getcurrentDC (), LOGPIXELSX); popport (); rpaper.left = 0; rpaper.top = 0; rpaper.right = shellprintinfo.pagesetupinfo.ptPaperSize.x * res / 1000L; rpaper.bottom = shellprintinfo.pagesetupinfo.ptPaperSize.y * res / 1000L; rpage.left = rpaper.left + (shellprintinfo.pagesetupinfo.rtMinMargin.left * res / 1000L); rpage.top = rpaper.top + (shellprintinfo.pagesetupinfo.rtMinMargin.top * res / 1000L); rpage.right = rpaper.right - (shellprintinfo.pagesetupinfo.rtMinMargin.right * res / 1000L); rpage.bottom = rpaper.bottom - (shellprintinfo.pagesetupinfo.rtMinMargin.bottom * res / 1000L); shellprintinfo.margins.left = shellprintinfo.pagesetupinfo.rtMargin.left * res / 1000L; shellprintinfo.margins.top = shellprintinfo.pagesetupinfo.rtMargin.top * res / 1000L; shellprintinfo.margins.right = shellprintinfo.pagesetupinfo.rtMargin.right * res / 1000L; shellprintinfo.margins.bottom = shellprintinfo.pagesetupinfo.rtMargin.bottom * res / 1000L; #endif shellprintinfo.paperrect.top = max (rpage.top, rpaper.top + shellprintinfo.margins.top); shellprintinfo.paperrect.left = max (rpage.left, rpaper.left + shellprintinfo.margins.left); shellprintinfo.paperrect.bottom = min (rpage.bottom, rpaper.bottom - shellprintinfo.margins.bottom); shellprintinfo.paperrect.right = min (rpage.right, rpaper.right - shellprintinfo.margins.right); } /*shellcopyprintinfo*/
QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const { Q_D(const QMacPrintEngine); QVariant ret; if (!d->session && d->valueCache.contains(key)) return *d->valueCache.find(key); switch (key) { case PPK_CollateCopies: ret = false; break; case PPK_ColorMode: ret = QPrinter::Color; break; case PPK_Creator: break; case PPK_DocumentName: break; case PPK_FullPage: ret = d->fullPage; break; case PPK_NumberOfCopies: ret = 1; break; case PPK_Orientation: PMOrientation orientation; PMGetOrientation(d->format, &orientation); ret = orientation == kPMPortrait ? QPrinter::Portrait : QPrinter::Landscape; break; case PPK_OutputFileName: ret = d->outputFilename; break; case PPK_PageOrder: break; case PPK_PaperSource: break; case PPK_PageRect: { // PageRect is returned in device pixels QRect r; PMRect macrect, macpaper; qreal hRatio = d->resolution.hRes / 72; qreal vRatio = d->resolution.vRes / 72; if (d->hasCustomPaperSize) { r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio)); if (d->hasCustomPageMargins) { r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio), -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio)); } else { QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList(); r.adjust(qRound(margins.at(0).toDouble() * hRatio), qRound(margins.at(1).toDouble() * vRatio), -qRound(margins.at(2).toDouble() * hRatio), -qRound(margins.at(3).toDouble()) * vRatio); } } else if (PMGetAdjustedPageRect(d->format, ¯ect) == noErr && PMGetAdjustedPaperRect(d->format, &macpaper) == noErr) { if (d->fullPage || d->hasCustomPageMargins) { r.setCoords(int(macpaper.left * hRatio), int(macpaper.top * vRatio), int(macpaper.right * hRatio), int(macpaper.bottom * vRatio)); r.translate(-r.x(), -r.y()); if (d->hasCustomPageMargins) { r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio), -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio)); } } else { r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio), int(macrect.right * hRatio), int(macrect.bottom * vRatio)); r.translate(int(-macpaper.left * hRatio), int(-macpaper.top * vRatio)); } } ret = r; break; } case PPK_PaperSize: ret = d->paperSize(); break; case PPK_PaperRect: { QRect r; PMRect macrect; if (d->hasCustomPaperSize) { r = QRect(0, 0, qRound(d->customSize.width()), qRound(d->customSize.height())); } else if (PMGetAdjustedPaperRect(d->format, ¯ect) == noErr) { qreal hRatio = d->resolution.hRes / 72; qreal vRatio = d->resolution.vRes / 72; r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio), int(macrect.right * hRatio), int(macrect.bottom * vRatio)); r.translate(-r.x(), -r.y()); } ret = r; break; } case PPK_PrinterName: { CFIndex currIndex; PMPrinter unused; QCFType<CFArrayRef> printerList; OSStatus status = PMSessionCreatePrinterList(d->session, &printerList, &currIndex, &unused); if (status != noErr) qWarning("QMacPrintEngine::printerName: Problem getting list of printers: %ld", long(status)); if (currIndex != -1 && printerList && currIndex < CFArrayGetCount(printerList)) { const CFStringRef name = static_cast<CFStringRef>(CFArrayGetValueAtIndex(printerList, currIndex)); if (name) ret = QCFString::toQString(name); } break; } case PPK_Resolution: { ret = d->resolution.hRes; break; } case PPK_SupportedResolutions: ret = d->supportedResolutions(); break; case PPK_CustomPaperSize: ret = d->customSize; break; case PPK_PageMargins: { QList<QVariant> margins; if (d->hasCustomPageMargins) { margins << d->leftMargin << d->topMargin << d->rightMargin << d->bottomMargin; } else { PMPaperMargins paperMargins; PMPaper paper; PMGetPageFormatPaper(d->format, &paper); PMPaperGetMargins(paper, &paperMargins); margins << paperMargins.left << paperMargins.top << paperMargins.right << paperMargins.bottom; } ret = margins; break; } default: break; } return ret; }
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) { if ( m_err ) return ; wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().GetNativeData() ; m_err = PMSessionBeginPage(native->m_macPrintSession, native->m_macPageFormat, nil); #if wxMAC_USE_CORE_GRAPHICS CGContextRef pageContext; #endif if ( m_err == noErr ) { #if wxMAC_USE_CORE_GRAPHICS #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 m_err = PMSessionGetCGGraphicsContext(native->m_macPrintSession, &pageContext ); #else m_err = PMSessionGetGraphicsContext(native->m_macPrintSession, kPMGraphicsContextCoreGraphics, (void**) &pageContext ); #endif #else m_err = PMSessionGetGraphicsContext(native->m_macPrintSession, kPMGraphicsContextQuickdraw, (void**) &dc->m_macPort ); #endif } if ( m_err != noErr ) { PMSessionEndPage(native->m_macPrintSession); PMSessionEndDocument(native->m_macPrintSession); } else { PMRect rPage; m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage); if ( !m_err ) { #if wxMAC_USE_CORE_GRAPHICS PMRect paperRect ; PMGetAdjustedPaperRect( native->m_macPageFormat , &paperRect ) ; // make sure (0,0) is at the upper left of the printable area (wx conventions) // Core Graphics initially has the lower left of the paper as 0,0 CGContextTranslateCTM( pageContext , -paperRect.left , paperRect.bottom ) ; CGContextScaleCTM( pageContext , 1 , -1 ) ; #else dc->m_macLocalOrigin.x = (int) rPage.left; dc->m_macLocalOrigin.y = (int) rPage.top; #endif } // since this is a non-critical error, we set the flag back m_err = noErr ; } #if wxMAC_USE_CORE_GRAPHICS dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) ); #endif }
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; }