r14792 by fschmid - Start of moving the color loader code into the fileplugins.
scribus-commit
scribus-commit at lists.scribus.net
Mon Feb 22 13:00:55 CET 2010
Revision: 14792
Author: fschmid
Date: 2010-02-22T11:53:28.354006Z
Commit message: Start of moving the color loader code into the fileplugins.
Changeset:
M /trunk/Scribus/scribus/plugins/import/ai/importai.cpp
M /trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
M /trunk/Scribus/scribus/util_color.cpp
M /trunk/Scribus/scribus/plugins/import/ai/importaiplugin.h
M /trunk/Scribus/scribus/loadsaveplugin.cpp
M /trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
M /trunk/Scribus/scribus/plugins/import/ai/importai.h
M /trunk/Scribus/scribus/loadsaveplugin.h
M /trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
M /trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
M /trunk/Scribus/scribus/plugins/import/ai/importaiplugin.cpp
Diffs:
Index: scribus/loadsaveplugin.h
===================================================================
--- scribus/loadsaveplugin.h (revision 14791)
+++ scribus/loadsaveplugin.h (revision 14792)
@@ -56,6 +56,8 @@
// Static functions:
// Return a list of file extensions
+ static const QStringList getExtensionsForColors(const int id = 47);
+ // Return a list of file extensions
static const QStringList getExtensionsForImport(const int id = 47);
// Return a list of file extensions
static const QStringList getExtensionsForPreview(const int id = 47);
@@ -183,9 +185,9 @@
{
public:
// Default ctor to make QValueList happy
- FileFormat() : load(false), save(false), thumb(false), plug(0) {}
+ FileFormat() : load(false), save(false), thumb(false), colorReading(false), plug(0) {}
// Standard ctor that sets up a valid FileFormat
- FileFormat(LoadSavePlugin * plug) : load(false), save(false), thumb(false), plug(plug) {}
+ FileFormat(LoadSavePlugin * plug) : load(false), save(false), thumb(false), colorReading(false), plug(plug) {}
// Load a file with this format
bool loadFile(const QString & fileName, int flags, int index = 0) const;
// Save a file with this format
@@ -230,6 +232,8 @@
bool save;
// Do we support thumbnails
bool thumb;
+ // Can we load colors?
+ bool colorReading;
// Priority of this format from 0 (lowest, tried last) to
// 255 (highest, tried first). 64-128 recommended in general.
// Priority controls the order options are displayed in when a file
Index: scribus/loadsaveplugin.cpp
===================================================================
--- scribus/loadsaveplugin.cpp (revision 14791)
+++ scribus/loadsaveplugin.cpp (revision 14792)
@@ -60,6 +60,38 @@
return getDialogFilter(false);
}
+const QStringList LoadSavePlugin::getExtensionsForColors(const int id)
+{
+ QList<FileFormat>::const_iterator it(findFormat(id));
+ QList<FileFormat>::const_iterator itEnd(formats.constEnd());
+ QStringList filterList;
+ // We know the list is sorted by id, then priority, so we can just take the
+ // highest priority entry for each ID, and we can start with the first entry
+ // in the list.
+ //First, check if we even have any plugins to load with
+ if (it!=itEnd)
+ {
+ if (((*it).load) && ((*it).colorReading))
+ filterList.append((*it).fileExtensions);
+ unsigned int lastID = (*it).formatId;
+ ++it;
+ for ( ; it != itEnd ; ++it )
+ {
+ // Find the next load/save (as appropriate) plugin for the next format type
+ if ((((*it).load) && ((*it).colorReading)) && ((*it).formatId > lastID))
+ {
+ // And add it to the filter list, since we know it's
+ // the highest priority because of the sort order.
+ filterList.append((*it).fileExtensions);
+ lastID = (*it).formatId;
+ }
+ }
+ }
+ else
+ qDebug("%s", tr("No File Loader Plugins Found").toLocal8Bit().data());
+ return filterList;
+}
+
const QStringList LoadSavePlugin::getExtensionsForImport(const int id)
{
QList<FileFormat>::const_iterator it(findFormat(id));
Index: scribus/util_color.cpp
===================================================================
--- scribus/util_color.cpp (revision 14791)
+++ scribus/util_color.cpp (revision 14792)
@@ -32,6 +32,7 @@
#include "sctextstream.h"
#include "sccolorengine.h"
#include "fileloader.h"
+#include "loadsaveplugin.h"
#include "plugins/formatidlist.h"
#include "util.h"
#include "util_formats.h"
@@ -589,7 +590,7 @@
{
QFileInfo fi = QFileInfo(fileName);
QString ext = fi.suffix().toLower();
- if (extensionIndicatesEPSorPS(ext) || (ext == "ai"))
+ if (extensionIndicatesEPSorPS(ext))
{
QString tmp, tmp2, FarNam;
double c, m, y, k;
@@ -692,43 +693,6 @@
}
if (tmp.startsWith("%%EndComments"))
{
- if (ext == "ai")
- {
- while (!ts.atEnd())
- {
- bool isX = false;
- tmp = readLinefromDataStream(ts);
- if ((tmp.endsWith("Xa") || tmp.endsWith(" k") || tmp.endsWith(" x")) && (tmp.length() > 4))
- {
- ScTextStream ts2(&tmp, QIODevice::ReadOnly);
- ts2 >> c >> m >> y >> k;
- if (tmp.endsWith(" x"))
- {
- isX = true;
- int an = tmp.indexOf("(");
- int en = tmp.lastIndexOf(")");
- FarNam = tmp.mid(an+1, en-an-1);
- FarNam = FarNam.simplified();
- }
- tmp = readLinefromDataStream(ts);
- if (tmp.endsWith("Pc"))
- {
- if (!isX)
- {
- tmp = tmp.trimmed();
- tmp = tmp.remove(0,1);
- int en = tmp.indexOf(")");
- FarNam = tmp.mid(0, en);
- FarNam = FarNam.simplified();
- }
- cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
- cc.setSpotColor(true);
- if (!EditColors.contains(FarNam))
- EditColors.insert(FarNam, cc);
- }
- }
- }
- }
if (!isAtend)
break;
}
@@ -738,19 +702,22 @@
}
else
{
- FileLoader fl(fileName);
- int test = fl.TestFile();
- if ((test == FORMATID_SLA150IMPORT) || (test == FORMATID_SLA134IMPORT) ||
- (test == FORMATID_SLA13XIMPORT) || (test == FORMATID_SLA12XIMPORT))
+ QStringList allFormatsV = LoadSavePlugin::getExtensionsForColors();
+ if (allFormatsV.contains(ext))
{
- ColorList LColors;
- if (fl.ReadColors(fileName, LColors))
+ FileLoader fl(fileName);
+ int testResult = fl.TestFile();
+ if (testResult != -1)
{
- ColorList::Iterator it;
- for (it = LColors.begin(); it != LColors.end(); ++it)
+ ColorList LColors;
+ if (fl.ReadColors(fileName, LColors))
{
- if (!EditColors.contains(it.key()))
- EditColors.insert(it.key(), it.value());
+ ColorList::Iterator it;
+ for (it = LColors.begin(); it != LColors.end(); ++it)
+ {
+ if (!EditColors.contains(it.key()))
+ EditColors.insert(it.key(), it.value());
+ }
}
}
}
Index: scribus/plugins/fileloader/scribus12format/scribus12format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus12format/scribus12format.cpp (revision 14791)
+++ scribus/plugins/fileloader/scribus12format/scribus12format.cpp (revision 14792)
@@ -111,10 +111,12 @@
fmt.formatId = FORMATID_SLA12XIMPORT;
fmt.load = true;
fmt.save = false;
+ fmt.colorReading = true;
fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive);
fmt.mimeTypes = QStringList();
fmt.mimeTypes.append("application/x-scribus");
+ fmt.fileExtensions = QStringList() << "sla" << "sla.gz" << "scd" << "scd.gz";
fmt.priority = 64;
registerFormat(fmt);
}
Index: scribus/plugins/fileloader/scribus13format/scribus13format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus13format/scribus13format.cpp (revision 14791)
+++ scribus/plugins/fileloader/scribus13format/scribus13format.cpp (revision 14792)
@@ -94,10 +94,12 @@
fmt.formatId = FORMATID_SLA13XIMPORT;
fmt.load = true;
fmt.save = false; //Only support 134format saving in 134cvs
+ fmt.colorReading = true;
fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive);
fmt.mimeTypes = QStringList();
fmt.mimeTypes.append("application/x-scribus");
+ fmt.fileExtensions = QStringList() << "sla" << "sla.gz" << "scd" << "scd.gz";
fmt.priority = 64;
registerFormat(fmt);
}
Index: scribus/plugins/fileloader/scribus150format/scribus150format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus150format/scribus150format.cpp (revision 14791)
+++ scribus/plugins/fileloader/scribus150format/scribus150format.cpp (revision 14792)
@@ -98,10 +98,12 @@
fmt.formatId = FORMATID_SLA150IMPORT;
fmt.load = true;
fmt.save = true;
+ fmt.colorReading = true;
fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive);
fmt.mimeTypes = QStringList();
fmt.mimeTypes.append("application/x-scribus");
+ fmt.fileExtensions = QStringList() << "sla" << "sla.gz" << "scd" << "scd.gz";
fmt.priority = 64;
registerFormat(fmt);
}
Index: scribus/plugins/fileloader/scribus134format/scribus134format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus134format/scribus134format.cpp (revision 14791)
+++ scribus/plugins/fileloader/scribus134format/scribus134format.cpp (revision 14792)
@@ -96,10 +96,12 @@
fmt.formatId = FORMATID_SLA134IMPORT;
fmt.load = true;
fmt.save = true;
+ fmt.colorReading = true;
fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive);
fmt.mimeTypes = QStringList();
fmt.mimeTypes.append("application/x-scribus");
+ fmt.fileExtensions = QStringList() << "sla" << "sla.gz" << "scd" << "scd.gz";
fmt.priority = 64;
registerFormat(fmt);
}
Index: scribus/plugins/import/ai/importaiplugin.cpp
===================================================================
--- scribus/plugins/import/ai/importaiplugin.cpp (revision 14791)
+++ scribus/plugins/import/ai/importaiplugin.cpp (revision 14792)
@@ -100,6 +100,7 @@
fmt.load = true;
fmt.save = false;
fmt.thumb = true;
+ fmt.colorReading = true;
fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::AI); // MIME types
fmt.priority = 64; // Priority
registerFormat(fmt);
@@ -185,3 +186,23 @@
delete dia;
return ret;
}
+
+bool ImportAIPlugin::readColors(const QString& fileName, ColorList &colors)
+{
+ bool wasUndo = false;
+ if( fileName.isEmpty() )
+ return false;
+ if (UndoManager::undoEnabled())
+ {
+ UndoManager::instance()->setUndoEnabled(false);
+ wasUndo = true;
+ }
+ m_Doc = NULL;
+ AIPlug *dia = new AIPlug(m_Doc, lfCreateThumbnail);
+ Q_CHECK_PTR(dia);
+ bool ret = dia->readColors(fileName, colors);
+ if (wasUndo)
+ UndoManager::instance()->setUndoEnabled(true);
+ delete dia;
+ return ret;
+}
Index: scribus/plugins/import/ai/importai.cpp
===================================================================
--- scribus/plugins/import/ai/importai.cpp (revision 14791)
+++ scribus/plugins/import/ai/importai.cpp (revision 14792)
@@ -253,6 +253,95 @@
return tmpImage;
}
+bool AIPlug::readColors(const QString& fNameIn, ColorList & colors)
+{
+ QString fName = fNameIn;
+ bool success = false;
+ cancel = false;
+ double x, y, b, h;
+ convertedPDF = false;
+ CustColors.clear();
+ importedColors.clear();
+ importedGradients.clear();
+ importedPatterns.clear();
+ QFileInfo fi = QFileInfo(fName);
+/* Check if the file is an old style AI or one of the newer PDF wrapped ones */
+ QFile fT(fName);
+ if (fT.open(QIODevice::ReadOnly))
+ {
+ QByteArray tempBuf(9, ' ');
+ fT.read(tempBuf.data(), 8);
+ fT.close();
+ if (tempBuf.startsWith("%PDF"))
+ {
+ QFileInfo bF2(fName);
+ QString tmpFile = ScPaths::getTempFileDir()+ "/"+bF2.baseName()+"_tmp.ai";
+ if (!extractFromPDF(fName, tmpFile))
+ return false;
+ convertedPDF = true;
+ fName = tmpFile;
+ }
+ }
+ QFile fT2(fName);
+ if (fT2.open(QIODevice::ReadOnly))
+ {
+ QByteArray tempBuf(25, ' ');
+ fT2.read(tempBuf.data(), 20);
+ fT2.close();
+ /* Illustrator CS files might be compressed
+ the compressed Data starts right after the "%AI12_CompressedData" comment
+ Compression is a simple zlib compression */
+ if (tempBuf.startsWith("%AI12_CompressedData"))
+ decompressAIData(fName);
+ }
+ progressDialog = NULL;
+/* Set default Page to size defined in Preferences */
+ x = 0.0;
+ y = 0.0;
+ b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
+ h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
+ parseHeader(fName, x, y, b, h);
+ docX = x;
+ docY = y;
+ docWidth = b - x;
+ docHeight = h - y;
+ m_Doc = new ScribusDoc();
+ m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
+ m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
+ m_Doc->addPage(0);
+ m_Doc->setGUI(false, ScCore->primaryMainWindow(), 0);
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ ColorList::Iterator it;
+ for (it = CustColors.begin(); it != CustColors.end(); ++it)
+ {
+ if (!m_Doc->PageColors.contains(it.key()))
+ {
+ m_Doc->PageColors.insert(it.key(), it.value());
+ importedColors.append(it.key());
+ }
+ }
+ Elements.clear();
+ m_Doc->setLoading(true);
+ m_Doc->DoDrawing = false;
+ m_Doc->scMW()->setScriptRunning(true);
+ QString CurDirP = QDir::currentPath();
+ QDir::setCurrent(fi.path());
+ convert(fName);
+ if (importedColors.count() != 0)
+ {
+ colors = m_Doc->PageColors;
+ success = true;
+ }
+ m_Doc->scMW()->setScriptRunning(false);
+ m_Doc->setLoading(false);
+ delete m_Doc;
+ QDir::setCurrent(CurDirP);
+ if (convertedPDF)
+ QFile::remove(fName);
+ return success;
+}
+
bool AIPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
{
QString fName = fNameIn;
@@ -769,12 +858,13 @@
{
QString tmp, BBox, tmp2, FarNam;
ScColor cc;
-// double c, m, yc, k;
+ double c, m, yc, k;
bool found = false;
QFile f(fName);
if (f.open(QIODevice::ReadOnly))
{
/* Try to find Bounding Box */
+ bool isAtend = false;
QDataStream ts(&f);
while (!ts.atEnd())
{
@@ -826,8 +916,133 @@
if (res.count() > 0)
docTitle = res[0];
}
+ if ((tmp.startsWith("%%CMYKCustomColor")) || (tmp.startsWith("%%CMYKProcessColor")))
+ {
+ if (tmp.contains("(atend)"))
+ isAtend = true;
+ else
+ {
+ if (tmp.startsWith("%%CMYKCustomColor"))
+ tmp = tmp.remove(0,18);
+ else if (tmp.startsWith("%%CMYKProcessColor"))
+ tmp = tmp.remove(0,19);
+ ScTextStream ts2(&tmp, QIODevice::ReadOnly);
+ ts2 >> c >> m >> yc >> k;
+ FarNam = ts2.readAll();
+ FarNam = FarNam.trimmed();
+ FarNam = FarNam.remove(0,1);
+ FarNam = FarNam.remove(FarNam.length()-1,1);
+ FarNam = FarNam.simplified();
+ cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc), qRound(255 * k));
+ cc.setSpotColor(true);
+ if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
+ CustColors.insert(FarNam, cc);
+ while (!ts.atEnd())
+ {
+ quint64 oldPos = ts.device()->pos();
+ tmp = readLinefromDataStream(ts);
+ if (!tmp.startsWith("%%+"))
+ {
+ ts.device()->seek(oldPos);
+ break;
+ }
+ tmp = tmp.remove(0,3);
+ ScTextStream ts2(&tmp, QIODevice::ReadOnly);
+ ts2 >> c >> m >> yc >> k;
+ FarNam = ts2.readAll();
+ FarNam = FarNam.trimmed();
+ FarNam = FarNam.remove(0,1);
+ FarNam = FarNam.remove(FarNam.length()-1,1);
+ FarNam = FarNam.simplified();
+ cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc), qRound(255 * k));
+ cc.setSpotColor(true);
+ if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
+ CustColors.insert(FarNam, cc);
+ }
+ }
+ }
+ if ((tmp.startsWith("%%RGBCustomColor")) || (tmp.startsWith("%%RGBProcessColor")))
+ {
+ if (tmp.contains("(atend)"))
+ isAtend = true;
+ else
+ {
+ if (tmp.startsWith("%%RGBCustomColor"))
+ tmp = tmp.remove(0,17);
+ else if (tmp.startsWith("%%RGBProcessColor"))
+ tmp = tmp.remove(0,18);
+ ScTextStream ts2(&tmp, QIODevice::ReadOnly);
+ ts2 >> c >> m >> yc;
+ FarNam = ts2.readAll();
+ FarNam = FarNam.trimmed();
+ FarNam = FarNam.remove(0,1);
+ FarNam = FarNam.remove(FarNam.length()-1,1);
+ FarNam = FarNam.simplified();
+ cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc));
+ if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
+ CustColors.insert(FarNam, cc);
+ while (!ts.atEnd())
+ {
+ quint64 oldPos = ts.device()->pos();
+ tmp = readLinefromDataStream(ts);
+ if (!tmp.startsWith("%%+"))
+ {
+ ts.device()->seek(oldPos);
+ break;
+ }
+ tmp = tmp.remove(0,3);
+ ScTextStream ts2(&tmp, QIODevice::ReadOnly);
+ ts2 >> c >> m >> yc;
+ FarNam = ts2.readAll();
+ FarNam = FarNam.trimmed();
+ FarNam = FarNam.remove(0,1);
+ FarNam = FarNam.remove(FarNam.length()-1,1);
+ FarNam = FarNam.simplified();
+ cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc));
+ if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
+ CustColors.insert(FarNam, cc);
+ }
+ }
+ }
if (tmp.startsWith("%%EndComments"))
- break;
+ {
+ while (!ts.atEnd())
+ {
+ bool isX = false;
+ tmp = readLinefromDataStream(ts);
+ if ((tmp.endsWith("Xa") || tmp.endsWith(" k") || tmp.endsWith(" x")) && (tmp.length() > 4))
+ {
+ ScTextStream ts2(&tmp, QIODevice::ReadOnly);
+ ts2 >> c >> m >> yc >> k;
+ if (tmp.endsWith(" x"))
+ {
+ isX = true;
+ int an = tmp.indexOf("(");
+ int en = tmp.lastIndexOf(")");
+ FarNam = tmp.mid(an+1, en-an-1);
+ FarNam = FarNam.simplified();
+ }
+ tmp = readLinefromDataStream(ts);
+ if (tmp.endsWith("Pc"))
+ {
+ if (!isX)
+ {
+ tmp = tmp.trimmed();
+ tmp = tmp.remove(0,1);
+ int en = tmp.indexOf(")");
+ FarNam = tmp.mid(0, en);
+ FarNam = FarNam.simplified();
+ }
+ cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc), qRound(255 * k));
+ cc.setSpotColor(true);
+ if (!CustColors.contains(FarNam))
+ CustColors.insert(FarNam, cc);
+ }
+ }
+ }
+ if (!isAtend)
+ break;
+ }
}
f.close();
if (found)
@@ -841,7 +1056,6 @@
h = ScCLocale::toDoubleC(bb[3]);
}
}
- importColorsFromFile(fName, CustColors);
}
return found;
}
Index: scribus/plugins/import/ai/importaiplugin.h
===================================================================
--- scribus/plugins/import/ai/importaiplugin.h (revision 14791)
+++ scribus/plugins/import/ai/importaiplugin.h (revision 14792)
@@ -34,6 +34,7 @@
virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const;
virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
virtual QImage readThumbnail(const QString& fileName);
+ virtual bool readColors(const QString& fileName, ColorList & colors);
virtual void addToMainWindowMenu(ScribusMainWindow *) {};
public slots:
Index: scribus/plugins/import/ai/importai.h
===================================================================
--- scribus/plugins/import/ai/importai.h (revision 14791)
+++ scribus/plugins/import/ai/importai.h (revision 14792)
@@ -53,6 +53,7 @@
*/
bool import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
QImage readThumbnail(QString fn);
+ bool readColors(const QString& fileName, ColorList & colors);
private:
More information about the scribus-commit
mailing list