コード例 #1
0
ファイル: printmac.cpp プロジェクト: Duion/Torsion
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
{
    ValidateOrCreate() ;
    PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ;
    PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
        kPMLandscape : kPMPortrait , false ) ;
    // collate cannot be set
#if 0 // not yet tested
    if ( m_printerName.Length() > 0 )
        PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
#endif
    PMColorMode color ;
    PMGetColorMode(  (PMPrintSettings) m_macPrintSettings, &color ) ;
    if ( data.GetColour() )
    {
        if ( color == kPMBlackAndWhite )
            PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
    }
    else
        PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
    
    // PMDuplexMode not yet accessible via API
    // PMQualityMode not yet accessible via API
    // todo paperSize
    PMResolution res;
    PMPrinter printer;
    PMTag tag = kPMMaxSquareResolution;
    PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
    PMPrinterGetPrinterResolution(printer, tag, &res);
    PMSetResolution((PMPageFormat) m_macPageFormat, &res);

    return true ;
}
コード例 #2
0
ファイル: printmac.cpp プロジェクト: BloodRedd/gamekit
void wxOSXPrintData::TransferResolutionFrom( const wxPrintData &data )
{
    PMPrinter printer;
    PMSessionGetCurrentPrinter(m_macPrintSession, &printer);

    UInt32 resCount;
    PMResolution *resolutions = GetSupportedResolutions(printer, &resCount);
    if (resolutions)
    {
        wxPrintQuality quality = data.GetQuality();
        if (quality >= 0)
            quality = wxPRINT_QUALITY_HIGH;

        PMResolution res = resolutions[((quality - wxPRINT_QUALITY_DRAFT) * (resCount - 1)) / 3];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
        if ( PMPrinterSetOutputResolution != NULL )
            PMPrinterSetOutputResolution(printer, m_macPrintSettings, &res);
        else
#endif
        {
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
            PMSetResolution( m_macPageFormat, &res);
#endif
        }
        
        free(resolutions);
    }
}
コード例 #3
0
ファイル: Printer.cpp プロジェクト: ffostertw/praat
	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
	}
コード例 #4
0
// --------------------------------------------------------------------------------------------------------------
static OSStatus MySetupPageFormatForPrinting(PMPrintSession printSession, void *docDataP, PMPageFormat *pageFormatP)
{
    OSStatus status = noErr;
    PMPageFormat pageFormat = GetPageFormatFromPrivateData(docDataP);
    if (!pageFormat)
    {
        status = PMCreatePageFormat(&pageFormat);
        if(status == noErr)
        {
            status = PMSessionDefaultPageFormat(printSession, pageFormat);
	    if(status == noErr){
		PMResolution appDrawingResolution;
		
		// for illustrative purposes, this sample will draw at 300,300 dpi resolution
		appDrawingResolution.hRes = appDrawingResolution.vRes = 300.;
		status = PMSetResolution(pageFormat, &appDrawingResolution);
	    }
            if (status == noErr)
                SetPageFormatOnPrivateData(docDataP, pageFormat);
            else{
                (void)PMRelease(pageFormat);
                pageFormat = NULL;
            }
        }
    }else{
	// we already have a page format so we'll validate it
        status = PMSessionValidatePageFormat(printSession, pageFormat,
                                        kPMDontWantBoolean);
        if(status){	// if validate failed!
            SetPageFormatOnPrivateData(docDataP, NULL);
            (void)PMRelease(pageFormat);
            pageFormat = NULL;
        }
    }
    
    DoErrorAlert(status, kMyPrintErrorFormatStrKey);
    
    *pageFormatP = pageFormat;
    return status;
}
コード例 #5
0
ファイル: qprinter_mac.cpp プロジェクト: gestiweb/eneboo
bool
QPrinter::prepare(PMPageFormat *f)
{
  if (!psession && PMCreateSession(&psession) != noErr)
    return FALSE;
  if (*f == kPMNoPageFormat) {
    if (PMCreatePageFormat(f) != noErr)
      return FALSE;
    if (PMSessionDefaultPageFormat(psession, *f) != noErr)
      return FALSE;
  } else {
    if (PMSessionValidatePageFormat(psession, *f, kPMDontWantBoolean) != noErr)
      return FALSE;
  }
  if (page_size != carbonSize2QPrinterSize(*f))
    qprinterSize2CarbonSize(page_size, *f, psession);
  PMSetOrientation(*f, orientation() == Portrait ? kPMPortrait : kPMLandscape, TRUE);
  PMResolution pres;
  pres.hRes = res;
  pres.vRes = res;
  PMSetResolution(*f, &pres);
  return TRUE;
}
コード例 #6
0
ファイル: printmac.cpp プロジェクト: EdgarTx/wx
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
{
    ValidateOrCreate() ;
    PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ;
    if ( data.IsOrientationReversed() )
        PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
            kPMReverseLandscape : kPMReversePortrait , false ) ;
    else
        PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
            kPMLandscape : kPMPortrait , false ) ;
    // collate cannot be set
#if 0 // not yet tested
    if ( !m_printerName.empty() )
        PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
#endif
#ifndef __LP64__
    PMColorMode color ;
    PMGetColorMode(  (PMPrintSettings) m_macPrintSettings, &color ) ;
    if ( data.GetColour() )
    {
        if ( color == kPMBlackAndWhite )
            PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
    }
    else
        PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
#endif

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    if ( &PMSetDuplex!=NULL )
    {
        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( (PMPrintSettings) m_macPrintSettings, mode ) ;
    }
#endif
    // PMQualityMode not yet accessible via API
    // todo paperSize

    PMResolution res;
    PMPrinter printer;
    PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 
    PMPrinterGetOutputResolution( printer,  
        (PMPrintSettings) m_macPrintSettings,  &res) ;
    // TODO transfer ? into page format ?
#else
    PMTag tag = kPMMaxSquareResolution;
    PMPrinterGetPrinterResolution(printer, tag, &res);
    PMSetResolution((PMPageFormat) 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((PMPrintSession) m_macPrintSession,
            (PMPageFormat) m_macPageFormat,
            kPMDontWantBoolean) ;

    return true ;
}
コード例 #7
0
ファイル: printmac.cpp プロジェクト: czxxjtu/wxPython-1
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 ;
}