Rev 20561 | Rev 21527 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 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 | */ |
||
2688 | craig | 7 | |
10862 | cbradney | 8 | #include <QByteArray> |
10223 | cbradney | 9 | #include <QCursor> |
13085 | jghali | 10 | #include <QDebug> |
9764 | jghali | 11 | #include <QDrag> |
10862 | cbradney | 12 | #include <QFile> |
13 | #include <QList> |
||
16546 | jghali | 14 | #include <QMessageBox> |
9764 | jghali | 15 | #include <QMimeData> |
10862 | cbradney | 16 | #include <QRegExp> |
9922 | fschmid | 17 | #include <QStack> |
10862 | cbradney | 18 | |
290 | Franz | 19 | #include <cstdlib> |
4930 | cbradney | 20 | |
19093 | craig | 21 | #include "importps.h" |
22 | |||
23 | |||
10862 | cbradney | 24 | #include "commonstrings.h" |
25 | #include "loadsaveplugin.h" |
||
26 | #include "prefscontext.h" |
||
27 | #include "prefsfile.h" |
||
28 | #include "prefsmanager.h" |
||
29 | #include "prefstable.h" |
||
19093 | craig | 30 | #include "scclocale.h" |
10862 | cbradney | 31 | #include "scconfig.h" |
12841 | jghali | 32 | #include "scmimedata.h" |
1693 | craig | 33 | #include "scpaths.h" |
10862 | cbradney | 34 | #include "scribusXml.h" |
35 | #include "scribuscore.h" |
||
19093 | craig | 36 | #include "scribusdoc.h" |
37 | #include "scribusview.h" |
||
13503 | cbradney | 38 | #include "sctextstream.h" |
3934 | cbradney | 39 | #include "selection.h" |
14170 | jghali | 40 | #include "ui/customfdialog.h" |
41 | #include "ui/multiprogressdialog.h" |
||
42 | #include "ui/propertiespalette.h" |
||
19605 | jghali | 43 | #include "ui/scmessagebox.h" |
4930 | cbradney | 44 | #include "undomanager.h" |
2529 | craig | 45 | #include "util.h" |
12015 | fschmid | 46 | #include "util_color.h" |
10212 | cbradney | 47 | #include "util_formats.h" |
10203 | cbradney | 48 | #include "util_math.h" |
19093 | craig | 49 | |
13011 | fschmid | 50 | #ifdef HAVE_PODOFO |
51 | #include <podofo/podofo.h> |
||
52 | #endif |
||
290 | Franz | 53 | |
10862 | cbradney | 54 | |
5346 | mrdocs | 55 | extern SCRIBUS_API ScribusQApp * ScQApp; |
4645 | subik | 56 | |
8052 | jghali | 57 | EPSPlug::EPSPlug(ScribusDoc* doc, int flags) |
290 | Franz | 58 | { |
12971 | jghali | 59 | tmpSel = new Selection(this, false); |
60 | m_Doc = doc; |
||
61 | progressDialog = NULL; |
||
5539 | mrdocs | 62 | interactive = (flags & LoadSavePlugin::lfInteractive); |
8052 | jghali | 63 | } |
64 | |||
13371 | jghali | 65 | bool EPSPlug::import(QString fName, const TransactionSettings &trSettings, int flags, bool showProgress) |
8052 | jghali | 66 | { |
19809 | craig | 67 | #ifdef Q_OS_OSX |
68 | #if QT_VERSION >= 0x050300 |
||
69 | showProgress = false; |
||
70 | #endif |
||
71 | #endif |
||
72 | |||
8052 | jghali | 73 | bool success = false; |
74 | interactive = (flags & LoadSavePlugin::lfInteractive); |
||
4923 | avox | 75 | cancel = false; |
12015 | fschmid | 76 | double x, y, b, h; |
290 | Franz | 77 | bool ret = false; |
78 | bool found = false; |
||
79 | CustColors.clear(); |
||
80 | QFileInfo fi = QFileInfo(fName); |
||
10516 | cbradney | 81 | QString ext = fi.suffix().toLower(); |
5243 | cbradney | 82 | if ( !ScCore->usingGUI() ) { |
4999 | avox | 83 | interactive = false; |
84 | showProgress = false; |
||
85 | } |
||
5781 | cbradney | 86 | if ( showProgress ) |
87 | { |
||
88 | ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW(); |
||
10508 | cbradney | 89 | progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw); |
4923 | avox | 90 | QStringList barNames, barTexts; |
91 | barNames << "GI"; |
||
4949 | cbradney | 92 | barTexts << tr("Analyzing PostScript:"); |
9803 | fschmid | 93 | QList<bool> barsNumeric; |
5370 | cbradney | 94 | barsNumeric << false; |
95 | progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric); |
||
4923 | avox | 96 | progressDialog->setOverallTotalSteps(3); |
97 | progressDialog->setOverallProgress(0); |
||
98 | progressDialog->setProgress("GI", 0); |
||
99 | progressDialog->show(); |
||
10724 | cbradney | 100 | connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested())); |
5243 | cbradney | 101 | qApp->processEvents(); |
4923 | avox | 102 | } |
4999 | avox | 103 | else { |
104 | progressDialog = NULL; |
||
105 | } |
||
4923 | avox | 106 | |
319 | Franz | 107 | /* Set default Page to size defined in Preferences */ |
290 | Franz | 108 | x = 0.0; |
109 | y = 0.0; |
||
13876 | cbradney | 110 | b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth; |
111 | h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight; |
||
10136 | cbradney | 112 | if (extensionIndicatesEPSorPS(ext)) |
290 | Franz | 113 | { |
4000 | fschmid | 114 | QString tmp, BBox, tmp2, FarNam; |
2886 | fschmid | 115 | ScColor cc; |
290 | Franz | 116 | QFile f(fName); |
8501 | cbradney | 117 | if (f.open(QIODevice::ReadOnly)) |
290 | Franz | 118 | { |
119 | /* Try to find Bounding Box */ |
||
9991 | fschmid | 120 | QDataStream ts(&f); |
290 | Franz | 121 | while (!ts.atEnd()) |
122 | { |
||
9991 | fschmid | 123 | tmp = readLinefromDataStream(ts); |
290 | Franz | 124 | if (tmp.startsWith("%%BoundingBox:")) |
125 | { |
||
126 | found = true; |
||
127 | BBox = tmp.remove("%%BoundingBox:"); |
||
128 | } |
||
129 | if (!found) |
||
130 | { |
||
131 | if (tmp.startsWith("%%BoundingBox")) |
||
132 | { |
||
133 | found = true; |
||
134 | BBox = tmp.remove("%%BoundingBox"); |
||
135 | } |
||
136 | } |
||
137 | if (tmp.startsWith("%%EndComments")) |
||
12015 | fschmid | 138 | break; |
290 | Franz | 139 | } |
140 | f.close(); |
||
141 | if (found) |
||
142 | { |
||
10603 | fschmid | 143 | QStringList bb = BBox.split(" ", QString::SkipEmptyParts); |
319 | Franz | 144 | if (bb.count() == 4) |
145 | { |
||
13497 | jghali | 146 | x = ScCLocale::toDoubleC(bb[0]); |
147 | y = ScCLocale::toDoubleC(bb[1]); |
||
148 | b = ScCLocale::toDoubleC(bb[2]); |
||
149 | h = ScCLocale::toDoubleC(bb[3]); |
||
319 | Franz | 150 | } |
290 | Franz | 151 | } |
152 | } |
||
12015 | fschmid | 153 | importColorsFromFile(fName, CustColors); |
290 | Franz | 154 | } |
13011 | fschmid | 155 | #ifdef HAVE_PODOFO |
156 | else if (extensionIndicatesPDF(ext)) |
||
157 | { |
||
158 | try |
||
159 | { |
||
160 | PoDoFo::PdfError::EnableDebug( false ); |
||
13016 | cbradney | 161 | #if (PODOFO_VERSION == 0 && PODOFO_MINOR > 6) |
162 | PoDoFo::PdfError::EnableLogging( false ); |
||
163 | #endif |
||
13011 | fschmid | 164 | #if (PODOFO_VERSION == 0 && PODOFO_MINOR == 5 && PODOFO_REVISION == 99) || PODOFO_MINOR > 5 |
165 | PoDoFo::PdfMemDocument doc( fName.toLocal8Bit().data() ); |
||
166 | #else |
||
167 | PoDoFo::PdfDocument doc( fName.toLocal8Bit().data() ); |
||
168 | #endif |
||
169 | PoDoFo::PdfPage *curPage = doc.GetPage(0); |
||
170 | if (curPage != NULL) |
||
171 | { |
||
172 | PoDoFo::PdfRect rect = curPage->GetMediaBox(); |
||
173 | b = rect.GetWidth() - rect.GetLeft(); |
||
174 | h = rect.GetHeight() - rect.GetBottom(); |
||
175 | } |
||
176 | } |
||
177 | catch(PoDoFo::PdfError& e) |
||
178 | { |
||
13085 | jghali | 179 | qDebug("%s", "PoDoFo error while reading page size!"); |
13011 | fschmid | 180 | e.PrintErrorMsg(); |
181 | } |
||
182 | } |
||
183 | #endif |
||
7527 | fschmid | 184 | baseX = 0; |
185 | baseY = 0; |
||
5539 | mrdocs | 186 | if (!interactive || (flags & LoadSavePlugin::lfInsertPage)) |
290 | Franz | 187 | { |
5781 | cbradney | 188 | m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false); |
189 | m_Doc->addPage(0); |
||
190 | m_Doc->view()->addPage(0, true); |
||
7527 | fschmid | 191 | baseX = 0; |
192 | baseY = 0; |
||
290 | Franz | 193 | } |
506 | fschmid | 194 | else |
195 | { |
||
5781 | cbradney | 196 | if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc)) |
506 | fschmid | 197 | { |
5798 | jghali | 198 | m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true); |
5781 | cbradney | 199 | ScCore->primaryMainWindow()->HaveNewDoc(); |
506 | fschmid | 200 | ret = true; |
7527 | fschmid | 201 | baseX = 0; |
202 | baseY = 0; |
||
506 | fschmid | 203 | } |
204 | } |
||
7527 | fschmid | 205 | if ((!ret) && (interactive)) |
206 | { |
||
207 | baseX = m_Doc->currentPage()->xOffset(); |
||
208 | baseY = m_Doc->currentPage()->yOffset(); |
||
209 | } |
||
3207 | craig | 210 | if ((ret) || (!interactive)) |
550 | fschmid | 211 | { |
212 | if (b-x > h-y) |
||
14991 | cbradney | 213 | m_Doc->setPageOrientation(1); |
550 | fschmid | 214 | else |
14991 | cbradney | 215 | m_Doc->setPageOrientation(0); |
216 | m_Doc->setPageSize("Custom"); |
||
550 | fschmid | 217 | } |
1065 | cbradney | 218 | ColorList::Iterator it; |
290 | Franz | 219 | for (it = CustColors.begin(); it != CustColors.end(); ++it) |
220 | { |
||
5781 | cbradney | 221 | if (!m_Doc->PageColors.contains(it.key())) |
10516 | cbradney | 222 | m_Doc->PageColors.insert(it.key(), it.value()); |
290 | Franz | 223 | } |
12015 | fschmid | 224 | boundingBoxRect.addRect(0, 0, b-x, h-y); |
290 | Franz | 225 | Elements.clear(); |
5781 | cbradney | 226 | m_Doc->setLoading(true); |
227 | m_Doc->DoDrawing = false; |
||
16105 | fschmid | 228 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
16016 | fschmid | 229 | m_Doc->view()->updatesOn(false); |
14754 | jghali | 230 | m_Doc->scMW()->setScriptRunning(true); |
9380 | fschmid | 231 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
10398 | cbradney | 232 | QString CurDirP = QDir::currentPath(); |
10516 | cbradney | 233 | QDir::setCurrent(fi.path()); |
290 | Franz | 234 | if (convert(fName, x, y, b, h)) |
235 | { |
||
7580 | cbradney | 236 | // m_Doc->m_Selection->clear(); |
237 | tmpSel->clear(); |
||
290 | Franz | 238 | QDir::setCurrent(CurDirP); |
7691 | fschmid | 239 | // if ((Elements.count() > 1) && (interactive)) |
240 | if (Elements.count() > 1) |
||
16105 | fschmid | 241 | m_Doc->groupObjectsList(Elements); |
5781 | cbradney | 242 | m_Doc->DoDrawing = true; |
14754 | jghali | 243 | m_Doc->scMW()->setScriptRunning(false); |
5781 | cbradney | 244 | m_Doc->setLoading(false); |
9380 | fschmid | 245 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
3207 | craig | 246 | if ((Elements.count() > 0) && (!ret) && (interactive)) |
290 | Franz | 247 | { |
8262 | fschmid | 248 | if (flags & LoadSavePlugin::lfScripted) |
290 | Franz | 249 | { |
8262 | fschmid | 250 | bool loadF = m_Doc->isLoading(); |
251 | m_Doc->setLoading(false); |
||
252 | m_Doc->changed(); |
||
253 | m_Doc->setLoading(loadF); |
||
16105 | fschmid | 254 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
8262 | fschmid | 255 | { |
16016 | fschmid | 256 | m_Doc->m_Selection->delaySignalsOn(); |
257 | for (int dre=0; dre<Elements.count(); ++dre) |
||
258 | { |
||
259 | m_Doc->m_Selection->addItem(Elements.at(dre), true); |
||
260 | } |
||
261 | m_Doc->m_Selection->delaySignalsOff(); |
||
262 | m_Doc->m_Selection->setGroupRect(); |
||
263 | m_Doc->view()->updatesOn(true); |
||
8262 | fschmid | 264 | } |
290 | Franz | 265 | } |
8262 | fschmid | 266 | else |
267 | { |
||
268 | m_Doc->DragP = true; |
||
269 | m_Doc->DraggedElem = 0; |
||
270 | m_Doc->DragElements.clear(); |
||
11835 | fschmid | 271 | m_Doc->m_Selection->delaySignalsOn(); |
9856 | fschmid | 272 | for (int dre=0; dre<Elements.count(); ++dre) |
8262 | fschmid | 273 | { |
274 | tmpSel->addItem(Elements.at(dre), true); |
||
275 | } |
||
276 | tmpSel->setGroupRect(); |
||
277 | ScriXmlDoc *ss = new ScriXmlDoc(); |
||
12841 | jghali | 278 | ScElemMimeData* md = new ScElemMimeData(); |
14744 | fschmid | 279 | md->setScribusElem(ss->WriteElem(m_Doc, tmpSel)); |
12971 | jghali | 280 | delete ss; |
281 | /*#ifndef Q_WS_MAC*/ |
||
4546 | subik | 282 | // see #2196 |
8262 | fschmid | 283 | m_Doc->itemSelection_DeleteItem(tmpSel); |
12971 | jghali | 284 | /*#else |
13085 | jghali | 285 | qDebug() << "psimport: leaving items on page"; |
12971 | jghali | 286 | #endif*/ |
8262 | fschmid | 287 | m_Doc->view()->updatesOn(true); |
11835 | fschmid | 288 | m_Doc->m_Selection->delaySignalsOff(); |
13371 | jghali | 289 | // We must copy the TransationSettings object as it is owned |
290 | // by handleObjectImport method afterwards |
||
291 | TransactionSettings* transacSettings = new TransactionSettings(trSettings); |
||
292 | m_Doc->view()->handleObjectImport(md, transacSettings); |
||
8262 | fschmid | 293 | m_Doc->DragP = false; |
294 | m_Doc->DraggedElem = 0; |
||
295 | m_Doc->DragElements.clear(); |
||
7991 | fschmid | 296 | } |
290 | Franz | 297 | } |
298 | else |
||
357 | Franz | 299 | { |
5781 | cbradney | 300 | m_Doc->changed(); |
6556 | fschmid | 301 | m_Doc->reformPages(); |
16105 | fschmid | 302 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
16016 | fschmid | 303 | m_Doc->view()->updatesOn(true); |
357 | Franz | 304 | } |
8052 | jghali | 305 | success = true; |
290 | Franz | 306 | } |
307 | else |
||
308 | { |
||
309 | QDir::setCurrent(CurDirP); |
||
5781 | cbradney | 310 | m_Doc->DoDrawing = true; |
14754 | jghali | 311 | m_Doc->scMW()->setScriptRunning(false); |
7452 | fschmid | 312 | m_Doc->view()->updatesOn(true); |
9380 | fschmid | 313 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
290 | Franz | 314 | } |
3207 | craig | 315 | if (interactive) |
5781 | cbradney | 316 | m_Doc->setLoading(false); |
5004 | cbradney | 317 | //CB If we have a gui we must refresh it if we have used the progressbar |
16105 | fschmid | 318 | if (!(flags & LoadSavePlugin::lfLoadAsPattern)) |
16016 | fschmid | 319 | { |
320 | if ((showProgress) && (!interactive)) |
||
321 | m_Doc->view()->DrawNew(); |
||
322 | } |
||
8052 | jghali | 323 | return success; |
290 | Franz | 324 | } |
325 | |||
7580 | cbradney | 326 | EPSPlug::~EPSPlug() |
327 | { |
||
11677 | jghali | 328 | if (progressDialog) |
329 | delete progressDialog; |
||
7580 | cbradney | 330 | delete tmpSel; |
331 | } |
||
332 | |||
333 | |||
290 | Franz | 334 | bool EPSPlug::convert(QString fn, double x, double y, double b, double h) |
335 | { |
||
4194 | fschmid | 336 | QStringList args; |
337 | QString cmd, cmd1, cmd2, cmd3, tmp, tmp2, tmp3, tmp4; |
||
3120 | fschmid | 338 | // import.prolog do not cope with filenames containing blank spaces |
339 | // so take care that output filename does not (win32 compatibility) |
||
6592 | jghali | 340 | QString tmpFile = getShortPathName(ScPaths::getTempFileDir())+ "/ps.out"; |
341 | QString errFile = getShortPathName(ScPaths::getTempFileDir())+ "/ps.err"; |
||
1693 | craig | 342 | QString pfad = ScPaths::instance().libDir(); |
16577 | craig | 343 | QString pfad2 = QDir::toNativeSeparators(pfad + "import.prolog"); |
1735 | fschmid | 344 | QFileInfo fi = QFileInfo(fn); |
10516 | cbradney | 345 | QString ext = fi.suffix().toLower(); |
4923 | avox | 346 | |
347 | if (progressDialog) { |
||
348 | progressDialog->setOverallProgress(1); |
||
5243 | cbradney | 349 | qApp->processEvents(); |
4923 | avox | 350 | } |
12015 | fschmid | 351 | /* |
352 | // Destill the eps with ghostscript to get a clean eps file |
||
353 | QString cleanFile = getShortPathName(ScPaths::getTempFileDir())+ "/clean.eps"; |
||
4194 | fschmid | 354 | args.append( "-q" ); |
355 | args.append( "-dNOPAUSE" ); |
||
12015 | fschmid | 356 | args.append( "-sDEVICE=epswrite" ); |
357 | args.append( "-dBATCH" ); |
||
358 | args.append( "-dSAFER" ); |
||
359 | args.append( "-dDEVICEWIDTH=250000" ); |
||
360 | args.append( "-dDEVICEHEIGHT=250000" ); |
||
16577 | craig | 361 | args.append( QString("-sOutputFile=%1").arg(QDir::toNativeSeparators(cleanFile)) ); |
362 | args.append( QDir::toNativeSeparators(fn) ); |
||
12015 | fschmid | 363 | System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args, errFile, errFile, &cancel); |
364 | args.clear(); |
||
365 | */ |
||
366 | args.append( "-q" ); |
||
367 | args.append( "-dNOPAUSE" ); |
||
12919 | fschmid | 368 | args.append( "-dNODISPLAY" ); |
4194 | fschmid | 369 | args.append( "-dBATCH" ); |
4978 | avox | 370 | args.append( "-dDELAYBIND" ); |
2523 | craig | 371 | // Add any extra font paths being used by Scribus to gs's font search |
372 | // path We have to use Scribus's prefs context, not a plugin context, to |
||
373 | // get to the required information. |
||
2856 | cbradney | 374 | PrefsContext *pc = PrefsManager::instance()->prefsFile->getContext("Fonts"); |
2523 | craig | 375 | PrefsTable *extraFonts = pc->getTable("ExtraFontDirs"); |
4194 | fschmid | 376 | const char sep = ScPaths::envPathSeparator; |
2523 | craig | 377 | if (extraFonts->getRowCount() >= 1) |
4194 | fschmid | 378 | cmd = QString("-sFONTPATH=%1").arg(extraFonts->get(0,0)); |
2523 | craig | 379 | for (int i = 1; i < extraFonts->getRowCount(); ++i) |
4194 | fschmid | 380 | cmd += QString("%1%2").arg(sep).arg(extraFonts->get(i,0)); |
381 | if( !cmd.isEmpty() ) |
||
382 | args.append( cmd ); |
||
2523 | craig | 383 | // then finish building the command and call gs |
12919 | fschmid | 384 | args.append( QString("-g%1x%2").arg(tmp2.setNum(qRound((b-x)*4))).arg(tmp3.setNum(qRound((h-y)*4))) ); |
385 | args.append( "-r288"); |
||
4788 | avox | 386 | args.append( "-dTextAlphaBits=4" ); |
387 | args.append( "-dGraphicsAlphaBits=4" ); |
||
4194 | fschmid | 388 | args.append( "-c" ); |
389 | args.append( tmp.setNum(-x) ); |
||
390 | args.append( tmp.setNum(-y) ); |
||
391 | args.append( "translate" ); |
||
16577 | craig | 392 | args.append( QString("-sTraceFile=%1").arg(QDir::toNativeSeparators(tmpFile)) ); |
5781 | cbradney | 393 | QString exportPath = m_Doc->DocName + "-" + fi.baseName(); |
4801 | avox | 394 | QFileInfo exportFi(exportPath); |
395 | if ( !exportFi.isWritable() ) { |
||
396 | PrefsContext* docContext = PrefsManager::instance()->prefsFile->getContext("docdirs", false); |
||
397 | QString docDir = "."; |
||
398 | QString prefsDocDir=PrefsManager::instance()->documentDir(); |
||
399 | if (!prefsDocDir.isEmpty()) |
||
400 | docDir = docContext->get("docsopen", prefsDocDir); |
||
401 | else |
||
402 | docDir = docContext->get("docsopen", "."); |
||
403 | exportFi.setFile(docDir + "/" + exportFi.baseName()); |
||
404 | } |
||
13085 | jghali | 405 | //qDebug() << QString("using export path %1").arg(exportFi.absFilePath()); |
16577 | craig | 406 | args.append( QString("-sExportFiles=%1").arg(QDir::toNativeSeparators(exportFi.absoluteFilePath())) ); |
4194 | fschmid | 407 | args.append( pfad2 ); |
16577 | craig | 408 | args.append( QDir::toNativeSeparators(fn) ); |
4194 | fschmid | 409 | args.append( "-c" ); |
410 | args.append( "flush" ); |
||
411 | args.append( "cfile" ); |
||
412 | args.append( "closefile" ); |
||
413 | args.append( "quit" ); |
||
10493 | fschmid | 414 | QByteArray finalCmd = args.join(" ").toLocal8Bit(); |
11777 | jghali | 415 | int ret = System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args, errFile, errFile, &cancel); |
416 | if (ret != 0 && !cancel) |
||
290 | Franz | 417 | { |
2791 | craig | 418 | qDebug("PostScript import failed when calling gs as: \n%s\n", finalCmd.data()); |
13085 | jghali | 419 | qDebug("%s", "Ghostscript diagnostics:\n"); |
4801 | avox | 420 | QFile diag(errFile); |
8501 | cbradney | 421 | if (diag.open(QIODevice::ReadOnly) && !diag.atEnd() ) { |
8665 | cbradney | 422 | char buf[121]; |
423 | while (diag.readLine(buf, 120) > 0) { |
||
424 | qDebug("\t%s", buf); |
||
4725 | avox | 425 | } |
426 | diag.close(); |
||
427 | } |
||
428 | else { |
||
13085 | jghali | 429 | qDebug("%s", "-- no output --"); |
4725 | avox | 430 | } |
6591 | jghali | 431 | if (progressDialog) |
432 | progressDialog->close(); |
||
290 | Franz | 433 | QString mess = tr("Importing File:\n%1\nfailed!").arg(fn); |
19605 | jghali | 434 | ScMessageBox::critical(0, tr("Fatal Error"), mess); |
290 | Franz | 435 | return false; |
436 | } |
||
11777 | jghali | 437 | if(progressDialog && !cancel) { |
4923 | avox | 438 | progressDialog->setOverallProgress(2); |
439 | progressDialog->setLabel("GI", tr("Generating Items")); |
||
5243 | cbradney | 440 | qApp->processEvents(); |
4923 | avox | 441 | } |
442 | if (!cancel) { |
||
10136 | cbradney | 443 | parseOutput(tmpFile, extensionIndicatesEPSorPS(ext)); |
4923 | avox | 444 | } |
2921 | fschmid | 445 | QFile::remove(tmpFile); |
12015 | fschmid | 446 | // QFile::remove(cleanFile); |
4923 | avox | 447 | if (progressDialog) |
448 | progressDialog->close(); |
||
290 | Franz | 449 | return true; |
450 | } |
||
451 | |||
1735 | fschmid | 452 | void EPSPlug::parseOutput(QString fn, bool eps) |
290 | Franz | 453 | { |
454 | QString tmp, token, params, lasttoken, lastPath, currPath; |
||
537 | fschmid | 455 | int z, lcap, ljoin, dc, pagecount; |
4962 | avox | 456 | int failedImages = 0; |
319 | Franz | 457 | double dcp; |
4770 | avox | 458 | bool fillRuleEvenOdd = true; |
290 | Franz | 459 | PageItem* ite; |
9922 | fschmid | 460 | QStack<PageItem*> groupStack; |
16105 | fschmid | 461 | QStack< QList<PageItem*> > groupStackP; |
9919 | jghali | 462 | QStack<int> gsStack; |
463 | QStack<uint> gsStackMarks; |
||
290 | Franz | 464 | QFile f(fn); |
465 | lasttoken = ""; |
||
537 | fschmid | 466 | pagecount = 1; |
8501 | cbradney | 467 | if (f.open(QIODevice::ReadOnly)) |
290 | Franz | 468 | { |
9763 | jghali | 469 | int fProgress = 0; |
470 | int fSize = (int) f.size(); |
||
4923 | avox | 471 | if (progressDialog) { |
9763 | jghali | 472 | progressDialog->setTotalSteps("GI", fSize); |
5243 | cbradney | 473 | qApp->processEvents(); |
4923 | avox | 474 | } |
290 | Franz | 475 | lastPath = ""; |
476 | currPath = ""; |
||
477 | LineW = 0; |
||
478 | Opacity = 1; |
||
4546 | subik | 479 | CurrColor = CommonStrings::None; |
8528 | cbradney | 480 | JoinStyle = Qt::MiterJoin; |
481 | CapStyle = Qt::FlatCap; |
||
292 | Franz | 482 | DashPattern.clear(); |
13497 | jghali | 483 | ScTextStream ts(&f); |
4923 | avox | 484 | int line_cnt = 0; |
485 | while (!ts.atEnd() && !cancel) |
||
290 | Franz | 486 | { |
487 | tmp = ""; |
||
488 | tmp = ts.readLine(); |
||
4923 | avox | 489 | if (progressDialog && (++line_cnt % 100 == 0)) { |
10516 | cbradney | 490 | int fPos = f.pos(); |
9856 | fschmid | 491 | int progress = static_cast<int>(ceil(fPos / (double) fSize * 100)); |
9763 | jghali | 492 | if (progress > fProgress) |
493 | { |
||
494 | progressDialog->setProgress("GI", fPos); |
||
495 | qApp->processEvents(); |
||
496 | fProgress = progress; |
||
497 | } |
||
4923 | avox | 498 | } |
4801 | avox | 499 | token = tmp.section(' ', 0, 0); |
500 | params = tmp.section(' ', 1, -1, QString::SectionIncludeTrailingSep); |
||
5006 | avox | 501 | if (lasttoken == "sp" && !eps && token != "sp" ) //av: messes up anyway: && (!interactive)) |
537 | fschmid | 502 | { |
5781 | cbradney | 503 | m_Doc->addPage(pagecount); |
504 | m_Doc->view()->addPage(pagecount, true); |
||
537 | fschmid | 505 | pagecount++; |
506 | } |
||
290 | Franz | 507 | if (token == "n") |
508 | { |
||
509 | Coords.resize(0); |
||
510 | FirstM = true; |
||
511 | WasM = false; |
||
512 | ClosedPath = false; |
||
513 | } |
||
514 | else if (token == "m") |
||
515 | WasM = true; |
||
516 | else if (token == "c") |
||
517 | { |
||
518 | Curve(&Coords, params); |
||
519 | currPath += params; |
||
520 | } |
||
521 | else if (token == "l") |
||
522 | { |
||
523 | LineTo(&Coords, params); |
||
524 | currPath += params; |
||
525 | } |
||
4770 | avox | 526 | else if (token == "fill-winding") |
527 | { |
||
528 | fillRuleEvenOdd = false; |
||
529 | } |
||
530 | else if (token == "fill-evenodd") |
||
531 | { |
||
532 | fillRuleEvenOdd = true; |
||
533 | } |
||
290 | Franz | 534 | else if (token == "f") |
535 | { |
||
4770 | avox | 536 | //TODO: pattern -> Imageframe + Clip |
290 | Franz | 537 | if (Coords.size() != 0) |
538 | { |
||
539 | if ((Elements.count() != 0) && (lastPath == currPath)) |
||
540 | { |
||
17293 | jghali | 541 | ite = Elements.last(); |
1394 | cbradney | 542 | ite->setFillColor(CurrColor); |
543 | ite->setFillTransparency(1.0 - Opacity); |
||
8017 | fschmid | 544 | lastPath = ""; |
290 | Franz | 545 | } |
546 | else |
||
547 | { |
||
548 | if (ClosedPath) |
||
20561 | jghali | 549 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColor, CommonStrings::None); |
290 | Franz | 550 | else |
20561 | jghali | 551 | z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColor, CommonStrings::None); |
5781 | cbradney | 552 | ite = m_Doc->Items->at(z); |
4801 | avox | 553 | ite->PoLine = Coords.copy(); //FIXME: try to avoid copy if FPointArray when properly shared |
5781 | cbradney | 554 | ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset()); |
290 | Franz | 555 | ite->ClipEdited = true; |
556 | ite->FrameType = 3; |
||
4770 | avox | 557 | ite->fillRule = (fillRuleEvenOdd); |
1065 | cbradney | 558 | FPoint wh = getMaxClipF(&ite->PoLine); |
3934 | cbradney | 559 | ite->setWidthHeight(wh.x(),wh.y()); |
290 | Franz | 560 | ite->Clip = FlattenPath(ite->PoLine, ite->Segments); |
1394 | cbradney | 561 | ite->setFillTransparency(1.0 - Opacity); |
11705 | fschmid | 562 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
20699 | craig | 563 | m_Doc->adjustItemSize(ite); |
16252 | fschmid | 564 | if (ite->itemType() == PageItem::Polygon) |
565 | ite->ContourLine = ite->PoLine.copy(); |
||
16105 | fschmid | 566 | if ((groupStack.count() != 0) && (groupStackP.count() != 0)) |
567 | groupStackP.top().append(ite); |
||
290 | Franz | 568 | Elements.append(ite); |
8017 | fschmid | 569 | lastPath = currPath; |
290 | Franz | 570 | } |
571 | currPath = ""; |
||
572 | } |
||
573 | } |
||
574 | else if (token == "s") |
||
575 | { |
||
576 | if (Coords.size() != 0) |
||
577 | { |
||
13013 | fschmid | 578 | // LineW = qMax(LineW, 0.01); // Set Linewidth to be a least 0.01 pts, a Stroke without a Linewidth makes no sense |
290 | Franz | 579 | if ((Elements.count() != 0) && (lastPath == currPath)) |
580 | { |
||
17293 | jghali | 581 | ite = Elements.last(); |
1394 | cbradney | 582 | ite->setLineColor(CurrColor); |
4580 | cbradney | 583 | ite->setLineWidth(LineW); |
292 | Franz | 584 | ite->PLineEnd = CapStyle; |
585 | ite->PLineJoin = JoinStyle; |
||
1394 | cbradney | 586 | ite->setLineTransparency(1.0 - Opacity); |
292 | Franz | 587 | ite->DashOffset = DashOffset; |
588 | ite->DashValues = DashPattern; |
||
290 | Franz | 589 | } |
590 | else |
||
591 | { |
||
592 | if (ClosedPath) |
||
20561 | jghali | 593 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColor); |
290 | Franz | 594 | else |
20561 | jghali | 595 | z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColor); |
5781 | cbradney | 596 | ite = m_Doc->Items->at(z); |
4801 | avox | 597 | ite->PoLine = Coords.copy(); //FIXME: try to avoid copy when FPointArray is properly shared |
5781 | cbradney | 598 | ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset()); |
290 | Franz | 599 | ite->ClipEdited = true; |
600 | ite->FrameType = 3; |
||
292 | Franz | 601 | ite->PLineEnd = CapStyle; |
602 | ite->PLineJoin = JoinStyle; |
||
603 | ite->DashOffset = DashOffset; |
||
604 | ite->DashValues = DashPattern; |
||
1065 | cbradney | 605 | FPoint wh = getMaxClipF(&ite->PoLine); |
3934 | cbradney | 606 | ite->setWidthHeight(wh.x(), wh.y()); |
290 | Franz | 607 | ite->Clip = FlattenPath(ite->PoLine, ite->Segments); |
1394 | cbradney | 608 | ite->setLineTransparency(1.0 - Opacity); |
20699 | craig | 609 | m_Doc->adjustItemSize(ite); |
16252 | fschmid | 610 | if (ite->itemType() == PageItem::Polygon) |
611 | ite->ContourLine = ite->PoLine.copy(); |
||
13011 | fschmid | 612 | ite->setLineWidth(LineW); |
11705 | fschmid | 613 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
16105 | fschmid | 614 | if ((groupStack.count() != 0) && (groupStackP.count() != 0)) |
615 | groupStackP.top().append(ite); |
||
290 | Franz | 616 | Elements.append(ite); |
617 | } |
||
8017 | fschmid | 618 | lastPath = ""; |
290 | Franz | 619 | currPath = ""; |
620 | } |
||
621 | } |
||
622 | else if (token == "co") |
||
7991 | fschmid | 623 | CurrColor = parseColor(params, eps); |
1488 | fschmid | 624 | else if (token == "corgb") |
7991 | fschmid | 625 | CurrColor = parseColor(params, eps, colorModelRGB); |
290 | Franz | 626 | else if (token == "ci") |
627 | { |
||
6451 | fschmid | 628 | if (Coords.size() != 0) |
629 | { |
||
17293 | jghali | 630 | QPainterPath tmpPath = Coords.toQPainterPath(true); |
631 | tmpPath = boundingBoxRect.intersected(tmpPath); |
||
632 | if ((tmpPath.boundingRect().width() != 0) && (tmpPath.boundingRect().height() != 0)) |
||
6451 | fschmid | 633 | { |
17293 | jghali | 634 | clipCoords.fromQPainterPath(tmpPath); |
20561 | jghali | 635 | z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseY, 10, 10, 0, CommonStrings::None, CommonStrings::None); |
12015 | fschmid | 636 | ite = m_Doc->Items->at(z); |
17293 | jghali | 637 | ite->PoLine = clipCoords.copy(); //FIXME: try to avoid copy if FPointArray when properly shared |
12015 | fschmid | 638 | ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset()); |
639 | ite->ClipEdited = true; |
||
640 | ite->FrameType = 3; |
||
641 | FPoint wh = getMaxClipF(&ite->PoLine); |
||
642 | ite->setWidthHeight(wh.x(),wh.y()); |
||
643 | ite->Clip = FlattenPath(ite->PoLine, ite->Segments); |
||
20699 | craig | 644 | m_Doc->adjustItemSize(ite, true); |
16252 | fschmid | 645 | ite->ContourLine = ite->PoLine.copy(); |
12015 | fschmid | 646 | ite->setItemName( tr("Group%1").arg(m_Doc->GroupCounter)); |
647 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
||
648 | Elements.append(ite); |
||
16105 | fschmid | 649 | if ((groupStack.count() != 0) && (groupStackP.count() != 0)) |
650 | groupStackP.top().append(ite); |
||
12015 | fschmid | 651 | groupStack.push(ite); |
16105 | fschmid | 652 | QList<PageItem*> gElements; |
653 | groupStackP.push(gElements); |
||
12015 | fschmid | 654 | gsStackMarks.push(gsStack.count()); |
655 | m_Doc->GroupCounter++; |
||
6451 | fschmid | 656 | } |
657 | } |
||
4923 | avox | 658 | Coords = FPointArray(0); |
290 | Franz | 659 | lastPath = ""; |
660 | currPath = ""; |
||
661 | } |
||
6451 | fschmid | 662 | else if (token == "gs") |
663 | { |
||
664 | gsStack.push(1); |
||
665 | } |
||
666 | else if (token == "gr") |
||
667 | { |
||
11762 | jghali | 668 | // #6834 : self defense against incorrectly balanced save/restore |
669 | if (gsStack.count() > 0) |
||
670 | gsStack.pop(); |
||
16105 | fschmid | 671 | if ((groupStack.count() != 0) && (groupStackP.count() != 0)) |
6451 | fschmid | 672 | { |
8546 | cbradney | 673 | if (gsStack.count() < static_cast<int>(gsStackMarks.top())) |
6451 | fschmid | 674 | { |
675 | PageItem *ite = groupStack.pop(); |
||
16105 | fschmid | 676 | QList<PageItem*> gList = groupStackP.pop(); |
677 | for (int d = 0; d < gList.count(); d++) |
||
8769 | fschmid | 678 | { |
16105 | fschmid | 679 | Elements.removeAll(gList.at(d)); |
8769 | fschmid | 680 | } |
16105 | fschmid | 681 | m_Doc->groupObjectsToItem(ite, gList); |
6451 | fschmid | 682 | gsStackMarks.pop(); |
683 | } |
||
684 | } |
||
685 | } |
||
290 | Franz | 686 | else if (token == "w") |
687 | { |
||
13497 | jghali | 688 | ScTextStream Lw(¶ms, QIODevice::ReadOnly); |
290 | Franz | 689 | Lw >> LineW; |
690 | } |
||
292 | Franz | 691 | else if (token == "ld") |
692 | { |
||
13497 | jghali | 693 | ScTextStream Lw(¶ms, QIODevice::ReadOnly); |
292 | Franz | 694 | Lw >> dc; |
695 | Lw >> DashOffset; |
||
696 | DashPattern.clear(); |
||
697 | if (dc != 0) |
||
698 | { |
||
699 | for (int dcc = 0; dcc < dc; ++dcc) |
||
700 | { |
||
701 | Lw >> dcp; |
||
702 | DashPattern.append(dcp); |
||
703 | } |
||
704 | } |
||
705 | } |
||
706 | else if (token == "lc") |
||
707 | { |
||
13497 | jghali | 708 | ScTextStream Lw(¶ms, QIODevice::ReadOnly); |
292 | Franz | 709 | Lw >> lcap; |
710 | switch (lcap) |
||
711 | { |
||
712 | case 0: |
||
713 | CapStyle = Qt::FlatCap; |
||
714 | break; |
||
715 | case 1: |
||
716 | CapStyle = Qt::RoundCap; |
||
717 | break; |
||
718 | case 2: |
||
719 | CapStyle = Qt::SquareCap; |
||
720 | break; |
||
721 | default: |
||
722 | CapStyle = Qt::FlatCap; |
||
723 | break; |
||
724 | } |
||
725 | } |
||
726 | else if (token == "lj") |
||
727 | { |
||
13497 | jghali | 728 | ScTextStream Lw(¶ms, QIODevice::ReadOnly); |
292 | Franz | 729 | Lw >> ljoin; |
730 | switch (ljoin) |
||
731 | { |
||
732 | case 0: |
||
733 | JoinStyle = Qt::MiterJoin; |
||
734 | break; |
||
735 | case 1: |
||
736 | JoinStyle = Qt::RoundJoin; |
||
737 | break; |
||
738 | case 2: |
||
739 | JoinStyle = Qt::BevelJoin; |
||
740 | break; |
||
741 | default: |
||
742 | JoinStyle = Qt::MiterJoin; |
||
743 | break; |
||
744 | } |
||
745 | } |
||
4717 | avox | 746 | else if (token == "cp") { |
290 | Franz | 747 | ClosedPath = true; |
4717 | avox | 748 | } |
749 | else if (token == "im") { |
||
4962 | avox | 750 | if ( !Image(params) ) |
751 | ++failedImages; |
||
4717 | avox | 752 | } |
290 | Franz | 753 | lasttoken = token; |
754 | } |
||
755 | f.close(); |
||
6451 | fschmid | 756 | if (groupStack.count() != 0) |
757 | { |
||
758 | while (!groupStack.isEmpty()) |
||
759 | { |
||
760 | PageItem *ite = groupStack.pop(); |
||
16105 | fschmid | 761 | QList<PageItem*> gList = groupStackP.pop(); |
762 | for (int d = 0; d < gList.count(); d++) |
||
8769 | fschmid | 763 | { |
16105 | fschmid | 764 | Elements.removeAll(gList.at(d)); |
8769 | fschmid | 765 | } |
16105 | fschmid | 766 | m_Doc->groupObjectsToItem(ite, gList); |
6451 | fschmid | 767 | } |
768 | } |
||
290 | Franz | 769 | } |
4962 | avox | 770 | if (failedImages > 0) |
771 | { |
||
772 | QString mess = tr("Converting of %1 images failed!").arg(failedImages); |
||
19605 | jghali | 773 | ScMessageBox::critical(0, tr("Error"), mess); |
4962 | avox | 774 | } |
290 | Franz | 775 | } |
776 | |||
4962 | avox | 777 | bool EPSPlug::Image(QString vals) |
4717 | avox | 778 | { |
779 | double x, y, w, h, angle; |
||
780 | int horpix, verpix; |
||
781 | QString filename, device; |
||
13497 | jghali | 782 | ScTextStream Code(&vals, QIODevice::ReadOnly); |
4717 | avox | 783 | Code >> x; |
784 | Code >> y; |
||
785 | Code >> w; |
||
786 | Code >> h; |
||
787 | Code >> angle; |
||
788 | Code >> horpix; |
||
789 | Code >> verpix; |
||
790 | Code >> device; |
||
10394 | cbradney | 791 | filename = Code.readAll().trimmed(); |
4999 | avox | 792 | if (device.startsWith("psd")) { |
793 | filename = filename.mid(0, filename.length()-3) + "psd"; |
||
794 | } |
||
20424 | jghali | 795 | |
10516 | cbradney | 796 | qDebug("%s", QString("import %7 image %1: %2x%3 @ (%4,%5) °%6").arg(filename).arg(w).arg(h).arg(x).arg(y).arg(angle).arg(device).toLocal8Bit().data()); |
4717 | avox | 797 | QString rawfile = filename.mid(0, filename.length()-3) + "dat"; |
798 | QStringList args; |
||
799 | args.append( "-q" ); |
||
800 | args.append( "-dNOPAUSE" ); |
||
20424 | jghali | 801 | args.append( QString("-sDEVICE=%1").arg(device) ); |
4717 | avox | 802 | args.append( "-dBATCH" ); |
803 | args.append( QString("-g%1x%2").arg(horpix).arg(verpix) ); |
||
16577 | craig | 804 | args.append( QString("-sOutputFile=%1").arg(QDir::toNativeSeparators(filename)) ); |
805 | args.append( QDir::toNativeSeparators(rawfile) ); |
||
4717 | avox | 806 | args.append( "-c" ); |
807 | args.append( "showpage" ); |
||
808 | args.append( "quit" ); |
||
10493 | fschmid | 809 | QByteArray finalCmd = args.join(" ").toLocal8Bit(); |
10006 | cbradney | 810 | int ret = System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args); |
4717 | avox | 811 | if (ret != 0) |
812 | { |
||
813 | qDebug("PostScript image conversion failed when calling gs as: \n%s\n", finalCmd.data()); |
||
4986 | avox | 814 | qDebug("Ghostscript diagnostics: %d\n", ret); |
4725 | avox | 815 | QFile diag(filename); |
8501 | cbradney | 816 | if (diag.open(QIODevice::ReadOnly)) { |
8665 | cbradney | 817 | char buf[121]; |
4740 | avox | 818 | long int len; |
819 | bool gs_error = false; |
||
820 | do { |
||
8665 | cbradney | 821 | len = diag.readLine(buf, 120); |
822 | gs_error |= (strstr(buf,"Error")==NULL); |
||
4740 | avox | 823 | if (gs_error) |
8665 | cbradney | 824 | qDebug("\t%s", buf); |
4725 | avox | 825 | } |
4740 | avox | 826 | while (len > 0); |
4725 | avox | 827 | diag.close(); |
4983 | avox | 828 | } |
4725 | avox | 829 | else { |
13085 | jghali | 830 | qDebug("%s", "-- no output --"); |
4725 | avox | 831 | } |
13085 | jghali | 832 | qDebug("%s", "Failed file was:\n"); |
4983 | avox | 833 | QFile dat(rawfile); |
8501 | cbradney | 834 | if (dat.open(QIODevice::ReadOnly)) { |
8665 | cbradney | 835 | char buf[121]; |
4983 | avox | 836 | long int len; |
837 | do { |
||
8665 | cbradney | 838 | len = dat.readLine(buf, 120); |
839 | qDebug("\t%s", buf); |
||
4983 | avox | 840 | } |
8665 | cbradney | 841 | while ( len > 0 && !(strstr(buf, "image")==NULL) ); |
4983 | avox | 842 | dat.close(); |
843 | } |
||
844 | else { |
||
13085 | jghali | 845 | qDebug("%s", "-- empty --"); |
4983 | avox | 846 | } |
4717 | avox | 847 | } |
4923 | avox | 848 | QFile::remove(rawfile); |
20561 | jghali | 849 | int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset(), w, h, LineW, CommonStrings::None, CurrColor); |
5781 | cbradney | 850 | PageItem * ite = m_Doc->Items->at(z); |
851 | ite->setXYPos(m_Doc->currentPage()->xOffset() + x, m_Doc->currentPage()->yOffset() + y); |
||
4717 | avox | 852 | ite->setWidthHeight(w, h); |
853 | ite->clearContents(); |
||
854 | /* FPoint a(x, y); |
||
855 | FPoint b(x+w, y); |
||
856 | FPoint c(x+w, y-h); |
||
857 | FPoint d(x, y-h); |
||
858 | ite->PoLine.resize(0); |
||
859 | ite->PoLine.addQuadPoint(a, a, b, b); |
||
860 | ite->PoLine.addQuadPoint(b, b, c, c); |
||
861 | ite->PoLine.addQuadPoint(c, c, d, d); |
||
862 | ite->PoLine.addQuadPoint(d, d, a, a); |
||
5781 | cbradney | 863 | ite->PoLine.translate(m_Doc->currentPage->xOffset() - x, m_Doc->currentPage->yOffset() - y); |
4717 | avox | 864 | ite->ClipEdited = true; |
865 | ite->Clip = FlattenPath(ite->PoLine, ite->Segments); |
||
4976 | avox | 866 | */ |
5781 | cbradney | 867 | m_Doc->loadPict(filename, ite, -1); |
4717 | avox | 868 | ite->setRotation(angle); |
869 | ite->setImageScalingMode(false, true); // fit to frame, keep ratio |
||
20699 | craig | 870 | // m_Doc->view()->adjustItemSize(ite); |
4962 | avox | 871 | Elements.append(ite); |
872 | return ret == 0; |
||
4717 | avox | 873 | } |
874 | |||
875 | |||
290 | Franz | 876 | void EPSPlug::LineTo(FPointArray *i, QString vals) |
877 | { |
||
2877 | cbradney | 878 | if (vals.isEmpty()) |
290 | Franz | 879 | return; |
880 | double x1, x2, y1, y2; |
||
13457 | cbradney | 881 | x1 = ScCLocale::toDoubleC(vals.section(' ', 0, 0, QString::SectionSkipEmpty)); |
882 | y1 = ScCLocale::toDoubleC(vals.section(' ', 1, 1, QString::SectionSkipEmpty)); |
||
883 | x2 = ScCLocale::toDoubleC(vals.section(' ', 2, 2, QString::SectionSkipEmpty)); |
||
884 | y2 = ScCLocale::toDoubleC(vals.section(' ', 3, 3, QString::SectionSkipEmpty)); |
||
290 | Franz | 885 | if ((!FirstM) && (WasM)) |
886 | i->setMarker(); |
||
887 | FirstM = false; |
||
888 | WasM = false; |
||
889 | i->addPoint(FPoint(x1, y1)); |
||
890 | i->addPoint(FPoint(x1, y1)); |
||
891 | i->addPoint(FPoint(x2, y2)); |
||
892 | i->addPoint(FPoint(x2, y2)); |
||
893 | } |
||
894 | |||
895 | void EPSPlug::Curve(FPointArray *i, QString vals) |
||
896 | { |
||
2877 | cbradney | 897 | if (vals.isEmpty()) |
290 | Franz | 898 | return; |
899 | double x1, x2, y1, y2, x3, y3, x4, y4; |
||
13457 | cbradney | 900 | x1 = ScCLocale::toDoubleC(vals.section(' ', 0, 0, QString::SectionSkipEmpty)); |
901 | y1 = ScCLocale::toDoubleC(vals.section(' ', 1, 1, QString::SectionSkipEmpty)); |
||
902 | x2 = ScCLocale::toDoubleC(vals.section(' ', 2, 2, QString::SectionSkipEmpty)); |
||
903 | y2 = ScCLocale::toDoubleC(vals.section(' ', 3, 3, QString::SectionSkipEmpty)); |
||
904 | x3 = ScCLocale::toDoubleC(vals.section(' ', 4, 4, QString::SectionSkipEmpty)); |
||
905 | y3 = ScCLocale::toDoubleC(vals.section(' ', 5, 5, QString::SectionSkipEmpty)); |
||
906 | x4 = ScCLocale::toDoubleC(vals.section(' ', 6, 6, QString::SectionSkipEmpty)); |
||
907 | y4 = ScCLocale::toDoubleC(vals.section(' ', 7, 7, QString::SectionSkipEmpty)); |
||
290 | Franz | 908 | if ((!FirstM) && (WasM)) |
909 | i->setMarker(); |
||
910 | FirstM = false; |
||
911 | WasM = false; |
||
912 | i->addPoint(FPoint(x1, y1)); |
||
913 | i->addPoint(FPoint(x2, y2)); |
||
914 | i->addPoint(FPoint(x4, y4)); |
||
915 | i->addPoint(FPoint(x3, y3)); |
||
916 | } |
||
917 | |||
7991 | fschmid | 918 | QString EPSPlug::parseColor(QString vals, bool eps, colorModel model) |
290 | Franz | 919 | { |
4546 | subik | 920 | QString ret = CommonStrings::None; |
2877 | cbradney | 921 | if (vals.isEmpty()) |
290 | Franz | 922 | return ret; |
1488 | fschmid | 923 | double c, m, y, k, r, g, b; |
2886 | fschmid | 924 | ScColor tmp; |
13497 | jghali | 925 | ScTextStream Code(&vals, QIODevice::ReadOnly); |
1488 | fschmid | 926 | if (model == colorModelRGB) |
290 | Franz | 927 | { |
1488 | fschmid | 928 | Code >> r; |
929 | Code >> g; |
||
930 | Code >> b; |
||
931 | Code >> Opacity; |
||
7928 | fschmid | 932 | // Why adding 0.5 here color values range from 0 to 255 not 1 to 256 ?? |
933 | /* int Rc = static_cast<int>(r * 255 + 0.5); |
||
1488 | fschmid | 934 | int Gc = static_cast<int>(g * 255 + 0.5); |
7928 | fschmid | 935 | int Bc = static_cast<int>(b * 255 + 0.5); */ |
936 | int Rc = qRound(r * 255); |
||
937 | int Gc = qRound(g * 255); |
||
938 | int Bc = qRound(b * 255); |
||
1488 | fschmid | 939 | tmp.setColorRGB(Rc, Gc, Bc); |
290 | Franz | 940 | } |
1488 | fschmid | 941 | else |
942 | { |
||
943 | Code >> c; |
||
944 | Code >> m; |
||
945 | Code >> y; |
||
946 | Code >> k; |
||
947 | Code >> Opacity; |
||
7928 | fschmid | 948 | int Cc = qRound(c * 255); |
949 | int Mc = qRound(m * 255); |
||
950 | int Yc = qRound(y * 255); |
||
951 | int Kc = qRound(k * 255); |
||
1488 | fschmid | 952 | tmp.setColor(Cc, Mc, Yc, Kc); |
953 | } |
||
15771 | fschmid | 954 | tmp.setSpotColor(false); |
955 | tmp.setRegistrationColor(false); |
||
956 | QString namPrefix = "FromEPS"; |
||
957 | if (!eps) |
||
958 | namPrefix = "FromPS"; |
||
959 | QString fNam = m_Doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp); |
||
960 | ret = fNam; |
||
290 | Franz | 961 | return ret; |
962 | } |