diff options
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp | 90 |
1 files changed, 60 insertions, 30 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp index 693faa64..439fd804 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp @@ -1,23 +1,27 @@ #include "Renderer.h" #include <poppler/qt5/poppler-qt5.h> +#include <QThread> static Poppler::Document *DOC; +QHash<int, QImage> loadingHash; Renderer::Renderer(){ DOC = 0; needpass = false; pnum = 0; + degrees = 0; } Renderer::~Renderer(){ - + //qDeleteAll(loadingHash); + loadingHash.clear(); } -//bool Renderer::loadMultiThread(){ return true; } +bool Renderer::loadMultiThread(){ return true; } -QJsonObject Renderer::properties(){ +/*QJsonObject Renderer::properties(){ return QJsonObject(); //TO-DO -} +}*/ bool Renderer::loadDocument(QString path, QString password){ //qDebug() << "Load Document:" << path; @@ -27,13 +31,13 @@ bool Renderer::loadDocument(QString path, QString password){ DOC=0; needpass = false; pnum=0; - docpath = path; + docpath = path; } //Load the Document (if needed); if(DOC==0){ //qDebug() << "Loading Document"; DOC = Poppler::Document::load(path); - docpath = path; + docpath = path; } if(DOC==0){ @@ -65,36 +69,62 @@ bool Renderer::loadDocument(QString path, QString password){ return false; //nothing to load } -QImage Renderer::renderPage(int pagenum, QSize DPI){ - //qDebug() << "Render Page:" << pagenum << DPI; - if(DOC==0){ return QImage(); } - Poppler::Page *PAGE = DOC->page(pagenum); - QImage img; - if(PAGE!=0){ - //qDebug() << "Render Page:" << pagenum; - img = PAGE->renderToImage(DPI.width(),DPI.height()); - delete PAGE; +void Renderer::renderPage(int pagenum, QSize DPI, int degrees){ + //qDebug() << "Render Page:" << pagenum << DPI << degrees; + if(DOC!=0){ + Poppler::Page *PAGE = DOC->page(pagenum); + QImage img; + if(PAGE!=0){ + Poppler::Page::Rotation rotation; + switch(degrees) { + case 90: + rotation = Poppler::Page::Rotation::Rotate90; + break; + case 180: + rotation = Poppler::Page::Rotation::Rotate180; + break; + case 270: + rotation = Poppler::Page::Rotation::Rotate270; + break; + default: + rotation = Poppler::Page::Rotation::Rotate0; + } + img = PAGE->renderToImage(DPI.width(),DPI.height(), -1, -1, -1, -1, rotation); + loadingHash.insert(pagenum, img); + delete PAGE; + } + //qDebug() << "Done Render Page:" << pagenum << img.size(); + }else{ + loadingHash.insert(pagenum, QImage()); } - //qDebug() << "Done Render Page:" << pagenum << img.size(); - return img; + emit PageLoaded(pagenum); } QList<TextData*> Renderer::searchDocument(QString text, bool matchCase){ QList<TextData*> results; - /*for(int i = 0; i < pnum; i++) { - int count = fz_search_page_number(CTX, DOC, i, text.toLatin1().data(), rectBuffer, 1000); - //qDebug() << "Page " << i+1 << ": Count, " << count; - for(int j = 0; j < count; j++) { - TextData *t = new TextData(rectBuffer[j], i+1, text); - //MuPDF search does not match case, so retrieve the exact text at the location found and determine whether or not it matches the case of the search text if the user selected to match case - if(matchCase){ - fz_stext_page *sPage = fz_new_stext_page_from_page_number(CTX, DOC, i, NULL); - QString currentStr = QString(fz_copy_selection(CTX, sPage, *fz_rect_min(&rectBuffer[j]), *fz_rect_max(&rectBuffer[j]), false)); - if(currentStr.contains(text, Qt::CaseSensitive)){ results.append(t); } - }else{ - results.append(t); + for(int i = 0; i < pnum; i++) { + QList<Poppler::TextBox*> textList = DOC->page(i)->textList(); + for(int j = 0; j < textList.size(); j++) { + if(textList[j]->text().contains(text, + (matchCase) ? Qt::CaseSensitive : Qt::CaseInsensitive)) { + TextData *t = new TextData(textList[j]->boundingBox(), i+1, text); + results.append(t); } } - }*/ + } return results; } + +QImage Renderer::imageHash(int pagenum) { + return loadingHash[pagenum]; +} + +int Renderer::hashSize() { + return loadingHash.keys().length(); +} + +void Renderer::clearHash() { + loadingHash.clear(); +} + +bool Renderer::supportsExtraFeatures() { return false; } |