int callGS(const QStringList& args_in, const QString device) { QString cmd; QStringList args; PrefsManager* prefsManager = PrefsManager::instance(); args.append( "-q" ); args.append( "-dNOPAUSE" ); args.append( "-dQUIET" ); args.append( "-dPARANOIDSAFER" ); args.append( "-dBATCH" ); // Choose rendering device if (!device.isEmpty()) args.append( QString("-sDEVICE=%1").arg(device) ); // user specified device else if (!ScCore->havePNGAlpha()) args.append( "-sDEVICE=png16m" ); else args.append( "-sDEVICE=pngalpha" ); // and antialiasing if (prefsManager->appPrefs.gs_AntiAliasText) args.append( "-dTextAlphaBits=4" ); if (prefsManager->appPrefs.gs_AntiAliasGraphics) args.append( "-dGraphicsAlphaBits=4" ); // Add any extra font paths being used by Scribus to gs's font search path PrefsContext *pc = PrefsManager::instance()->prefsFile->getContext("Fonts"); PrefsTable *extraFonts = pc->getTable("ExtraFontDirs"); const char sep = ScPaths::envPathSeparator; if (extraFonts->getRowCount() >= 1) cmd = QString("-sFONTPATH=%1").arg(QDir::convertSeparators(extraFonts->get(0,0))); for (int i = 1; i < extraFonts->getRowCount(); ++i) cmd += QString("%1%2").arg(sep).arg(QDir::convertSeparators(extraFonts->get(i,0))); if( !cmd.isEmpty() ) args.append( cmd ); args += args_in; args.append("-c"); args.append("showpage"); // qDebug(args.join(" ").toAscii()); return System( getShortPathName(prefsManager->ghostscriptExecutable()), args ); }
int callGS(const QString& args_in, const QString device) { PrefsManager* prefsManager=PrefsManager::instance(); QString cmd1 = getShortPathName(prefsManager->ghostscriptExecutable()); cmd1 += " -q -dNOPAUSE -dQUIET -dPARANOIDSAFER -dBATCH"; // Choose rendering device if (!device.isEmpty()) // user specified device cmd1 += " -sDEVICE="+device; else if (!ScCore->havePNGAlpha()) cmd1 += " -sDEVICE=png16m"; else cmd1 += " -sDEVICE=pngalpha"; // and antialiasing if (prefsManager->appPrefs.extToolPrefs.gs_AntiAliasText) cmd1 += " -dTextAlphaBits=4"; if (prefsManager->appPrefs.extToolPrefs.gs_AntiAliasGraphics) cmd1 += " -dGraphicsAlphaBits=4"; // Add any extra font paths being used by Scribus to gs's font search path PrefsContext *pc = PrefsManager::instance()->prefsFile->getContext("Fonts"); PrefsTable *extraFonts = pc->getTable("ExtraFontDirs"); #ifndef _WIN32 if (extraFonts->getRowCount() >= 1) cmd1 += QString(" -sFONTPATH='%1'").arg(extraFonts->get(0,0)); for (int i = 1; i < extraFonts->getRowCount(); ++i) cmd1 += QString(":'%1'").arg(extraFonts->get(i,0)); #else if (extraFonts->getRowCount() >= 1) cmd1 += QString(" -sFONTPATH=\"%1\"").arg(extraFonts->get(0,0)); for (int i = 1; i < extraFonts->getRowCount(); ++i) cmd1 += QString(";\"%1\"").arg(extraFonts->get(i,0)); #endif // then add any user specified args and run gs cmd1 += " " + args_in + " -c showpage"; // qDebug("Calling gs as: %s", cmd1.ascii()); return system(cmd1.toLocal8Bit().constData()); }
void ScripterCore::SavePlugPrefs() { PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin"); if (!prefs) { qDebug("scriptplugin: Unable to load prefs"); return; } PrefsTable* prefRecentScripts = prefs->getTable("recentscripts"); if (!prefRecentScripts) { qDebug("scriptplugin: Unable to get recent scripts"); return; } for (int i = 0; i < RecentScripts.count(); i++) { prefRecentScripts->set(i, 0, RecentScripts[i]); } // then save more general preferences prefs->set("extensionscripts", m_enableExtPython); prefs->set("importall", m_importAllNames); prefs->set("startupscript", m_startupScript); }
void ScripterCore::ReadPlugPrefs() { PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin"); if (!prefs) { qDebug("scriptplugin: Unable to load prefs"); return; } PrefsTable* prefRecentScripts = prefs->getTable("recentscripts"); if (!prefRecentScripts) { qDebug("scriptplugin: Unable to get recent scripts"); return; } // Load recent scripts from the prefs for (int i = 0; i < prefRecentScripts->getRowCount(); i++) SavedRecentScripts.append(prefRecentScripts->get(i,0)); // then get more general preferences m_enableExtPython = prefs->getBool("extensionscripts",false); m_importAllNames = prefs->getBool("importall",true); m_startupScript = prefs->get("startupscript", QString::null); // and have the console window set up its position }
bool EPSPlug::convert(QString fn, double x, double y, double b, double h) { QStringList args; QString cmd, cmd1, cmd2, cmd3, tmp, tmp2, tmp3, tmp4; // import.prolog do not cope with filenames containing blank spaces // so take care that output filename does not (win32 compatibility) QString tmpFile = getShortPathName(ScPaths::getTempFileDir())+ "/ps.out"; QString errFile = getShortPathName(ScPaths::getTempFileDir())+ "/ps.err"; QString pfad = ScPaths::instance().libDir(); QString pfad2 = QDir::toNativeSeparators(pfad + "import.prolog"); QFileInfo fi = QFileInfo(fn); QString ext = fi.suffix().toLower(); if (progressDialog) { progressDialog->setOverallProgress(1); qApp->processEvents(); } /* // Destill the eps with ghostscript to get a clean eps file QString cleanFile = getShortPathName(ScPaths::getTempFileDir())+ "/clean.eps"; args.append( "-q" ); args.append( "-dNOPAUSE" ); args.append( "-sDEVICE=epswrite" ); args.append( "-dBATCH" ); args.append( "-dSAFER" ); args.append( "-dDEVICEWIDTH=250000" ); args.append( "-dDEVICEHEIGHT=250000" ); args.append( QString("-sOutputFile=%1").arg(QDir::toNativeSeparators(cleanFile)) ); args.append( QDir::toNativeSeparators(fn) ); System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args, errFile, errFile, &cancel); args.clear(); */ args.append( "-q" ); args.append( "-dNOPAUSE" ); args.append( "-dNODISPLAY" ); args.append( "-dBATCH" ); args.append( "-dDELAYBIND" ); // Add any extra font paths being used by Scribus to gs's font search // path We have to use Scribus's prefs context, not a plugin context, to // get to the required information. PrefsContext *pc = PrefsManager::instance()->prefsFile->getContext("Fonts"); PrefsTable *extraFonts = pc->getTable("ExtraFontDirs"); const char sep = ScPaths::envPathSeparator; if (extraFonts->getRowCount() >= 1) cmd = QString("-sFONTPATH=%1").arg(extraFonts->get(0,0)); for (int i = 1; i < extraFonts->getRowCount(); ++i) cmd += QString("%1%2").arg(sep).arg(extraFonts->get(i,0)); if( !cmd.isEmpty() ) args.append( cmd ); // then finish building the command and call gs args.append( QString("-g%1x%2").arg(tmp2.setNum(qRound((b-x)*4))).arg(tmp3.setNum(qRound((h-y)*4))) ); args.append( "-r288"); args.append( "-dTextAlphaBits=4" ); args.append( "-dGraphicsAlphaBits=4" ); args.append( "-c" ); args.append( tmp.setNum(-x) ); args.append( tmp.setNum(-y) ); args.append( "translate" ); args.append( QString("-sTraceFile=%1").arg(QDir::toNativeSeparators(tmpFile)) ); QString exportPath = m_Doc->DocName + "-" + fi.baseName(); QFileInfo exportFi(exportPath); if ( !exportFi.isWritable() ) { PrefsContext* docContext = PrefsManager::instance()->prefsFile->getContext("docdirs", false); QString docDir = "."; QString prefsDocDir=PrefsManager::instance()->documentDir(); if (!prefsDocDir.isEmpty()) docDir = docContext->get("docsopen", prefsDocDir); else docDir = docContext->get("docsopen", "."); exportFi.setFile(docDir + "/" + exportFi.baseName()); } //qDebug() << QString("using export path %1").arg(exportFi.absFilePath()); args.append( QString("-sExportFiles=%1").arg(QDir::toNativeSeparators(exportFi.absoluteFilePath())) ); args.append( pfad2 ); args.append( QDir::toNativeSeparators(fn) ); args.append( "-c" ); args.append( "flush" ); args.append( "cfile" ); args.append( "closefile" ); args.append( "quit" ); QByteArray finalCmd = args.join(" ").toLocal8Bit(); int ret = System(getShortPathName(PrefsManager::instance()->ghostscriptExecutable()), args, errFile, errFile, &cancel); if (ret != 0 && !cancel) { qDebug("PostScript import failed when calling gs as: \n%s\n", finalCmd.data()); qDebug("%s", "Ghostscript diagnostics:\n"); QFile diag(errFile); if (diag.open(QIODevice::ReadOnly) && !diag.atEnd() ) { char buf[121]; while (diag.readLine(buf, 120) > 0) { qDebug("\t%s", buf); } diag.close(); } else { qDebug("%s", "-- no output --"); } if (progressDialog) progressDialog->close(); QString mess = tr("Importing File:\n%1\nfailed!").arg(fn); ScMessageBox::critical(0, tr("Fatal Error"), mess); return false; } if(progressDialog && !cancel) { progressDialog->setOverallProgress(2); progressDialog->setLabel("GI", tr("Generating Items")); qApp->processEvents(); } if (!cancel) { parseOutput(tmpFile, extensionIndicatesEPSorPS(ext)); } QFile::remove(tmpFile); // QFile::remove(cleanFile); if (progressDialog) progressDialog->close(); return true; }