aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-pdf
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf')
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp30
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.h2
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp84
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp27
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/Renderer.h21
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.cpp36
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.h4
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/textData.h38
8 files changed, 125 insertions, 117 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
index 9515e719..128d95fb 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
@@ -21,8 +21,6 @@ PrintWidget::PrintWidget(Renderer *backend, QWidget *parent) :
scene = new QGraphicsScene(this);
scene->setBackgroundBrush(Qt::gray);
this->setScene(scene);
- this->degrees = 0;
- this->rotMatrix = QMatrix(1, 0, 0, 1, 0 ,0);
/*QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
@@ -132,13 +130,16 @@ void PrintWidget::highlightText(TextData *text) {
if(!text->highlighted()) {
double pageHeight = pages.at(text->page()-1)->boundingRect().height();
QRectF rect = text->loc();
- if(degrees != 0) {
+ if(BACKEND->rotatedDegrees() != 0) {
QSize center = BACKEND->imageHash(text->page()-1).size()/2;
//Rotates the rectangle by the page's center
+ //Currently broken when degrees are 90 or 270
double cx = center.width(), cy = center.height();
rect.adjust(-cx, -cy, -cx, -cy);
- rect = rotMatrix.mapRect(rect);
- if(degrees == 180)
+ QMatrix matrix;
+ matrix.rotate(BACKEND->rotatedDegrees());
+ rect = matrix.mapRect(rect);
+ if(BACKEND->rotatedDegrees() == 180)
rect.adjust(cx, cy, cx, cy);
else
rect.adjust(cy, cx, cy, cx);
@@ -210,18 +211,9 @@ void PrintWidget::populateScene()
for (int i = 0; i < numPages; i++) {
QImage pagePicture = BACKEND->imageHash(i);
- //qDebug() << "Loading Image:" << i;
- QSize paperSize = BACKEND->imageHash(i).size();
+ QSize paperSize = pagePicture.size();
- //Changes the paper orientation if rotated by 90 or 270 degrees
- if(degrees == 90 or degrees == 270)
- paperSize.transpose();
-
- if(degrees != 0) {
- pagePicture = pagePicture.transformed(rotMatrix, Qt::SmoothTransformation);
- //qDebug() << "Rotating by: " << degrees << " degrees";
- }
if(pagePicture.isNull()) {
qDebug() << "NULL IMAGE ON PAGE " << i;
continue;
@@ -317,11 +309,3 @@ void PrintWidget::fit(bool doFitting) {
//zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
}
-
-//Makes sure degrees is between 0 and 360 then rotates the matrix and
-void PrintWidget::setDegrees(int degrees) {
- //Mods by 360, but adds and remods because of how C++ treats negative mods
- this->degrees = ( ( ( this->degrees + degrees ) % 360 ) + 360 ) % 360;
- rotMatrix.rotate(degrees);
- this->updatePreview();
-}
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
index 476ef596..98bcd259 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
@@ -106,7 +106,6 @@ private:
void setZoomMode(ZoomMode);
QGraphicsScene *scene;
- QMatrix rotMatrix;
int curPage, publicPageNum;
ViewMode viewMode;
ZoomMode zoomMode;
@@ -136,7 +135,6 @@ public slots:
void setCurrentPage(int);
void setVisible(bool) Q_DECL_OVERRIDE;
void highlightText(TextData*);
- void setDegrees(int);
void updatePreview();
void fitView();
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp
index 48c67b0e..db255f02 100644
--- a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp
@@ -62,6 +62,7 @@ Renderer::Renderer(){
qDebug() << "Creating Context";
CTX = fz_new_context(NULL, &locks, FZ_STORE_UNLIMITED);
needpass = false;
+ degrees = 0;
}
Renderer::~Renderer(){
@@ -76,15 +77,6 @@ Renderer::~Renderer(){
bool Renderer::loadMultiThread(){ return false; }
-void Renderer::cleanup() {
- /*for(int i = 0; i < dataHash.size(); i++) {
- fz_drop_pixmap(CTX, dataHash[i]->pix);
- fz_drop_display_list(CTX, dataHash[i]->list);
- }
- fz_drop_document(CTX, DOC);
- fz_drop_context(CTX);*/
-}
-
bool Renderer::loadDocument(QString path, QString password){
//first time through
if(path != docpath) {
@@ -145,6 +137,7 @@ bool Renderer::loadDocument(QString path, QString password){
void renderer(Data *data, Renderer *obj)
{
int pagenum = data->pagenumber;
+ //qDebug() << "Rendering:" << pagenum;
fz_context *ctx = data->ctx;
fz_display_list *list = data->list;
fz_rect bbox = data->bbox;
@@ -162,41 +155,45 @@ void renderer(Data *data, Renderer *obj)
fz_drop_context(ctx);
- dataHash.insert(pagenum, data);
+ if(dataHash.find(pagenum) == dataHash.end())
+ dataHash.insert(pagenum, data);
+ else
+ dataHash[pagenum] = data;
emit obj->PageLoaded(pagenum);
}
//Consider rendering through a display list
-void Renderer::renderPage(int pagenum, QSize DPI){
- //qDebug() << "- Rendering Page:" << pagenum;
- fz_matrix matrix;
- fz_rect bbox;
- fz_irect rbox;
- fz_pixmap *pixmap;
- fz_display_list *list;
-
- double pageDPI = 96.0;
- double sf = DPI.width() / pageDPI;
- fz_scale(&matrix, DPI.width()/pageDPI, DPI.height()/pageDPI);
-
- fz_page *PAGE = fz_load_page(CTX, DOC, pagenum);
- fz_bound_page(CTX, PAGE, &bbox);
- emit OrigSize(QSizeF(bbox.x1 - bbox.x0, bbox.y1 - bbox.y0));
-
- fz_transform_rect(&bbox, &matrix);
- list = fz_new_display_list(CTX, &bbox);
- fz_device *dev = fz_new_list_device(CTX, list);
- fz_run_page(CTX, PAGE, dev, &fz_identity, NULL);
-
- fz_close_device(CTX, dev);
- fz_drop_device(CTX, dev);
- fz_drop_page(CTX, PAGE);
-
- pixmap = fz_new_pixmap_with_bbox(CTX, fz_device_rgb(CTX), fz_round_rect(&rbox, &bbox), NULL, 0);
- fz_clear_pixmap_with_value(CTX, pixmap, 0xff);
-
- //pixmap = fz_new_pixmap_from_page_number(CTX, DOC, pagenum, &matrix, fz_device_rgb(CTX), 0);
- Data *data = new Data(pagenum, CTX, list, bbox, pixmap, matrix, sf);
+void Renderer::renderPage(int pagenum, QSize DPI, int degrees){
+ qDebug() << "- Rendering Page:" << pagenum << degrees;
+ Data *data;
+ fz_matrix matrix;
+ fz_rect bbox;
+ fz_irect rbox;
+ fz_pixmap *pixmap;
+ fz_display_list *list;
+
+ double pageDPI = 96.0;
+ double sf = DPI.width() / pageDPI;
+ fz_scale(&matrix, sf, sf);
+ fz_pre_rotate(&matrix, degrees);
+
+ fz_page *PAGE = fz_load_page(CTX, DOC, pagenum);
+ fz_bound_page(CTX, PAGE, &bbox);
+ emit OrigSize(QSizeF(bbox.x1 - bbox.x0, bbox.y1 - bbox.y0));
+
+ fz_transform_rect(&bbox, &matrix);
+ list = fz_new_display_list(CTX, &bbox);
+ fz_device *dev = fz_new_list_device(CTX, list);
+ fz_run_page(CTX, PAGE, dev, &fz_identity, NULL);
+
+ fz_close_device(CTX, dev);
+ fz_drop_device(CTX, dev);
+ fz_drop_page(CTX, PAGE);
+
+ pixmap = fz_new_pixmap_with_bbox(CTX, fz_device_rgb(CTX), fz_round_rect(&rbox, &bbox), NULL, 0);
+ fz_clear_pixmap_with_value(CTX, pixmap, 0xff);
+
+ data = new Data(pagenum, CTX, list, bbox, pixmap, matrix, sf);
data->renderThread = QtConcurrent::run(&renderer, data, this);
}
@@ -232,5 +229,10 @@ int Renderer::hashSize() {
}
void Renderer::clearHash() {
- dataHash.clear();
+ for(int i = 0; i < dataHash.size(); i++) {
+ fz_drop_pixmap(CTX, dataHash[i]->pix);
+ fz_drop_display_list(CTX, dataHash[i]->list);
+ }
+ qDeleteAll(dataHash);
+ dataHash.clear();
}
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp
index e37d715d..62548f78 100644
--- a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp
@@ -9,6 +9,7 @@ Renderer::Renderer(){
DOC = 0;
needpass = false;
pnum = 0;
+ degrees = 0;
}
Renderer::~Renderer(){
@@ -68,18 +69,28 @@ bool Renderer::loadDocument(QString path, QString password){
return false; //nothing to load
}
-void Renderer::cleanup() {}
-
-void Renderer::renderPage(int pagenum, QSize DPI){
- //qDebug() << "Render Page:" << pagenum << DPI;
+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){
- //qDebug() << "Render Page:" << pagenum;
- img = PAGE->renderToImage(DPI.width(),DPI.height());
+ 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);
- //qDebug() << "Image after creation:" << img.isNull();
delete PAGE;
}
//qDebug() << "Done Render Page:" << pagenum << img.size();
@@ -96,7 +107,7 @@ QList<TextData*> Renderer::searchDocument(QString text, bool matchCase){
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);
+ TextData *t = new TextData(textList[j]->boundingBox(), i+1, text, degrees);
results.append(t);
}
}
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer.h b/src-qt5/desktop-utils/lumina-pdf/Renderer.h
index b983d14b..870267a8 100644
--- a/src-qt5/desktop-utils/lumina-pdf/Renderer.h
+++ b/src-qt5/desktop-utils/lumina-pdf/Renderer.h
@@ -1,5 +1,4 @@
-// ================================
-// Simple abstraction class between backend renderers
+// ================================ // Simple abstraction class between backend renderers
// ================================
// Written by Ken Moore: Feb 26, 2018
// Available under the 3-Clause BSD License
@@ -22,6 +21,7 @@ private:
QString docpath; //save the path for the currently-loaded document
QString doctitle;
QJsonObject jobj;
+ int degrees;
public:
Renderer();
@@ -33,20 +33,27 @@ public:
bool needPassword(){ return needpass; }
QString title(){ return doctitle; }
QJsonObject properties() { return jobj; }
+ int hashSize();
+ QImage imageHash(int pagenum);
+ int rotatedDegrees() { return degrees; }
//Main access functions
bool loadDocument(QString path, QString password);
- void renderPage(int pagenum, QSize DPI);
+ void renderPage(int pagenum, QSize DPI, int degrees=0);
QList<TextData*> searchDocument(QString text, bool matchCase);
- void cleanup();
- QImage imageHash(int pagenum);
- int hashSize();
- void clearHash();
+ void clearHash();
+ //Makes sure degrees is between 0 and 360 then rotates the matrix and
+ void setDegrees(int degrees) {
+ //Mods by 360, but adds and remods because of how C++ treats negative mods
+ this->degrees = ( ( ( this->degrees + degrees ) % 360 ) + 360 ) % 360;
+ emit reloadPages(this->degrees);
+ }
signals:
void PageLoaded(int);
void OrigSize(QSizeF);
+ void reloadPages(int);
};
#endif
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
index e056b0b2..1d1df0ce 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
@@ -31,9 +31,9 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
CurrentPage = 1;
lastdir = QDir::homePath();
BACKEND = new Renderer();
+ PROPDIALOG=nullptr;
//Create the interface widgets
WIDGET = new PrintWidget(BACKEND, this->centralWidget());
- WIDGET->setVisible(false);
WIDGET->setContextMenuPolicy(Qt::CustomContextMenu);
WIDGET->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
loadingQueue.clear();
@@ -58,6 +58,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
connect(WIDGET, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)) );
connect(WIDGET, SIGNAL(currentPageChanged()), this, SLOT(updatePageNumber()) );
connect(BACKEND, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) );
+ connect(BACKEND, SIGNAL(reloadPages(int)), this, SLOT(startLoadingPages(int)));
PrintDLG = new QPrintDialog(this);
connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) );
@@ -103,8 +104,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
//connect(ui->actionSelect_Mode, &QAction::triggered, this, [&] { this->setScroll(false); });
connect(ui->actionZoom_In, &QAction::triggered, WIDGET, [&] { WIDGET->zoomIn(1.2); });
connect(ui->actionZoom_Out, &QAction::triggered, WIDGET, [&] { WIDGET->zoomOut(1.2); });
- connect(ui->actionRotate_Counterclockwise, &QAction::triggered, this, [&] { if(results.size() != 0) { foreach(TextData *x, results) { x->highlighted(false); } } WIDGET->setDegrees(-90); });
- connect(ui->actionRotate_Clockwise, &QAction::triggered, this, [&] { if(results.size() != 0) { foreach(TextData *x, results) { x->highlighted(false); } } WIDGET->setDegrees(90); });
+ connect(ui->actionRotate_Counterclockwise, &QAction::triggered, this, [&] { if(results.size() != 0) { foreach(TextData *x, results) { x->highlighted(false); } } BACKEND->setDegrees(-90); });
+ connect(ui->actionRotate_Clockwise, &QAction::triggered, this, [&] { if(results.size() != 0) { foreach(TextData *x, results) { x->highlighted(false); } } BACKEND->setDegrees(90); });
connect(ui->actionZoom_In_2, &QAction::triggered, WIDGET, [&] { WIDGET->zoomIn(1.2); });
connect(ui->actionZoom_Out_2, &QAction::triggered, WIDGET, [&] { WIDGET->zoomOut(1.2); });
connect(ui->actionFirst_Page, SIGNAL(triggered()), this, SLOT(firstPage()) );
@@ -211,8 +212,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
//TESTING features/functionality
ui->actionSettings->setEnabled(TESTING);
ui->actionSettings->setVisible(TESTING);
- //ui->actionBookmarks->setEnabled(TESTING);
- //ui->actionBookmarks->setVisible(TESTING);
+ ui->actionBookmarks->setEnabled(TESTING);
+ ui->actionBookmarks->setVisible(TESTING);
ui->actionScroll_Mode->setEnabled(TESTING);
ui->actionScroll_Mode->setVisible(TESTING);
ui->actionSelect_Mode->setEnabled(TESTING);
@@ -240,20 +241,18 @@ void MainUI::loadFile(QString path){
if(!ok){ break; } //cancelled
}
//Clear the current display
-
- WIDGET->setVisible(false);
- BACKEND->clearHash();
+ WIDGET->setVisible(false);
QTimer::singleShot(10, WIDGET, SLOT(updatePreview()));
//Load the new document info
this->setWindowTitle( BACKEND->title());
if(BACKEND->needPassword()){ return; } //cancelled;
qDebug() << " - Document Setup : start loading pages now";
- QTimer::singleShot(50, this, SLOT(startLoadingPages()) );
+ QTimer::singleShot(50, [&]() { startLoadingPages(0); } );
}
-void MainUI::loadPage(int num, MainUI *obj, QSize dpi){
+void MainUI::loadPage(int num, MainUI *obj, QSize dpi, int degrees){
//qDebug() << " - Render Page:" << num;
- BACKEND->renderPage(num, dpi);
+ BACKEND->renderPage(num, dpi, degrees);
//qDebug() << "Image at" << num << "accessed outside:" << BACKEND->imageHash(num).isNull();
}
@@ -364,10 +363,14 @@ void MainUI::endPresentation(){
updatePageNumber();
}
-void MainUI::startLoadingPages(){
- //qDebug() <<"Start Loading Pages";
- if(BACKEND->hashSize() != 0) { return; } //currently loaded[ing]
+void MainUI::startLoadingPages(int degrees){
+ qDebug() <<"Start Loading Pages";
+ //if(BACKEND->hashSize() != 0) { return; } //currently loaded[ing]
loadingQueue.clear();
+ if(PROPDIALOG)
+ delete PROPDIALOG;
+ BACKEND->clearHash();
+ WIDGET->setVisible(false);
//qDebug() << "Update Progress Bar";
progress->setRange(0, BACKEND->numPages());
progress->setValue(0);
@@ -388,9 +391,9 @@ void MainUI::startLoadingPages(){
for(int i=0; i<BACKEND->numPages(); i++){
//qDebug() << " - Kickoff page load:" << i;
if(BACKEND->loadMultiThread()) {
- QtConcurrent::run(this, &MainUI::loadPage, i, this, DPI);
+ QtConcurrent::run(this, &MainUI::loadPage, i, this, DPI, degrees);
}else{
- BACKEND->renderPage(i, DPI);
+ BACKEND->renderPage(i, DPI, degrees);
}
}
//qDebug() << "Finish page loading kickoff";
@@ -401,7 +404,6 @@ void MainUI::slotPageLoaded(int page){
int finished = loadingQueue.size();
//qDebug() << "Page Loaded:" << page << finished;
if(finished == BACKEND->numPages()){
- BACKEND->cleanup();
//qDebug() << " - finished:" << finished;
progAct->setVisible(false);
WIDGET->setVisible(true);
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h
index 89fbed1d..311bb46d 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h
@@ -62,7 +62,7 @@ private:
//PDF Page Loading cache variables
Renderer *BACKEND;
- void loadPage(int num, MainUI *obj, QSize dpi);
+ void loadPage(int num, MainUI *obj, QSize dpi, int degrees);
//Functions/variables for the presentation mode
PresentationLabel *presentationLabel;
@@ -73,7 +73,7 @@ private:
void endPresentation();
private slots:
- void startLoadingPages();
+ void startLoadingPages(int degrees = 0);
void slotPageLoaded(int);
//Simplification routines
diff --git a/src-qt5/desktop-utils/lumina-pdf/textData.h b/src-qt5/desktop-utils/lumina-pdf/textData.h
index 050e04d6..9bf7e5bb 100644
--- a/src-qt5/desktop-utils/lumina-pdf/textData.h
+++ b/src-qt5/desktop-utils/lumina-pdf/textData.h
@@ -5,27 +5,31 @@
class TextData {
private:
- QRectF _loc;
- bool _highlighted=false;
- int _page=0;
- QString _text="";
+ QRectF p_loc;
+ bool p_highlighted=false;
+ int p_page=0;
+ QString p_text="";
+ //int p_degrees=0;
public:
- TextData(QRectF _loc, int _page, QString _text) {
- this->_loc = _loc;
- this->_page = _page;
- this->_text = _text;
- }
+ TextData(QRectF _loc, int _page, QString _text) :
+ p_loc(_loc),
+ p_page(_page),
+ p_text(_text)
+ //p_degrees(_degrees)
+ { }
- QRectF loc() { return this->_loc; }
- bool highlighted() { return this->_highlighted; }
- int page() { return this->_page; }
- QString text() { return this->_text; }
+ QRectF loc() { return p_loc; }
+ bool highlighted() { return p_highlighted; }
+ int page() { return p_page; }
+ QString text() { return p_text; }
+ //int degrees() { return p_degrees; }
- void loc(QRect loc) { this->_loc = loc; }
- void highlighted(bool highlighted) { this->_highlighted = highlighted; }
- void page(int page) { this->_page = page; }
- void text(QString text) { this->_text = text; }
+ void loc(QRect loc) { p_loc = loc; }
+ void highlighted(bool highlighted) { p_highlighted = highlighted; }
+ void page(int page) { p_page = page; }
+ void text(QString text) { p_text = text; }
+ //void degrees(int degrees) { p_degrees = degrees; }
};
#endif
bgstack15