Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 11836 → Rev 11839

/trunk/Scribus/scribus/cmykfw.cpp
42,6 → 42,7
#include "scrspinbox.h"
#include "util.h"
#include "util_color.h"
#include "util_formats.h"
#include "util_icon.h"
 
 
615,104 → 616,208
}
if (n != 0)
{
QFile fiC(pfadC2);
if (fiC.open(QIODevice::ReadOnly))
QFileInfo fi = QFileInfo(pfadC2);
QString ext = fi.suffix().toLower();
if (extensionIndicatesEPSorPS(ext) || (ext == "ai"))
{
QString ColorEn, Cname;
int Rval, Gval, Bval, Kval;
QTextStream tsC(&fiC);
ColorEn = tsC.readLine();
if (ColorEn.startsWith("<?xml version="))
QString tmp, tmp2, FarNam;
double c, m, y, k;
ScColor cc;
QFile f(pfadC2);
if (f.open(QIODevice::ReadOnly))
{
QByteArray docBytes("");
loadRawText(pfadC2, docBytes);
QString docText("");
docText = QString::fromUtf8(docBytes);
QDomDocument docu("scridoc");
docu.setContent(docText);
ScColor lf = ScColor();
QDomElement elem = docu.documentElement();
QDomNode PAGE = elem.firstChild();
while(!PAGE.isNull())
QDataStream ts(&f);
while (!ts.atEnd())
{
QDomElement pg = PAGE.toElement();
if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
tmp = readLinefromDataStream(ts);
if (((tmp.startsWith("%%CMYKCustomColor")) || (tmp.startsWith("%%CMYKProcessColor"))) && extensionIndicatesEPSorPS(ext))
{
if (pg.hasAttribute("CMYK"))
lf.setNamedColor(pg.attribute("CMYK"));
else
lf.fromQColor(QColor(pg.attribute("RGB")));
if (pg.hasAttribute("Spot"))
lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
else
lf.setSpotColor(false);
if (pg.hasAttribute("Register"))
lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
else
lf.setRegistrationColor(false);
CurrSwatch.insert(pg.attribute("NAME"), lf);
if (tmp.startsWith("%%CMYKCustomColor"))
tmp = tmp.remove(0,18);
else if (tmp.startsWith("%%CMYKProcessColor"))
tmp = tmp.remove(0,19);
QTextStream ts2(&tmp, QIODevice::ReadOnly);
ts2 >> c >> m >> y >> k;
FarNam = ts2.readAll();
FarNam = FarNam.trimmed();
FarNam = FarNam.remove(0,1);
FarNam = FarNam.remove(FarNam.length()-1,1);
FarNam = FarNam.simplified();
cc = ScColor(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
cc.setSpotColor(true);
if (!CurrSwatch.contains(FarNam))
CurrSwatch.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);
QTextStream ts2(&tmp, QIODevice::ReadOnly);
ts2 >> c >> m >> y >> k;
FarNam = ts2.readAll();
FarNam = FarNam.trimmed();
FarNam = FarNam.remove(0,1);
FarNam = FarNam.remove(FarNam.length()-1,1);
FarNam = FarNam.simplified();
cc = ScColor(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
cc.setSpotColor(true);
if (!CurrSwatch.contains(FarNam))
CurrSwatch.insert(FarNam, cc);
}
}
PAGE=PAGE.nextSibling();
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))
{
QTextStream 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(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
cc.setSpotColor(true);
if (!CurrSwatch.contains(FarNam))
CurrSwatch.insert(FarNam, cc);
}
}
}
}
break;
}
}
f.close();
}
else
CurrSwatch.insert("White", ScColor(0, 0, 0, 0));
CurrSwatch.insert("Black", ScColor(0, 0, 0, 255));
}
else
{
QFile fiC(pfadC2);
if (fiC.open(QIODevice::ReadOnly))
{
while (!tsC.atEnd())
QString ColorEn, Cname;
int Rval, Gval, Bval, Kval;
QTextStream tsC(&fiC);
ColorEn = tsC.readLine();
if (ColorEn.startsWith("<?xml version="))
{
ScColor tmp;
ColorEn = tsC.readLine();
if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
continue;
QTextStream CoE(&ColorEn, QIODevice::ReadOnly);
CoE >> Rval;
CoE >> Gval;
CoE >> Bval;
if (cus)
QByteArray docBytes("");
loadRawText(pfadC2, docBytes);
QString docText("");
docText = QString::fromUtf8(docBytes);
QDomDocument docu("scridoc");
docu.setContent(docText);
ScColor lf = ScColor();
QDomElement elem = docu.documentElement();
QDomNode PAGE = elem.firstChild();
while(!PAGE.isNull())
{
CoE >> Kval;
Cname = CoE.readAll().trimmed();
tmp.setColor(Rval, Gval, Bval, Kval);
QDomElement pg = PAGE.toElement();
if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
{
if (pg.hasAttribute("CMYK"))
lf.setNamedColor(pg.attribute("CMYK"));
else
lf.fromQColor(QColor(pg.attribute("RGB")));
if (pg.hasAttribute("Spot"))
lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
else
lf.setSpotColor(false);
if (pg.hasAttribute("Register"))
lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
else
lf.setRegistrationColor(false);
CurrSwatch.insert(pg.attribute("NAME"), lf);
}
PAGE=PAGE.nextSibling();
}
else
}
else
{
while (!tsC.atEnd())
{
Cname = CoE.readAll().trimmed();
tmp.setColorRGB(Rval, Gval, Bval);
}
if ((n<customSetStartIndex) && (Cname.length()==0))
{
if (!cus)
Cname=QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).toUpper();
ScColor tmp;
ColorEn = tsC.readLine();
if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
continue;
QTextStream CoE(&ColorEn, QIODevice::ReadOnly);
CoE >> Rval;
CoE >> Gval;
CoE >> Bval;
if (cus)
{
CoE >> Kval;
Cname = CoE.readAll().trimmed();
tmp.setColor(Rval, Gval, Bval, Kval);
}
else
Cname=QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).toUpper();
Cname.replace(" ","0");
{
Cname = CoE.readAll().trimmed();
tmp.setColorRGB(Rval, Gval, Bval);
}
if ((n<customSetStartIndex) && (Cname.length()==0))
{
if (!cus)
Cname=QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).toUpper();
else
Cname=QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).toUpper();
Cname.replace(" ","0");
}
if (CurrSwatch.contains(Cname))
{
if (tmp==CurrSwatch[Cname])
continue;
Cname=QString("%1%2").arg(Cname).arg(CurrSwatch.count());
}
CurrSwatch.insert(Cname, tmp);
}
if (CurrSwatch.contains(Cname))
{
if (tmp==CurrSwatch[Cname])
continue;
Cname=QString("%1%2").arg(Cname).arg(CurrSwatch.count());
}
CurrSwatch.insert(Cname, tmp);
}
fiC.close();
}
fiC.close();
else
{
CurrSwatch.insert("White", ScColor(0, 0, 0, 0));
CurrSwatch.insert("Black", ScColor(0, 0, 0, 255));
ScColor cc = ScColor(255, 255, 255, 255);
cc.setRegistrationColor(true);
CurrSwatch.insert("Registration", cc);
CurrSwatch.insert("Blue", ScColor(255, 255, 0, 0));
CurrSwatch.insert("Cyan", ScColor(255, 0, 0, 0));
CurrSwatch.insert("Green", ScColor(255, 0, 255, 0));
CurrSwatch.insert("Red", ScColor(0, 255, 255, 0));
CurrSwatch.insert("Yellow", ScColor(0, 0, 255, 0));
CurrSwatch.insert("Magenta", ScColor(0, 255, 0, 0));
}
}
else
{
CurrSwatch.insert("White", ScColor(0, 0, 0, 0));
CurrSwatch.insert("Black", ScColor(0, 0, 0, 255));
ScColor cc = ScColor(255, 255, 255, 255);
cc.setRegistrationColor(true);
CurrSwatch.insert("Registration", cc);
CurrSwatch.insert("Blue", ScColor(255, 255, 0, 0));
CurrSwatch.insert("Cyan", ScColor(255, 0, 0, 0));
CurrSwatch.insert("Green", ScColor(255, 0, 255, 0));
CurrSwatch.insert("Red", ScColor(0, 255, 255, 0));
CurrSwatch.insert("Yellow", ScColor(0, 0, 255, 0));
CurrSwatch.insert("Magenta", ScColor(0, 255, 0, 0));
}
}
ColorSwatch->clear();
ColorSwatch->insertFancyPixmapItems(CurrSwatch);
/trunk/Scribus/scribus/colorm.cpp
223,22 → 223,6
QDataStream s(&fx);
s.writeRawData(xmlpi, strlen(xmlpi));
s.writeRawData(cs, cs.length());
/* CMYKColor cmyk;
QTextStream tsx(&fx);
QString tmp;
ColorList::Iterator itc;
tsx << "Color Set:"+dia->getEditText()+"\n";
int cp, mp, yp, kp;
for (itc = EditColors.begin(); itc != EditColors.end(); ++itc)
{
ScColorEngine::getCMYKValues(itc.data(), m_Doc, cmyk);
cmyk.getValues(cp, mp, yp, kp);
tsx << tmp.setNum(cp) << "\t" ;
tsx << tmp.setNum(mp) << "\t" ;
tsx << tmp.setNum(yp) << "\t" ;
tsx << tmp.setNum(kp) << "\t" ;
tsx << itc.key() << "\n" ;
} */
fx.close();
if (dia->getEditText() != Name)
{
257,16 → 241,6
void ColorManager::loadDefaults(const QString &txt)
{
int c = LoadColSet->currentIndex();
/* QList<QAction*> cAct = LoadColSet->actions();
int a = 0;
for (a = 0; a < cAct.count(); a++)
{
if (txt == cAct.at(a)->text())
{
c = a;
break;
}
} */
bool cus = false;
setCurrentComboItem(LoadColSet, txt);
EditColors.clear();
308,118 → 282,129
}
if (txt != "Scribus Small")
{
QFile fiC(pfadC2);
if (fiC.open(QIODevice::ReadOnly))
QFileInfo fi = QFileInfo(pfadC2);
QString ext = fi.suffix().toLower();
if (extensionIndicatesEPSorPS(ext) || (ext == "ai"))
{
QString ColorEn, Cname;
int Rval, Gval, Bval, Kval;
QTextStream tsC(&fiC);
ColorEn = tsC.readLine();
if (ColorEn.startsWith("<?xml version="))
importColorsFromFile(pfadC2);
EditColors.insert("White", ScColor(0, 0, 0, 0));
EditColors.insert("Black", ScColor(0, 0, 0, 255));
}
else
{
QFile fiC(pfadC2);
if (fiC.open(QIODevice::ReadOnly))
{
QByteArray docBytes("");
loadRawText(pfadC2, docBytes);
QString docText("");
docText = QString::fromUtf8(docBytes);
QDomDocument docu("scridoc");
docu.setContent(docText);
ScColor lf = ScColor();
QDomElement elem = docu.documentElement();
QDomNode PAGE = elem.firstChild();
while(!PAGE.isNull())
QString ColorEn, Cname;
int Rval, Gval, Bval, Kval;
QTextStream tsC(&fiC);
ColorEn = tsC.readLine();
if (ColorEn.startsWith("<?xml version="))
{
QDomElement pg = PAGE.toElement();
if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
QByteArray docBytes("");
loadRawText(pfadC2, docBytes);
QString docText("");
docText = QString::fromUtf8(docBytes);
QDomDocument docu("scridoc");
docu.setContent(docText);
ScColor lf = ScColor();
QDomElement elem = docu.documentElement();
QDomNode PAGE = elem.firstChild();
while(!PAGE.isNull())
{
if (pg.hasAttribute("CMYK"))
lf.setNamedColor(pg.attribute("CMYK"));
else
lf.fromQColor(QColor(pg.attribute("RGB")));
if (pg.hasAttribute("Spot"))
lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
else
lf.setSpotColor(false);
if (pg.hasAttribute("Register"))
lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
else
lf.setRegistrationColor(false);
EditColors.insert(pg.attribute("NAME"), lf);
QDomElement pg = PAGE.toElement();
if(pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
{
if (pg.hasAttribute("CMYK"))
lf.setNamedColor(pg.attribute("CMYK"));
else
lf.fromQColor(QColor(pg.attribute("RGB")));
if (pg.hasAttribute("Spot"))
lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
else
lf.setSpotColor(false);
if (pg.hasAttribute("Register"))
lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
else
lf.setRegistrationColor(false);
EditColors.insert(pg.attribute("NAME"), lf);
}
PAGE=PAGE.nextSibling();
}
PAGE=PAGE.nextSibling();
}
}
else
{
while (!tsC.atEnd())
else
{
ScColor tmp;
ColorEn = tsC.readLine().trimmed();
if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
continue;
if (ColorEn[0].isNumber()) {
QTextStream CoE(&ColorEn, QIODevice::ReadOnly);
CoE >> Rval;
CoE >> Gval;
CoE >> Bval;
if (cus)
while (!tsC.atEnd())
{
ScColor tmp;
ColorEn = tsC.readLine().trimmed();
if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
continue;
if (ColorEn[0].isNumber()) {
QTextStream CoE(&ColorEn, QIODevice::ReadOnly);
CoE >> Rval;
CoE >> Gval;
CoE >> Bval;
if (cus)
{
CoE >> Kval;
Cname = CoE.readAll().trimmed();
tmp.setColor(Rval, Gval, Bval, Kval);
}
else
{
Cname = CoE.readAll().trimmed();
tmp.setColorRGB(Rval, Gval, Bval);
}
}
else
{
CoE >> Kval;
Cname = CoE.readAll().trimmed();
QStringList fields = ColorEn.split(QChar(9), QString::SkipEmptyParts);
if (fields.count() != 5)
continue;
Cname = fields[0];
Rval = fields[1].toInt();
Gval = fields[2].toInt();
Bval = fields[3].toInt();
Kval = fields[4].toInt();
tmp.setColor(Rval, Gval, Bval, Kval);
}
else
if ((c<customSetStartIndex) && (Cname.length()==0))
{
Cname = CoE.readAll().trimmed();
tmp.setColorRGB(Rval, Gval, Bval);
if (!cus)
Cname=QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).toUpper();
else
Cname=QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).toUpper();
Cname.replace(" ","0");
}
if (EditColors.contains(Cname))
{
if (tmp==EditColors[Cname])
continue;
Cname=QString("%1%2").arg(Cname).arg(EditColors.count());
}
EditColors.insert(Cname, tmp);
}
else
{
QStringList fields = ColorEn.split(QChar(9), QString::SkipEmptyParts);
if (fields.count() != 5)
continue;
Cname = fields[0];
Rval = fields[1].toInt();
Gval = fields[2].toInt();
Bval = fields[3].toInt();
Kval = fields[4].toInt();
tmp.setColor(Rval, Gval, Bval, Kval);
}
if ((c<customSetStartIndex) && (Cname.length()==0))
{
if (!cus)
Cname=QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).toUpper();
else
Cname=QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).toUpper();
Cname.replace(" ","0");
}
if (EditColors.contains(Cname))
{
if (tmp==EditColors[Cname])
continue;
Cname=QString("%1%2").arg(Cname).arg(EditColors.count());
}
EditColors.insert(Cname, tmp);
}
fiC.close();
}
fiC.close();
else
{
setCurrentComboItem(LoadColSet, "Scribus Small");
EditColors.insert("White", ScColor(0, 0, 0, 0));
EditColors.insert("Black", ScColor(0, 0, 0, 255));
ScColor cc = ScColor(255, 255, 255, 255);
cc.setRegistrationColor(true);
EditColors.insert("Registration", cc);
EditColors.insert("Blue", ScColor(255, 255, 0, 0));
EditColors.insert("Cyan", ScColor(255, 0, 0, 0));
EditColors.insert("Green", ScColor(255, 0, 255, 0));
EditColors.insert("Red", ScColor(0, 255, 255, 0));
EditColors.insert("Yellow", ScColor(0, 0, 255, 0));
EditColors.insert("Magenta", ScColor(0, 255, 0, 0));
}
}
else
{
setCurrentComboItem(LoadColSet, "Scribus Small");
EditColors.insert("White", ScColor(0, 0, 0, 0));
EditColors.insert("Black", ScColor(0, 0, 0, 255));
ScColor cc = ScColor(255, 255, 255, 255);
cc.setRegistrationColor(true);
EditColors.insert("Registration", cc);
EditColors.insert("Blue", ScColor(255, 255, 0, 0));
EditColors.insert("Cyan", ScColor(255, 0, 0, 0));
EditColors.insert("Green", ScColor(255, 0, 255, 0));
EditColors.insert("Red", ScColor(0, 255, 255, 0));
EditColors.insert("Yellow", ScColor(0, 0, 255, 0));
EditColors.insert("Magenta", ScColor(0, 255, 0, 0));
}
}
updateCList();
}
438,10 → 423,19
fileName = dia.selectedFile();
else
return;
int oldCount = EditColors.count();
if (!fileName.isEmpty())
dirs->set("colors", fileName.left(fileName.lastIndexOf("/")));
importColorsFromFile(fileName);
if (EditColors.count() == oldCount)
QMessageBox::information(this, tr("Information"), "<qt>" + tr("The file %1 does not contain colors which can be imported.\nIf the file was a PostScript-based, try to import it with File -&gt; Import. \nNot all files have DSC conformant comments where the color descriptions are located.\n This prevents importing colors from some files.\nSee the Edit Colors section of the documentation for more details.").arg(fileName) + "</qt>", 1, 0, 0);
}
 
void ColorManager::importColorsFromFile(QString fileName)
{
if (!fileName.isEmpty())
{
int oldCount = EditColors.count();
dirs->set("colors", fileName.left(fileName.lastIndexOf("/")));
QFileInfo fi = QFileInfo(fileName);
QString ext = fi.suffix().toLower();
if (extensionIndicatesEPSorPS(ext) || (ext == "ai"))
456,7 → 450,7
while (!ts.atEnd())
{
tmp = readLinefromDataStream(ts);
if ((tmp.startsWith("%%CMYKCustomColor")) || (tmp.startsWith("%%CMYKProcessColor")))
if (((tmp.startsWith("%%CMYKCustomColor")) || (tmp.startsWith("%%CMYKProcessColor"))) && extensionIndicatesEPSorPS(ext))
{
if (tmp.startsWith("%%CMYKCustomColor"))
tmp = tmp.remove(0,18);
502,19 → 496,31
{
while (!ts.atEnd())
{
bool isX = false;
tmp = readLinefromDataStream(ts);
if ((tmp.endsWith("Xa") || tmp.endsWith(" k")) && (tmp.length() > 4))
if ((tmp.endsWith("Xa") || tmp.endsWith(" k") || tmp.endsWith(" x")) && (tmp.length() > 4))
{
QTextStream 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"))
{
tmp = tmp.trimmed();
tmp = tmp.remove(0,1);
int en = tmp.indexOf(")");
FarNam = tmp.mid(0, en);
FarNam = FarNam.simplified();
if (!isX)
{
tmp = tmp.trimmed();
tmp = tmp.remove(0,1);
int en = tmp.indexOf(")");
FarNam = tmp.mid(0, en);
FarNam = FarNam.simplified();
}
cc = ScColor(static_cast<int>(255 * c), static_cast<int>(255 * m), static_cast<int>(255 * y), static_cast<int>(255 * k));
cc.setSpotColor(true);
if (!EditColors.contains(FarNam))
548,9 → 554,6
updateCList();
}
}
if (EditColors.count() == oldCount)
QMessageBox::information(this, tr("Information"), "<qt>" + tr("The file %1 does not contain colors which can be imported.\nIf the file was a PostScript-based, try to import it with File -&gt; Import. \nNot all files have DSC conformant comments where the color descriptions are located.\n This prevents importing colors from some files.\nSee the Edit Colors section of the documentation for more details.").arg(fileName) + "</qt>", 1, 0, 0);
}
}
 
/trunk/Scribus/scribus/colorm.h
52,6 → 52,7
 
private:
void updateButtons();
void importColorsFromFile(QString fileName);
ColorListBox* colorListBox;
QGroupBox* ColorsGroup;
QGroupBox* ColsSetGroup;