void KookaPrint::printFittingToPage(KookaImage *img) { if( ! img || ! m_painter ) return; KookaImage tmpImg; QString psMode = m_printer->option( OPT_RATIO ); bool maintainAspect = (psMode == "1"); QSize s = maxPageSize(); double wAspect = double(s.width()) / double(img->width()); double hAspect = double(s.height()) / double(img->height()); // take the smaller one. double aspect = wAspect; if( hAspect < wAspect ) aspect = hAspect; // default: maintain aspect ratio. int newWidth = int( double( img->width() ) * aspect ); int newHeight = int( double( img->height()) * aspect ); if( ! maintainAspect ) { newWidth = int( double( img->width() ) * wAspect ); newHeight = int( double( img->height() ) * hAspect ); } tmpImg = img->smoothScale(newWidth, newHeight, QImage::ScaleFree); m_painter->drawImage( 0,0, tmpImg ); }
QPoint KookaPrint::printPosBottomLeft(const QSize& imgSize) const { QSize max = maxPageSize(); int eMargin = extraMarginPix(); /* take the half extra margin */ return QPoint( eMargin+(max.width() - imgSize.width())/2, eMargin+(max.height() - imgSize.height())/2 + imgSize.height() ); }
void EDA_DRAW_FRAME::Process_PageSettings( wxCommandEvent& event ) { FRAME_T smallSizeFrames[] = { FRAME_PCB, FRAME_PCB_MODULE_EDITOR, FRAME_PCB_MODULE_VIEWER, FRAME_PCB_MODULE_VIEWER_MODAL, FRAME_PCB_FOOTPRINT_WIZARD, FRAME_PCB_FOOTPRINT_PREVIEW, FRAME_CVPCB_DISPLAY }; // Fix the max page size: it is MAX_PAGE_SIZE_EDITORS // or MAX_PAGE_SIZE_PCBNEW for Pcbnew draw frames, due to the small internal // units that do not allow too large draw areas wxSize maxPageSize( MAX_PAGE_SIZE_EDITORS_MILS, MAX_PAGE_SIZE_EDITORS_MILS ); for( unsigned ii = 0; ii < arrayDim( smallSizeFrames ); ii++ ) { if( IsType( smallSizeFrames[ii] ) ) { maxPageSize.x = maxPageSize.y = MAX_PAGE_SIZE_PCBNEW_MILS; break; } } DIALOG_PAGES_SETTINGS dlg( this, maxPageSize ); dlg.SetWksFileName( BASE_SCREEN::m_PageLayoutDescrFileName ); if( dlg.ShowModal() == wxID_OK ) { #ifdef EESCHEMA RedrawScreen( wxPoint( 0, 0 ), false ); #else GetCanvas()->Refresh(); #endif } }
bool KookaPrint::printImage( KookaImage *img ) { bool result = true; if( ! m_printer || !img) return false; QString psMode = m_printer->option( OPT_PSGEN_DRAFT ); kdDebug(28000) << "User setting for quality: " << psMode << endl; #if 0 if( psMode == "1" ) m_printer->setResolution( 75 ); else m_printer->setResolution( 600 ); #endif /* Create painter _after_ setting Resolution */ QPainter painter(m_printer); m_painter = &painter; KookaImage tmpImg; QPoint pt(0, 0); // the top-left corner (image will be centered) // We use a QPaintDeviceMetrics to know the actual page size in pixel, // this gives the real painting area QPaintDeviceMetrics printermetrics( m_painter->device() ); int screenRes = m_printer->option( OPT_SCREEN_RES ).toInt(); // int printerRes = printermetrics.logicalDpiX(); int printerRes = m_printer->resolution(); QString scale = m_printer->option( OPT_SCALING ); int reso = screenRes; if( scale == "scan" ) { /* Scale to original size */ reso = m_printer->option( OPT_SCAN_RES ).toInt(); } else if( scale == "custom" ) { // kdDebug(28000) << "Not yet implemented: Custom scale" << endl; double userWidthInch = (m_printer->option( OPT_WIDTH ).toDouble() / 25.4 ); reso = int( double(img->width()) / userWidthInch ); kdDebug(28000) << "Custom resolution: " << reso << endl; } else if( scale == "fitpage" ) { kdDebug(28000) << "Printing using maximum space on page" << endl; printFittingToPage( img ); reso = 0; // to skip the printing on this page. } /* Scale the image for printing */ kdDebug(28000) << "Printer-Resolution: " << printerRes << " and scale-Reso: " << reso << endl; QSize margins = m_printer->margins(); kdDebug(28000) << "Printer-Margins left: " << margins.width() << " and top " << margins.height() << endl; if( reso > 0) { double sizeInch = double(img->width()) / double(reso); int newWidth = int(sizeInch * printerRes); printerRes = printermetrics.logicalDpiY(); sizeInch = double(img->height()) / double(reso); int newHeight = int(sizeInch * printerRes ); kdDebug(28000) << "Scaling to printer size " << newWidth << " x " << newHeight << endl; tmpImg = img->smoothScale(newWidth, newHeight, QImage::ScaleFree); QSize sz = tmpImg.size(); // the current image size QSize maxOnPage = maxPageSize(); // the maximum space on one side int maxRows, maxCols; int subpagesCnt = tmpImg.cutToTiles( maxOnPage, maxRows, maxCols ); kdDebug(28000) << "Subpages count: " << subpagesCnt << " Columns:" << maxCols << " Rows:" << maxRows << endl; int cnt = 0; for( int row = 0; row < maxRows; row++ ) { for( int col = 0; col < maxCols; col++ ) { const QRect part = tmpImg.getTileRect( row, col ); const QSize imgSize = part.size(); kdDebug(28000) << "Printing part from " << part.x() << "/" << part.y() << " width:"<< part.width() << " and height " << part.height() << endl; QImage tileImg = tmpImg.copy( part ); m_painter->drawImage( printPosTopLeft(imgSize), tileImg ); drawCornerMarker( imgSize, row, col, maxRows, maxCols ); cnt++; if( cnt < subpagesCnt ) m_printer->newPage(); } } } m_painter = 0; // no, this is not a memory leak. return result; }
int KookaPrint::extraMarginPix() const { QSize max = maxPageSize(); /* take the half extra margin */ return int(double(max.width())*double(m_extraMarginPercent) / 100.0 / 2.0); }