2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2006-2009 Luigi Toscano <luigi.toscano@tiscali.it>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2011-06-01 08:49:49 +00:00
|
|
|
#include <core/action.h>
|
|
|
|
#include <core/document.h>
|
|
|
|
#include <core/fileprinter.h>
|
|
|
|
#include <core/page.h>
|
|
|
|
#include <core/sourcereference.h>
|
|
|
|
#include <core/textpage.h>
|
2007-01-03 14:30:48 +00:00
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "TeXFont.h"
|
2014-09-11 19:12:27 +00:00
|
|
|
#include "debug_dvi.h"
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "dviFile.h"
|
|
|
|
#include "dviPageInfo.h"
|
|
|
|
#include "dviRenderer.h"
|
2007-12-30 16:41:10 +00:00
|
|
|
#include "dviexport.h"
|
2009-11-21 00:57:56 +00:00
|
|
|
#include "generator_dvi.h"
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "pageSize.h"
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QStack>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QVector>
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2014-09-18 20:17:10 +00:00
|
|
|
#include <KAboutData>
|
2014-10-08 11:37:04 +00:00
|
|
|
#include <KLocalizedString>
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QDebug>
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-26 22:53:40 +00:00
|
|
|
#ifdef DVI_OPEN_BUSYLOOP
|
2015-03-03 22:44:23 +00:00
|
|
|
#include <QThread>
|
2009-05-26 22:53:40 +00:00
|
|
|
#endif
|
2009-05-25 16:04:36 +00:00
|
|
|
|
2015-11-28 19:24:41 +00:00
|
|
|
OKULAR_EXPORT_PLUGIN(DviGenerator, "libokularGenerator_dvi.json")
|
2007-12-02 20:57:24 +00:00
|
|
|
|
|
|
|
DviGenerator::DviGenerator(QObject *parent, const QVariantList &args)
|
|
|
|
: Okular::Generator(parent, args)
|
2017-09-05 21:27:18 +00:00
|
|
|
, m_fontExtracted(false)
|
|
|
|
, m_docSynopsis(nullptr)
|
|
|
|
, m_dviRenderer(nullptr)
|
2007-12-02 20:57:24 +00:00
|
|
|
{
|
2009-05-11 15:14:17 +00:00
|
|
|
setFeature(Threaded);
|
2007-01-26 16:35:30 +00:00
|
|
|
setFeature(TextExtraction);
|
2009-11-21 00:57:56 +00:00
|
|
|
setFeature(FontInfo);
|
2007-12-30 16:41:10 +00:00
|
|
|
setFeature(PrintPostscript);
|
2008-12-14 23:18:52 +00:00
|
|
|
if (Okular::FilePrinter::ps2pdfAvailable()) {
|
|
|
|
setFeature(PrintToFile);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
bool DviGenerator::loadDocument(const QString &fileName, QVector<Okular::Page *> &pagesVector)
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2014-09-11 19:12:27 +00:00
|
|
|
// qCDebug(OkularDviDebug) << "file:" << fileName;
|
2015-01-29 19:55:57 +00:00
|
|
|
QUrl base(QUrl::fromLocalFile(fileName));
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
(void)userMutex();
|
|
|
|
|
2017-03-02 20:04:59 +00:00
|
|
|
m_dviRenderer = new dviRenderer(documentMetaData(TextHintingMetaData, QVariant()).toBool());
|
2014-10-05 05:36:05 +00:00
|
|
|
connect(m_dviRenderer, &dviRenderer::error, this, &DviGenerator::error);
|
|
|
|
connect(m_dviRenderer, &dviRenderer::warning, this, &DviGenerator::warning);
|
|
|
|
connect(m_dviRenderer, &dviRenderer::notice, this, &DviGenerator::notice);
|
2009-05-26 22:53:40 +00:00
|
|
|
#ifdef DVI_OPEN_BUSYLOOP
|
2009-05-25 16:04:36 +00:00
|
|
|
static const ushort s_waitTime = 800; // milliseconds
|
|
|
|
static const int s_maxIterations = 10;
|
|
|
|
int iter = 0;
|
|
|
|
for (; !m_dviRenderer->isValidFile(fileName) && iter < s_maxIterations; ++iter) {
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug).nospace() << "file not valid after iteration #" << iter << "/" << s_maxIterations << ", waiting for " << s_waitTime;
|
2015-03-03 22:44:23 +00:00
|
|
|
QThread::msleep(s_waitTime);
|
2009-05-25 16:04:36 +00:00
|
|
|
}
|
|
|
|
if (iter >= s_maxIterations && !m_dviRenderer->isValidFile(fileName)) {
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "file still not valid after" << s_maxIterations;
|
2009-05-25 16:04:36 +00:00
|
|
|
delete m_dviRenderer;
|
|
|
|
m_dviRenderer = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-26 22:53:40 +00:00
|
|
|
#else
|
|
|
|
if (!m_dviRenderer->isValidFile(fileName)) {
|
|
|
|
delete m_dviRenderer;
|
2017-09-05 21:27:18 +00:00
|
|
|
m_dviRenderer = nullptr;
|
2009-05-26 22:53:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2006-06-27 22:17:35 +00:00
|
|
|
if (!m_dviRenderer->setFile(fileName, base)) {
|
2009-05-07 21:43:13 +00:00
|
|
|
delete m_dviRenderer;
|
2017-09-05 21:27:18 +00:00
|
|
|
m_dviRenderer = nullptr;
|
2006-06-27 22:17:35 +00:00
|
|
|
return false;
|
2009-05-07 21:43:13 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "# of pages:" << m_dviRenderer->dviFile->total_pages;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2014-10-08 22:17:53 +00:00
|
|
|
m_resolution = dpi().height();
|
2007-12-27 15:38:29 +00:00
|
|
|
loadPages(pagesVector);
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-08 16:46:51 +00:00
|
|
|
bool DviGenerator::doCloseDocument()
|
2006-07-14 10:54:29 +00:00
|
|
|
{
|
|
|
|
delete m_docSynopsis;
|
2017-09-05 21:27:18 +00:00
|
|
|
m_docSynopsis = nullptr;
|
2006-07-14 10:54:29 +00:00
|
|
|
delete m_dviRenderer;
|
2017-09-05 21:27:18 +00:00
|
|
|
m_dviRenderer = nullptr;
|
2006-07-14 10:54:29 +00:00
|
|
|
|
2009-05-11 11:41:20 +00:00
|
|
|
m_linkGenerated.clear();
|
2009-11-21 00:57:56 +00:00
|
|
|
m_fontExtracted = false;
|
2006-07-14 10:54:29 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-16 19:38:00 +00:00
|
|
|
void DviGenerator::fillViewportFromAnchor(Okular::DocumentViewport &vp, const Anchor anch, const Okular::Page *page) const
|
|
|
|
{
|
|
|
|
fillViewportFromAnchor(vp, anch, page->width(), page->height());
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
void DviGenerator::fillViewportFromAnchor(Okular::DocumentViewport &vp, const Anchor anch, int pW, int pH) const
|
2006-06-30 22:35:48 +00:00
|
|
|
{
|
2021-08-21 23:14:34 +00:00
|
|
|
vp.pageNumber = static_cast<quint16>(anch.page) - 1;
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2021-08-21 23:14:34 +00:00
|
|
|
SimplePageSize ps = m_dviRenderer->sizeOfPage(PageNumber(vp.pageNumber));
|
2006-06-30 22:35:48 +00:00
|
|
|
double resolution = 0;
|
2010-01-09 15:08:53 +00:00
|
|
|
if (ps.isValid()) {
|
|
|
|
resolution = (double)(pW) / ps.width().getLength_in_inch();
|
|
|
|
} else {
|
|
|
|
resolution = m_resolution;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-06-30 22:35:48 +00:00
|
|
|
double py = (double)anch.distance_from_top.getLength_in_inch() * resolution + 0.5;
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
vp.rePos.normalizedX = 0.5;
|
|
|
|
vp.rePos.normalizedY = py / (double)pH;
|
2006-06-30 22:35:48 +00:00
|
|
|
vp.rePos.enabled = true;
|
2006-09-21 08:45:36 +00:00
|
|
|
vp.rePos.pos = Okular::DocumentViewport::Center;
|
2006-06-30 22:35:48 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2022-03-31 14:16:40 +00:00
|
|
|
QList<Okular::ObjectRect *> DviGenerator::generateDviLinks(const dviPageInfo *pageInfo)
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2022-03-31 14:16:40 +00:00
|
|
|
QList<Okular::ObjectRect *> dviLinks;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
int pageWidth = pageInfo->width, pageHeight = pageInfo->height;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2019-12-23 06:06:25 +00:00
|
|
|
for (const Hyperlink &dviLink : qAsConst(pageInfo->hyperLinkList)) {
|
2007-12-27 15:38:29 +00:00
|
|
|
QRect boxArea = dviLink.box;
|
2006-06-27 22:17:35 +00:00
|
|
|
double nl = (double)boxArea.left() / pageWidth, nt = (double)boxArea.top() / pageHeight, nr = (double)boxArea.right() / pageWidth, nb = (double)boxArea.bottom() / pageHeight;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
QString linkText = dviLink.linkText;
|
2015-10-29 12:37:11 +00:00
|
|
|
if (linkText.startsWith(QLatin1String("#"))) {
|
2007-12-27 15:38:29 +00:00
|
|
|
linkText = linkText.mid(1);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2007-12-27 15:38:29 +00:00
|
|
|
Anchor anch = m_dviRenderer->findAnchor(linkText);
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2017-09-05 21:27:18 +00:00
|
|
|
Okular::Action *okuLink = nullptr;
|
2006-06-28 20:40:47 +00:00
|
|
|
|
2006-06-30 22:35:48 +00:00
|
|
|
/* distinguish between local (-> anchor) and remote links */
|
|
|
|
if (anch.isValid()) {
|
|
|
|
/* internal link */
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::DocumentViewport vp;
|
2007-12-27 15:38:29 +00:00
|
|
|
fillViewportFromAnchor(vp, anch, pageWidth, pageHeight);
|
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
okuLink = new Okular::GotoAction(QLatin1String(""), vp);
|
2006-06-27 22:17:35 +00:00
|
|
|
} else {
|
2014-08-24 20:52:23 +00:00
|
|
|
okuLink = new Okular::BrowseAction(QUrl::fromUserInput(dviLink.linkText));
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
2006-06-28 20:40:47 +00:00
|
|
|
if (okuLink) {
|
2007-12-27 15:38:29 +00:00
|
|
|
Okular::ObjectRect *orlink = new Okular::ObjectRect(nl, nt, nr, nb, false, Okular::ObjectRect::Action, okuLink);
|
2006-06-28 20:40:47 +00:00
|
|
|
dviLinks.push_front(orlink);
|
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
return dviLinks;
|
|
|
|
}
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
QImage DviGenerator::image(Okular::PixmapRequest *request)
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
dviPageInfo *pageInfo = new dviPageInfo();
|
|
|
|
pageSize ps;
|
2009-05-11 15:14:17 +00:00
|
|
|
QImage ret;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
pageInfo->width = request->width();
|
|
|
|
pageInfo->height = request->height();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2006-10-25 15:35:53 +00:00
|
|
|
pageInfo->pageNumber = request->pageNumber() + 1;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
// pageInfo->resolution = m_resolution;
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
QMutexLocker lock(userMutex());
|
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
if (m_dviRenderer) {
|
|
|
|
SimplePageSize s = m_dviRenderer->sizeOfPage(pageInfo->pageNumber);
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
/* if ( s.width() != pageInfo->width) */
|
|
|
|
// if (!useDocumentSpecifiedSize)
|
|
|
|
// s = userPreferredSize;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-09-13 21:53:24 +00:00
|
|
|
if (s.isValid()) {
|
2020-02-21 15:11:42 +00:00
|
|
|
pageInfo->resolution = (double)(pageInfo->width) / s.width().getLength_in_inch();
|
|
|
|
} else {
|
|
|
|
pageInfo->resolution = (double)(pageInfo->width) / ps.width().getLength_in_inch();
|
2009-09-13 21:53:24 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
m_dviRenderer->drawPage(pageInfo);
|
|
|
|
|
|
|
|
if (!pageInfo->img.isNull()) {
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "Image OK";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
ret = pageInfo->img;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 11:41:20 +00:00
|
|
|
if (!m_linkGenerated[request->pageNumber()]) {
|
|
|
|
request->page()->setObjectRects(generateDviLinks(pageInfo));
|
|
|
|
m_linkGenerated[request->pageNumber()] = true;
|
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
lock.unlock();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
delete pageInfo;
|
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
return ret;
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 18:42:37 +00:00
|
|
|
Okular::TextPage *DviGenerator::textPage(Okular::TextRequest *request)
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2018-02-01 18:42:37 +00:00
|
|
|
const Okular::Page *page = request->page();
|
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug);
|
2006-06-27 22:17:35 +00:00
|
|
|
dviPageInfo *pageInfo = new dviPageInfo();
|
|
|
|
pageSize ps;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
pageInfo->width = page->width();
|
|
|
|
pageInfo->height = page->height();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
pageInfo->pageNumber = page->number() + 1;
|
|
|
|
|
|
|
|
pageInfo->resolution = m_resolution;
|
2009-05-11 15:14:17 +00:00
|
|
|
|
|
|
|
QMutexLocker lock(userMutex());
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
// get page text from m_dviRenderer
|
2017-09-05 21:27:18 +00:00
|
|
|
Okular::TextPage *ktp = nullptr;
|
2006-06-27 22:17:35 +00:00
|
|
|
if (m_dviRenderer) {
|
2009-09-13 21:53:24 +00:00
|
|
|
SimplePageSize s = m_dviRenderer->sizeOfPage(pageInfo->pageNumber);
|
|
|
|
pageInfo->resolution = (double)(pageInfo->width) / ps.width().getLength_in_inch();
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
m_dviRenderer->getText(pageInfo);
|
2009-05-11 15:14:17 +00:00
|
|
|
lock.unlock();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
ktp = extractTextFromPage(pageInfo);
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
delete pageInfo;
|
2007-01-31 18:31:19 +00:00
|
|
|
return ktp;
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
Okular::TextPage *DviGenerator::extractTextFromPage(dviPageInfo *pageInfo)
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
QList<Okular::TextEntity *> textOfThePage;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2006-07-01 21:17:42 +00:00
|
|
|
QVector<TextBox>::ConstIterator it = pageInfo->textBoxList.constBegin();
|
|
|
|
QVector<TextBox>::ConstIterator itEnd = pageInfo->textBoxList.constEnd();
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
int pageWidth = pageInfo->width, pageHeight = pageInfo->height;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
for (; it != itEnd; ++it) {
|
|
|
|
TextBox curTB = *it;
|
2007-12-27 15:38:29 +00:00
|
|
|
textOfThePage.push_back(new Okular::TextEntity(curTB.text, new Okular::NormalizedRect(curTB.box, pageWidth, pageHeight)));
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::TextPage *ktp = new Okular::TextPage(textOfThePage);
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
return ktp;
|
|
|
|
}
|
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
Okular::DocumentInfo DviGenerator::generateDocumentInfo(const QSet<Okular::DocumentInfo::Key> &keys) const
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
2014-05-11 09:17:49 +00:00
|
|
|
Okular::DocumentInfo docInfo;
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2014-05-11 09:17:49 +00:00
|
|
|
if (keys.contains(Okular::DocumentInfo::MimeType)) {
|
2015-10-29 12:37:11 +00:00
|
|
|
docInfo.set(Okular::DocumentInfo::MimeType, QStringLiteral("application/x-dvi"));
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
QMutexLocker lock(userMutex());
|
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
if (m_dviRenderer && m_dviRenderer->dviFile) {
|
|
|
|
dvifile *dvif = m_dviRenderer->dviFile;
|
|
|
|
|
|
|
|
// read properties from dvif
|
2014-05-11 09:17:49 +00:00
|
|
|
// docInfo.set( "filename", dvif->filename, i18n("Filename") );
|
|
|
|
if (keys.contains(Okular::DocumentInfo::CustomKeys)) {
|
2015-10-29 12:37:11 +00:00
|
|
|
docInfo.set(QStringLiteral("generatorDate"), dvif->generatorString, i18n("Generator/Date"));
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2014-05-11 09:17:49 +00:00
|
|
|
if (keys.contains(Okular::DocumentInfo::Pages)) {
|
|
|
|
docInfo.set(Okular::DocumentInfo::Pages, QString::number(dvif->total_pages));
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
2014-05-11 09:17:49 +00:00
|
|
|
return docInfo;
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
|
2006-06-30 22:35:48 +00:00
|
|
|
{
|
|
|
|
if (m_docSynopsis) {
|
|
|
|
return m_docSynopsis;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
m_docSynopsis = new Okular::DocumentSynopsis();
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
userMutex()->lock();
|
|
|
|
|
2006-07-01 21:17:42 +00:00
|
|
|
QVector<PreBookmark> prebookmarks = m_dviRenderer->getPrebookmarks();
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2009-05-11 15:14:17 +00:00
|
|
|
userMutex()->unlock();
|
|
|
|
|
2006-06-30 22:35:48 +00:00
|
|
|
if (prebookmarks.isEmpty()) {
|
|
|
|
return m_docSynopsis;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-06-30 22:35:48 +00:00
|
|
|
|
2007-12-26 20:08:29 +00:00
|
|
|
QStack<QDomElement> stack;
|
|
|
|
|
2008-11-11 18:48:40 +00:00
|
|
|
QVector<PreBookmark>::ConstIterator it = prebookmarks.constBegin();
|
|
|
|
QVector<PreBookmark>::ConstIterator itEnd = prebookmarks.constEnd();
|
2006-06-30 22:35:48 +00:00
|
|
|
for (; it != itEnd; ++it) {
|
2007-12-26 20:08:29 +00:00
|
|
|
QDomElement domel = m_docSynopsis->createElement((*it).title);
|
2006-06-30 22:35:48 +00:00
|
|
|
Anchor a = m_dviRenderer->findAnchor((*it).anchorName);
|
|
|
|
if (a.isValid()) {
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::DocumentViewport vp;
|
2007-12-27 15:38:29 +00:00
|
|
|
|
2021-08-21 23:14:34 +00:00
|
|
|
const Okular::Page *p = document()->page(static_cast<quint16>(a.page) - 1);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
fillViewportFromAnchor(vp, a, (int)p->width(), (int)p->height());
|
2015-10-29 12:37:11 +00:00
|
|
|
domel.setAttribute(QStringLiteral("Viewport"), vp.toString());
|
2006-06-30 22:35:48 +00:00
|
|
|
}
|
|
|
|
if (stack.isEmpty()) {
|
2007-12-26 20:08:29 +00:00
|
|
|
m_docSynopsis->appendChild(domel);
|
2006-06-30 22:35:48 +00:00
|
|
|
} else {
|
2007-12-26 20:08:29 +00:00
|
|
|
stack.top().appendChild(domel);
|
2006-06-30 22:35:48 +00:00
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < (*it).noOfChildren; ++i) {
|
|
|
|
stack.push(domel);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-06-30 22:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_docSynopsis;
|
|
|
|
}
|
|
|
|
|
2009-11-21 00:57:56 +00:00
|
|
|
Okular::FontInfo::List DviGenerator::fontsForPage(int page)
|
|
|
|
{
|
|
|
|
Q_UNUSED(page);
|
|
|
|
|
|
|
|
Okular::FontInfo::List list;
|
|
|
|
|
|
|
|
// the list of the fonts is extracted once
|
|
|
|
if (m_fontExtracted) {
|
|
|
|
return list;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2009-11-21 00:57:56 +00:00
|
|
|
|
|
|
|
if (m_dviRenderer && m_dviRenderer->dviFile && m_dviRenderer->dviFile->font_pool) {
|
2019-12-23 06:06:25 +00:00
|
|
|
const QList<TeXFontDefinition *> fonts = m_dviRenderer->dviFile->font_pool->fontList;
|
|
|
|
for (const TeXFontDefinition *font : fonts) {
|
2009-11-21 00:57:56 +00:00
|
|
|
Okular::FontInfo of;
|
|
|
|
QString name;
|
|
|
|
int zoom = (int)(font->enlargement * 100 + 0.5);
|
2011-11-15 09:14:43 +00:00
|
|
|
#ifdef HAVE_FREETYPE
|
2009-11-21 00:57:56 +00:00
|
|
|
if (font->getFullFontName().isEmpty()) {
|
2015-10-29 12:37:11 +00:00
|
|
|
name = QStringLiteral("%1, %2%").arg(font->fontname).arg(zoom);
|
2009-11-21 00:57:56 +00:00
|
|
|
} else {
|
2016-10-29 14:32:24 +00:00
|
|
|
name = QStringLiteral("%1 (%2), %3%").arg(font->fontname, font->getFullFontName(), QString::number(zoom));
|
2009-11-21 00:57:56 +00:00
|
|
|
}
|
2011-11-15 09:14:43 +00:00
|
|
|
#else
|
|
|
|
name = QString("%1, %2%").arg(font->fontname).arg(zoom);
|
|
|
|
#endif
|
2009-11-21 00:57:56 +00:00
|
|
|
of.setName(name);
|
|
|
|
|
|
|
|
QString fontFileName;
|
|
|
|
if (!(font->flags & TeXFontDefinition::FONT_VIRTUAL)) {
|
2017-09-05 21:27:18 +00:00
|
|
|
if (font->font != nullptr) {
|
2009-11-21 00:57:56 +00:00
|
|
|
fontFileName = font->font->errorMessage;
|
|
|
|
} else {
|
|
|
|
fontFileName = i18n("Font file not found");
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2009-11-21 00:57:56 +00:00
|
|
|
|
|
|
|
if (fontFileName.isEmpty()) {
|
|
|
|
fontFileName = font->filename;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2009-11-21 00:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
of.setFile(fontFileName);
|
|
|
|
|
|
|
|
Okular::FontInfo::FontType ft;
|
|
|
|
switch (font->getFontType()) {
|
|
|
|
case TeXFontDefinition::TEX_PK:
|
|
|
|
ft = Okular::FontInfo::TeXPK;
|
|
|
|
break;
|
|
|
|
case TeXFontDefinition::TEX_VIRTUAL:
|
|
|
|
ft = Okular::FontInfo::TeXVirtual;
|
|
|
|
break;
|
|
|
|
case TeXFontDefinition::TEX_FONTMETRIC:
|
|
|
|
ft = Okular::FontInfo::TeXFontMetric;
|
|
|
|
break;
|
|
|
|
case TeXFontDefinition::FREETYPE:
|
|
|
|
ft = Okular::FontInfo::TeXFreeTypeHandled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
of.setType(ft);
|
|
|
|
|
|
|
|
// DVI has not the concept of "font embedding"
|
|
|
|
of.setEmbedType(Okular::FontInfo::NotEmbedded);
|
|
|
|
of.setCanBeExtracted(false);
|
|
|
|
|
|
|
|
list.append(of);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fontExtracted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2007-12-27 15:38:29 +00:00
|
|
|
void DviGenerator::loadPages(QVector<Okular::Page *> &pagesVector)
|
2006-06-27 22:17:35 +00:00
|
|
|
{
|
|
|
|
QSize pageRequiredSize;
|
|
|
|
|
|
|
|
int numofpages = m_dviRenderer->dviFile->total_pages;
|
|
|
|
pagesVector.resize(numofpages);
|
|
|
|
|
2009-05-11 11:41:20 +00:00
|
|
|
m_linkGenerated.fill(false, numofpages);
|
|
|
|
|
2014-09-11 19:12:27 +00:00
|
|
|
// qCDebug(OkularDviDebug) << "resolution:" << m_resolution << ", dviFile->preferred?";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
/* get the suggested size */
|
|
|
|
if (m_dviRenderer->dviFile->suggestedPageSize) {
|
|
|
|
pageRequiredSize = m_dviRenderer->dviFile->suggestedPageSize->sizeInPixel(m_resolution);
|
|
|
|
} else {
|
|
|
|
pageSize ps;
|
|
|
|
pageRequiredSize = ps.sizeInPixel(m_resolution);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < numofpages; ++i) {
|
2014-09-11 19:12:27 +00:00
|
|
|
// qCDebug(OkularDviDebug) << "getting status of page" << i << ":";
|
2006-06-27 22:17:35 +00:00
|
|
|
|
|
|
|
if (pagesVector[i]) {
|
|
|
|
delete pagesVector[i];
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Page *page = new Okular::Page(i, pageRequiredSize.width(), pageRequiredSize.height(), Okular::Rotation0);
|
2007-12-27 15:38:29 +00:00
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
pagesVector[i] = page;
|
|
|
|
}
|
2014-09-11 19:12:27 +00:00
|
|
|
qCDebug(OkularDviDebug) << "pagesVector successfully inizialized!";
|
2006-11-17 22:15:15 +00:00
|
|
|
|
|
|
|
// filling the pages with the source references rects
|
|
|
|
const QVector<DVI_SourceFileAnchor> &sourceAnchors = m_dviRenderer->sourceAnchors();
|
2022-03-21 23:59:42 +00:00
|
|
|
QVector<QList<Okular::SourceRefObjectRect *>> refRects(numofpages);
|
2019-12-23 06:06:25 +00:00
|
|
|
for (const DVI_SourceFileAnchor &sfa : sourceAnchors) {
|
2006-11-17 22:15:15 +00:00
|
|
|
if (sfa.page < 1 || (int)sfa.page > numofpages) {
|
|
|
|
continue;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2006-11-17 22:15:15 +00:00
|
|
|
|
2014-10-08 22:17:53 +00:00
|
|
|
Okular::NormalizedPoint p(-1.0, (double)sfa.distance_from_top.getLength_in_pixel(dpi().height()) / (double)pageRequiredSize.height());
|
2006-11-17 22:15:15 +00:00
|
|
|
Okular::SourceReference *sourceRef = new Okular::SourceReference(sfa.fileName, sfa.line);
|
|
|
|
refRects[sfa.page - 1].append(new Okular::SourceRefObjectRect(p, sourceRef));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < refRects.size(); ++i) {
|
|
|
|
if (!refRects.at(i).isEmpty()) {
|
|
|
|
pagesVector[i]->setSourceReferences(refRects.at(i));
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-27 22:17:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 22:52:30 +00:00
|
|
|
Okular::Document::PrintError DviGenerator::print(QPrinter &printer)
|
2007-12-30 16:41:10 +00:00
|
|
|
{
|
|
|
|
// Create tempfile to write to
|
2014-09-17 22:30:39 +00:00
|
|
|
QTemporaryFile tf(QDir::tempPath() + QLatin1String("/okular_XXXXXX.ps"));
|
2007-12-30 16:41:10 +00:00
|
|
|
if (!tf.open()) {
|
2021-12-14 22:52:30 +00:00
|
|
|
return Okular::Document::TemporaryFileOpenPrintError;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2007-12-30 16:41:10 +00:00
|
|
|
|
2021-08-21 23:14:34 +00:00
|
|
|
const QList<int> pageList = Okular::FilePrinter::pageList(printer, static_cast<quint16>(m_dviRenderer->totalPages()), document()->currentPage() + 1, document()->bookmarkedPageList());
|
2007-12-30 16:41:10 +00:00
|
|
|
QString pages;
|
|
|
|
QStringList printOptions;
|
|
|
|
// List of pages to print.
|
2019-12-23 06:06:25 +00:00
|
|
|
for (const int p : pageList) {
|
2015-10-29 12:37:11 +00:00
|
|
|
pages += QStringLiteral(",%1").arg(p);
|
2007-12-30 16:41:10 +00:00
|
|
|
}
|
|
|
|
if (!pages.isEmpty()) {
|
2015-10-29 12:37:11 +00:00
|
|
|
printOptions << QStringLiteral("-pp") << pages.mid(1);
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2007-12-30 16:41:10 +00:00
|
|
|
|
|
|
|
QEventLoop el;
|
|
|
|
m_dviRenderer->setEventLoop(&el);
|
2011-06-05 22:40:22 +00:00
|
|
|
m_dviRenderer->exportPS(tf.fileName(), printOptions, &printer, document()->orientation());
|
2007-12-30 16:41:10 +00:00
|
|
|
|
|
|
|
tf.close();
|
|
|
|
|
|
|
|
// Error messages are handled by the generator - ugly, but it works.
|
2021-12-14 22:52:30 +00:00
|
|
|
return Okular::Document::NoPrintError;
|
2007-12-30 16:41:10 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 19:38:00 +00:00
|
|
|
QVariant DviGenerator::metaData(const QString &key, const QVariant &option) const
|
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
if (key == QLatin1String("NamedViewport") && !option.toString().isEmpty()) {
|
2009-05-16 19:38:00 +00:00
|
|
|
const Anchor anchor = m_dviRenderer->parseReference(option.toString());
|
|
|
|
if (anchor.isValid()) {
|
2021-08-21 23:14:34 +00:00
|
|
|
const Okular::Page *page = document()->page(static_cast<quint16>(anchor.page) - 1);
|
2009-05-16 19:38:00 +00:00
|
|
|
Q_ASSERT_X(page, "DviGenerator::metaData()", "NULL page as result of valid Anchor");
|
|
|
|
Okular::DocumentViewport viewport;
|
2010-01-08 00:01:28 +00:00
|
|
|
fillViewportFromAnchor(viewport, anchor, page);
|
2009-05-16 19:38:00 +00:00
|
|
|
if (viewport.isValid()) {
|
|
|
|
return viewport.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
2007-12-30 16:41:10 +00:00
|
|
|
|
2017-01-14 18:19:12 +00:00
|
|
|
Q_LOGGING_CATEGORY(OkularDviDebug, "org.kde.okular.generators.dvi.core", QtWarningMsg)
|
|
|
|
Q_LOGGING_CATEGORY(OkularDviShellDebug, "org.kde.okular.generators.dvi.shell", QtWarningMsg)
|
2014-09-11 19:12:27 +00:00
|
|
|
|
2006-06-27 22:17:35 +00:00
|
|
|
#include "generator_dvi.moc"
|