diff options
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 16 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp | 76 |
2 files changed, 49 insertions, 43 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index 128d95fb..7c0fd323 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -129,15 +129,20 @@ void PrintWidget::highlightText(TextData *text) { //Creates a rectangle around the text if the text has not already been highlighted if(!text->highlighted()) { double pageHeight = pages.at(text->page()-1)->boundingRect().height(); + int degrees = BACKEND->rotatedDegrees(); + //Shows the text's location on a non-rotated page QRectF rect = text->loc(); - if(BACKEND->rotatedDegrees() != 0) { + //Rotates the rectangle by the page's center and gets the right calculation for text's new location + if(degrees != 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 + + if(degrees == 90 or degrees == 270) + center.transpose(); + double cx = center.width(), cy = center.height(); rect.adjust(-cx, -cy, -cx, -cy); - QMatrix matrix; - matrix.rotate(BACKEND->rotatedDegrees()); + QMatrix matrix; + matrix.rotate(BACKEND->rotatedDegrees()); rect = matrix.mapRect(rect); if(BACKEND->rotatedDegrees() == 180) rect.adjust(cx, cy, cx, cy); @@ -146,6 +151,7 @@ void PrintWidget::highlightText(TextData *text) { } //Moves the rectangle onto the right page rect.moveTop(rect.y() + pageHeight*(text->page()-1)); + //Transparent yellow for the highlight box QBrush highlightFill(QColor(255, 255, 177, 100)); QPen highlightOutline(QColor(255, 255, 100, 125)); scene->addRect(rect, highlightOutline, highlightFill); diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp index db255f02..c75a32bb 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp @@ -62,7 +62,7 @@ Renderer::Renderer(){ qDebug() << "Creating Context"; CTX = fz_new_context(NULL, &locks, FZ_STORE_UNLIMITED); needpass = false; - degrees = 0; + degrees = 0; } Renderer::~Renderer(){ @@ -137,7 +137,7 @@ bool Renderer::loadDocument(QString path, QString password){ void renderer(Data *data, Renderer *obj) { int pagenum = data->pagenumber; - //qDebug() << "Rendering:" << pagenum; + //qDebug() << "Rendering:" << pagenum; fz_context *ctx = data->ctx; fz_display_list *list = data->list; fz_rect bbox = data->bbox; @@ -155,45 +155,45 @@ void renderer(Data *data, Renderer *obj) fz_drop_context(ctx); - if(dataHash.find(pagenum) == dataHash.end()) - dataHash.insert(pagenum, data); - else - dataHash[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, 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); + //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); } @@ -233,6 +233,6 @@ void Renderer::clearHash() { fz_drop_pixmap(CTX, dataHash[i]->pix); fz_drop_display_list(CTX, dataHash[i]->list); } - qDeleteAll(dataHash); - dataHash.clear(); + qDeleteAll(dataHash); + dataHash.clear(); } |