Exemple #1
0
void qprinterSize2CarbonSize(QPrinter::PageSize &size, PMPageFormat &format, PMPrintSession session)
{
  if (size >= QPrinter::Custom)
    return;
  // Basically, get the supported pages supported by the printer and see what will work,
  // Since we document undefined behavior when we don't specify anything, don't worry if we can't.
  PaperSize newSize = sizes[size];
  CFArrayRef formats;
  PMPrinter printer;

  if (PMSessionGetCurrentPrinter(session, &printer) == noErr
      && PMSessionCreatePageFormatList(session, printer, &formats) == noErr) {
    CFIndex total = CFArrayGetCount(formats);
    PMPageFormat tmp;
    PMRect paper;
    for (CFIndex idx = 0; idx < total; ++idx) {
      tmp = (PMPageFormat)CFArrayGetValueAtIndex(formats, idx);
      PMGetUnadjustedPaperRect(tmp, &paper);
      int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
      int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
      if (newSize.w == wMM && newSize.h == hMM) {
        PMCopyPageFormat(tmp, format);
        break;
      }
    }
    CFRelease(formats);
  }
}
void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps)
{
    Q_Q(QMacPrintEngine);
    QSizeF newSize = qt_paperSizeToQSizeF(ps);
    QCFType<CFArrayRef> formats;
    PMPrinter printer;

    if (PMSessionGetCurrentPrinter(session, &printer) == noErr
        && PMSessionCreatePageFormatList(session, printer, &formats) == noErr) {
        CFIndex total = CFArrayGetCount(formats);
        PMPageFormat tmp;
        PMRect paper;
        for (CFIndex idx = 0; idx < total; ++idx) {
            tmp = static_cast<PMPageFormat>(
                                        const_cast<void *>(CFArrayGetValueAtIndex(formats, idx)));
            PMGetUnadjustedPaperRect(tmp, &paper);
            int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
            int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
            if (newSize.width() == wMM && newSize.height() == hMM) {
                PMCopyPageFormat(tmp, format);
                // reset the orientation and resolution as they are lost in the copy.
                q->setProperty(QPrintEngine::PPK_Orientation, orient);
                if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) {
                    // Don't know, warn for the moment.
                    qWarning("QMacPrintEngine, problem setting format and resolution for this page size");
                }
                break;
            }
        }
    }
}
Exemple #3
0
QPrinter::PageSize carbonSize2QPrinterSize(const PMPageFormat pformat)
{
  PMRect paper;
  PMGetUnadjustedPaperRect(pformat, &paper);
  int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
  int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
  for (int i = QPrinter::A4; i < QPrinter::NPageSize; ++i) {
    if (sizes[i].w == wMM && sizes[i].h == hMM)
      return (QPrinter::PageSize)i;
  }
  return QPrinter::Custom;
}
QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const
{
    PMRect paper;
    PMGetUnadjustedPaperRect(format, &paper);
    int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5);
    int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5);
    for (int i = QPrinter::A4; i < QPrinter::NPaperSize; ++i) {
        QSizeF s = qt_paperSizeToQSizeF(QPrinter::PaperSize(i));
        if (s.width() == wMM && s.height() == hMM)
            return (QPrinter::PaperSize)i;
    }
    return QPrinter::Custom;
}
Exemple #5
0
bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
{
    OSStatus err = noErr ;
    
    UInt32 copies ;
    err = PMGetCopies( m_macPrintSettings , &copies ) ;
    if ( err == noErr )
        data.SetNoCopies( copies ) ; 
          
    PMOrientation orientation ;
    err = PMGetOrientation(  m_macPageFormat , &orientation ) ;
    if ( err == noErr )
    {
        if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
            data.SetOrientation( wxPORTRAIT  );
        else
            data.SetOrientation( wxLANDSCAPE );
    }

    // collate cannot be set
#if 0
    {
        wxMacCFStringHolder name ;
        PMPrinter printer ;
        PMSessionGetCurrentPrinter( m_macPrintSession ,
            &printer ) ;
        m_printerName = name.AsString() ;
    }
#endif
    
    PMColorMode color ;
    err = PMGetColorMode( m_macPrintSettings, &color ) ;
    if ( err == noErr )
        data.SetColour( !(color == kPMBlackAndWhite) ) ;
        
    // PMDuplexMode not yet accessible via API
    // PMQualityMode not yet accessible via API
    // todo paperSize
	PMRect rPaper;
    err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
    if ( err == noErr )
    {
        data.SetPaperSize( wxSize (
            (int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
             (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) );
    }
    return true ;
}
Exemple #6
0
void wxOSXPrintData::TransferTo( wxPageSetupDialogData* data )
{
#if wxOSX_USE_COCOA
    UpdateToPMState();
#endif
    PMRect rPaper;
    OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
    if ( err == noErr )
    {
        wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
             (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
        data->SetPaperSize(sz);

        PMRect rPage ;
        err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
        if ( err == noErr )
        {
            data->SetMinMarginTopLeft( wxPoint (
                (int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
                (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;

            data->SetMinMarginBottomRight( wxPoint (
                (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm),
                (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ;

            if ( data->GetMarginTopLeft().x < data->GetMinMarginTopLeft().x )
                data->SetMarginTopLeft( wxPoint( data->GetMinMarginTopLeft().x ,
                    data->GetMarginTopLeft().y ) ) ;

            if ( data->GetMarginBottomRight().x < data->GetMinMarginBottomRight().x )
                data->SetMarginBottomRight( wxPoint( data->GetMinMarginBottomRight().x ,
                    data->GetMarginBottomRight().y ) );

            if ( data->GetMarginTopLeft().y < data->GetMinMarginTopLeft().y )
                data->SetMarginTopLeft( wxPoint( data->GetMarginTopLeft().x , data->GetMinMarginTopLeft().y ) );

            if ( data->GetMarginBottomRight().y < data->GetMinMarginBottomRight().y )
                data->SetMarginBottomRight( wxPoint( data->GetMarginBottomRight().x ,
                    data->GetMinMarginBottomRight().y) );
        }
    }
}
Exemple #7
0
void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
{
    PMRect rPaper;
    OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
    if ( err == noErr )
    {
        PMRect rPage ;
        err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
        if ( err == noErr )
        {
            data->SetMinMarginTopLeft( wxPoint (
                (int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
                (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;

            data->SetMinMarginBottomRight( wxPoint (
                (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm),
                (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ;
        }
    }
}
Exemple #8
0
bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
{
    OSStatus err = noErr ;

    UInt32 copies ;
    err = PMGetCopies( m_macPrintSettings , &copies ) ;
    if ( err == noErr )
        data.SetNoCopies( copies ) ;

    PMOrientation orientation ;
    err = PMGetOrientation(  m_macPageFormat , &orientation ) ;
    if ( err == noErr )
    {
        if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
        {
            data.SetOrientation( wxPORTRAIT  );
            data.SetOrientationReversed( orientation == kPMReversePortrait );
        }
        else
        {
            data.SetOrientation( wxLANDSCAPE );
            data.SetOrientationReversed( orientation == kPMReverseLandscape );
        }
    }

    // collate cannot be set
#if 0
    {
        wxMacCFStringHolder name ;
        PMPrinter printer ;
        PMSessionGetCurrentPrinter( m_macPrintSession ,
            &printer ) ;
        m_printerName = name.AsString() ;
    }
#endif

#ifndef __LP64__
    PMColorMode color ;
    err = PMGetColorMode( m_macPrintSettings, &color ) ;
    if ( err == noErr )
        data.SetColour( !(color == kPMBlackAndWhite) ) ;
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    if ( &PMGetDuplex!=NULL )
    {
        PMDuplexMode mode = 0 ;
        PMGetDuplex( (PMPrintSettings) m_macPrintSettings, &mode ) ;
        switch( mode )
        {
            case kPMDuplexNoTumble :
                data.SetDuplex(wxDUPLEX_HORIZONTAL);
                break ;
            case kPMDuplexTumble :
                data.SetDuplex(wxDUPLEX_VERTICAL);
                break ;
            case kPMDuplexNone :
            default :
                data.SetDuplex(wxDUPLEX_SIMPLEX);
                break ;
        }
    }
#endif
    // PMQualityMode not yet accessible via API
    
    PMPaper paper ;
    PMGetPageFormatPaper( m_macPageFormat, &paper );
    
    PMRect rPaper;
    err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
    if ( err == noErr )
    {
        wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
             (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
        data.SetPaperSize(sz);
        wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
        if (id != wxPAPER_NONE)
        {
            data.SetPaperId(id);
        }
    }
    return true ;
}