File indexing completed on 2024-05-12 16:36:44
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com> 0003 Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "KPrPdfPrintJob.h" 0022 0023 #include "KPrView.h" 0024 #include "KoPAPageBase.h" 0025 #include "KoPAUtil.h" 0026 #include "KoPAPageProvider.h" 0027 #include <KoPageLayout.h> 0028 #include <KoZoomHandler.h> 0029 #include <QPainter> 0030 KPrPdfPrintJob::KPrPdfPrintJob(KPrView *view) 0031 : KoPAPrintJob(view) 0032 { 0033 } 0034 0035 KPrPdfPrintJob::~KPrPdfPrintJob() 0036 { 0037 } 0038 0039 void KPrPdfPrintJob::startPrinting(RemovePolicy removePolicy) 0040 { 0041 int fromPage = m_printer.fromPage() > 0 ? m_printer.fromPage() - 1: 0; 0042 int toPage = m_printer.toPage() > 0 ? m_printer.toPage() - 1: m_pages.size() - 1; 0043 0044 Q_ASSERT( fromPage >= 0 && fromPage < m_pages.size() ); 0045 Q_ASSERT( toPage >= 0 && toPage < m_pages.size() ); 0046 0047 KoZoomHandler zoomHandler; 0048 zoomHandler.setResolution( m_printer.resolution(), m_printer.resolution() ); 0049 m_printer.setFullPage(true); 0050 const KoPageLayout & firstLayout = m_pages.at(fromPage)->pageLayout(); 0051 m_printer.setPaperSize(QSizeF(firstLayout.width,firstLayout.height),QPrinter::Millimeter); 0052 QPainter painter( &m_printer ); 0053 0054 for ( int i = fromPage; i <= toPage; ++i ) { 0055 0056 KoPAPageBase *page = m_pages.at(i); 0057 const KoPageLayout & layout = page->pageLayout(); 0058 m_printer.setPaperSize(QSizeF(layout.width,layout.height),QPrinter::Millimeter); 0059 QSize size = m_printer.pageRect().size(); 0060 painter.save(); 0061 if (i != fromPage) { 0062 m_printer.newPage(); 0063 } 0064 KoPAUtil::setZoom(layout, size, zoomHandler); 0065 QRect pageRect(KoPAUtil::pageRect( layout, size, zoomHandler)); 0066 painter.setClipRect( pageRect ); 0067 painter.setRenderHint( QPainter::Antialiasing ); 0068 painter.translate( pageRect.topLeft() ); 0069 m_pageProvider->setPageData(i + 1, page); 0070 page->paintPage( painter, zoomHandler ); 0071 painter.restore(); 0072 } 0073 0074 if ( removePolicy == DeleteWhenDone ) { 0075 deleteLater(); 0076 } 0077 }