Esempio n. 1
0
QPrinter::OutputFormat QPrinterProto::outputFormat() const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    return item->outputFormat();
  return QPrinter::NativeFormat;
}
Esempio n. 2
0
int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, FileDeletePolicy fileDeletePolicy,
                               PageSelectPolicy pageSelectPolicy, const QString &pageRange,
                               QPrinter::Orientation documentOrientation )
{

    if ( fileList.size() < 1 ) {
        return -8;
    }

    for (QStringList::ConstIterator it = fileList.constBegin(); it != fileList.constEnd(); ++it) {
        if (!QFile::exists(*it)) {
            return -7;
        }
    }

    if ( printer.printerState() == QPrinter::Aborted || printer.printerState() == QPrinter::Error ) {
        return -6;
    }

    QString exe;
    QStringList argList;
    int ret;

    // Print to File if a filename set, assumes there must be only 1 file
    if ( !printer.outputFileName().isEmpty() ) {

        if ( QFile::exists( printer.outputFileName() ) ) {
            QFile::remove( printer.outputFileName() );
        }

        QFileInfo inputFileInfo = QFileInfo( fileList[0] );
        QFileInfo outputFileInfo = QFileInfo( printer.outputFileName() );

        bool doDeleteFile = (fileDeletePolicy == FilePrinter::SystemDeletesFiles);
        if ( inputFileInfo.suffix() == outputFileInfo.suffix() ) {
            if ( doDeleteFile ) {
                bool res = QFile::rename( fileList[0], printer.outputFileName() );
                if ( res ) {
                    doDeleteFile = false;
                    ret = 0;
                } else {
                    ret = -5;
                }
            } else {
                bool res = QFile::copy( fileList[0], printer.outputFileName() );
                if ( res ) {
                    ret = 0;
                } else {
                    ret = -5;
                }
            }
        } else if ( inputFileInfo.suffix() == "ps" && printer.outputFormat() == QPrinter::PdfFormat && ps2pdfAvailable() ) {
            exe = "ps2pdf";
            argList << fileList[0] << printer.outputFileName();
            kDebug(OkularDebug) << "Executing" << exe << "with arguments" << argList;
            ret = KProcess::execute( exe, argList );
        } else if ( inputFileInfo.suffix() == "pdf" && printer.outputFormat() == QPrinter::PostScriptFormat && pdf2psAvailable() ) {
            exe = "pdf2ps";
            argList << fileList[0] << printer.outputFileName();
            kDebug(OkularDebug) << "Executing" << exe << "with arguments" << argList;
            ret = KProcess::execute( exe, argList );
        } else {
            ret = -5;
        }

        if ( doDeleteFile ) {
            QFile::remove( fileList[0] );
        }


    } else {  // Print to a printer via lpr command

        //Decide what executable to use to print with, need the CUPS version of lpr if available
        //Some distros name the CUPS version of lpr as lpr-cups or lpr.cups so try those first 
        //before default to lpr, or failing that to lp

        if ( !KStandardDirs::findExe("lpr-cups").isEmpty() ) {
            exe = "lpr-cups";
        } else if ( !KStandardDirs::findExe("lpr.cups").isEmpty() ) {
            exe = "lpr.cups";
        } else if ( !KStandardDirs::findExe("lpr").isEmpty() ) {
            exe = "lpr";
        } else if ( !KStandardDirs::findExe("lp").isEmpty() ) {
            exe = "lp";
        } else {
            return -9;
        }

        bool useCupsOptions = cupsAvailable();
        argList = printArguments( printer, fileDeletePolicy, pageSelectPolicy, 
                                  useCupsOptions, pageRange, exe, documentOrientation ) << fileList;
        kDebug(OkularDebug) << "Executing" << exe << "with arguments" << argList;

        ret = KProcess::execute( exe, argList );

    }

    return ret;
}
Esempio n. 3
0
void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
{
  QgsDebugMsg( "Entered" );
  if ( !p || !mIterator || !viewPort || !theQgsMapToPixel )
  {
    return;
  }

  // last pipe filter has only 1 band
  int bandNumber = 1;
  mIterator->startRasterRead( bandNumber, viewPort->mWidth, viewPort->mHeight, viewPort->mDrawnExtent );

  //number of cols/rows in output pixels
  int nCols = 0;
  int nRows = 0;
  //shift to top left point for the raster part
  int topLeftCol = 0;
  int topLeftRow = 0;

  // We know that the output data type of last pipe filter is QImage data

  QgsRasterBlock *block;

  // readNextRasterPart calcs and resets  nCols, nRows, topLeftCol, topLeftRow
  while ( mIterator->readNextRasterPart( bandNumber, nCols, nRows,
                                         &block, topLeftCol, topLeftRow ) )
  {
    if ( !block )
    {
      QgsDebugMsg( "Cannot get block" );
      continue;
    }

    QImage img = block->image();

    // Because of bug in Acrobat Reader we must use "white" transparent color instead
    // of "black" for PDF. See #9101.
    QPrinter *printer = dynamic_cast<QPrinter *>( p->device() );
    if ( printer && printer->outputFormat() == QPrinter::PdfFormat )
    {
      QgsDebugMsg( "PdfFormat" );

      img = img.convertToFormat( QImage::Format_ARGB32 );
      QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
      QRgb transparentWhite = qRgba( 255, 255, 255, 0 );
      for ( int x = 0; x < img.width(); x++ )
      {
        for ( int y = 0; y < img.height(); y++ )
        {
          if ( img.pixel( x, y ) == transparentBlack )
          {
            img.setPixel( x, y, transparentWhite );
          }
        }
      }
    }

    drawImage( p, viewPort, img, topLeftCol, topLeftRow );

    delete block;
  }
}
Esempio n. 4
0
int Printer::outputFormat(lua_State * L) // const : OutputFormat 
{
	QPrinter* lhs = ValueBinding<MyQPrinter>::check( L, 1 );
	Util::push( L, lhs->outputFormat() );
	return 1; 
}