Rev 22829 | Rev 22915 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
16729 | fschmid | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | |||
22738 | jghali | 8 | #include <cstdlib> |
9 | |||
16729 | fschmid | 10 | #include <QByteArray> |
11 | #include <QCursor> |
||
22738 | jghali | 12 | #include <QDebug> |
16729 | fschmid | 13 | #include <QDrag> |
14 | #include <QFile> |
||
17851 | fschmid | 15 | #include <QInputDialog> |
16729 | fschmid | 16 | #include <QList> |
17 | #include <QMimeData> |
||
18 | #include <QRegExp> |
||
19 | #include <QStack> |
||
22738 | jghali | 20 | |
17869 | fschmid | 21 | #include <poppler/ErrorCodes.h> |
22 | #include <poppler/GlobalParams.h> |
||
20125 | fschmid | 23 | #include <poppler/OptionalContent.h> |
17869 | fschmid | 24 | #include <poppler/PageTransition.h> |
25 | #include <poppler/ViewerPreferences.h> |
||
26 | #include <poppler/poppler-config.h> |
||
22154 | jghali | 27 | #include <poppler/cpp/poppler-version.h> |
17869 | fschmid | 28 | #include <poppler/SplashOutputDev.h> |
29 | #include <poppler/splash/SplashBitmap.h> |
||
16729 | fschmid | 30 | |
31 | #include "importpdf.h" |
||
22738 | jghali | 32 | #include "importpdfconfig.h" |
33 | #include "slaoutput.h" |
||
16729 | fschmid | 34 | |
35 | #include "commonstrings.h" |
||
36 | #include "loadsaveplugin.h" |
||
37 | #include "pagesize.h" |
||
17880 | fschmid | 38 | #include "pdfimportoptions.h" |
17849 | fschmid | 39 | #include "pdfoptions.h" |
16729 | fschmid | 40 | #include "prefscontext.h" |
41 | #include "prefsfile.h" |
||
42 | #include "prefsmanager.h" |
||
43 | #include "prefstable.h" |
||
44 | #include "rawimage.h" |
||
45 | #include "scclocale.h" |
||
46 | #include "sccolorengine.h" |
||
47 | #include "scconfig.h" |
||
48 | #include "scmimedata.h" |
||
49 | #include "scpaths.h" |
||
50 | #include "scribus.h" |
||
51 | #include "scribusXml.h" |
||
52 | #include "scribuscore.h" |
||
53 | #include "sctextstream.h" |
||
54 | #include "selection.h" |
||
55 | #include "undomanager.h" |
||
56 | #include "util.h" |
||
57 | #include "util_formats.h" |
||
58 | #include "util_math.h" |
||
59 | |||
17031 | jghali | 60 | #include "ui/customfdialog.h" |
61 | #include "ui/missing.h" |
||
62 | #include "ui/multiprogressdialog.h" |
||
63 | #include "ui/propertiespalette.h" |
||
16729 | fschmid | 64 | |
65 | PdfPlug::PdfPlug(ScribusDoc* doc, int flags) |
||
66 | { |
||
67 | tmpSele = new Selection(this, false); |
||
68 | m_Doc = doc; |
||
69 | importerFlags = flags; |
||
70 | interactive = (flags & LoadSavePlugin::lfInteractive); |
||
22527 | craig | 71 | progressDialog = nullptr; |
72 | m_pdfDoc = nullptr; |
||
16729 | fschmid | 73 | } |
74 | |||
22635 | craig | 75 | QImage PdfPlug::readThumbnail(const QString& fName) |
16729 | fschmid | 76 | { |
17869 | fschmid | 77 | QString pdfFile = QDir::toNativeSeparators(fName); |
78 | globalParams = new GlobalParams(); |
||
79 | if (globalParams) |
||
80 | { |
||
22269 | jghali | 81 | #if defined(Q_OS_WIN32) && POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 62, 0) |
82 | GooString *fname = new GooString(pdfFile.toUtf8().data()); |
||
83 | #else |
||
17869 | fschmid | 84 | GooString *fname = new GooString(QFile::encodeName(pdfFile).data()); |
22269 | jghali | 85 | #endif |
17869 | fschmid | 86 | globalParams->setErrQuiet(gTrue); |
22527 | craig | 87 | PDFDoc *pdfDoc = new PDFDoc(fname, nullptr, nullptr, nullptr); |
17869 | fschmid | 88 | if (pdfDoc) |
89 | { |
||
90 | if (pdfDoc->getErrorCode() == errEncrypted) |
||
91 | { |
||
92 | delete pdfDoc; |
||
93 | delete globalParams; |
||
94 | return QImage(); |
||
95 | } |
||
96 | if (pdfDoc->isOk()) |
||
97 | { |
||
98 | double h = pdfDoc->getPageMediaHeight(1); |
||
99 | double w = pdfDoc->getPageMediaWidth(1); |
||
100 | double scale = qMin(500.0 / h, 500.0 / w); |
||
101 | double hDPI = 72.0 * scale; |
||
102 | double vDPI = 72.0 * scale; |
||
103 | SplashColor bgColor; |
||
104 | bgColor[0] = 255; |
||
105 | bgColor[1] = 255; |
||
106 | bgColor[2] = 255; |
||
19806 | jghali | 107 | SplashOutputDev *dev = new SplashOutputDev(splashModeXBGR8, 4, gFalse, bgColor, gTrue); |
17869 | fschmid | 108 | dev->setVectorAntialias(gTrue); |
109 | dev->setFreeTypeHinting(gTrue, gFalse); |
||
110 | dev->startDoc(pdfDoc); |
||
111 | pdfDoc->displayPage(dev, 1, hDPI, vDPI, 0, gTrue, gFalse, gFalse); |
||
112 | SplashBitmap *bitmap = dev->getBitmap(); |
||
113 | int bw = bitmap->getWidth(); |
||
114 | int bh = bitmap->getHeight(); |
||
17870 | fschmid | 115 | SplashColorPtr dataPtr = bitmap->getDataPtr(); |
116 | if (QSysInfo::BigEndian == QSysInfo::ByteOrder) |
||
17869 | fschmid | 117 | { |
17870 | fschmid | 118 | uchar c; |
119 | int count = bw * bh * 4; |
||
120 | for (int k = 0; k < count; k += 4) |
||
17869 | fschmid | 121 | { |
17870 | fschmid | 122 | c = dataPtr[k]; |
123 | dataPtr[k] = dataPtr[k+3]; |
||
124 | dataPtr[k+3] = c; |
||
125 | c = dataPtr[k+1]; |
||
126 | dataPtr[k+1] = dataPtr[k+2]; |
||
127 | dataPtr[k+2] = c; |
||
17869 | fschmid | 128 | } |
129 | } |
||
17870 | fschmid | 130 | // construct a qimage SHARING the raw bitmap data in memory |
131 | QImage tmpimg( dataPtr, bw, bh, QImage::Format_ARGB32 ); |
||
132 | QImage image = tmpimg.copy(); |
||
133 | image.setText("XSize", QString("%1").arg(w)); |
||
134 | image.setText("YSize", QString("%1").arg(h)); |
||
135 | delete dev; |
||
136 | delete pdfDoc; |
||
137 | delete globalParams; |
||
138 | return image; |
||
17869 | fschmid | 139 | } |
22609 | craig | 140 | delete pdfDoc; |
141 | delete globalParams; |
||
17869 | fschmid | 142 | } |
143 | } |
||
144 | return QImage(); |
||
145 | } |
||
146 | /* Old Code to be backed up |
||
16729 | fschmid | 147 | QString tmp, cmd1, cmd2; |
148 | QString pdfFile = QDir::toNativeSeparators(fName); |
||
21527 | craig | 149 | QString tmpFile = QDir::toNativeSeparators(ScPaths::tempFileDir() + "sc.png"); |
16729 | fschmid | 150 | int ret = -1; |
151 | tmp.setNum(1); |
||
152 | QStringList args; |
||
153 | args.append("-r72"); |
||
154 | args.append("-sOutputFile="+tmpFile); |
||
155 | args.append("-dFirstPage="+tmp); |
||
156 | args.append("-dLastPage="+tmp); |
||
157 | args.append(pdfFile); |
||
158 | ret = callGS(args); |
||
159 | if (ret == 0) |
||
160 | { |
||
161 | QImage image; |
||
162 | image.load(tmpFile); |
||
163 | QFile::remove(tmpFile); |
||
164 | image.setText("XSize", QString("%1").arg(image.width())); |
||
165 | image.setText("YSize", QString("%1").arg(image.height())); |
||
166 | return image; |
||
167 | } |
||
168 | return QImage(); |
||
17869 | fschmid | 169 | */ |
16729 | fschmid | 170 | |
22609 | craig | 171 | bool PdfPlug::import(const QString& fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress) |
16729 | fschmid | 172 | { |
19809 | craig | 173 | #ifdef Q_OS_OSX |
174 | #if QT_VERSION >= 0x050300 |
||
175 | showProgress = false; |
||
176 | #endif |
||
177 | #endif |
||
16729 | fschmid | 178 | bool success = false; |
179 | interactive = (flags & LoadSavePlugin::lfInteractive); |
||
180 | importerFlags = flags; |
||
181 | cancel = false; |
||
17635 | jghali | 182 | double b, h; |
16729 | fschmid | 183 | bool ret = false; |
22635 | craig | 184 | QFileInfo fi = QFileInfo(fNameIn); |
16729 | fschmid | 185 | if ( !ScCore->usingGUI() ) |
186 | { |
||
187 | interactive = false; |
||
188 | showProgress = false; |
||
189 | } |
||
190 | baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/")); |
||
191 | if ( showProgress ) |
||
192 | { |
||
22609 | craig | 193 | ScribusMainWindow* mw = (m_Doc==nullptr) ? ScCore->primaryMainWindow() : m_Doc->scMW(); |
16729 | fschmid | 194 | progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw ); |
195 | QStringList barNames, barTexts; |
||
196 | barNames << "GI"; |
||
197 | barTexts << tr("Analyzing File:"); |
||
198 | QList<bool> barsNumeric; |
||
199 | barsNumeric << false; |
||
200 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
201 | progressDialog->setOverallTotalSteps(3); |
||
202 | progressDialog->setOverallProgress(0); |
||
203 | progressDialog->setProgress("GI", 0); |
||
204 | progressDialog->show(); |
||
205 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
||
206 | qApp->processEvents(); |
||
207 | } |
||
208 | else |
||
22527 | craig | 209 | progressDialog = nullptr; |
16729 | fschmid | 210 | /* Set default Page to size defined in Preferences */ |
211 | b = 0.0; |
||
212 | h = 0.0; |
||
213 | if (progressDialog) |
||
214 | { |
||
215 | progressDialog->setOverallProgress(1); |
||
216 | qApp->processEvents(); |
||
217 | } |
||
218 | if (b == 0.0) |
||
219 | b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth; |
||
220 | if (h == 0.0) |
||
221 | h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight; |
||
222 | docWidth = b; |
||
223 | docHeight = h; |
||
224 | baseX = 0; |
||
225 | baseY = 0; |
||
226 | if (!interactive || (flags & LoadSavePlugin::lfInsertPage)) |
||
227 | { |
||
228 | m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false); |
||
229 | m_Doc->addPage(0); |
||
230 | m_Doc->view()->addPage(0, true); |
||
231 | baseX = 0; |
||
232 | baseY = 0; |
||
233 | } |
||
234 | else |
||
235 | { |
||
236 | if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc)) |
||
237 | { |
||
17078 | fschmid | 238 | m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, 0, 0, 0, 0, 1, "Custom", true); |
16729 | fschmid | 239 | ScCore->primaryMainWindow()->HaveNewDoc(); |
240 | ret = true; |
||
241 | baseX = 0; |
||
242 | baseY = 0; |
||
243 | baseX = m_Doc->currentPage()->xOffset(); |
||
244 | baseY = m_Doc->currentPage()->yOffset(); |
||
245 | } |
||
246 | } |
||
247 | if ((!ret) && (interactive)) |
||
248 | { |
||
249 | baseX = m_Doc->currentPage()->xOffset(); |
||
250 | baseY = m_Doc->currentPage()->yOffset(); |
||
251 | } |
||
252 | if ((ret) || (!interactive)) |
||
253 | { |
||
254 | if (docWidth > docHeight) |
||
255 | m_Doc->setPageOrientation(1); |
||
256 | else |
||
257 | m_Doc->setPageOrientation(0); |
||
258 | m_Doc->setPageSize("Custom"); |
||
259 | } |
||
22527 | craig | 260 | if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr)) |
19856 | fschmid | 261 | m_Doc->view()->Deselect(); |
16729 | fschmid | 262 | Elements.clear(); |
263 | m_Doc->setLoading(true); |
||
264 | m_Doc->DoDrawing = false; |
||
22527 | craig | 265 | if ((!(flags & LoadSavePlugin::lfLoadAsPattern)) && (m_Doc->view() != nullptr)) |
16729 | fschmid | 266 | m_Doc->view()->updatesOn(false); |
267 | m_Doc->scMW()->setScriptRunning(true); |
||
18181 | fschmid | 268 | qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); |
16729 | fschmid | 269 | QString CurDirP = QDir::currentPath(); |
270 | QDir::setCurrent(fi.path()); |
||
22635 | craig | 271 | if (convert(fNameIn)) |
16729 | fschmid | 272 | { |
273 | tmpSele->clear(); |
||
274 | QDir::setCurrent(CurDirP); |
||
17905 | fschmid | 275 | if ((Elements.count() == 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc))) |
276 | { |
||
277 | PageItem *gr = Elements[0]; |
||
18514 | fschmid | 278 | if (gr->isGroup()) |
279 | m_Doc->resizeGroupToContents(gr); |
||
17905 | fschmid | 280 | } |
16729 | fschmid | 281 | if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc))) |
17905 | fschmid | 282 | { |
283 | PageItem *gr = m_Doc->groupObjectsList(Elements); |
||
284 | m_Doc->resizeGroupToContents(gr); |
||
285 | } |
||
16729 | fschmid | 286 | m_Doc->DoDrawing = true; |
287 | m_Doc->scMW()->setScriptRunning(false); |
||
288 | m_Doc->setLoading(false); |
||
289 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
290 | if ((Elements.count() > 0) && (!ret) && (interactive)) |
||
291 | { |
||
292 | if (flags & LoadSavePlugin::lfScripted) |
||
293 | { |
||
294 | bool loadF = m_Doc->isLoading(); |
||
295 | m_Doc->setLoading(false); |
||
296 | m_Doc->changed(); |
||
297 | m_Doc->setLoading(loadF); |
||
298 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
299 | { |
||
300 | m_Doc->m_Selection->delaySignalsOn(); |
||
301 | for (int dre=0; dre<Elements.count(); ++dre) |
||
302 | { |
||
303 | m_Doc->m_Selection->addItem(Elements.at(dre), true); |
||
304 | } |
||
305 | m_Doc->m_Selection->delaySignalsOff(); |
||
306 | m_Doc->m_Selection->setGroupRect(); |
||
22527 | craig | 307 | if (m_Doc->view() != nullptr) |
19856 | fschmid | 308 | m_Doc->view()->updatesOn(true); |
16729 | fschmid | 309 | } |
310 | } |
||
311 | else |
||
312 | { |
||
313 | m_Doc->DragP = true; |
||
22609 | craig | 314 | m_Doc->DraggedElem = nullptr; |
16729 | fschmid | 315 | m_Doc->DragElements.clear(); |
316 | m_Doc->m_Selection->delaySignalsOn(); |
||
317 | for (int dre=0; dre<Elements.count(); ++dre) |
||
318 | { |
||
319 | tmpSele->addItem(Elements.at(dre), true); |
||
320 | } |
||
321 | tmpSele->setGroupRect(); |
||
22686 | jghali | 322 | ScElemMimeData* md = ScriXmlDoc::writeToMimeData(m_Doc, tmpSele); |
16729 | fschmid | 323 | m_Doc->itemSelection_DeleteItem(tmpSele); |
324 | m_Doc->view()->updatesOn(true); |
||
325 | m_Doc->m_Selection->delaySignalsOff(); |
||
326 | // We must copy the TransationSettings object as it is owned |
||
327 | // by handleObjectImport method afterwards |
||
328 | TransactionSettings* transacSettings = new TransactionSettings(trSettings); |
||
329 | m_Doc->view()->handleObjectImport(md, transacSettings); |
||
330 | m_Doc->DragP = false; |
||
22609 | craig | 331 | m_Doc->DraggedElem = nullptr; |
16729 | fschmid | 332 | m_Doc->DragElements.clear(); |
333 | } |
||
334 | } |
||
335 | else |
||
336 | { |
||
337 | m_Doc->changed(); |
||
338 | m_Doc->reformPages(); |
||
339 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
340 | m_Doc->view()->updatesOn(true); |
||
341 | } |
||
342 | success = true; |
||
343 | } |
||
344 | else |
||
345 | { |
||
346 | QDir::setCurrent(CurDirP); |
||
347 | m_Doc->DoDrawing = true; |
||
348 | m_Doc->scMW()->setScriptRunning(false); |
||
349 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
350 | m_Doc->view()->updatesOn(true); |
||
351 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
18076 | fschmid | 352 | success = false; |
16729 | fschmid | 353 | } |
354 | if (interactive) |
||
355 | m_Doc->setLoading(false); |
||
356 | //CB If we have a gui we must refresh it if we have used the progressbar |
||
357 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
||
358 | { |
||
359 | if ((showProgress) && (!interactive)) |
||
360 | m_Doc->view()->DrawNew(); |
||
361 | } |
||
18181 | fschmid | 362 | qApp->restoreOverrideCursor(); |
16729 | fschmid | 363 | return success; |
364 | } |
||
365 | |||
366 | PdfPlug::~PdfPlug() |
||
367 | { |
||
22609 | craig | 368 | delete progressDialog; |
16729 | fschmid | 369 | delete tmpSele; |
370 | } |
||
371 | |||
21958 | craig | 372 | bool PdfPlug::convert(const QString& fn) |
16729 | fschmid | 373 | { |
17448 | fschmid | 374 | bool firstPg = true; |
375 | int currentLayer = m_Doc->activeLayer(); |
||
17498 | fschmid | 376 | int baseLayer = m_Doc->activeLayer(); |
16729 | fschmid | 377 | importedColors.clear(); |
19489 | jghali | 378 | if (progressDialog) |
16729 | fschmid | 379 | { |
380 | progressDialog->setOverallProgress(2); |
||
381 | progressDialog->setLabel("GI", tr("Generating Items")); |
||
382 | qApp->processEvents(); |
||
383 | } |
||
384 | QFile f(fn); |
||
385 | oldDocItemCount = m_Doc->Items->count(); |
||
386 | if (progressDialog) |
||
387 | { |
||
388 | progressDialog->setBusyIndicator("GI"); |
||
389 | qApp->processEvents(); |
||
390 | } |
||
391 | |||
392 | globalParams = new GlobalParams(); |
||
22527 | craig | 393 | GooString *userPW = nullptr; |
16729 | fschmid | 394 | if (globalParams) |
395 | { |
||
22269 | jghali | 396 | #if defined(Q_OS_WIN32) && POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 62, 0) |
397 | GooString *fname = new GooString(fn.toUtf8().data()); |
||
398 | #else |
||
16729 | fschmid | 399 | GooString *fname = new GooString(QFile::encodeName(fn).data()); |
22269 | jghali | 400 | #endif |
16729 | fschmid | 401 | globalParams->setErrQuiet(gTrue); |
17448 | fschmid | 402 | GBool hasOcg = gFalse; |
403 | QList<OptionalContentGroup*> ocgGroups; |
||
16729 | fschmid | 404 | // globalParams->setPrintCommands(gTrue); |
22527 | craig | 405 | PDFDoc *pdfDoc = new PDFDoc(fname, nullptr, nullptr, nullptr); |
16729 | fschmid | 406 | if (pdfDoc) |
407 | { |
||
17851 | fschmid | 408 | if (pdfDoc->getErrorCode() == errEncrypted) |
409 | { |
||
410 | delete pdfDoc; |
||
22527 | craig | 411 | pdfDoc = nullptr; |
17851 | fschmid | 412 | if (progressDialog) |
413 | progressDialog->hide(); |
||
414 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
21961 | craig | 415 | ScribusMainWindow* mw = m_Doc->scMW(); |
17851 | fschmid | 416 | bool ok; |
417 | QString text = QInputDialog::getText(mw, tr("Open PDF-File"), tr("Password"), QLineEdit::Normal, "", &ok); |
||
418 | if (ok && !text.isEmpty()) |
||
419 | { |
||
22269 | jghali | 420 | #if defined(Q_OS_WIN32) && POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 62, 0) |
421 | fname = new GooString(fn.toUtf8().data()); |
||
422 | #else |
||
17851 | fschmid | 423 | fname = new GooString(QFile::encodeName(fn).data()); |
22269 | jghali | 424 | #endif |
17851 | fschmid | 425 | userPW = new GooString(text.toLocal8Bit().data()); |
22527 | craig | 426 | pdfDoc = new PDFDoc(fname, userPW, userPW, nullptr); |
17851 | fschmid | 427 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
428 | } |
||
429 | if ((!pdfDoc) || (pdfDoc->getErrorCode() != errNone)) |
||
430 | { |
||
431 | if (progressDialog) |
||
432 | progressDialog->close(); |
||
433 | delete pdfDoc; |
||
434 | delete globalParams; |
||
435 | return false; |
||
436 | } |
||
437 | if (progressDialog) |
||
438 | progressDialog->show(); |
||
439 | } |
||
16729 | fschmid | 440 | if (pdfDoc->isOk()) |
441 | { |
||
17880 | fschmid | 442 | std::vector<int> pageNs; |
443 | QString pageString = "*"; |
||
444 | m_pdfDoc = pdfDoc; |
||
16729 | fschmid | 445 | double hDPI = 72.0; |
446 | double vDPI = 72.0; |
||
447 | int firstPage = 1; |
||
448 | int lastPage = pdfDoc->getNumPages(); |
||
18004 | fschmid | 449 | GBool useMediaBox = gTrue; |
20125 | fschmid | 450 | GBool crop = gTrue; |
18004 | fschmid | 451 | GBool printing = gFalse; |
22741 | jghali | 452 | const PDFRectangle *mediaBox = pdfDoc->getPage(1)->getMediaBox(); |
18004 | fschmid | 453 | QRectF mediaRect = QRectF(QPointF(mediaBox->x1, mediaBox->y1), QPointF(mediaBox->x2, mediaBox->y2)).normalized(); |
454 | bool boxesAreDifferent = false; |
||
455 | if (getCBox(Crop_Box, 1) != mediaRect) |
||
456 | boxesAreDifferent = true; |
||
457 | else if (getCBox(Trim_Box, 1) != mediaRect) |
||
458 | boxesAreDifferent = true; |
||
459 | else if (getCBox(Bleed_Box, 1) != mediaRect) |
||
460 | boxesAreDifferent = true; |
||
461 | else if (getCBox(Art_Box, 1) != mediaRect) |
||
462 | boxesAreDifferent = true; |
||
463 | bool cropped = false; |
||
464 | int contentRect = Media_Box; |
||
465 | if (((interactive) || (importerFlags & LoadSavePlugin::lfCreateDoc)) && ((lastPage > 1) || boxesAreDifferent)) |
||
17880 | fschmid | 466 | { |
467 | if (progressDialog) |
||
468 | progressDialog->hide(); |
||
469 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
470 | PdfImportOptions *optImp = new PdfImportOptions(ScCore->primaryMainWindow()); |
||
17885 | fschmid | 471 | QFileInfo fi = QFileInfo(fn); |
18006 | fschmid | 472 | optImp->setUpOptions(fi.fileName(), firstPage, lastPage, interactive, boxesAreDifferent, this); |
17880 | fschmid | 473 | if (!optImp->exec()) |
474 | { |
||
475 | if (progressDialog) |
||
476 | progressDialog->close(); |
||
477 | delete optImp; |
||
478 | delete pdfDoc; |
||
479 | delete globalParams; |
||
480 | return false; |
||
481 | } |
||
482 | pageString = optImp->getPagesString(); |
||
20125 | fschmid | 483 | contentRect = optImp->getCropBox(); |
484 | cropped = optImp->croppingEnabled(); |
||
485 | if (!cropped) |
||
486 | crop = cropped; |
||
22826 | jghali | 487 | // When displaying pages slices, we should always set useMediaBox to true |
488 | // in order to use MediaBox (x, y) as coordinate system |
||
20125 | fschmid | 489 | if (contentRect != Media_Box) |
490 | useMediaBox = gFalse; |
||
22826 | jghali | 491 | if (cropped) |
492 | useMediaBox = gTrue; |
||
20125 | fschmid | 493 | /* if (cb > Media_Box) |
18004 | fschmid | 494 | { |
495 | cropped = true; |
||
496 | contentRect = cb; |
||
20125 | fschmid | 497 | } */ |
17880 | fschmid | 498 | delete optImp; |
499 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
||
500 | if (progressDialog) |
||
501 | progressDialog->show(); |
||
502 | } |
||
503 | parsePagesString(pageString, &pageNs, lastPage); |
||
504 | firstPage = pageNs[0]; |
||
17448 | fschmid | 505 | SlaOutputDev *dev = new SlaOutputDev(m_Doc, &Elements, &importedColors, importerFlags); |
506 | if (dev->isOk()) |
||
17444 | fschmid | 507 | { |
17448 | fschmid | 508 | OCGs* ocg = pdfDoc->getOptContentConfig(); |
509 | if (ocg) |
||
17444 | fschmid | 510 | { |
17448 | fschmid | 511 | hasOcg = ocg->hasOCGs(); |
512 | if (hasOcg) |
||
17444 | fschmid | 513 | { |
17498 | fschmid | 514 | QStringList ocgNames; |
17448 | fschmid | 515 | Array *order = ocg->getOrderArray(); |
516 | if (order) |
||
17444 | fschmid | 517 | { |
17448 | fschmid | 518 | for (int i = 0; i < order->getLength (); ++i) |
17444 | fschmid | 519 | { |
22154 | jghali | 520 | Object orderItem = order->get(i); |
17448 | fschmid | 521 | if (orderItem.isDict()) |
17444 | fschmid | 522 | { |
22906 | jghali | 523 | POPPLER_CONST_075 Object POPPLER_REF ref = order->getNF(i); |
17448 | fschmid | 524 | if (ref.isRef()) |
525 | { |
||
526 | OptionalContentGroup *oc = ocg->findOcgByRef(ref.getRef()); |
||
17498 | fschmid | 527 | QString ocgName = UnicodeParsedString(oc->getName()); |
528 | if (!ocgNames.contains(ocgName)) |
||
529 | { |
||
530 | ocgGroups.prepend(oc); |
||
531 | ocgNames.append(ocgName); |
||
532 | } |
||
17448 | fschmid | 533 | } |
17444 | fschmid | 534 | } |
17498 | fschmid | 535 | else |
536 | { |
||
22703 | jghali | 537 | #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 69, 0) |
538 | const auto& ocgs = ocg->getOCGs (); |
||
539 | for (const auto& ocg : ocgs) |
||
17498 | fschmid | 540 | { |
22703 | jghali | 541 | OptionalContentGroup *oc = ocg.second.get(); |
542 | QString ocgName = UnicodeParsedString(oc->getName()); |
||
543 | if (!ocgNames.contains(ocgName)) |
||
544 | { |
||
545 | ocgGroups.prepend(oc); |
||
546 | ocgNames.append(ocgName); |
||
547 | } |
||
548 | } |
||
549 | #else |
||
550 | GooList *ocgs = ocg->getOCGs (); |
||
551 | for (int i = 0; i < ocgs->getLength (); ++i) |
||
552 | { |
||
17498 | fschmid | 553 | OptionalContentGroup *oc = (OptionalContentGroup *)ocgs->get(i); |
554 | QString ocgName = UnicodeParsedString(oc->getName()); |
||
555 | if (!ocgNames.contains(ocgName)) |
||
556 | { |
||
557 | ocgGroups.prepend(oc); |
||
558 | ocgNames.append(ocgName); |
||
559 | } |
||
560 | } |
||
22703 | jghali | 561 | #endif |
17498 | fschmid | 562 | } |
17444 | fschmid | 563 | } |
564 | } |
||
17448 | fschmid | 565 | else |
17444 | fschmid | 566 | { |
22703 | jghali | 567 | #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 69, 0) |
568 | const auto& ocgs = ocg->getOCGs (); |
||
569 | for (const auto& ocg : ocgs) |
||
17448 | fschmid | 570 | { |
22703 | jghali | 571 | OptionalContentGroup *oc = ocg.second.get(); |
572 | QString ocgName = UnicodeParsedString(oc->getName()); |
||
573 | if (!ocgNames.contains(ocgName)) |
||
574 | { |
||
575 | ocgGroups.prepend(oc); |
||
576 | ocgNames.append(ocgName); |
||
577 | } |
||
578 | } |
||
579 | #else |
||
580 | GooList *ocgs = ocg->getOCGs (); |
||
581 | for (int i = 0; i < ocgs->getLength (); ++i) |
||
582 | { |
||
17448 | fschmid | 583 | OptionalContentGroup *oc = (OptionalContentGroup *)ocgs->get(i); |
17498 | fschmid | 584 | QString ocgName = UnicodeParsedString(oc->getName()); |
585 | if (!ocgNames.contains(ocgName)) |
||
586 | { |
||
587 | ocgGroups.prepend(oc); |
||
588 | ocgNames.append(ocgName); |
||
589 | } |
||
17448 | fschmid | 590 | } |
22703 | jghali | 591 | #endif |
17444 | fschmid | 592 | } |
593 | } |
||
594 | } |
||
18000 | fschmid | 595 | bool rotated = false; |
17419 | fschmid | 596 | dev->startDoc(pdfDoc, pdfDoc->getXRef(), pdfDoc->getCatalog()); |
16729 | fschmid | 597 | int rotate = pdfDoc->getPageRotate(firstPage); |
18000 | fschmid | 598 | if ((rotate == 90) || (rotate == 270)) |
599 | rotated = true; |
||
18018 | fschmid | 600 | dev->rotate = rotate; |
18000 | fschmid | 601 | rotate = 0; |
16729 | fschmid | 602 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
603 | { |
||
17448 | fschmid | 604 | if (hasOcg) |
605 | { |
||
17498 | fschmid | 606 | QString actL = m_Doc->activeLayerName(); |
17448 | fschmid | 607 | for (int a = 0; a < ocgGroups.count(); a++) |
608 | { |
||
609 | OptionalContentGroup *oc = ocgGroups[a]; |
||
17498 | fschmid | 610 | if (actL != UnicodeParsedString(oc->getName())) |
611 | currentLayer = m_Doc->addLayer(UnicodeParsedString(oc->getName()), false); |
||
17448 | fschmid | 612 | else |
17498 | fschmid | 613 | currentLayer = m_Doc->layerIDFromName(UnicodeParsedString(oc->getName())); |
20125 | fschmid | 614 | if (oc->getState() == OptionalContentGroup::On) |
17448 | fschmid | 615 | m_Doc->setLayerVisible(currentLayer, true); |
20125 | fschmid | 616 | else if (oc->getViewState() == OptionalContentGroup::ocUsageOn) |
617 | m_Doc->setLayerVisible(currentLayer, true); |
||
17448 | fschmid | 618 | else |
619 | m_Doc->setLayerVisible(currentLayer, false); |
||
620 | if ((oc->getPrintState() == OptionalContentGroup::ocUsageOn) || (oc->getPrintState() == OptionalContentGroup::ocUsageUnset)) |
||
621 | m_Doc->setLayerPrintable(currentLayer, true); |
||
622 | else |
||
623 | m_Doc->setLayerPrintable(currentLayer, false); |
||
624 | oc->setState(OptionalContentGroup::Off); |
||
625 | } |
||
626 | dev->layersSetByOCG = true; |
||
627 | } |
||
22154 | jghali | 628 | |
629 | Object info = pdfDoc->getDocInfo(); |
||
630 | if (info.isDict()) |
||
631 | { |
||
632 | Object obj; |
||
633 | Dict *infoDict = info.getDict(); |
||
634 | obj = infoDict->lookup((char*) "Title"); |
||
635 | if (obj.isString()) |
||
636 | { |
||
637 | m_Doc->documentInfo().setTitle(UnicodeParsedString(obj.getString())); |
||
638 | } |
||
639 | obj = infoDict->lookup((char*) "Author"); |
||
640 | if (obj.isString()) |
||
641 | { |
||
642 | m_Doc->documentInfo().setAuthor(UnicodeParsedString(obj.getString())); |
||
643 | } |
||
644 | obj = infoDict->lookup((char*) "Subject"); |
||
645 | if (obj.isString()) |
||
646 | { |
||
647 | m_Doc->documentInfo().setSubject(UnicodeParsedString(obj.getString())); |
||
648 | } |
||
649 | obj = infoDict->lookup((char*) "Keywords"); |
||
650 | if (obj.isString()) |
||
651 | { |
||
652 | // s1 = obj.getString(); |
||
653 | m_Doc->documentInfo().setKeywords(UnicodeParsedString(obj.getString())); |
||
654 | } |
||
655 | } |
||
656 | info = Object(); |
||
22738 | jghali | 657 | |
18004 | fschmid | 658 | if (cropped) |
17885 | fschmid | 659 | { |
18004 | fschmid | 660 | QRectF crBox = getCBox(contentRect, pageNs[0]); |
18000 | fschmid | 661 | if (rotated) |
662 | { |
||
18004 | fschmid | 663 | m_Doc->setPageWidth(crBox.height()); |
664 | m_Doc->setPageHeight(crBox.width()); |
||
18000 | fschmid | 665 | } |
666 | else |
||
667 | { |
||
18004 | fschmid | 668 | m_Doc->setPageHeight(crBox.height()); |
669 | m_Doc->setPageWidth(crBox.width()); |
||
18000 | fschmid | 670 | } |
17885 | fschmid | 671 | } |
672 | else |
||
673 | { |
||
18000 | fschmid | 674 | if (rotated) |
675 | { |
||
676 | m_Doc->setPageWidth(pdfDoc->getPageMediaHeight(pageNs[0])); |
||
677 | m_Doc->setPageHeight(pdfDoc->getPageMediaWidth(pageNs[0])); |
||
678 | } |
||
679 | else |
||
680 | { |
||
681 | m_Doc->setPageHeight(pdfDoc->getPageMediaHeight(pageNs[0])); |
||
682 | m_Doc->setPageWidth(pdfDoc->getPageMediaWidth(pageNs[0])); |
||
683 | } |
||
17885 | fschmid | 684 | } |
17838 | fschmid | 685 | m_Doc->setPageSize("Custom"); |
18394 | fschmid | 686 | // m_Doc->pdfOptions().PresentVals.clear(); |
17880 | fschmid | 687 | for (uint ap = 0; ap < pageNs.size(); ++ap) |
17448 | fschmid | 688 | { |
17880 | fschmid | 689 | int pp = pageNs[ap]; |
17498 | fschmid | 690 | m_Doc->setActiveLayer(baseLayer); |
17448 | fschmid | 691 | if (firstPg) |
692 | firstPg = false; |
||
693 | else |
||
17880 | fschmid | 694 | m_Doc->addPage(ap); |
22089 | jghali | 695 | QRectF mdBox = getCBox(0, pp); |
18004 | fschmid | 696 | QRectF crBox = getCBox(contentRect, pp); |
697 | if (cropped) |
||
17885 | fschmid | 698 | { |
18000 | fschmid | 699 | if (rotated) |
700 | { |
||
18004 | fschmid | 701 | m_Doc->currentPage()->setInitialWidth(crBox.height()); |
702 | m_Doc->currentPage()->setInitialHeight(crBox.width()); |
||
703 | m_Doc->currentPage()->setWidth(crBox.height()); |
||
704 | m_Doc->currentPage()->setHeight(crBox.width()); |
||
705 | dev->cropOffsetX = crBox.y(); |
||
706 | dev->cropOffsetY = crBox.x(); |
||
18000 | fschmid | 707 | } |
708 | else |
||
709 | { |
||
18004 | fschmid | 710 | m_Doc->currentPage()->setInitialHeight(crBox.height()); |
711 | m_Doc->currentPage()->setInitialWidth(crBox.width()); |
||
712 | m_Doc->currentPage()->setHeight(crBox.height()); |
||
713 | m_Doc->currentPage()->setWidth(crBox.width()); |
||
714 | dev->cropOffsetX = crBox.x(); |
||
715 | dev->cropOffsetY = crBox.y(); |
||
18000 | fschmid | 716 | } |
17885 | fschmid | 717 | } |
718 | else |
||
719 | { |
||
18000 | fschmid | 720 | if (rotated) |
721 | { |
||
722 | m_Doc->currentPage()->setInitialWidth(pdfDoc->getPageMediaHeight(pp)); |
||
723 | m_Doc->currentPage()->setInitialHeight(pdfDoc->getPageMediaWidth(pp)); |
||
724 | m_Doc->currentPage()->setWidth(pdfDoc->getPageMediaHeight(pp)); |
||
725 | m_Doc->currentPage()->setHeight(pdfDoc->getPageMediaWidth(pp)); |
||
726 | } |
||
727 | else |
||
728 | { |
||
729 | m_Doc->currentPage()->setInitialHeight(pdfDoc->getPageMediaHeight(pp)); |
||
730 | m_Doc->currentPage()->setInitialWidth(pdfDoc->getPageMediaWidth(pp)); |
||
731 | m_Doc->currentPage()->setHeight(pdfDoc->getPageMediaHeight(pp)); |
||
732 | m_Doc->currentPage()->setWidth(pdfDoc->getPageMediaWidth(pp)); |
||
733 | } |
||
17885 | fschmid | 734 | } |
17448 | fschmid | 735 | m_Doc->currentPage()->MPageNam = CommonStrings::trMasterPageNormal; |
736 | m_Doc->currentPage()->m_pageSize = "Custom"; |
||
737 | m_Doc->reformPages(true); |
||
738 | if (hasOcg) |
||
739 | { |
||
20125 | fschmid | 740 | // int numObj = m_Doc->Items->count(); |
741 | // if (cropped) |
||
22527 | craig | 742 | // pdfDoc->displayPageSlice(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, crBox.x(), crBox.y(), crBox.width(), crBox.height(), nullptr, nullptr, dev->annotations_callback, dev); |
20125 | fschmid | 743 | // else |
22527 | craig | 744 | // pdfDoc->displayPage(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, nullptr, nullptr, dev->annotations_callback, dev); |
20125 | fschmid | 745 | // int numObj2 = m_Doc->Items->count(); |
746 | // int countObj = numObj2 - numObj; |
||
17448 | fschmid | 747 | for (int a = 0; a < ocgGroups.count(); a++) |
748 | { |
||
749 | OptionalContentGroup *oc = ocgGroups[a]; |
||
20125 | fschmid | 750 | // m_Doc->setActiveLayer(UnicodeParsedString(oc->getName())); |
751 | // currentLayer = m_Doc->activeLayer(); |
||
17448 | fschmid | 752 | oc->setState(OptionalContentGroup::On); |
20125 | fschmid | 753 | if (cropped) |
22527 | craig | 754 | pdfDoc->displayPageSlice(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, crBox.x() - mdBox.x(), mdBox.bottom() - crBox.bottom(), crBox.width(), crBox.height(), nullptr, nullptr, dev->annotations_callback, dev); |
20125 | fschmid | 755 | else |
22527 | craig | 756 | pdfDoc->displayPage(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, nullptr, nullptr, dev->annotations_callback, dev); |
20125 | fschmid | 757 | oc->setState(OptionalContentGroup::Off); |
758 | // for (int dd = 0; dd < countObj; dd++) |
||
759 | // { |
||
760 | // PageItem *iteD = m_Doc->Items->takeAt(numObj2); |
||
761 | // delete iteD; |
||
762 | // } |
||
763 | // numObj2 = m_Doc->Items->count(); |
||
17448 | fschmid | 764 | } |
765 | } |
||
766 | else |
||
18004 | fschmid | 767 | { |
768 | if (cropped) |
||
22527 | craig | 769 | pdfDoc->displayPageSlice(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, crBox.x() - mdBox.x(), mdBox.bottom() - crBox.bottom(), crBox.width(), crBox.height(), nullptr, nullptr, dev->annotations_callback, dev); |
18004 | fschmid | 770 | else |
22527 | craig | 771 | pdfDoc->displayPage(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, nullptr, nullptr, dev->annotations_callback, dev); |
18004 | fschmid | 772 | } |
22738 | jghali | 773 | |
17859 | fschmid | 774 | PDFPresentationData ef; |
22154 | jghali | 775 | Object trans = pdfDoc->getPage(pp)->getTrans(); |
776 | Object *transi = &trans; |
||
17859 | fschmid | 777 | if (transi->isDict()) |
778 | { |
||
779 | m_Doc->pdfOptions().PresentMode = true; |
||
780 | PageTransition *pgTrans = new PageTransition(transi); |
||
18394 | fschmid | 781 | ef.pageViewDuration = pdfDoc->getPage(pp)->getDuration(); |
17859 | fschmid | 782 | ef.pageEffectDuration = pgTrans->getDuration(); |
783 | ef.Dm = pgTrans->getAlignment() == transitionHorizontal ? 0 : 1; |
||
784 | ef.M = pgTrans->getDirection() == transitionInward ? 0 : 1; |
||
785 | int ang = pgTrans->getAngle(); |
||
786 | if (ang == 0) |
||
787 | ef.Di = 0; |
||
788 | else if (ang == 270) |
||
789 | ef.Di = 1; |
||
790 | else if (ang == 90) |
||
791 | ef.Di = 2; |
||
792 | else if (ang == 180) |
||
793 | ef.Di = 3; |
||
794 | else if (ang == 315) |
||
795 | ef.Di = 4; |
||
796 | PageTransitionType trType = pgTrans->getType(); |
||
797 | if (trType == transitionReplace) |
||
798 | ef.effectType = 0; |
||
799 | else if (trType == transitionBlinds) |
||
800 | ef.effectType = 1; |
||
801 | else if (trType == transitionBox) |
||
802 | ef.effectType = 2; |
||
803 | else if (trType == transitionDissolve) |
||
804 | ef.effectType = 3; |
||
805 | else if (trType == transitionGlitter) |
||
806 | ef.effectType = 4; |
||
807 | else if (trType == transitionSplit) |
||
808 | ef.effectType = 5; |
||
809 | else if (trType == transitionWipe) |
||
810 | ef.effectType = 6; |
||
811 | else if (trType == transitionPush) |
||
812 | ef.effectType = 7; |
||
813 | else if (trType == transitionCover) |
||
814 | ef.effectType = 8; |
||
815 | else if (trType == transitionUncover) |
||
816 | ef.effectType = 9; |
||
817 | else if (trType == transitionFade) |
||
818 | ef.effectType = 10; |
||
819 | delete pgTrans; |
||
820 | } |
||
18394 | fschmid | 821 | m_Doc->currentPage()->PresentVals = ef; |
17448 | fschmid | 822 | } |
17847 | fschmid | 823 | int numjs = pdfDoc->getCatalog()->numJS(); |
824 | if (numjs > 0) |
||
825 | { |
||
826 | NameTree *jsNameTreeP = new NameTree(); |
||
22154 | jghali | 827 | Object catDict = pdfDoc->getXRef()->getCatalog(); |
17847 | fschmid | 828 | if (catDict.isDict()) |
829 | { |
||
22154 | jghali | 830 | Object names = catDict.dictLookup("Names"); |
17847 | fschmid | 831 | if (names.isDict()) |
832 | { |
||
22154 | jghali | 833 | Object obj = names.dictLookup("JavaScript"); |
834 | jsNameTreeP->init(pdfDoc->getXRef(), &obj); |
||
17847 | fschmid | 835 | } |
836 | for (int a = 0; a < numjs; a++) |
||
837 | { |
||
838 | m_Doc->JavaScripts.insert(UnicodeParsedString(jsNameTreeP->getName(a)), UnicodeParsedString(pdfDoc->getCatalog()->getJS(a))); |
||
839 | } |
||
22154 | jghali | 840 | names = catDict.dictLookup("OpenAction"); |
17857 | fschmid | 841 | if (names.isDict()) |
842 | { |
||
22527 | craig | 843 | LinkAction *linkAction = nullptr; |
17857 | fschmid | 844 | linkAction = LinkAction::parseAction(&names, pdfDoc->getCatalog()->getBaseURI()); |
845 | if (linkAction) |
||
846 | { |
||
847 | LinkJavaScript *jsa = (LinkJavaScript*)linkAction; |
||
848 | if (jsa->isOk()) |
||
849 | { |
||
850 | QString script = UnicodeParsedString(jsa->getScript()); |
||
851 | if (script.startsWith("this.")) |
||
852 | { |
||
853 | script.remove(0, 5); |
||
854 | script.remove("()"); |
||
855 | if (m_Doc->JavaScripts.contains(script)) |
||
856 | m_Doc->pdfOptions().openAction = script; |
||
857 | } |
||
858 | } |
||
859 | } |
||
860 | } |
||
17847 | fschmid | 861 | } |
862 | delete jsNameTreeP; |
||
863 | } |
||
17849 | fschmid | 864 | m_Doc->pdfOptions().Version = (PDFOptions::PDFVersion)qMin(15, qMax(13, pdfDoc->getPDFMajorVersion() * 10 + pdfDoc->getPDFMinorVersion())); |
865 | ViewerPreferences *viewPrefs = pdfDoc->getCatalog()->getViewerPreferences(); |
||
866 | if (viewPrefs) |
||
867 | { |
||
868 | m_Doc->pdfOptions().Binding = viewPrefs->getDirection() == ViewerPreferences::directionL2R ? 0 : 1; |
||
869 | m_Doc->pdfOptions().hideMenuBar = viewPrefs->getHideMenubar(); |
||
870 | m_Doc->pdfOptions().hideToolBar = viewPrefs->getHideToolbar(); |
||
871 | m_Doc->pdfOptions().fitWindow = viewPrefs->getFitWindow(); |
||
872 | } |
||
873 | Catalog::PageMode pgm = pdfDoc->getCatalog()->getPageMode(); |
||
874 | m_Doc->pdfOptions().displayFullscreen = (pgm == Catalog::pageModeFullScreen); |
||
875 | m_Doc->pdfOptions().displayThumbs = (pgm == Catalog::pageModeThumbs); |
||
876 | m_Doc->pdfOptions().displayBookmarks = (pgm == Catalog::pageModeOutlines); |
||
877 | m_Doc->pdfOptions().displayLayers = (pgm == Catalog::pageModeOC); |
||
878 | Catalog::PageLayout pgl = pdfDoc->getCatalog()->getPageLayout(); |
||
879 | if (pgl == Catalog::pageLayoutSinglePage) |
||
880 | m_Doc->pdfOptions().PageLayout = PDFOptions::SinglePage; |
||
881 | else if (pgl == Catalog::pageLayoutOneColumn) |
||
882 | m_Doc->pdfOptions().PageLayout = PDFOptions::OneColumn; |
||
20300 | fschmid | 883 | else if ((pgl == Catalog::pageLayoutTwoColumnLeft) || (pgl == Catalog::pageLayoutTwoPageLeft)) |
884 | { |
||
885 | m_Doc->resetPage(1); |
||
886 | m_Doc->setPageSetFirstPage(1, 0); |
||
17849 | fschmid | 887 | m_Doc->pdfOptions().PageLayout = PDFOptions::TwoColumnLeft; |
20300 | fschmid | 888 | } |
889 | else if ((pgl == Catalog::pageLayoutTwoColumnRight) || (pgl == Catalog::pageLayoutTwoPageRight)) |
||
890 | { |
||
891 | m_Doc->resetPage(1); |
||
892 | m_Doc->setPageSetFirstPage(1, 1); |
||
17849 | fschmid | 893 | m_Doc->pdfOptions().PageLayout = PDFOptions::TwoColumnRight; |
20300 | fschmid | 894 | } |
16729 | fschmid | 895 | } |
896 | else |
||
17448 | fschmid | 897 | { |
898 | if (hasOcg) |
||
899 | { |
||
900 | for (int a = 0; a < ocgGroups.count(); a++) |
||
901 | { |
||
902 | ocgGroups[a]->setState(OptionalContentGroup::On); |
||
903 | } |
||
904 | } |
||
22527 | craig | 905 | pdfDoc->displayPage(dev, firstPage, hDPI, vDPI, rotate, useMediaBox, crop, printing, nullptr, nullptr, dev->annotations_callback, dev); |
17448 | fschmid | 906 | } |
16729 | fschmid | 907 | } |
908 | delete dev; |
||
909 | } |
||
910 | } |
||
911 | delete pdfDoc; |
||
912 | } |
||
913 | delete globalParams; |
||
22609 | craig | 914 | globalParams = nullptr; |
16729 | fschmid | 915 | |
916 | // qDebug() << "converting finished"; |
||
917 | // qDebug() << "Imported" << Elements.count() << "Elements"; |
||
918 | |||
919 | if (Elements.count() == 0) |
||
920 | { |
||
921 | if (importedColors.count() != 0) |
||
922 | { |
||
923 | for (int cd = 0; cd < importedColors.count(); cd++) |
||
924 | { |
||
925 | m_Doc->PageColors.remove(importedColors[cd]); |
||
926 | } |
||
927 | } |
||
928 | } |
||
929 | |||
930 | if (progressDialog) |
||
931 | progressDialog->close(); |
||
932 | return true; |
||
933 | } |
||
934 | |||
18004 | fschmid | 935 | QImage PdfPlug::readPreview(int pgNum, int width, int height, int box) |
17880 | fschmid | 936 | { |
937 | if (!m_pdfDoc) |
||
938 | return QImage(); |
||
22088 | jghali | 939 | |
17880 | fschmid | 940 | double h = m_pdfDoc->getPageMediaHeight(pgNum); |
941 | double w = m_pdfDoc->getPageMediaWidth(pgNum); |
||
942 | double scale = qMin(height / h, width / w); |
||
943 | double hDPI = 72.0 * scale; |
||
944 | double vDPI = 72.0 * scale; |
||
945 | SplashColor bgColor; |
||
946 | bgColor[0] = 255; |
||
947 | bgColor[1] = 255; |
||
948 | bgColor[2] = 255; |
||
19806 | jghali | 949 | SplashOutputDev *dev = new SplashOutputDev(splashModeXBGR8, 4, gFalse, bgColor, gTrue); |
17880 | fschmid | 950 | dev->setVectorAntialias(gTrue); |
951 | dev->setFreeTypeHinting(gTrue, gFalse); |
||
952 | dev->startDoc(m_pdfDoc); |
||
953 | m_pdfDoc->displayPage(dev, pgNum, hDPI, vDPI, 0, gTrue, gFalse, gFalse); |
||
954 | SplashBitmap *bitmap = dev->getBitmap(); |
||
955 | int bw = bitmap->getWidth(); |
||
956 | int bh = bitmap->getHeight(); |
||
957 | SplashColorPtr dataPtr = bitmap->getDataPtr(); |
||
958 | if (QSysInfo::BigEndian == QSysInfo::ByteOrder) |
||
959 | { |
||
960 | uchar c; |
||
961 | int count = bw * bh * 4; |
||
962 | for (int k = 0; k < count; k += 4) |
||
963 | { |
||
964 | c = dataPtr[k]; |
||
965 | dataPtr[k] = dataPtr[k+3]; |
||
966 | dataPtr[k+3] = c; |
||
967 | c = dataPtr[k+1]; |
||
968 | dataPtr[k+1] = dataPtr[k+2]; |
||
969 | dataPtr[k+2] = c; |
||
970 | } |
||
971 | } |
||
972 | // construct a qimage SHARING the raw bitmap data in memory |
||
973 | QImage tmpimg( dataPtr, bw, bh, QImage::Format_ARGB32 ); |
||
974 | QImage image = tmpimg.copy(); |
||
975 | image.setText("XSize", QString("%1").arg(w)); |
||
976 | image.setText("YSize", QString("%1").arg(h)); |
||
18004 | fschmid | 977 | if (box > Media_Box) |
978 | { |
||
979 | QRectF cRect = getCBox(box, pgNum); |
||
22088 | jghali | 980 | QRectF mediaRect = getCBox(0, pgNum); |
981 | cRect.moveTo(cRect.x() - mediaRect.x(), cRect.y() - mediaRect.y()); |
||
18004 | fschmid | 982 | QPainter pp; |
983 | pp.begin(&image); |
||
984 | pp.setBrush(Qt::NoBrush); |
||
22829 | jghali | 985 | pp.setPen(QPen(Qt::red, 3.0)); |
18004 | fschmid | 986 | pp.translate(0, bh); |
987 | pp.scale(scale, -scale); |
||
988 | pp.drawRect(cRect); |
||
989 | pp.end(); |
||
990 | } |
||
17880 | fschmid | 991 | delete dev; |
992 | return image; |
||
993 | } |
||
994 | |||
18004 | fschmid | 995 | QRectF PdfPlug::getCBox(int box, int pgNum) |
996 | { |
||
22741 | jghali | 997 | const PDFRectangle *cBox = nullptr; |
18060 | jghali | 998 | if (box == Media_Box) |
999 | cBox = m_pdfDoc->getPage(pgNum)->getMediaBox(); |
||
1000 | else if (box == Bleed_Box) |
||
18004 | fschmid | 1001 | cBox = m_pdfDoc->getPage(pgNum)->getBleedBox(); |
1002 | else if (box == Trim_Box) |
||
1003 | cBox = m_pdfDoc->getPage(pgNum)->getTrimBox(); |
||
1004 | else if (box == Crop_Box) |
||
1005 | cBox = m_pdfDoc->getPage(pgNum)->getCropBox(); |
||
1006 | else if (box == Art_Box) |
||
1007 | cBox = m_pdfDoc->getPage(pgNum)->getArtBox(); |
||
1008 | QRectF cRect = QRectF(QPointF(cBox->x1, cBox->y1), QPointF(cBox->x2, cBox->y2)).normalized(); |
||
1009 | return cRect; |
||
1010 | } |
||
1011 | |||
22514 | jghali | 1012 | QString PdfPlug::UnicodeParsedString(POPPLER_CONST GooString *s1) |
16729 | fschmid | 1013 | { |
1014 | if ( !s1 || s1->getLength() == 0 ) |
||
1015 | return QString(); |
||
1016 | GBool isUnicode; |
||
1017 | int i; |
||
1018 | Unicode u; |
||
1019 | QString result; |
||
1020 | if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getLength() > 1 && (s1->getChar(1) & 0xff) == 0xff)) |
||
1021 | { |
||
1022 | isUnicode = gTrue; |
||
1023 | i = 2; |
||
1024 | result.reserve((s1->getLength() - 2) / 2); |
||
1025 | } |
||
1026 | else |
||
1027 | { |
||
1028 | isUnicode = gFalse; |
||
1029 | i = 0; |
||
1030 | result.reserve(s1->getLength()); |
||
1031 | } |
||
1032 | while (i < s1->getLength()) |
||
1033 | { |
||
1034 | if (isUnicode) |
||
1035 | { |
||
1036 | u = ((s1->getChar(i) & 0xff) << 8) | (s1->getChar(i+1) & 0xff); |
||
1037 | i += 2; |
||
1038 | } |
||
1039 | else |
||
1040 | { |
||
1041 | u = s1->getChar(i) & 0xff; |
||
1042 | ++i; |
||
1043 | } |
||
1044 | result += QChar( u ); |
||
1045 | } |
||
1046 | return result; |
||
1047 | } |