File indexing completed on 2024-05-19 04:35:09
0001 /* 0002 SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "generator_comicbook.h" 0008 0009 #include <QPainter> 0010 #include <QPrinter> 0011 0012 #include <KAboutData> 0013 #include <KLocalizedString> 0014 0015 #include <core/document.h> 0016 #include <core/fileprinter.h> 0017 #include <core/page.h> 0018 0019 #include "debug_comicbook.h" 0020 0021 OKULAR_EXPORT_PLUGIN(ComicBookGenerator, "libokularGenerator_comicbook.json") 0022 0023 ComicBookGenerator::ComicBookGenerator(QObject *parent, const QVariantList &args) 0024 : Generator(parent, args) 0025 { 0026 setFeature(Threaded); 0027 setFeature(PrintNative); 0028 setFeature(PrintToFile); 0029 } 0030 0031 ComicBookGenerator::~ComicBookGenerator() 0032 { 0033 } 0034 0035 bool ComicBookGenerator::loadDocument(const QString &fileName, QVector<Okular::Page *> &pagesVector) 0036 { 0037 if (!mDocument.open(fileName)) { 0038 const QString errString = mDocument.lastErrorString(); 0039 if (!errString.isEmpty()) { 0040 Q_EMIT error(errString, -1); 0041 } 0042 return false; 0043 } 0044 0045 mDocument.pages(&pagesVector); 0046 return true; 0047 } 0048 0049 bool ComicBookGenerator::doCloseDocument() 0050 { 0051 mDocument.close(); 0052 0053 return true; 0054 } 0055 0056 QImage ComicBookGenerator::image(Okular::PixmapRequest *request) 0057 { 0058 int width = request->width(); 0059 int height = request->height(); 0060 0061 QImage image = mDocument.pageImage(request->pageNumber()); 0062 0063 return image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 0064 } 0065 0066 Okular::Document::PrintError ComicBookGenerator::print(QPrinter &printer) 0067 { 0068 QPainter p(&printer); 0069 0070 QList<int> pageList = Okular::FilePrinter::pageList(printer, document()->pages(), document()->currentPage() + 1, document()->bookmarkedPageList()); 0071 0072 for (int i = 0; i < pageList.count(); ++i) { 0073 QImage image = mDocument.pageImage(pageList[i] - 1); 0074 0075 if ((image.width() > printer.width()) || (image.height() > printer.height())) { 0076 image = image.scaled(printer.width(), printer.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 0077 } 0078 0079 if (i != 0) { 0080 printer.newPage(); 0081 } 0082 0083 p.drawImage(0, 0, image); 0084 } 0085 0086 return Okular::Document::NoPrintError; 0087 } 0088 0089 #include "generator_comicbook.moc"