ScColorProfile ScLcmsColorMgmtEngineImpl::openProfileFromMem(ScColorMgmtEngine& engine, const QByteArray& data)
{
	ScColorProfile profile;
	cmsHPROFILE lcmsProf = NULL;
	cmsSetErrorHandler(&cmsErrorHandler);
	try
	{
		lcmsProf = cmsOpenProfileFromMem((LPVOID) data.data(), data.size());
		if (lcmsProf)
		{
			ScLcmsColorProfileImpl* profData = new ScLcmsColorProfileImpl(engine, lcmsProf);
			QString desc = profData->productDescription();
			if (!desc.isEmpty())
				profData->m_profilePath = QString("memprofile://%1").arg(desc);
			profData->m_profileData = data;
			profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData));
		}
		if (profile.isNull() && lcmsProf)
		{
			cmsCloseProfile(lcmsProf);
			lcmsProf = NULL;
		}
	}
	catch (lcmsException& e)
	{
		std::cerr << e.what() << std::endl;
		if (profile.isNull() && lcmsProf)
			cmsCloseProfile(lcmsProf);
		profile = ScColorProfile();
	}
	cmsSetErrorHandler(NULL);
	return profile;
}
ScColorProfile ScLcmsColorMgmtEngineImpl::createProfile_Lab(ScColorMgmtEngine& engine)
{
	QString internalProfilePath("memprofile://Internal Lab profile");
	ScColorProfile profile = m_profileCache->profile(internalProfilePath);
	if (!profile.isNull())
		return profile;

	cmsHPROFILE lcmsProf = NULL;
	cmsSetErrorHandler(&cmsErrorHandler);
	try
	{
		lcmsProf = cmsCreateLabProfile(NULL);
		if (lcmsProf)
		{
			ScLcmsColorProfileImpl* profData = new ScLcmsColorProfileImpl(engine, lcmsProf);
			profData->m_profilePath = internalProfilePath;
			profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData));
			m_profileCache->addProfile(profile);
		}
		if (profile.isNull() && lcmsProf)
		{
			cmsCloseProfile(lcmsProf);
			lcmsProf = NULL;
		}
	}
	catch (lcmsException& e)
	{
		std::cerr << e.what() << std::endl;
		if (profile.isNull() && lcmsProf)
			cmsCloseProfile(lcmsProf);
		profile = ScColorProfile();
	}
	cmsSetErrorHandler(NULL);
	return profile;
}
Exemplo n.º 3
0
ScColorProfile ScLcms2ColorMgmtEngineImpl::openProfileFromFile(ScColorMgmtEngine& engine, const QString& filePath)
{
	// Search profile in profile cache first
	ScColorProfile profile = m_profileCache->profile(filePath);
	if (!profile.isNull())
		return profile;
	cmsHPROFILE lcmsProf = NULL;
	QFile file(filePath);
	if (file.open(QFile::ReadOnly))
	{
		// We do not use lcms cmsOpenProfileFromFile() to avoid limitations
		// of I/O on 8bit filenames on Windows
		QByteArray data = file.readAll();
		if (!data.isEmpty())
		{
			lcmsProf = cmsOpenProfileFromMem(data.data(), data.size());
			if (lcmsProf)
			{
				ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf);
				profData->m_profileData = data;
				profData->m_profilePath = filePath;
				profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData));
				m_profileCache->addProfile(profile);
			}
			if (profile.isNull() && lcmsProf)
			{
				cmsCloseProfile(lcmsProf);
				lcmsProf = NULL;
			}
		}
		file.close();
	}
	return profile;
}
Exemplo n.º 4
0
void ScImgDataLoader_PS::loadEmbeddedProfile(const QString& fn, int /* page */)
{
	QChar tc;
	QString tmp;
	m_embeddedProfile.resize(0);
	m_profileComponents = 0;
	if ( !QFile::exists(fn) )
		return;
	QFile f(fn);
	if (f.open(QIODevice::ReadOnly))
	{
		QDataStream ts(&f);
		while (!ts.atEnd())
		{
			tmp = readLinefromDataStream(ts);
			if (tmp.startsWith("%%BeginICCProfile:"))
			{
				QByteArray psdata;
				while (!ts.atEnd())
				{
					tmp = readLinefromDataStream(ts);
					for (int a = 2; a < tmp.length(); a += 2)
					{
						bool ok;
						ushort data = tmp.mid(a, 2).toUShort(&ok, 16);
						psdata.resize(psdata.size()+1);
						psdata[psdata.size()-1] = data;
					}
					if (tmp.startsWith("%%EndICCProfile"))
					{
						ScColorMgmtEngine engine(ScCore->defaultEngine);
						ScColorProfile prof = engine.openProfileFromMem(psdata);
						if (prof)
						{
							if (prof.colorSpace() == ColorSpace_Rgb)
								m_profileComponents = 3;
							if (prof.colorSpace() == ColorSpace_Cmyk)
								m_profileComponents = 4;
							m_imageInfoRecord.profileName = prof.productDescription();
							m_imageInfoRecord.isEmbedded = true;
							m_embeddedProfile = psdata;
						}
						break;
					}
				}
			}
		}
	}
}
void ScColorProfileCache::addProfile(const ScColorProfile& profile)
{
	QString path = profile.profilePath();
	if (path.isEmpty())
		return;

	QMap<QString, QWeakPointer<ScColorProfileData> >::iterator iter = m_profileMap.find(path);
	if (iter != m_profileMap.end())
	{
		QSharedPointer<ScColorProfileData> strongRef = iter.value().toStrongRef();
		if (strongRef) return;
	}

	m_profileMap.insert(path, profile.weakRef());
}
Exemplo n.º 6
0
void ScImgDataLoader_JPEG::loadEmbeddedProfile(const QString& fn, int /*page*/)
{
	m_embeddedProfile.resize(0);
	m_profileComponents = 0;
	if (!QFile::exists(fn))
		return;
	struct jpeg_decompress_struct cinfo;
	struct my_error_mgr         jerr;
	FILE     *infile;
	cinfo.err = jpeg_std_error (&jerr.pub);
	jerr.pub.error_exit = my_error_exit;
	infile = NULL;
	if (setjmp (jerr.setjmp_buffer))
	{
		jpeg_destroy_decompress (&cinfo);
		if (infile)
			fclose (infile);
		return;
	}
	jpeg_create_decompress (&cinfo);
	if ((infile = fopen (fn.toLocal8Bit(), "rb")) == NULL)
		return;
	jpeg_stdio_src(&cinfo, infile);
	jpeg_save_markers(&cinfo, ICC_MARKER, 0xFFFF);
	jpeg_read_header(&cinfo, true);
	unsigned int EmbedLen = 0;
	unsigned char* EmbedBuffer;
	if (read_jpeg_marker(ICC_MARKER,&cinfo, &EmbedBuffer, &EmbedLen))
	{
		QByteArray profArray = QByteArray((const char*) EmbedBuffer, EmbedLen);
		ScColorProfile prof  = ScColorMgmtEngine::openProfileFromMem(profArray);
		if (prof)
		{
			if (prof.colorSpace() == ColorSpace_Rgb)
				m_profileComponents = 3;
			if (prof.colorSpace() == ColorSpace_Cmyk)
				m_profileComponents = 4;
			if (prof.colorSpace() == ColorSpace_Gray)
				m_profileComponents = 1;
			m_embeddedProfile = profArray;
		}
		free(EmbedBuffer);
	}
	fclose (infile);
	jpeg_destroy_decompress (&cinfo);
}
ScColorSpace ScColorMgmtEngineData::createColorSpace(ScColorProfile& profile, eColorFormat colorFormat)
{
	ScColorSpace colorSpace;
	eColorSpaceType profileCSpace = profile.colorSpace();
	if (profileCSpace == ColorSpace_Rgb)
	{
		if (colorFormat == Format_RGB_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_RGB8(profile));
		else if (colorFormat == Format_RGB_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_RGB16(profile));
		else if (colorFormat == Format_RGBA_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_RGBA8(profile));
		else if (colorFormat == Format_RGBA_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_RGBA16(profile));
		else if (colorFormat == Format_ARGB_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_ARGB8(profile));
		else if (colorFormat == Format_ARGB_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_ARGB16(profile));
		else if (colorFormat == Format_BGRA_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_BGRA8(profile));
		else if (colorFormat == Format_BGRA_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_BGRA16(profile));
	}
	else if (profileCSpace == ColorSpace_Cmyk)
	{
		if (colorFormat == Format_CMYK_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_CMYK8(profile));
		else if (colorFormat == Format_CMYK_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_CMYK16(profile));
		else if (colorFormat == Format_CMYKA_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_CMYKA8(profile));
		else if (colorFormat == Format_CMYKA_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_CMYKA16(profile));
		else if (colorFormat == Format_YMCK_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_YMCK8(profile));
		else if (colorFormat == Format_YMCK_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_YMCK16(profile));
	}
	else if (profileCSpace == ColorSpace_Gray)
	{
		if (colorFormat == Format_GRAY_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_GRAY8(profile));
		else if (colorFormat == Format_GRAY_16)
			colorSpace = ScColorSpace(new ScColorSpaceData_GRAY16(profile));
	}
	else if (profileCSpace == ColorSpace_Lab)
	{
		if (colorFormat == Format_LabA_8)
			colorSpace = ScColorSpace(new ScColorSpaceData_LabA8(profile));
		if (colorFormat == Format_Lab_Dbl)
			colorSpace = ScColorSpace(new ScColorSpaceData_LabD(profile));
	}
	return colorSpace;
}
Exemplo n.º 8
0
ScColorProfile ScLcms2ColorMgmtEngineImpl::openProfileFromMem(ScColorMgmtEngine& engine, const QByteArray& data)
{
	ScColorProfile profile;
	cmsHPROFILE	lcmsProf = cmsOpenProfileFromMem((const void *) data.data(), data.size());
	if (lcmsProf)
	{
		ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf);
		QString desc = profData->productDescription();
		if (!desc.isEmpty())
			profData->m_profilePath = QString("memprofile://%1").arg(desc);
		profData->m_profileData = data;
		profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData));
	}
	if (profile.isNull() && lcmsProf)
	{
		cmsCloseProfile(lcmsProf);
		lcmsProf = NULL;
	}
	return profile;
}
Exemplo n.º 9
0
ScColorProfile ScLcms2ColorMgmtEngineImpl::createProfile_Lab(ScColorMgmtEngine& engine)
{
	QString internalProfilePath("memprofile://Internal Lab profile");
	ScColorProfile profile = m_profileCache->profile(internalProfilePath);
	if (!profile.isNull())
		return profile;

	cmsHPROFILE lcmsProf = cmsCreateLab2Profile(NULL);
	if (lcmsProf)
	{
		ScLcms2ColorProfileImpl* profData = new ScLcms2ColorProfileImpl(engine, lcmsProf);
		profData->m_profilePath = internalProfilePath;
		profile = ScColorProfile(dynamic_cast<ScColorProfileData*>(profData));
		m_profileCache->addProfile(profile);
	}
	if (profile.isNull() && lcmsProf)
	{
		cmsCloseProfile(lcmsProf);
		lcmsProf = NULL;
	}
	return profile;
}
Exemplo n.º 10
0
static PyObject *PDFfile_save(PDFfile *self)
{
	if (!ScCore->primaryMainWindow()->HaveDoc) {
		PyErr_SetString(PyExc_SystemError, "Need to open document first");
		return NULL;
	};

// copied from file scribus.cpp
//void ScribusMainWindow::SaveAsPDF()
	int Components = 3;
	QString nam = "";
	if (ScCore->primaryMainWindow()->bookmarkPalette->BView->topLevelItemCount() == 0)
		ScCore->primaryMainWindow()->doc->PDF_Options.Bookmarks = false;

// apply fonts attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.EmbedList.clear();
	int n = PyList_Size(self->fonts);
	for ( int i=0; i<n; ++i){
		QString tmpFon;
		tmpFon = QString(PyString_AsString(PyList_GetItem(self->fonts, i)));
		ScCore->primaryMainWindow()->doc->PDF_Options.EmbedList.append(tmpFon);
	}
// apply file attribute
	QString fn;
	fn = QString(PyString_AsString(self->file));
	ScCore->primaryMainWindow()->doc->PDF_Options.fileName = fn;
// apply pages attribute
	std::vector<int> pageNs;
	int nn=PyList_Size(self->pages);
	for (int i = 0; i < nn; ++i) {
		pageNs.push_back((int)PyInt_AsLong(PyList_GetItem(self->pages, i)));
	}
// apply thumbnails attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.Thumbnails = self->thumbnails;
// apply compress attribute
	self->compressmtd = minmaxi(self->compressmtd, 0, 3);
	ScCore->primaryMainWindow()->doc->PDF_Options.Compress = self->compress;
	ScCore->primaryMainWindow()->doc->PDF_Options.CompressMethod = (PDFOptions::PDFCompression) self->compressmtd;
// apply quality attribute
	self->quality = minmaxi(self->quality, 0, 4);
	ScCore->primaryMainWindow()->doc->PDF_Options.Quality = self->quality;
// apply resolusion attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.Resolution = PyInt_AsLong(self->resolution);
// apply downsample attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.RecalcPic = PyInt_AsLong(self->downsample);
	if (ScCore->primaryMainWindow()->doc->PDF_Options.RecalcPic)
		ScCore->primaryMainWindow()->doc->PDF_Options.PicRes = PyInt_AsLong(self->downsample);
	else
		ScCore->primaryMainWindow()->doc->PDF_Options.PicRes = ScCore->primaryMainWindow()->doc->PDF_Options.Resolution;
// apply bookmarks attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.Bookmarks = self->bookmarks;
// apply binding attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.Binding = self->binding;
// apply presentation attribute
	ScCore->primaryMainWindow()->doc->PDF_Options.PresentMode = self->presentation;

	QList<PDFPresentationData> PresentVals;
	PresentVals.clear();
	int tmpnum;
	tmpnum=PyList_Size(self->effval);
	for (int i=0; i<tmpnum; ++i) {
		PDFPresentationData t;
// How do I make this commented piece of code to work?
// I always get an error here
		PyObject *ti = PyList_GetItem(self->effval, i);
//		 if (!PyArg_ParseTuple(ti , "[iiiiii]",
//				  &t.pageEffectDuration, &t.pageViewDuration, &t.effectType, &t.Dm,
//				  &t.M, &t.Di)) {
//			 PyErr_SetString(PyExc_SystemError, "while parsing 'effval'. WHY THIS HAPPENED????");
//			 return NULL;
//		 }
//		 PresentVals.append(t);
				// pv 10/03/2004 crashed when pt is null
				if (ti)
				{
					// Do I Need to check if every PyInt_AsLong and PyList_GetItem funtion succeed???
					t.pageEffectDuration = PyInt_AsLong(PyList_GetItem(ti, 0));
					t.pageViewDuration = PyInt_AsLong(PyList_GetItem(ti, 1));
					t.effectType = PyInt_AsLong(PyList_GetItem(ti, 2));
					t.Dm = PyInt_AsLong(PyList_GetItem(ti, 3));
					t.M = PyInt_AsLong(PyList_GetItem(ti, 4));
					t.Di = PyInt_AsLong(PyList_GetItem(ti, 5));
					PresentVals.append(t);
				} // if ti=NULL

	}

	ScCore->primaryMainWindow()->doc->PDF_Options.PresentVals = PresentVals;
// apply lpival
	int n2 = PyList_Size(self->lpival);
	for (int i=0; i<n2; ++i){
		LPIData lpi;
		PyObject *t = PyList_GetItem(self->lpival, i);
// This code always raise exception - WHY???
//		char *s;
//		 if (!PyArg_ParseTuple(t, "[siii]", &s, &lpi.Frequency,
//				  &lpi.Angle, &lpi.SpotFunc)) {
//			 PyErr_SetString(PyExc_SystemError, "while parsing 'lpival'. WHY THIS HAPPENED????");
//			 return NULL;
//		 }
//		 ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings[QString(s)]=lpi;
		QString st;
		st = QString(PyString_AsString(PyList_GetItem(t,0)));
		lpi.Frequency = PyInt_AsLong(PyList_GetItem(t, 1));
		lpi.Angle = PyInt_AsLong(PyList_GetItem(t, 2));
		lpi.SpotFunc = PyInt_AsLong(PyList_GetItem(t, 3));
		ScCore->primaryMainWindow()->doc->PDF_Options.LPISettings[st]=lpi;
	}

	ScCore->primaryMainWindow()->doc->PDF_Options.Articles = self->article;
	ScCore->primaryMainWindow()->doc->PDF_Options.Encrypt = self->encrypt;
	ScCore->primaryMainWindow()->doc->PDF_Options.UseLPI = self->uselpi;
	ScCore->primaryMainWindow()->doc->PDF_Options.UseSpotColors = self->usespot;
	ScCore->primaryMainWindow()->doc->PDF_Options.doMultiFile = self->domulti;
	self->version = minmaxi(self->version, 12, 14);
	// FIXME: Sanity check version
	ScCore->primaryMainWindow()->doc->PDF_Options.Version = (PDFOptions::PDFVersion)self->version;
	if (self->encrypt)
	{
		int Perm = -64;
		if (ScCore->primaryMainWindow()->doc->PDF_Options.Version == PDFOptions::PDFVersion_14)
			Perm &= ~0x00240000;
		if (self->aprint)
			Perm += 4;
		if (self->achange)
			Perm += 8;
		if (self->acopy)
			Perm += 16;
		if (self->aanot)
			Perm += 32;
		ScCore->primaryMainWindow()->doc->PDF_Options.Permissions = Perm;
		ScCore->primaryMainWindow()->doc->PDF_Options.PassOwner = QString(PyString_AsString(self->owner));
		ScCore->primaryMainWindow()->doc->PDF_Options.PassUser = QString(PyString_AsString(self->user));
	}
	if (self->outdst == 0)
	{
		ScCore->primaryMainWindow()->doc->PDF_Options.UseRGB = true;
		ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles = false;
		ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2 = false;
	}
	else
	{
		ScCore->primaryMainWindow()->doc->PDF_Options.UseRGB = false;
		if (ScCore->primaryMainWindow()->doc->HasCMS)
		{
			ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles = self->profiles;
			ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2 = self->profilei;
			self->intents = minmaxi(self->intents, 0, 3);
			ScCore->primaryMainWindow()->doc->PDF_Options.Intent = self->intents;
			self->intenti = minmaxi(self->intenti, 0, 3);
			ScCore->primaryMainWindow()->doc->PDF_Options.Intent2 = self->intenti;
			ScCore->primaryMainWindow()->doc->PDF_Options.EmbeddedI = self->noembicc;
			ScCore->primaryMainWindow()->doc->PDF_Options.SolidProf = PyString_AsString(self->solidpr);
			ScCore->primaryMainWindow()->doc->PDF_Options.ImageProf = PyString_AsString(self->imagepr);
			ScCore->primaryMainWindow()->doc->PDF_Options.PrintProf = PyString_AsString(self->printprofc);
			if (ScCore->primaryMainWindow()->doc->PDF_Options.Version == PDFOptions::PDFVersion_X3)
			{
// Where does compiler find cms function when I have not included header for it
				ScColorProfile hIn;
				hIn = ScColorMgmtEngine::openProfileFromFile(ScCore->PrinterProfiles[ScCore->primaryMainWindow()->doc->PDF_Options.PrintProf]);
				nam = hIn.productDescription();
				if (hIn.colorSpace() == ColorSpace_Rgb)
					Components = 3;
				if (hIn.colorSpace() == ColorSpace_Cmyk)
					Components = 4;
				if (hIn.colorSpace() == ColorSpace_Gray)
					Components = 3;
				ScCore->primaryMainWindow()->doc->PDF_Options.Info = PyString_AsString(self->info);
				self->bleedt = minmaxd(self->bleedt, 0, ScCore->primaryMainWindow()->view->Doc->pageHeight*ScCore->primaryMainWindow()->view->Doc->unitRatio());
				ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Top = self->bleedt/ScCore->primaryMainWindow()->view->Doc->unitRatio();
				self->bleedl = minmaxd(self->bleedl, 0, ScCore->primaryMainWindow()->view->Doc->pageWidth*ScCore->primaryMainWindow()->view->Doc->unitRatio());
				ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Left = self->bleedl/ScCore->primaryMainWindow()->view->Doc->unitRatio();
				self->bleedr = minmaxd(self->bleedr, 0, ScCore->primaryMainWindow()->view->Doc->pageWidth*ScCore->primaryMainWindow()->view->Doc->unitRatio());
				ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Right = self->bleedr/ScCore->primaryMainWindow()->view->Doc->unitRatio();
				self->bleedb = minmaxd(self->bleedb, 0, ScCore->primaryMainWindow()->view->Doc->pageHeight*ScCore->primaryMainWindow()->view->Doc->unitRatio());
				ScCore->primaryMainWindow()->doc->PDF_Options.bleeds.Bottom = self->bleedb/ScCore->primaryMainWindow()->view->Doc->unitRatio();
				ScCore->primaryMainWindow()->doc->PDF_Options.Encrypt = false;
				ScCore->primaryMainWindow()->doc->PDF_Options.PresentMode = false;
			}
		}
		else
		{
			ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles = false;
			ScCore->primaryMainWindow()->doc->PDF_Options.UseProfiles2 = false;
		}

	}
	QMap<int,QPixmap> thumbs;
	for (uint ap = 0; ap < pageNs.size(); ++ap)
	{
		QPixmap pm(10,10);
		if (ScCore->primaryMainWindow()->doc->PDF_Options.Thumbnails)
			pm = QPixmap::fromImage(ScCore->primaryMainWindow()->view->PageToPixmap(pageNs[ap]-1, 100));
		thumbs.insert(pageNs[ap], pm);
	}
	ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view);
	QString errorMessage;
	if (!ScCore->primaryMainWindow()->getPDFDriver(fn, nam, Components, pageNs, thumbs, errorMessage)) {
		fn  = "Cannot write the File: " + fn;
		if (!errorMessage.isEmpty())
			fn += QString("\n%1").arg(errorMessage);
		PyErr_SetString(PyExc_SystemError, fn.toAscii());
		return NULL;
	}
//	Py_INCREF(Py_None);
//	return Py_None;
	Py_RETURN_NONE;
}
Exemplo n.º 11
0
void PDFExportDialog::updateDocOptions()
{
	m_opts.fileName = QDir::fromNativeSeparators(fileNameLineEdit->text());
	m_opts.doMultiFile = multiFile->isChecked();
	m_opts.openAfterExport = openAfterExportCheckBox->isChecked();
	m_opts.Thumbnails = Options->CheckBox1->isChecked();
	m_opts.Compress = Options->Compression->isChecked();
	m_opts.CompressMethod = (PDFOptions::PDFCompression) Options->CMethod->currentIndex();
	m_opts.Quality = Options->CQuality->currentIndex();
	m_opts.Resolution = Options->Resolution->value();
	m_opts.EmbedList = Options->FontsToEmbed;
	m_opts.SubsetList = Options->FontsToOutline;
	m_opts.RecalcPic = Options->DSColor->isChecked();
	m_opts.PicRes = Options->ValC->value();
	m_opts.embedPDF = Options->EmbedPDF->isChecked();
	m_opts.Bookmarks = Options->CheckBM->isChecked();
	m_opts.Binding = Options->ComboBind->currentIndex();
	m_opts.MirrorH = Options->MirrorH->isChecked();
	m_opts.MirrorV = Options->MirrorV->isChecked();
	m_opts.doClip = Options->ClipMarg->isChecked();
	m_opts.RotateDeg = Options->RotateDeg->currentIndex() * 90;
	m_opts.pageRangeSelection = Options->AllPages->isChecked() ? 0 : 1;
	m_opts.pageRangeString = Options->PageNr->text();
	m_opts.PresentMode = Options->CheckBox10->isChecked();
	if (m_opts.PresentMode)
	{
		for (int pg = 0; pg < m_doc->Pages->count(); ++pg)
		{
			m_doc->Pages->at(pg)->PresentVals = m_presEffects[pg];
		}
	}
	m_opts.Articles = Options->Article->isChecked();
	m_opts.Encrypt = Options->Encry->isChecked();
	m_opts.UseLPI = Options->UseLPI->isChecked();
	m_opts.useLayers = Options->useLayers->isChecked();
	m_opts.UseSpotColors = !Options->useSpot->isChecked();
	m_opts.displayBookmarks = Options->useBookmarks->isChecked();
	m_opts.displayFullscreen = Options->useFullScreen->isChecked();
	m_opts.displayLayers = Options->useLayers2->isChecked();
	m_opts.displayThumbs = Options->useThumbnails->isChecked();
	m_opts.hideMenuBar = Options->hideMenuBar->isChecked();
	m_opts.hideToolBar = Options->hideToolBar->isChecked();
	m_opts.fitWindow = Options->fitWindow->isChecked();
	m_opts.useDocBleeds = Options->docBleeds->isChecked();
	if (!Options->docBleeds->isChecked())
	{
		m_opts.bleeds.Top = Options->BleedTop->value() / m_unitRatio;
		m_opts.bleeds.Left = Options->BleedLeft->value() / m_unitRatio;
		m_opts.bleeds.Right = Options->BleedRight->value() / m_unitRatio;
		m_opts.bleeds.Bottom = Options->BleedBottom->value()/ m_unitRatio;
	}
	m_opts.markLength = Options->markLength->value() / m_unitRatio;
	m_opts.markOffset = Options->markOffset->value() / m_unitRatio;
	m_opts.cropMarks = Options->cropMarks->isChecked();
	m_opts.bleedMarks = Options->bleedMarks->isChecked();
	m_opts.registrationMarks = Options->registrationMarks->isChecked();
	m_opts.colorMarks = Options->colorMarks->isChecked();
	m_opts.docInfoMarks = Options->docInfoMarks->isChecked();
	int pgl = PDFOptions::SinglePage;
	if (Options->singlePage->isChecked())
		pgl = PDFOptions::SinglePage;
	else if (Options->continuousPages->isChecked())
		pgl = PDFOptions::OneColumn;
	else if (Options->doublePageLeft->isChecked())
		pgl = PDFOptions::TwoColumnLeft;
	else if (Options->doublePageRight->isChecked())
		pgl = PDFOptions::TwoColumnRight;
	m_opts.PageLayout = pgl;
	if (Options->actionCombo->currentIndex() != 0)
		m_opts.openAction = Options->actionCombo->currentText();
	else
		m_opts.openAction = "";
	if (Options->Encry->isChecked())
	{
		int Perm = -64;
		if (Options->PDFVersionCombo->currentIndex() == 1)
			Perm &= ~0x00240000;
		if (Options->PrintSec->isChecked())
			Perm += 4;
		if (Options->ModifySec->isChecked())
			Perm += 8;
		if (Options->CopySec->isChecked())
			Perm += 16;
		if (Options->AddSec->isChecked())
			Perm += 32;
		m_opts.Permissions = Perm;
		m_opts.PassOwner = Options->PassOwner->text();
		m_opts.PassUser = Options->PassUser->text();
	}
	if (Options->PDFVersionCombo->currentIndex() == 0)
		m_opts.Version = PDFOptions::PDFVersion_13;
	if (Options->PDFVersionCombo->currentIndex() == 1)
		m_opts.Version = PDFOptions::PDFVersion_14;
	if (Options->PDFVersionCombo->currentIndex() == 2)
		m_opts.Version = PDFOptions::PDFVersion_15;
	if (Options->PDFVersionCombo->currentIndex() == 3)
		m_opts.Version = PDFOptions::PDFVersion_X1a;
	if (Options->PDFVersionCombo->currentIndex() == 4)
		m_opts.Version = PDFOptions::PDFVersion_X3;
	if (Options->PDFVersionCombo->currentIndex() == 5)
		m_opts.Version = PDFOptions::PDFVersion_X4;
	if (Options->OutCombo->currentIndex() == 0)
	{
		m_opts.UseRGB = true;
		m_opts.isGrayscale = false;
		m_opts.UseProfiles = false;
		m_opts.UseProfiles2 = false;
	}
	else
	{
		if (Options->OutCombo->currentIndex() == 2)
		{
			m_opts.isGrayscale = true;
			m_opts.UseRGB = false;
			m_opts.UseProfiles = false;
			m_opts.UseProfiles2 = false;
		}
		else
		{
			m_opts.isGrayscale = false;
			m_opts.UseRGB = false;
			if (m_doc->HasCMS)
			{
				m_opts.UseProfiles = Options->EmbedProfs->isChecked();
				m_opts.UseProfiles2 = Options->EmbedProfs2->isChecked();
				if (m_opts.Version != PDFOptions::PDFVersion_X1a)
				{
					m_opts.Intent = Options->IntendS->currentIndex();
					m_opts.Intent2 = Options->IntendI->currentIndex();
					m_opts.EmbeddedI = Options->NoEmbedded->isChecked();
					m_opts.SolidProf = Options->SolidPr->currentText();
					m_opts.ImageProf = Options->ImageP->currentText();
				}
				m_opts.PrintProf = Options->PrintProfC->currentText();
				if ((m_opts.Version == PDFOptions::PDFVersion_X3) || (m_opts.Version == PDFOptions::PDFVersion_X1a) || (m_opts.Version == PDFOptions::PDFVersion_X4))
				{
					ScColorProfile hIn = m_doc->colorEngine.openProfileFromFile( m_printerProfiles[m_opts.PrintProf] );
					m_cmsDescriptor = hIn.productDescription();
					if (hIn.colorSpace() == ColorSpace_Rgb)
						m_components = 3;
					if (hIn.colorSpace() == ColorSpace_Cmyk)
						m_components = 4;
					if (hIn.colorSpace() == ColorSpace_Cmy)
						m_components = 3;
					m_opts.Info = Options->InfoString->text();
					m_opts.Encrypt = false;
					m_opts.MirrorH = false;
					m_opts.MirrorV = false;
					//#8306 : PDF/X-3 export ignores rotation setting
					//m_opts.RotateDeg = 0;
					m_opts.PresentMode = false;
				}
			}
			else
			{
				m_opts.UseProfiles = false;
				m_opts.UseProfiles2 = false;
			}
		}
	}
}
ScColorTransform ScLcmsColorMgmtEngineImpl::createProofingTransform(ScColorMgmtEngine& engine,
                                             const ScColorProfile& inputProfile , eColorFormat inputFormat,
	                                         const ScColorProfile& outputProfile, eColorFormat outputFormat,
                                             const ScColorProfile& proofProfile , eRenderIntent renderIntent, 
                                             eRenderIntent proofingIntent, long transformFlags)
{
	ScColorTransform transform(NULL);
	if (inputProfile.isNull() || outputProfile.isNull())
		return transform;
	int inputProfEngineID  = inputProfile.engine().engineID();
	int outputProfEngineID = outputProfile.engine().engineID();
	int proofProfEngineID  = proofProfile.engine().engineID();
	if ((engine.engineID()  != m_engineID) || (inputProfEngineID != m_engineID) || 
		(outputProfEngineID != m_engineID) || (proofProfEngineID != m_engineID))
		return transform;
	const ScLcmsColorProfileImpl* lcmsInputProf    = dynamic_cast<const ScLcmsColorProfileImpl*>(inputProfile.data());
	const ScLcmsColorProfileImpl* lcmsOutputProf   = dynamic_cast<const ScLcmsColorProfileImpl*>(outputProfile.data());
	const ScLcmsColorProfileImpl* lcmsProofingProf = dynamic_cast<const ScLcmsColorProfileImpl*>(proofProfile.data());
	if (!lcmsInputProf || !lcmsOutputProf || !lcmsProofingProf)
		return transform;

	long strategyFlags = 0;
	if (m_strategy.useBlackPointCompensation)
		strategyFlags |= Ctf_BlackPointCompensation;
	if (m_strategy.useBlackPreservation)
		strategyFlags |= Ctf_BlackPreservation;

	ScColorTransformInfo transInfo;
	transInfo.inputProfile    = inputProfile.productDescription();
	transInfo.outputProfile   = outputProfile.productDescription();
	transInfo.proofingProfile = proofProfile.productDescription();
	transInfo.inputFormat     = inputFormat;
	transInfo.outputFormat    = outputFormat;
	transInfo.renderIntent    = renderIntent;
	transInfo.proofingIntent  = proofingIntent;
	transInfo.flags = transformFlags | strategyFlags;

	DWORD lcmsFlags     = translateFlagsToLcmsFlags(transformFlags | strategyFlags);
	DWORD lcmsInputFmt  = translateFormatToLcmsFormat(inputFormat);
	DWORD lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat);
	int   lcmsIntent    = translateIntentToLcmsIntent(renderIntent);
	int   lcmsPrfIntent = translateIntentToLcmsIntent(proofingIntent);

	if (transInfo.inputProfile != transInfo.proofingProfile)
	{
		if (transInfo.proofingProfile == transInfo.outputProfile)
		{
			transInfo.proofingIntent = Intent_Relative_Colorimetric;
			lcmsPrfIntent = translateIntentToLcmsIntent(Intent_Relative_Colorimetric);
		}
		transform = m_transformPool->findTransform(transInfo);
		if (transform.isNull())
		{
			cmsSetErrorHandler(&cmsErrorHandler);
			cmsHTRANSFORM hTransform = NULL;
			try
			{
				hTransform = cmsCreateProofingTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, 
														lcmsOutputProf->m_profileHandle, lcmsOutputFmt,
														lcmsProofingProf->m_profileHandle, lcmsIntent, 
														lcmsPrfIntent, lcmsFlags | cmsFLAGS_SOFTPROOFING);
				if (hTransform)
				{
					ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform);
					newTrans->setTransformInfo(transInfo);
					transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans));
					m_transformPool->addTransform(transform, true);
				}
			}
			catch (lcmsException& e)
			{
				std::cerr << e.what() << std::endl;
				// #9922 : no idea why that crash in release mode
				/*if (transform.isNull() && hTransform)
					cmsDeleteTransform(hTransform);*/
				transform = ScColorTransform();
			}
			cmsSetErrorHandler(NULL);
		}
	}
	else
	{
		transformFlags  &= (~Ctf_Softproofing);
		transformFlags  &= (~Ctf_GamutCheck);
		lcmsFlags        = translateFlagsToLcmsFlags(transformFlags | strategyFlags);
		transInfo.flags  = transformFlags | strategyFlags;
		transInfo.renderIntent   = proofingIntent;
		transInfo.proofingIntent = (eRenderIntent) 0;
		if (transInfo.inputProfile == transInfo.outputProfile)
		{
			lcmsFlags |= cmsFLAGS_NULLTRANSFORM;
			transInfo.inputProfile    = QString();
			transInfo.outputProfile   = QString();
			transInfo.proofingProfile = QString();
			transInfo.renderIntent    = (eRenderIntent) 0;
			transInfo.proofingIntent  = (eRenderIntent) 0;
			transInfo.flags = 0;
		}
		transform = m_transformPool->findTransform(transInfo);
		if (transform.isNull())
		{
			cmsSetErrorHandler(&cmsErrorHandler);
			cmsHTRANSFORM hTransform = NULL;
			try
			{
				hTransform  = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, 
											     lcmsOutputProf->m_profileHandle, lcmsOutputFmt, 
												 lcmsPrfIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC);
				if (hTransform)
				{
					ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform);
					newTrans->setTransformInfo(transInfo);
					transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans));
					m_transformPool->addTransform(transform, true);
				}
			}
			catch (lcmsException& e)
			{
				std::cerr << e.what() << std::endl;
				// #9922 : no idea why that crash in release mode
				/*if (transform.isNull() && hTransform)
					cmsDeleteTransform(hTransform);*/
				transform = ScColorTransform();
			}
			cmsSetErrorHandler(NULL);
		}
	}
	return transform;
}
Exemplo n.º 13
0
bool ScImgDataLoader_JPEG::loadPicture(const QString& fn, int /*page*/, int res, bool thumbnail)
{
	bool isCMYK = false;
	bool fromPS = false;
	float xres = 72.0, yres = 72.0;
	if (!QFile::exists(fn))
		return false;
	ExifData ExifInf;
	struct jpeg_decompress_struct cinfo;
	struct my_error_mgr         jerr;
	FILE     *infile;
	cinfo.err = jpeg_std_error (&jerr.pub);
	jerr.pub.error_exit = my_error_exit;
	infile = NULL;

	initialize();
	m_imageInfoRecord.type = ImageTypeJPG;
	m_imageInfoRecord.exifInfo.thumbnail = QImage();
	if (setjmp (jerr.setjmp_buffer))
	{
		jpeg_destroy_decompress (&cinfo);
		if (infile)
			fclose (infile);
		return false;
	}
	jpeg_create_decompress (&cinfo);
	if ((infile = fopen (fn.toLocal8Bit(), "rb")) == NULL)
		return false;
	jpeg_stdio_src(&cinfo, infile);
	jpeg_save_markers(&cinfo, ICC_MARKER, 0xFFFF);
	jpeg_save_markers(&cinfo, PHOTOSHOP_MARKER, 0xFFFF);
	jpeg_read_header(&cinfo, true);
	jpeg_start_decompress(&cinfo);
	bool exi = ExifInf.scan(fn);
	if ((exi) && (ExifInf.exifDataValid))
	{
		if (cinfo.output_components == 4)
			m_imageInfoRecord.colorspace = ColorSpaceCMYK;
		else if (cinfo.output_components == 3)
			m_imageInfoRecord.colorspace = ColorSpaceRGB;
		else if (cinfo.output_components == 1)
			m_imageInfoRecord.colorspace = ColorSpaceGray;
		if ((!ExifInf.Thumbnail.isNull()) && thumbnail)
		{
			m_image = ExifInf.getThumbnail();
			m_imageInfoRecord.exifInfo.thumbnail = ExifInf.getThumbnail();
			if (cinfo.output_components == 4)
			{
				QRgb *s;
				unsigned char cc, cm, cy, ck;
				for( int yit=0; yit < m_image.height(); ++yit )
				{
					s = (QRgb*)(m_image.scanLine( yit ));
					for(int xit=0; xit < m_image.width(); ++xit )
					{
						cc = 255 - qRed(*s);
						cm = 255 - qGreen(*s);
						cy = 255 - qBlue(*s);
						ck = qMin(qMin(cc, cm), cy);
						*s = qRgba(cc-ck,cm-ck,cy-ck,ck);
						s++;
					}
				}
			}
		}
		else
			m_imageInfoRecord.exifInfo.thumbnail = QImage();
		m_imageInfoRecord.exifInfo.cameraName = ExifInf.getCameraModel();
		m_imageInfoRecord.exifInfo.cameraVendor = ExifInf.getCameraMake();
		m_imageInfoRecord.exifInfo.comment = ExifInf.getComment();
		m_imageInfoRecord.exifInfo.width = ExifInf.getWidth();
		m_imageInfoRecord.exifInfo.height = ExifInf.getHeight();
		m_imageInfoRecord.exifInfo.userComment = ExifInf.getUserComment();
		m_imageInfoRecord.exifInfo.dateTime = ExifInf.getDateTime();
		m_imageInfoRecord.exifInfo.ApertureFNumber = ExifInf.getApertureFNumber();
		m_imageInfoRecord.exifInfo.ExposureTime = ExifInf.getExposureTime();
		m_imageInfoRecord.exifInfo.ISOequivalent = ExifInf.getISOequivalent();
		m_imageInfoRecord.exifDataValid = true;
		if (cinfo.density_unit == 0)
		{
			xres = 72;
			yres = 72;
		}
		else if ( cinfo.density_unit == 1 )
		{
			xres = cinfo.X_density;
			yres = cinfo.Y_density;
		}
		else if ( cinfo.density_unit == 2 )
		{
			xres = cinfo.X_density * 2.54;
			yres = cinfo.Y_density * 2.54;
		}
		if( xres <= 1.0 || yres <= 1.0 || xres > 3000.0 || yres > 3000.0 )
		{
			xres = yres = 72.0;
			QFileInfo qfi(fn);
			m_message = QObject::tr("%1 may be corrupted : missing or wrong resolution tags").arg(qfi.fileName());
			m_msgType = warningMsg;
		}
		m_imageInfoRecord.xres = qRound(xres);
		m_imageInfoRecord.yres = qRound(yres);
		m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);
		if ((!ExifInf.Thumbnail.isNull()) && thumbnail)
		{
			jpeg_destroy_decompress(&cinfo);
			fclose(infile);
			return true;
		}
	}
	else
		m_imageInfoRecord.exifDataValid = false;
	m_imageInfoRecord.exifInfo.thumbnail = QImage();
	unsigned int EmbedLen = 0;
	unsigned char* EmbedBuffer;
	if (read_jpeg_marker(ICC_MARKER,&cinfo, &EmbedBuffer, &EmbedLen))
	{
		QByteArray profArray = QByteArray((const char*) EmbedBuffer, EmbedLen);
		ScColorProfile prof = ScColorMgmtEngine::openProfileFromMem(profArray);
		m_embeddedProfile   = profArray;
		m_imageInfoRecord.profileName = prof.productDescription();
		m_imageInfoRecord.isEmbedded  = true;
		free(EmbedBuffer);
	}
	else
	{
		m_imageInfoRecord.isEmbedded = false;
		m_imageInfoRecord.profileName = "";
	}
	unsigned int PhotoshopLen = 0;
	unsigned char * PhotoshopBuffer;
	if (cinfo.density_unit == 0)
	{
		xres = 72;
		yres = 72;
		m_image.setDotsPerMeterX(2834);
		m_image.setDotsPerMeterY(2834);
	}
	else if ( cinfo.density_unit == 1 )
	{
		xres = cinfo.X_density;
		yres = cinfo.Y_density;
		m_image.setDotsPerMeterX( int(100. * cinfo.X_density / 2.54) );
		m_image.setDotsPerMeterY( int(100. * cinfo.Y_density / 2.54) );
	}
	else if ( cinfo.density_unit == 2 )
	{
		xres = cinfo.X_density * 2.54;
		yres = cinfo.Y_density * 2.54;
		m_image.setDotsPerMeterX( int(100. * cinfo.X_density) );
		m_image.setDotsPerMeterY( int(100. * cinfo.Y_density) );
	}
	if( xres <= 1.0 || yres <= 1.0 || xres > 3000.0 || yres > 3000.0 )
	{
		xres = yres = 72.0;
		m_image.setDotsPerMeterX(2834);
		m_image.setDotsPerMeterY(2834);
		QFileInfo qfi(fn);
		m_message = QObject::tr("%1 may be corrupted : missing or wrong resolution tags").arg(qfi.fileName());
		m_msgType = warningMsg;
	}
	m_imageInfoRecord.xres = qRound(xres);
	m_imageInfoRecord.yres = qRound(yres);
	if (cinfo.output_components == 4)
	{
		isCMYK = true;
		m_imageInfoRecord.colorspace = ColorSpaceCMYK;
	}
	else if (cinfo.output_components == 3)
		m_imageInfoRecord.colorspace = ColorSpaceRGB;
	else if (cinfo.output_components == 1)
		m_imageInfoRecord.colorspace = ColorSpaceGray;
	m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);

	if (read_jpeg_marker(PHOTOSHOP_MARKER,&cinfo, &PhotoshopBuffer, &PhotoshopLen) )
	{
		if (PhotoshopLen != 0)
		{
			bool savEx = m_imageInfoRecord.exifDataValid;
			QByteArray arrayPhot(PhotoshopLen, ' ');
			arrayPhot = QByteArray::fromRawData((const char*)PhotoshopBuffer,PhotoshopLen);
			QDataStream strPhot(&arrayPhot,QIODevice::ReadOnly);
			strPhot.setByteOrder( QDataStream::BigEndian );
			PSDHeader fakeHeader;
			fakeHeader.width = cinfo.output_width;
			fakeHeader.height = cinfo.output_height;
			if (cinfo.output_components == 4)
				m_imageInfoRecord.colorspace = ColorSpaceCMYK;
			else if (cinfo.output_components == 3)
				m_imageInfoRecord.colorspace = ColorSpaceRGB;
			else if (cinfo.output_components == 1)
				m_imageInfoRecord.colorspace = ColorSpaceGray;
			m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);
			parseRessourceData(strPhot, fakeHeader, PhotoshopLen);
			// Photoshop resolution is more accurate than jpeg header resolution
			xres = m_imageInfoRecord.xres;
			yres = m_imageInfoRecord.yres;
			m_image.setDotsPerMeterX( int(100. * m_imageInfoRecord.xres / 2.54) );
			m_image.setDotsPerMeterY( int(100. * m_imageInfoRecord.yres / 2.54) );
			if( xres <= 1.0 || yres <= 1.0 || xres > 3000.0 || yres > 3000.0 )
			{
				xres = yres = 72.0;
				m_imageInfoRecord.xres = qRound(xres);
				m_imageInfoRecord.yres = qRound(yres);
				m_image.setDotsPerMeterX(2834);
				m_image.setDotsPerMeterY(2834);
				QFileInfo qfi(fn);
				m_message = QObject::tr("%1 may be corrupted : missing or wrong resolution tags").arg(qfi.fileName());
				m_msgType = warningMsg;
			}
			if (m_imageInfoRecord.exifDataValid && !m_imageInfoRecord.exifInfo.thumbnail.isNull() && thumbnail)
			{
				m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32 );
				m_imageInfoRecord.exifInfo.width = cinfo.output_width;
				m_imageInfoRecord.exifInfo.height = cinfo.output_height;
				if (cinfo.output_components == 4)
				{
					QRgb *d;
					QRgb *s;
					unsigned char cc, cm, cy, ck;
					for( int yit=0; yit < m_image.height(); ++yit )
					{
						d = (QRgb*)(m_image.scanLine( yit ));
						s = (QRgb*)(m_imageInfoRecord.exifInfo.thumbnail.scanLine( yit ));
						for(int xit=0; xit < m_image.width(); ++xit )
						{
							cc = 255 - qRed(*s);
							cm = 255 - qGreen(*s);
							cy = 255 - qBlue(*s);
							ck = qMin(qMin(cc, cm), cy);
							*d = qRgba(cc-ck,cm-ck,cy-ck,ck);
							s++;
							d++;
						}
					}
				}
				else
					m_image = m_imageInfoRecord.exifInfo.thumbnail.copy();
			}
			m_imageInfoRecord.valid = (m_imageInfoRecord.PDSpathData.size())>0?true:false; // The only interest is vectormask
			arrayPhot.clear();
			free( PhotoshopBuffer );
			if (m_imageInfoRecord.exifDataValid && !m_imageInfoRecord.exifInfo.thumbnail.isNull() && thumbnail)
			{
				jpeg_destroy_decompress(&cinfo);
				fclose(infile);
				return true;
			}
			m_imageInfoRecord.exifInfo.thumbnail = QImage();
			m_imageInfoRecord.exifDataValid = savEx;
			fromPS = true;
		}
	}
	if ( cinfo.output_components == 3 || cinfo.output_components == 4)
		m_image = QImage( cinfo.output_width, cinfo.output_height, QImage::Format_ARGB32 );
	else if ( cinfo.output_components == 1 )
	{
		m_image = QImage( cinfo.output_width, cinfo.output_height, QImage::Format_Indexed8 );
		m_image.setNumColors(256);
		for (int i=0; i<256; i++)
			m_image.setColor(i, qRgb(i,i,i));
	}
	if (!m_image.isNull())
	{
		uchar* data = m_image.bits();
		int bpl = m_image.bytesPerLine();
		while (cinfo.output_scanline < cinfo.output_height)
		{
			uchar *d = data + cinfo.output_scanline * bpl;
			(void) jpeg_read_scanlines(&cinfo, &d, 1);
		}
		if ( cinfo.output_components == 3 )
		{
			uchar *in;
			QRgb *out;
			for (uint j=0; j<cinfo.output_height; j++)
			{
				in = m_image.scanLine(j) + cinfo.output_width * 3;
				out = (QRgb*) m_image.scanLine(j);
				for (uint i=cinfo.output_width; i--; )
				{
					in -= 3;
					out[i] = qRgb(in[0], in[1], in[2]);
				}
			}
		}
		if ( cinfo.output_components == 4 )
		{
			int method = 0;
			if (cinfo.jpeg_color_space == JCS_YCCK)
				method = 1;
			else if (fromPS)
			{
				if ((cinfo.jpeg_color_space == JCS_CMYK) && (cinfo.saw_Adobe_marker) && (cinfo.Adobe_transform == 0))
					method = 2;
			}
			else if ((cinfo.jpeg_color_space == JCS_CMYK) && (cinfo.saw_Adobe_marker))
				method = 1;
			QRgb *ptr;
			unsigned char c, m, y ,k;
			unsigned char *p;
			for (int i = 0; i < m_image.height(); i++)
			{
				ptr = (QRgb*)  m_image.scanLine(i);
				if (method == 1)
				{
					for (int j = 0; j <  m_image.width(); j++)
					{
						p = (unsigned char *) ptr;
						c = p[0];
						m = p[1];
						y =  p[2];
						k =  p[3];
						*ptr = qRgba(255 - c, 255 - m, 255 - y, 255 - k);
						ptr++;
					}
				}
				else if (method == 2)
				{
					for (int j = 0; j <  m_image.width(); j++)
					{
						p = (unsigned char *) ptr;
						c = p[0];
						m = p[1];
						y =  p[2];
						k =  p[3];
						*ptr = qRgba(255 - c, 255 - m, 255 - y, k);
						ptr++;
					}
				}
				else
				{
					for (int j = 0; j <  m_image.width(); j++)
					{
						p = (unsigned char *) ptr;
						c = p[0];
						m = p[1];
						y =  p[2];
						k =  p[3];
						*ptr = qRgba(y, m, c, k);
						ptr++;
					}
				}
			}
			isCMYK = true;
		}
		else
			isCMYK = false;
		if ( cinfo.output_components == 1 )
		{
			QImage tmpImg = m_image.convertToFormat(QImage::Format_ARGB32);
			m_image = QImage( cinfo.output_width, cinfo.output_height, QImage::Format_ARGB32 );
			QRgb *s;
			QRgb *d;
			for( int yi=0; yi < tmpImg.height(); ++yi )
			{
				s = (QRgb*)(tmpImg.scanLine( yi ));
				d = (QRgb*)(m_image.scanLine( yi ));
				for(int xi=0; xi < tmpImg.width(); ++xi )
				{
					(*d) = (*s);
					s++;
					d++;
				}
			}
		}
	}
	(void) jpeg_finish_decompress(&cinfo);
	fclose (infile);
	jpeg_destroy_decompress (&cinfo);
	m_imageInfoRecord.layerInfo.clear();
	m_imageInfoRecord.BBoxX = 0;
	m_imageInfoRecord.BBoxH = m_image.height();
	return (!m_image.isNull());
}
Exemplo n.º 14
0
void DocumentChecker::checkItems(ScribusDoc *currDoc, struct CheckerPrefs checkerSettings)
{
    QString chstr;
    errorCodes itemError;

    QList<PageItem*> allItems;
    uint masterItemsCount = currDoc->MasterItems.count();
    for (uint i = 0; i < masterItemsCount; ++i)
    {
        PageItem* currItem = currDoc->MasterItems.at(i);
        if (currItem->isGroup())
            allItems = currItem->getItemList();
        else
            allItems.append(currItem);
        for (int ii = 0; ii < allItems.count(); ii++)
        {
            currItem = allItems.at(ii);
            if (!currItem->printEnabled())
                continue;
            if (!(currDoc->layerPrintable(currItem->LayerID)) && (checkerSettings.ignoreOffLayers))
                continue;
            itemError.clear();
            if (((currItem->isAnnotation()) || (currItem->isBookmark)) && (checkerSettings.checkAnnotations))
                itemError.insert(PDFAnnotField, 0);
            if ((currItem->hasSoftShadow() || (currItem->fillTransparency() != 0.0) || (currItem->lineTransparency() != 0.0) || (currItem->fillBlendmode() != 0) || (currItem->lineBlendmode() != 0)) && (checkerSettings.checkTransparency))
                itemError.insert(Transparency, 0);
            if ((currItem->GrType != 0) && (checkerSettings.checkTransparency))
            {
                if (currItem->GrType == 9)
                {
                    if (currItem->GrCol1transp != 1.0)
                        itemError.insert(Transparency, 0);
                    else if (currItem->GrCol2transp != 1.0)
                        itemError.insert(Transparency, 0);
                    else if (currItem->GrCol3transp != 1.0)
                        itemError.insert(Transparency, 0);
                    else if (currItem->GrCol4transp != 1.0)
                        itemError.insert(Transparency, 0);
                }
                else if (currItem->GrType == 11)
                {
                    for (int grow = 0; grow < currItem->meshGradientArray.count(); grow++)
                    {
                        for (int gcol = 0; gcol < currItem->meshGradientArray[grow].count(); gcol++)
                        {
                            if (currItem->meshGradientArray[grow][gcol].transparency != 1.0)
                                itemError.insert(Transparency, 0);
                        }
                    }
                }
                else if (currItem->GrType == 12)
                {
                    for (int grow = 0; grow < currItem->meshGradientPatches.count(); grow++)
                    {
                        meshGradientPatch patch = currItem->meshGradientPatches[grow];
                        if (currItem->meshGradientPatches[grow].TL.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                        if (currItem->meshGradientPatches[grow].TR.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                        if (currItem->meshGradientPatches[grow].BR.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                        if (currItem->meshGradientPatches[grow].BL.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                    }
                }
                else
                {
                    QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops();
                    for( int offset = 0 ; offset < colorStops.count() ; offset++ )
                    {
                        if (colorStops[offset]->opacity != 1.0)
                        {
                            itemError.insert(Transparency, 0);
                            break;
                        }
                    }
                }
            }
            if ((currItem->GrTypeStroke != 0) && (checkerSettings.checkTransparency))
            {
                QList<VColorStop*> colorStops = currItem->stroke_gradient.colorStops();
                for( int offset = 0 ; offset < colorStops.count() ; offset++ )
                {
                    if (colorStops[offset]->opacity != 1.0)
                    {
                        itemError.insert(Transparency, 0);
                        break;
                    }
                }
            }
            if ((currItem->GrMask > 0) && (checkerSettings.checkTransparency))
                itemError.insert(Transparency, 0);
            if ((currItem->OwnPage == -1) && (checkerSettings.checkOrphans))
                itemError.insert(ObjectNotOnPage, 0);
#ifdef HAVE_OSG
            if (currItem->asImageFrame() && !currItem->asOSGFrame())
#else
            if (currItem->asImageFrame())
#endif
            {

                // check image vs. frame sizes
                if (checkerSettings.checkPartFilledImageFrames && isPartFilledImageFrame(currItem))
                {
                    itemError.insert(PartFilledImageFrame, 0);
                }

                if ((!currItem->imageIsAvailable) && (checkerSettings.checkPictures))
                    itemError.insert(MissingImage, 0);
                else
                {
                    if (currItem->imageIsAvailable)
                    {
                        if (checkerSettings.checkTransparency && currItem->pixm.hasSmoothAlpha())
                            itemError.insert(Transparency, 0);
                    }
                    if  (((qRound(72.0 / currItem->imageXScale()) < checkerSettings.minResolution) || (qRound(72.0 / currItem->imageYScale()) < checkerSettings.minResolution))
                            && (currItem->isRaster) && (checkerSettings.checkResolution))
                        itemError.insert(ImageDPITooLow, 0);
                    if  (((qRound(72.0 / currItem->imageXScale()) > checkerSettings.maxResolution) || (qRound(72.0 / currItem->imageYScale()) > checkerSettings.maxResolution))
                            && (currItem->isRaster) && (checkerSettings.checkResolution))
                        itemError.insert(ImageDPITooHigh, 0);
                    QFileInfo fi = QFileInfo(currItem->Pfile);
                    QString ext = fi.suffix().toLower();
                    if (extensionIndicatesPDF(ext) && (checkerSettings.checkRasterPDF))
                        itemError.insert(PlacedPDF, 0);
                    if ((ext == "gif") && (checkerSettings.checkForGIF))
                        itemError.insert(ImageIsGIF, 0);

                    if (extensionIndicatesPDF(ext))
                    {
                        PDFAnalyzer analyst(currItem->Pfile);
                        QList<PDFColorSpace> usedColorSpaces;
                        bool hasTransparency = false;
                        QList<PDFFont> usedFonts;
                        int pageNum = qMin(qMax(1, currItem->pixm.imgInfo.actualPageNumber), currItem->pixm.imgInfo.numberOfPages) - 1;
                        QList<PDFImage> imgs;
                        bool succeeded = analyst.inspectPDF(pageNum, usedColorSpaces, hasTransparency, usedFonts, imgs);
                        if (succeeded)
                        {
                            if (checkerSettings.checkNotCMYKOrSpot || checkerSettings.checkDeviceColorsAndOutputIntent)
                            {
                                eColorSpaceType currPrintProfCS = ColorSpace_Unknown;
                                if (currDoc->HasCMS)
                                {
                                    ScColorProfile printerProf = currDoc->DocPrinterProf;
                                    currPrintProfCS = printerProf.colorSpace();
                                }
                                if (checkerSettings.checkNotCMYKOrSpot)
                                {
                                    for (int i=0; i<usedColorSpaces.size(); ++i)
                                    {
                                        if (usedColorSpaces[i] == CS_DeviceRGB || usedColorSpaces[i] == CS_ICCBased || usedColorSpaces[i] == CS_CalGray
                                                || usedColorSpaces[i] == CS_CalRGB || usedColorSpaces[i] == CS_Lab)
                                        {
                                            itemError.insert(NotCMYKOrSpot, 0);
                                            break;
                                        }
                                    }
                                }
                                if (checkerSettings.checkDeviceColorsAndOutputIntent && currDoc->HasCMS)
                                {
                                    for (int i=0; i<usedColorSpaces.size(); ++i)
                                    {
                                        if (currPrintProfCS == ColorSpace_Cmyk && (usedColorSpaces[i] == CS_DeviceRGB || usedColorSpaces[i] == CS_DeviceGray))
                                        {
                                            itemError.insert(DeviceColorsAndOutputIntent, 0);
                                            break;
                                        }
                                        else if (currPrintProfCS == ColorSpace_Rgb && (usedColorSpaces[i] == CS_DeviceCMYK || usedColorSpaces[i] == CS_DeviceGray))
                                        {
                                            itemError.insert(DeviceColorsAndOutputIntent, 0);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (checkerSettings.checkTransparency && hasTransparency)
                                itemError.insert(Transparency, 0);
                            if (checkerSettings.checkFontNotEmbedded || checkerSettings.checkFontIsOpenType)
                            {
                                for (int i=0; i<usedFonts.size(); ++i)
                                {
                                    PDFFont currentFont = usedFonts[i];
                                    if (!currentFont.isEmbedded && checkerSettings.checkFontNotEmbedded)
                                        itemError.insert(FontNotEmbedded, 0);
                                    if (currentFont.isEmbedded && currentFont.isOpenType && checkerSettings.checkFontIsOpenType)
                                        itemError.insert(EmbeddedFontIsOpenType, 0);
                                }
                            }
                            if (checkerSettings.checkResolution)
                            {
                                for (int i=0; i<imgs.size(); ++i)
                                {
                                    if ((imgs[i].dpiX < checkerSettings.minResolution) || (imgs[i].dpiY < checkerSettings.minResolution))
                                        itemError.insert(ImageDPITooLow, 0);
                                    if ((imgs[i].dpiX > checkerSettings.maxResolution) || (imgs[i].dpiY > checkerSettings.maxResolution))
                                        itemError.insert(ImageDPITooHigh, 0);
                                }
                            }
                        }
                    }
                }
            }
            if ((currItem->asTextFrame()) || (currItem->asPathText()))
            {
                if ( currItem->frameOverflows() && (checkerSettings.checkOverflow) && (!((currItem->isAnnotation()) && ((currItem->annotation().Type() == Annotation::Combobox) || (currItem->annotation().Type() == Annotation::Listbox)))))
                    itemError.insert(TextOverflow, 0);

                if (checkerSettings.checkEmptyTextFrames && (currItem->itemText.length()==0 || currItem->frameUnderflows()))
                    itemError.insert(EmptyTextFrame, 0);

                if (currItem->isAnnotation())
                {
                    ScFace::FontFormat fformat = currItem->itemText.defaultStyle().charStyle().font().format();
                    if (!(fformat == ScFace::SFNT || fformat == ScFace::TTCF))
                        itemError.insert(WrongFontInAnnotation, 0);
                }
                for (int e = currItem->firstInFrame(); e <= currItem->lastInFrame(); ++e)
                {
                    uint chr = currItem->itemText.text(e).unicode();
                    if ((chr == 13) || (chr == 32) || (chr == 29) || (chr == 28) || (chr == 27) || (chr == 26) || (chr == 25))
                        continue;
                    if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
                    {
                        chstr = currItem->itemText.text(e);
                        if (chstr.toUpper() != currItem->itemText.text(e))
                            chstr = chstr.toUpper();
                        chr = chstr[0].unicode();
                    }
                    if (chr == 9)
                    {
                        for (int t1 = 0; t1 < currItem->itemText.paragraphStyle(e).tabValues().count(); t1++)
                        {
                            if (currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar.isNull())
                                continue;
                            chstr = QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar);
                            if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
                            {
                                if (chstr.toUpper() != QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar))
                                    chstr = chstr.toUpper();
                            }
                            chr = chstr[0].unicode();
                            if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
                                itemError.insert(MissingGlyph, e);
                        }
                        for (int t1 = 0; t1 < currItem->itemText.defaultStyle().tabValues().count(); t1++)
                        {
                            if (currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar.isNull())
                                continue;
                            chstr = QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar);
                            if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
                            {
                                if (chstr.toUpper() != QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar))
                                    chstr = chstr.toUpper();
                            }
                            chr = chstr[0].unicode();
                            if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
                                itemError.insert(MissingGlyph, e);
                        }
                        continue;
                    }
                    if ((chr == 30) || (chr == 23))
                    {
                        for (int numco = 0x30; numco < 0x3A; ++numco)
                        {
                            if ((!currItem->itemText.charStyle(e).font().canRender(numco)) && (checkerSettings.checkGlyphs))
                                itemError.insert(MissingGlyph, e);
                        }
                        continue;
                    }
                    if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
                        itemError.insert(MissingGlyph, e);
                }
            }
            if (((currItem->fillColor() != CommonStrings::None) || (currItem->lineColor() != CommonStrings::None)) && (checkerSettings.checkNotCMYKOrSpot))
            {
                bool rgbUsed = false;
                if ((currItem->fillColor() != CommonStrings::None))
                {
                    ScColor tmpC = currDoc->PageColors[currItem->fillColor()];
                    if (tmpC.getColorModel() == colorModelRGB)
                        rgbUsed = true;
                }
                if ((currItem->lineColor() != CommonStrings::None))
                {
                    ScColor tmpC = currDoc->PageColors[currItem->lineColor()];
                    if (tmpC.getColorModel() == colorModelRGB)
                        rgbUsed = true;
                }
                if (rgbUsed)
                    itemError.insert(NotCMYKOrSpot, 0);
            }
            if (itemError.count() != 0)
                currDoc->masterItemErrors.insert(currItem, itemError);
        }
        allItems.clear();
    }
    allItems.clear();
    uint docItemsCount = currDoc->DocItems.count();
    for (uint i = 0; i < docItemsCount; ++i)
    {
        PageItem* currItem = currDoc->DocItems.at(i);
        if (currItem->isGroup())
            allItems = currItem->getItemList();
        else
            allItems.append(currItem);
        for (int ii = 0; ii < allItems.count(); ii++)
        {
            currItem = allItems.at(ii);
            if (!currItem->printEnabled())
                continue;
            if (!(currDoc->layerPrintable(currItem->LayerID)) && (checkerSettings.ignoreOffLayers))
                continue;
            itemError.clear();
            if ((currItem->hasSoftShadow() || (currItem->fillTransparency() != 0.0) || (currItem->lineTransparency() != 0.0) || (currItem->fillBlendmode() != 0) || (currItem->lineBlendmode() != 0)) && (checkerSettings.checkTransparency))
                itemError.insert(Transparency, 0);
            if ((currItem->GrType != 0) && (checkerSettings.checkTransparency))
            {
                if (currItem->GrType == 9)
                {
                    if (currItem->GrCol1transp != 1.0)
                        itemError.insert(Transparency, 0);
                    else if (currItem->GrCol2transp != 1.0)
                        itemError.insert(Transparency, 0);
                    else if (currItem->GrCol3transp != 1.0)
                        itemError.insert(Transparency, 0);
                    else if (currItem->GrCol4transp != 1.0)
                        itemError.insert(Transparency, 0);
                }
                else if (currItem->GrType == 11)
                {
                    for (int grow = 0; grow < currItem->meshGradientArray.count(); grow++)
                    {
                        for (int gcol = 0; gcol < currItem->meshGradientArray[grow].count(); gcol++)
                        {
                            if (currItem->meshGradientArray[grow][gcol].transparency != 1.0)
                                itemError.insert(Transparency, 0);
                        }
                    }
                }
                else if (currItem->GrType == 12)
                {
                    for (int grow = 0; grow < currItem->meshGradientPatches.count(); grow++)
                    {
                        meshGradientPatch patch = currItem->meshGradientPatches[grow];
                        if (currItem->meshGradientPatches[grow].TL.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                        if (currItem->meshGradientPatches[grow].TR.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                        if (currItem->meshGradientPatches[grow].BR.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                        if (currItem->meshGradientPatches[grow].BL.transparency != 1.0)
                            itemError.insert(Transparency, 0);
                    }
                }
                else
                {
                    QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops();
                    for( int offset = 0 ; offset < colorStops.count() ; offset++ )
                    {
                        if (colorStops[offset]->opacity != 1.0)
                        {
                            itemError.insert(Transparency, 0);
                            break;
                        }
                    }
                }
            }
            if ((currItem->GrTypeStroke != 0) && (checkerSettings.checkTransparency))
            {
                QList<VColorStop*> colorStops = currItem->stroke_gradient.colorStops();
                for( int offset = 0 ; offset < colorStops.count() ; offset++ )
                {
                    if (colorStops[offset]->opacity != 1.0)
                    {
                        itemError.insert(Transparency, 0);
                        break;
                    }
                }
            }
            if ((currItem->GrMask > 0) && (checkerSettings.checkTransparency))
                itemError.insert(Transparency, 0);
            if (((currItem->isAnnotation()) || (currItem->isBookmark)) && (checkerSettings.checkAnnotations))
                itemError.insert(PDFAnnotField, 0);
            if ((currItem->OwnPage == -1) && (checkerSettings.checkOrphans))
                itemError.insert(ObjectNotOnPage, 0);
#ifdef HAVE_OSG
            if (currItem->asImageFrame() && !currItem->asOSGFrame())
#else
            if (currItem->asImageFrame())
#endif
            {

                // check image vs. frame sizes
                if (checkerSettings.checkPartFilledImageFrames && isPartFilledImageFrame(currItem))
                {
                    itemError.insert(PartFilledImageFrame, 0);
                }

                if ((!currItem->imageIsAvailable) && (checkerSettings.checkPictures))
                    itemError.insert(MissingImage, 0);
                else
                {
                    if (currItem->imageIsAvailable)
                    {
                        if (checkerSettings.checkTransparency && currItem->pixm.hasSmoothAlpha())
                            itemError.insert(Transparency, 0);
                    }
                    if  (((qRound(72.0 / currItem->imageXScale()) < checkerSettings.minResolution) || (qRound(72.0 / currItem->imageYScale()) < checkerSettings.minResolution))
                            && (currItem->isRaster) && (checkerSettings.checkResolution))
                        itemError.insert(ImageDPITooLow, 0);
                    if  (((qRound(72.0 / currItem->imageXScale()) > checkerSettings.maxResolution) || (qRound(72.0 / currItem->imageYScale()) > checkerSettings.maxResolution))
                            && (currItem->isRaster) && (checkerSettings.checkResolution))
                        itemError.insert(ImageDPITooHigh, 0);
                    QFileInfo fi = QFileInfo(currItem->Pfile);
                    QString ext = fi.suffix().toLower();
                    if (extensionIndicatesPDF(ext) && (checkerSettings.checkRasterPDF))
                        itemError.insert(PlacedPDF, 0);
                    if ((ext == "gif") && (checkerSettings.checkForGIF))
                        itemError.insert(ImageIsGIF, 0);

                    if (extensionIndicatesPDF(ext))
                    {
                        PDFAnalyzer analyst(currItem->Pfile);
                        QList<PDFColorSpace> usedColorSpaces;
                        bool hasTransparency = false;
                        QList<PDFFont> usedFonts;
                        int pageNum = qMin(qMax(1, currItem->pixm.imgInfo.actualPageNumber), currItem->pixm.imgInfo.numberOfPages) - 1;
                        QList<PDFImage> imgs;
                        bool succeeded = analyst.inspectPDF(pageNum, usedColorSpaces, hasTransparency, usedFonts, imgs);
                        if (succeeded)
                        {
                            if (checkerSettings.checkNotCMYKOrSpot || checkerSettings.checkDeviceColorsAndOutputIntent)
                            {
                                int currPrintProfCS = -1;
                                if (currDoc->HasCMS)
                                {
                                    ScColorProfile printerProf = currDoc->DocPrinterProf;
                                    currPrintProfCS = static_cast<int>(printerProf.colorSpace());
                                }
                                if (checkerSettings.checkNotCMYKOrSpot)
                                {
                                    for (int i=0; i<usedColorSpaces.size(); ++i)
                                    {
                                        if (usedColorSpaces[i] == CS_DeviceRGB || usedColorSpaces[i] == CS_ICCBased || usedColorSpaces[i] == CS_CalGray
                                                || usedColorSpaces[i] == CS_CalRGB || usedColorSpaces[i] == CS_Lab)
                                        {
                                            itemError.insert(NotCMYKOrSpot, 0);
                                            break;
                                        }
                                    }
                                }
                                if (checkerSettings.checkDeviceColorsAndOutputIntent && currDoc->HasCMS)
                                {
                                    for (int i=0; i<usedColorSpaces.size(); ++i)
                                    {
                                        if (currPrintProfCS == ColorSpace_Cmyk && (usedColorSpaces[i] == CS_DeviceRGB || usedColorSpaces[i] == CS_DeviceGray))
                                        {
                                            itemError.insert(DeviceColorsAndOutputIntent, 0);
                                            break;
                                        }
                                        else if (currPrintProfCS == ColorSpace_Rgb && (usedColorSpaces[i] == CS_DeviceCMYK || usedColorSpaces[i] == CS_DeviceGray))
                                        {
                                            itemError.insert(DeviceColorsAndOutputIntent, 0);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (checkerSettings.checkTransparency && hasTransparency)
                                itemError.insert(Transparency, 0);
                            if (checkerSettings.checkFontNotEmbedded || checkerSettings.checkFontIsOpenType)
                            {
                                for (int i=0; i<usedFonts.size(); ++i)
                                {
                                    PDFFont currentFont = usedFonts[i];
                                    if (!currentFont.isEmbedded && checkerSettings.checkFontNotEmbedded)
                                        itemError.insert(FontNotEmbedded, 0);
                                    if (currentFont.isEmbedded && currentFont.isOpenType && checkerSettings.checkFontIsOpenType)
                                        itemError.insert(EmbeddedFontIsOpenType, 0);
                                }
                            }
                            if (checkerSettings.checkResolution)
                            {
                                for (int i=0; i<imgs.size(); ++i)
                                {
                                    if ((imgs[i].dpiX < checkerSettings.minResolution) || (imgs[i].dpiY < checkerSettings.minResolution))
                                        itemError.insert(ImageDPITooLow, 0);
                                    if ((imgs[i].dpiX > checkerSettings.maxResolution) || (imgs[i].dpiY > checkerSettings.maxResolution))
                                        itemError.insert(ImageDPITooHigh, 0);
                                }
                            }
                        }
                    }
                }
            }
            if ((currItem->asTextFrame()) || (currItem->asPathText()))
            {
                if ( currItem->frameOverflows() && (checkerSettings.checkOverflow) && (!((currItem->isAnnotation()) && ((currItem->annotation().Type() == Annotation::Combobox) || (currItem->annotation().Type() == Annotation::Listbox)))))
                    itemError.insert(TextOverflow, 0);

                if (checkerSettings.checkEmptyTextFrames && (currItem->itemText.length()==0 || currItem->frameUnderflows()))
                    itemError.insert(EmptyTextFrame, 0);

                if (currItem->isAnnotation())
                {
                    ScFace::FontFormat fformat = currItem->itemText.defaultStyle().charStyle().font().format();
                    if (!(fformat == ScFace::SFNT || fformat == ScFace::TTCF))
                        itemError.insert(WrongFontInAnnotation, 0);
                }
                for (int e = currItem->firstInFrame(); e <= currItem->lastInFrame(); ++e)
                {
                    uint chr = currItem->itemText.text(e).unicode();
                    if ((chr == 13) || (chr == 32) || (chr == 29) || (chr == 28) || (chr == 27) || (chr == 26) || (chr == 25))
                        continue;
                    if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
                    {
                        chstr = currItem->itemText.text(e,1);
                        if (chstr.toUpper() != currItem->itemText.text(e,1))
                            chstr = chstr.toUpper();
                        chr = chstr[0].unicode();
                    }
                    if (chr == 9)
                    {
                        for (int t1 = 0; t1 < currItem->itemText.paragraphStyle(e).tabValues().count(); t1++)
                        {
                            if (currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar.isNull())
                                continue;
                            chstr = QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar);
                            if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
                            {
                                if (chstr.toUpper() != QString(currItem->itemText.paragraphStyle(e).tabValues()[t1].tabFillChar))
                                    chstr = chstr.toUpper();
                            }
                            chr = chstr[0].unicode();
                            if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
                                itemError.insert(MissingGlyph, e);
                        }
                        for (int t1 = 0; t1 < currItem->itemText.defaultStyle().tabValues().count(); t1++)
                        {
                            if (currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar.isNull())
                                continue;
                            chstr = QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar);
                            if ((currItem->itemText.charStyle(e).effects() & ScStyle_SmallCaps) || (currItem->itemText.charStyle(e).effects() & ScStyle_AllCaps))
                            {
                                if (chstr.toUpper() != QString(currItem->itemText.defaultStyle().tabValues()[t1].tabFillChar))
                                    chstr = chstr.toUpper();
                            }
                            chr = chstr[0].unicode();
                            if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
                                itemError.insert(MissingGlyph, e);
                        }
                        continue;
                    }
                    if ((chr == 30) || (chr == 23))
                    {
                        for (uint numco = 0x30; numco < 0x3A; ++numco)
                        {
                            if ((!currItem->itemText.charStyle(e).font().canRender(numco)) && (checkerSettings.checkGlyphs))
                                itemError.insert(MissingGlyph, e);
                        }
                        continue;
                    }
                    if ((!currItem->itemText.charStyle(e).font().canRender(chr)) && (checkerSettings.checkGlyphs))
                        itemError.insert(MissingGlyph, e);
                }
            }
            if (((currItem->fillColor() != CommonStrings::None) || (currItem->lineColor() != CommonStrings::None)) && (checkerSettings.checkNotCMYKOrSpot))
            {
                bool rgbUsed = false;
                if ((currItem->fillColor() != CommonStrings::None))
                {
                    ScColor tmpC = currDoc->PageColors[currItem->fillColor()];
                    if (tmpC.getColorModel() == colorModelRGB)
                        rgbUsed = true;
                }
                if ((currItem->lineColor() != CommonStrings::None))
                {
                    ScColor tmpC = currDoc->PageColors[currItem->lineColor()];
                    if (tmpC.getColorModel() == colorModelRGB)
                        rgbUsed = true;
                }
                if (rgbUsed)
                    itemError.insert(NotCMYKOrSpot, 0);
            }
            if (itemError.count() != 0)
                currDoc->docItemErrors.insert(currItem, itemError);
        }
        allItems.clear();
    }
}
void ScColorProfileCache::removeProfile(const ScColorProfile& profile)
{
	m_profileMap.remove(profile.profilePath());
}
Exemplo n.º 16
0
ScColorTransform ScLcms2ColorMgmtEngineImpl::createTransform(ScColorMgmtEngine& engine,
                                 const ScColorProfile& inputProfile , eColorFormat inputFormat,
	                             const ScColorProfile& outputProfile, eColorFormat outputFormat,
                                 eRenderIntent renderIntent, long transformFlags)
{
	ScColorTransform transform(NULL);
	if (inputProfile.isNull() || outputProfile.isNull())
		return transform;
	int inputProfEngineID  = inputProfile.engine().engineID();
	int outputProfEngineID = outputProfile.engine().engineID();
	if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || (outputProfEngineID != m_engineID))
		return transform;
	const ScLcms2ColorProfileImpl* lcmsInputProf  = dynamic_cast<const ScLcms2ColorProfileImpl*>(inputProfile.data());
	const ScLcms2ColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(outputProfile.data());
	if (!lcmsInputProf || !lcmsOutputProf)
		return transform;

	transformFlags &= (~Ctf_Softproofing);
	transformFlags &= (~Ctf_GamutCheck);
	long strategyFlags = 0;
	if (m_strategy.useBlackPointCompensation)
		strategyFlags |= Ctf_BlackPointCompensation;
	if (m_strategy.useBlackPreservation)
		strategyFlags |= Ctf_BlackPreservation;

	ScColorTransformInfo transInfo;
	transInfo.inputProfile  = inputProfile.productDescription();
	transInfo.outputProfile = outputProfile.productDescription();
	transInfo.proofingProfile = QString();
	transInfo.inputFormat   = inputFormat;
	transInfo.outputFormat  = outputFormat;
	transInfo.renderIntent  = renderIntent;
	transInfo.proofingIntent = (eRenderIntent) 0;
	transInfo.flags = transformFlags | strategyFlags;

	bool nullTransform = false;
	if (transInfo.inputProfile == transInfo.outputProfile)
	{
		// This is a null transform
		transInfo.inputProfile    = QString();
		transInfo.outputProfile   = QString();
		transInfo.proofingProfile = QString();
		transInfo.renderIntent    = (eRenderIntent) 0;
		transInfo.proofingIntent  = (eRenderIntent) 0;
		transInfo.flags = 0;
		nullTransform = true;
	}

	transform = m_transformPool->findTransform(transInfo);
	if (transform.isNull())
	{
		cmsUInt32Number lcmsFlags     = translateFlagsToLcmsFlags(transformFlags | strategyFlags);
		cmsUInt32Number lcmsInputFmt  = translateFormatToLcmsFormat(inputFormat);
		cmsUInt32Number lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat);
		int   lcmsIntent    = translateIntentToLcmsIntent(renderIntent);
		if (nullTransform)
			lcmsFlags |= cmsFLAGS_NULLTRANSFORM;
		cmsHTRANSFORM hTransform = NULL;
		hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, 
										lcmsOutputProf->m_profileHandle, lcmsOutputFmt, 
										lcmsIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC);
		if (hTransform)
		{
			ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform);
			newTrans->setTransformInfo(transInfo);
			transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans));
			m_transformPool->addTransform(transform, true);
		}
	}
	return transform;
}