diff options
author | ZackaryWelch <welch.zackary@gmail.com> | 2018-03-30 18:47:20 -0400 |
---|---|---|
committer | ZackaryWelch <welch.zackary@gmail.com> | 2018-03-30 18:47:20 -0400 |
commit | 62727f05297af2894d62630d387fb39e672b4451 (patch) | |
tree | 3c68671e3173fdce7e7994d702c9d3c348f218b6 /src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp | |
parent | Reset the default backend renderer to poppler. (diff) | |
download | lumina-62727f05297af2894d62630d387fb39e672b4451.tar.gz lumina-62727f05297af2894d62630d387fb39e672b4451.tar.bz2 lumina-62727f05297af2894d62630d387fb39e672b4451.zip |
Added support for internal links. Code added for Poppler backend but not enabled. Code enabled for MuPDF. Does not support extrnal links yet.
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp index 7f2baa5e..98a351bd 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp @@ -2,8 +2,22 @@ #include <poppler/qt5/poppler-qt5.h> #include <QThread> +class Link { + public: + Link(TextData *_data, Poppler::Link *_link) : data(_data), link(_link) { } + ~Link() { delete data; } + + TextData* getData() { return data; } + Poppler::Link* getLink() { return link; } + + private: + TextData *data; + Poppler::Link *link; +}; + static Poppler::Document *DOC; QHash<int, QImage> loadingHash; +QHash<int, QList<Link*>> linkHash; Renderer::Renderer(){ DOC = 0; @@ -29,6 +43,12 @@ bool Renderer::loadDocument(QString path, QString password){ //Clear out the old document first delete DOC; DOC=0; + if(linkHash.size() > 0) { + foreach(QList<Link*> linkArray, linkHash) { + qDeleteAll(linkArray); + } + linkHash.clear(); + } needpass = false; pnum=0; docpath = path; @@ -91,6 +111,17 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees){ } img = PAGE->renderToImage(DPI.width(), DPI.height(), -1, -1, -1, -1, rotation); loadingHash.insert(pagenum, img); + QList<Link*> linkArray; + foreach(Poppler::Link *link, PAGE->links()) { + QString location; + if(link->linkType() == Poppler::Link::LinkType::Goto) + location = dynamic_cast<Poppler::LinkGoto*>(link)->fileName(); + else if(link->linkType() == Poppler::Link::LinkType::Goto) + location = dynamic_cast<Poppler::LinkBrowse*>(link)->url(); + Link *newLink = new Link(new TextData(link->linkArea(), pagenum, location), link); + linkArray.append(newLink); + } + linkHash.insert(pagenum, linkArray); delete PAGE; } //qDebug() << "Done Render Page:" << pagenum << img.size(); @@ -132,4 +163,53 @@ bool Renderer::supportsExtraFeatures() { return false; } void Renderer::traverseOutline(void *, int) { } -void Renderer::handleLink(QString link) { } +void Renderer::handleLink(QString linkDest) { + Poppler::Link* trueLink; + foreach(QList<Link*> linkArray, linkHash) { + for(int i = 0; i < linkArray.size(); i++) { + Poppler::Link* link = linkArray[i]->getLink(); + if(link->linkType() == Poppler::Link::LinkType::Browse) { + if(linkDest == dynamic_cast<Poppler::LinkBrowse*>(link)->url()) + trueLink = link; + }else if(link->linkType() == Poppler::Link::LinkType::Goto) { + if(linkDest == dynamic_cast<Poppler::LinkGoto*>(link)->fileName()) + trueLink = link; + } + } + } + if(trueLink) { + if(trueLink->linkType() == Poppler::Link::LinkType::Goto) + emit goToPosition(dynamic_cast<Poppler::LinkGoto*>(trueLink)->destination().pageNumber(), 0, 0); + } +} + +TextData* Renderer::linkList(int pageNum, int entry) { + if(linkHash[pageNum].size() > 0) + return linkHash[pageNum][entry]->getData(); + else + return 0; +} + +int Renderer::linkSize(int pageNum) { return linkHash[pageNum].size(); } + +bool Renderer::isExternalLink(int pageNum, QString text) { + Poppler::Link* trueLink; + foreach(QList<Link*> linkArray, linkHash) { + for(int i = 0; i < linkArray.size(); i++) { + Poppler::Link* link = linkArray[i]->getLink(); + if(link->linkType() == Poppler::Link::LinkType::Browse) { + if(text == dynamic_cast<Poppler::LinkBrowse*>(link)->url()) + trueLink = link; + }else if(link->linkType() == Poppler::Link::LinkType::Goto) { + if(text == dynamic_cast<Poppler::LinkGoto*>(link)->fileName()) + trueLink = link; + } + } + } + if(trueLink) { + if(trueLink->linkType() == Poppler::Link::LinkType::Goto) + return dynamic_cast<Poppler::LinkGoto*>(trueLink)->isExternal(); + if(trueLink->linkType() == Poppler::Link::LinkType::Browse) + return true; + } +} |