QString PageItem_ImageFrame::infoDescription()
{
	QString htmlText;
	htmlText.append( tr("Image") + "<br/>");
	
	if (PictureIsAvailable)
	{
		QFileInfo fi = QFileInfo(Pfile);
		if (isInlineImage)
			htmlText.append( tr("Embedded Image") + "<br/>");
		else
			htmlText.append( tr("File:") + " " + fi.fileName() + "<br/>");
		htmlText.append( tr("Original PPI:") + " " + QString::number(qRound(pixm.imgInfo.xres))+" x "+QString::number(qRound(pixm.imgInfo.yres)) + "<br/>");
		htmlText.append( tr("Actual PPI:") + " " + QString::number(qRound(72.0 / imageXScale()))+" x "+ QString::number(qRound(72.0 / imageYScale())) + "<br/>");
		htmlText.append( tr("Colorspace:") + " ");
		QString cSpace;
		QString ext = fi.suffix().toLower();
		if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (pixm.imgInfo.type != ImageType7))
			htmlText.append( tr("Unknown"));
		else
			htmlText.append(colorSpaceText(pixm.imgInfo.colorspace));
		htmlText.append("<br/>");
		if (pixm.imgInfo.numberOfPages > 1)
		{
			if (pixm.imgInfo.actualPageNumber > 0)
				htmlText.append( tr("Page:") + " " + QString::number(pixm.imgInfo.actualPageNumber) + "/" + QString::number(pixm.imgInfo.numberOfPages)+ "<br/>");
			else
				htmlText.append( tr("Pages:") + " " + QString::number(pixm.imgInfo.numberOfPages)+ "<br/>");
		}
	}
	else
	{
		if (!Pfile.isEmpty())
		{
			QFileInfo fi = QFileInfo(Pfile);
			if (isInlineImage)
				htmlText.append( tr("Embedded Image missing") + "<br/>");
			else if (extensionIndicatesPDF(fi.suffix().toLower()))
				htmlText.append( tr("File:") + " " + fi.fileName() + " " + tr("missing or corrupt") + "<br/>");
			else
				htmlText.append( tr("File:") + " " + fi.fileName() + " " + tr("missing") + "<br/>");
		}
		else
			htmlText.append( tr("No Image Loaded") + "<br/>");
	}
	htmlText.append(PageItem::infoDescription());
	return htmlText;
}
Пример #2
0
void PicSearch::createPreview()
{
	QPixmap pm(200, 200);
	QFileInfo fi = QFileInfo(currentImage);
	int w = 200;
	int h = 200;
	bool mode = false;
	QString ext = fi.suffix().toLower();
	if (ext.isEmpty())
		ext = getImageType(currentImage);
	ScImage im;
	//No doc to send data anyway, so no doc to get into scimage.
	CMSettings cms(0, "", Intent_Perceptual);
	cms.allowColorManagement(false);
	if (im.loadPicture(currentImage, 1, cms, ScImage::Thumbnail, 72, &mode))
	{
		int ix,iy;
		if ((im.imgInfo.exifDataValid) && (!im.imgInfo.exifInfo.thumbnail.isNull()))
		{
			ix = im.imgInfo.exifInfo.width;
			iy = im.imgInfo.exifInfo.height;
		}
		else
		{
			ix = im.width();
			iy = im.height();
		}
		int xres = im.imgInfo.xres;
		int yres = im.imgInfo.yres;
		QString tmp = "";
		QString tmp2 = "";
		QImage im2;
		if ((ix > w-5) || (iy > h-44))
		{
			double sx = im.width() / static_cast<double>(w-5);
			double sy = im.height() / static_cast<double>(h-44);
			im2 = sy < sx ? im.scaled(qRound(im.width() / sx), qRound(im.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)
						: im.scaled(qRound(im.width() / sy), qRound(im.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
		}
		else
			im2 = im.qImage(); // no need to copy
		QPainter p;
		QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
		p.begin(&pm);
		p.fillRect(0, 0, w, h-44, b);
		p.fillRect(0, h-44, w, 44, QColor(255, 255, 255));
		p.drawImage((w - im2.width()) / 2, (h - 44 - im2.height()) / 2, im2);
		p.drawText(2, h-29, tr("Size:")+" "+tmp.setNum(ix)+" x "+tmp2.setNum(iy));
		p.drawText(2, h-17, tr("Resolution:")+" "+tmp.setNum(xres)+" x "+tmp2.setNum(yres)+" "+ tr("DPI"));
		QString cSpace;
		if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (im.imgInfo.type != ImageType7))
			cSpace = tr("Unknown");
		else
			cSpace=colorSpaceText(im.imgInfo.colorspace);
		p.drawText(2, h-5, tr("Colorspace:")+" "+cSpace);
		p.end();
		repaint();
	}
	previewLabel->setPixmap(pm);
}
void PageItem_ImageFrame::DrawObj_Item(ScPainter *p, QRectF /*e*/)
{
	if (m_Doc->RePos)
		return;
	if (m_Doc->layerOutline(LayerID))
		return;

	p->setFillRule(true);
	if ((fillColor() != CommonStrings::None) || (GrType != 0))
	{
		p->setupPolygon(&PoLine);
		p->fillPath();
	}
	p->save();
	if (Pfile.isEmpty())
	{
		if ((Frame) && (m_Doc->guidesPrefs().framesShown))
		{
			p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
			p->drawLine(FPoint(0, 0), FPoint(Width, Height));
			p->drawLine(FPoint(0, Height), FPoint(Width, 0));
		}
	}
	else
	{
		//If we are missing our image, draw a red cross in the frame
		if ((!PicArt) || (!PictureIsAvailable))
		{
			if ((Frame) && (m_Doc->guidesPrefs().framesShown))
			{
				p->setBrush(Qt::white);
				QString htmlText = "";
				QFileInfo fi = QFileInfo(Pfile);
				if (PictureIsAvailable)
				{
					p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
					if (isInlineImage)
						htmlText.append( tr("Embedded Image") + "\n");
					else
						htmlText.append( tr("File:") + " " + fi.fileName() + "\n");
					htmlText.append( tr("Original PPI:") + " " + QString::number(qRound(pixm.imgInfo.xres))+" x "+QString::number(qRound(pixm.imgInfo.yres)) + "\n");
					htmlText.append( tr("Actual PPI:") + " " + QString::number(qRound(72.0 / imageXScale()))+" x "+ QString::number(qRound(72.0 / imageYScale())) + "\n");
					htmlText.append( tr("Size:") + " " + QString::number(OrigW) + " x " + QString::number(OrigH) + "\n");
					htmlText.append( tr("Colorspace:") + " ");
					QString cSpace;
					QString ext = fi.suffix().toLower();
					if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (pixm.imgInfo.type != ImageType7))
						htmlText.append( tr("Unknown"));
					else
						htmlText.append(colorSpaceText(pixm.imgInfo.colorspace));
					if (pixm.imgInfo.numberOfPages > 1)
					{
						htmlText.append("\n");
						if (pixm.imgInfo.actualPageNumber > 0)
							htmlText.append( tr("Page:") + " " + QString::number(pixm.imgInfo.actualPageNumber) + "/" + QString::number(pixm.imgInfo.numberOfPages));
						else
							htmlText.append( tr("Pages:") + " " + QString::number(pixm.imgInfo.numberOfPages));
					}
				}
				else
				{
					p->setPen(Qt::red, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
					htmlText = fi.fileName();
				}
				p->drawLine(FPoint(0, 0), FPoint(Width, Height));
				p->drawLine(FPoint(0, Height), FPoint(Width, 0));
				p->setFont(QApplication::font());
				p->drawText(QRectF(0.0, 0.0, Width, Height), htmlText);
			}
		}
		else
		{
			p->setupPolygon(&PoLine);
			p->setClipPath();
			if (imageFlippedH())
			{
				p->translate(Width, 0);
				p->scale(-1, 1);
			}
			if (imageFlippedV())
			{
				p->translate(0, Height);
				p->scale(1, -1);
			}
			if (imageClip.size() != 0)
			{
				p->setupPolygon(&imageClip);
				p->setClipPath();
			}
			p->translate(LocalX*LocalScX, LocalY*LocalScY);
			p->rotate(LocalRot);
			double mscalex = 1.0 / LocalScX;
			double mscaley = 1.0 / LocalScY;
			p->scale(LocalScX, LocalScY);
			if (pixm.imgInfo.lowResType != 0)
			{
				p->scale(pixm.imgInfo.lowResScale, pixm.imgInfo.lowResScale);
				mscalex *= 1.0 / pixm.imgInfo.lowResScale;
				mscaley *= 1.0 / pixm.imgInfo.lowResScale;
			}
			if ((GrMask == 1) || (GrMask == 2) || (GrMask == 4) || (GrMask == 5))
			{
				if ((GrMask == 1) || (GrMask == 2))
					p->setMaskMode(1);
				else
					p->setMaskMode(3);
				if ((!gradientMaskVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientMaskVal)))
					gradientMaskVal = "";
				if (!(gradientMaskVal.isEmpty()) && (m_Doc->docGradients.contains(gradientMaskVal)))
					mask_gradient = m_Doc->docGradients[gradientMaskVal];
				p->mask_gradient = mask_gradient;
				if ((GrMask == 1) || (GrMask == 4))
					p->setGradientMask(VGradient::linear, FPoint(GrMaskStartX * mscalex, GrMaskStartY * mscaley), FPoint(GrMaskEndX * mscalex, GrMaskEndY * mscaley), FPoint(GrMaskStartX * mscalex, GrMaskStartY * mscaley), GrMaskScale, GrMaskSkew);
				else
					p->setGradientMask(VGradient::radial, FPoint(GrMaskStartX * mscalex, GrMaskStartY * mscaley), FPoint(GrMaskEndX * mscalex, GrMaskEndY * mscaley), FPoint(GrMaskFocalX * mscalex, GrMaskFocalY * mscaley), GrMaskScale, GrMaskSkew);
			}
			else if ((GrMask == 3) || (GrMask == 6) || (GrMask == 7) || (GrMask == 8))
			{
				if ((patternMaskVal.isEmpty()) || (!m_Doc->docPatterns.contains(patternMaskVal)))
					p->setMaskMode(0);
				else
				{
					p->setPatternMask(&m_Doc->docPatterns[patternMaskVal], patternMaskScaleX * mscalex, patternMaskScaleY * mscaley, patternMaskOffsetX, patternMaskOffsetY, patternMaskRotation, patternMaskSkewX, patternMaskSkewY, patternMaskMirrorX, patternMaskMirrorY);
					if (GrMask == 3)
						p->setMaskMode(2);
					else if (GrMask == 6)
						p->setMaskMode(4);
					else if (GrMask == 7)
						p->setMaskMode(5);
					else
						p->setMaskMode(6);
				}
			}
			else
				p->setMaskMode(0);
			p->drawImage(pixm.qImagePtr());
		}
	}
	p->restore();
}
bool PageItem_ImageFrame::createInfoGroup(QFrame *infoGroup, QGridLayout *infoGroupLayout)
{
	QLabel *infoCT, *fileT, *fileCT, *oPpiT, *oPpiCT, *aPpiT, *aPpiCT, *colT, *colCT;
	infoCT = new QLabel(infoGroup);
	fileCT = new QLabel(infoGroup);
	
	infoCT->setText( tr("Image"));
	infoGroupLayout->addWidget( infoCT, 0, 0, 1, 2, Qt::AlignHCenter );
	
	if (PictureIsAvailable)
	{
		fileT = new QLabel(infoGroup);
		oPpiT = new QLabel(infoGroup);
		oPpiCT = new QLabel(infoGroup);
		aPpiT = new QLabel(infoGroup);
		aPpiCT = new QLabel(infoGroup);
		colT = new QLabel(infoGroup);
		colCT = new QLabel(infoGroup);
		QFileInfo fi = QFileInfo(Pfile);
		fileCT->setText( tr("File:"));
		infoGroupLayout->addWidget( fileCT, 1, 0, Qt::AlignRight );
		if (isInlineImage)
			fileT->setText( tr("Embedded Image"));
		else
			fileT->setText(fi.fileName());
		infoGroupLayout->addWidget( fileT, 1, 1 );
		
		oPpiCT->setText( tr("Original PPI:"));
		infoGroupLayout->addWidget( oPpiCT, 2, 0, Qt::AlignRight );
		oPpiT->setText(QString::number(qRound(pixm.imgInfo.xres))+" x "+QString::number(qRound(pixm.imgInfo.yres)));
		infoGroupLayout->addWidget( oPpiT, 2, 1 );
		
		aPpiCT->setText( tr("Actual PPI:"));
		infoGroupLayout->addWidget( aPpiCT, 3, 0, Qt::AlignRight );
		aPpiT->setText(QString::number(qRound(72.0 / imageXScale()))+" x "+ QString::number(qRound(72.0 / imageYScale())));
		infoGroupLayout->addWidget( aPpiT, 3, 1 );
		
		colCT->setText( tr("Colorspace:"));
		infoGroupLayout->addWidget( colCT, 4, 0, Qt::AlignRight );
		QString cSpace;
		QString ext = fi.suffix().toLower();
		if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (pixm.imgInfo.type != ImageType7))
			cSpace = tr("Unknown");
		else
			cSpace=colorSpaceText(pixm.imgInfo.colorspace);
		colT->setText(cSpace);
		infoGroupLayout->addWidget( colT, 4, 1 );
	}
	else
	{
		if (!Pfile.isEmpty())
		{
			QFileInfo fi = QFileInfo(Pfile);
			fileCT->setText( tr("File:"));
			infoGroupLayout->addWidget( fileCT, 1, 0, Qt::AlignRight );
			fileT = new QLabel(infoGroup);
			if (isInlineImage)
				fileT->setText( tr("Embedded Image missing"));
			else if (extensionIndicatesPDF(fi.suffix().toLower()))
				fileT->setText(fi.fileName() + " " + tr("missing or corrupt"));
			else
				fileT->setText(fi.fileName() + " " + tr("missing"));
			infoGroupLayout->addWidget( fileT, 1, 1 );
		}
		else
		{
			fileCT->setText( tr("No Image Loaded"));
			infoGroupLayout->addWidget( fileCT, 1, 0, 1, 2, Qt::AlignHCenter );
		}
	}
	return true;
}
void PageItem_ImageFrame::DrawObj_Item(ScPainter *p, QRectF /*e*/, double sc)
{
	if(!m_Doc->RePos)
	{
		if (!m_Doc->layerOutline(LayerNr))
		{
			p->setFillRule(true);
			if ((fillColor() != CommonStrings::None) || (GrType != 0))
			{
				p->setupPolygon(&PoLine);
				p->fillPath();
			}
			p->save();
			if (imageClip.size() != 0)
			{
				p->setupPolygon(&imageClip);
				p->setClipPath();
			}
			p->setupPolygon(&PoLine);
			p->setClipPath();
			if (Pfile.isEmpty())
			{
				if ((Frame) && (m_Doc->guidesSettings.framesShown))
				{
					p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
					p->drawLine(FPoint(0, 0), FPoint(Width, Height));
					p->drawLine(FPoint(0, Height), FPoint(Width, 0));
				}
			}
			else
			{
				//If we are missing our image, draw a red cross in the frame
				if ((!PicArt) || (!PictureIsAvailable))
				{
					if ((Frame) && (m_Doc->guidesSettings.framesShown))
					{
						p->setBrush(Qt::white);
						QString htmlText = "";
						QFileInfo fi = QFileInfo(Pfile);
						if (PictureIsAvailable)
						{
							p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
							if (isInlineImage)
								htmlText.append( tr("Embedded Image") + "\n");
							else
								htmlText.append( tr("File:") + " " + fi.fileName() + "\n");
							htmlText.append( tr("Original PPI:") + " " + QString::number(qRound(pixm.imgInfo.xres))+" x "+QString::number(qRound(pixm.imgInfo.yres)) + "\n");
							htmlText.append( tr("Actual PPI:") + " " + QString::number(qRound(72.0 / imageXScale()))+" x "+ QString::number(qRound(72.0 / imageYScale())) + "\n");
							htmlText.append( tr("Size:") + " " + QString::number(OrigW) + " x " + QString::number(OrigH) + "\n");
							htmlText.append( tr("Colorspace:") + " ");
							QString cSpace;
							QString ext = fi.suffix().toLower();
							if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (pixm.imgInfo.type != ImageType7))
								htmlText.append( tr("Unknown"));
							else
								htmlText.append(colorSpaceText(pixm.imgInfo.colorspace));
							if (pixm.imgInfo.numberOfPages > 1)
							{
								htmlText.append("\n");
								if (pixm.imgInfo.actualPageNumber > 0)
									htmlText.append( tr("Page:") + " " + QString::number(pixm.imgInfo.actualPageNumber) + "/" + QString::number(pixm.imgInfo.numberOfPages));
								else
									htmlText.append( tr("Pages:") + " " + QString::number(pixm.imgInfo.numberOfPages));
							}
						}
						else
						{
							p->setPen(Qt::red, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
							htmlText = fi.fileName();
						}
						p->drawLine(FPoint(0, 0), FPoint(Width, Height));
						p->drawLine(FPoint(0, Height), FPoint(Width, 0));
						p->setFont(QApplication::font());
						p->drawText(QRectF(0.0, 0.0, Width, Height), htmlText);
					}
				}
				else
				{
					if (imageFlippedH())
					{
						p->translate(Width, 0);
						p->scale(-1, 1);
					}
					if (imageFlippedV())
					{
						p->translate(0, Height);
						p->scale(1, -1);
					}
					p->translate(LocalX*LocalScX, LocalY*LocalScY);
					p->scale(LocalScX, LocalScY);
					if (pixm.imgInfo.lowResType != 0)
						p->scale(pixm.imgInfo.lowResScale, pixm.imgInfo.lowResScale);
					p->drawImage(pixm.qImagePtr());
				}
			}
			p->restore();
		}
	}
}
Пример #6
0
bool EPSPlug::import(QString fName, const TransactionSettings &trSettings, int flags, bool showProgress)
{
#ifdef Q_OS_OSX
	#if QT_VERSION >= 0x050300
		showProgress = false;
	#endif
#endif

	bool success = false;
	interactive = (flags & LoadSavePlugin::lfInteractive);
	cancel = false;
	double x, y, b, h;
	bool ret = false;
	bool found = false;
	CustColors.clear();
	QFileInfo fi = QFileInfo(fName);
	QString ext = fi.suffix().toLower();
	if ( !ScCore->usingGUI() ) {
		interactive = false;
		showProgress = false;
	}
	if ( showProgress ) 
	{
		ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
		progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw);
		QStringList barNames, barTexts;
		barNames << "GI";
		barTexts << tr("Analyzing PostScript:");
		QList<bool> barsNumeric;
		barsNumeric << false;
		progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
		progressDialog->setOverallTotalSteps(3);
		progressDialog->setOverallProgress(0);
		progressDialog->setProgress("GI", 0);
		progressDialog->show();
		connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
		qApp->processEvents();
	}
	else {
		progressDialog = NULL;
	}
	
/* Set default Page to size defined in Preferences */
	x = 0.0;
	y = 0.0;
	b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
	h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
	if (extensionIndicatesEPSorPS(ext))
	{
		QString tmp, BBox, tmp2, FarNam;
		ScColor cc;
		QFile f(fName);
		if (f.open(QIODevice::ReadOnly))
		{
/* Try to find Bounding Box */
			QDataStream ts(&f);
			while (!ts.atEnd())
			{
				tmp = readLinefromDataStream(ts);
				if (tmp.startsWith("%%BoundingBox:"))
				{
					found = true;
					BBox = tmp.remove("%%BoundingBox:");
				}
				if (!found)
				{
					if (tmp.startsWith("%%BoundingBox"))
					{
						found = true;
						BBox = tmp.remove("%%BoundingBox");
					}
				}
				if (tmp.startsWith("%%EndComments"))
					break; 
			}
			f.close();
			if (found)
			{
				QStringList bb = BBox.split(" ", QString::SkipEmptyParts);
				if (bb.count() == 4)
				{
					x = ScCLocale::toDoubleC(bb[0]);
					y = ScCLocale::toDoubleC(bb[1]);
					b = ScCLocale::toDoubleC(bb[2]);
					h = ScCLocale::toDoubleC(bb[3]);
				}
			}
		}
		importColorsFromFile(fName, CustColors);
	}
#ifdef HAVE_PODOFO
	else if (extensionIndicatesPDF(ext))
	{
		try
		{
			PoDoFo::PdfError::EnableDebug( false );
#if (PODOFO_VERSION == 0 && PODOFO_MINOR > 6)
		PoDoFo::PdfError::EnableLogging( false );
#endif
#if (PODOFO_VERSION == 0 && PODOFO_MINOR == 5 && PODOFO_REVISION == 99) || PODOFO_MINOR > 5
			PoDoFo::PdfMemDocument doc( fName.toLocal8Bit().data() );
#else
			PoDoFo::PdfDocument doc( fName.toLocal8Bit().data() );
#endif
			PoDoFo::PdfPage *curPage = doc.GetPage(0);
			if (curPage != NULL)
			{
				PoDoFo::PdfRect rect = curPage->GetMediaBox();
				b = rect.GetWidth() - rect.GetLeft();
				h = rect.GetHeight() - rect.GetBottom();
			}
		}
		catch(PoDoFo::PdfError& e)
		{
			qDebug("%s", "PoDoFo error while reading page size!");
			e.PrintErrorMsg();
		}
	}
#endif
	baseX = 0;
	baseY = 0;
	if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
	{
		m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false);
		m_Doc->addPage(0);
		m_Doc->view()->addPage(0, true);
		baseX = 0;
		baseY = 0;
	}
	else
	{
		if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
		{
			m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
			ScCore->primaryMainWindow()->HaveNewDoc();
			ret = true;
			baseX = 0;
			baseY = 0;
		}
	}
	if ((!ret) && (interactive))
	{
		baseX = m_Doc->currentPage()->xOffset();
		baseY = m_Doc->currentPage()->yOffset();
	}
	if ((ret) || (!interactive))
	{
		if (b-x > h-y)
			m_Doc->setPageOrientation(1);
		else
			m_Doc->setPageOrientation(0);
		m_Doc->setPageSize("Custom");
	}
	ColorList::Iterator it;
	for (it = CustColors.begin(); it != CustColors.end(); ++it)
	{
		if (!m_Doc->PageColors.contains(it.key()))
			m_Doc->PageColors.insert(it.key(), it.value());
	}
	boundingBoxRect.addRect(0, 0, b-x, h-y);
	Elements.clear();
	m_Doc->setLoading(true);
	m_Doc->DoDrawing = false;
	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
		m_Doc->view()->updatesOn(false);
	m_Doc->scMW()->setScriptRunning(true);
	qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
	QString CurDirP = QDir::currentPath();
	QDir::setCurrent(fi.path());
	if (convert(fName, x, y, b, h))
	{
// 		m_Doc->m_Selection->clear();
		tmpSel->clear();
		QDir::setCurrent(CurDirP);
//		if ((Elements.count() > 1) && (interactive))
		if (Elements.count() > 1)
			m_Doc->groupObjectsList(Elements);
		m_Doc->DoDrawing = true;
		m_Doc->scMW()->setScriptRunning(false);
		m_Doc->setLoading(false);
		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
		if ((Elements.count() > 0) && (!ret) && (interactive))
		{
			if (flags & LoadSavePlugin::lfScripted)
			{
				bool loadF = m_Doc->isLoading();
				m_Doc->setLoading(false);
				m_Doc->changed();
				m_Doc->setLoading(loadF);
				if (!(flags & LoadSavePlugin::lfLoadAsPattern))
				{
					m_Doc->m_Selection->delaySignalsOn();
					for (int dre=0; dre<Elements.count(); ++dre)
					{
						m_Doc->m_Selection->addItem(Elements.at(dre), true);
					}
					m_Doc->m_Selection->delaySignalsOff();
					m_Doc->m_Selection->setGroupRect();
					m_Doc->view()->updatesOn(true);
				}
			}
			else
			{
				m_Doc->DragP = true;
				m_Doc->DraggedElem = 0;
				m_Doc->DragElements.clear();
				m_Doc->m_Selection->delaySignalsOn();
				for (int dre=0; dre<Elements.count(); ++dre)
				{
					tmpSel->addItem(Elements.at(dre), true);
				}
				tmpSel->setGroupRect();
				ScriXmlDoc *ss = new ScriXmlDoc();
				ScElemMimeData* md = new ScElemMimeData();
				md->setScribusElem(ss->WriteElem(m_Doc, tmpSel));
				delete ss;
/*#ifndef Q_WS_MAC*/
// see #2196
				m_Doc->itemSelection_DeleteItem(tmpSel);
/*#else
				qDebug() << "psimport: leaving items on page";
#endif*/
				m_Doc->view()->updatesOn(true);
				m_Doc->m_Selection->delaySignalsOff();
				// We must copy the TransationSettings object as it is owned
				// by handleObjectImport method afterwards
				TransactionSettings* transacSettings = new TransactionSettings(trSettings);
				m_Doc->view()->handleObjectImport(md, transacSettings);
				m_Doc->DragP = false;
				m_Doc->DraggedElem = 0;
				m_Doc->DragElements.clear();
			}
		}
		else
		{
			m_Doc->changed();
			m_Doc->reformPages();
			if (!(flags & LoadSavePlugin::lfLoadAsPattern))
				m_Doc->view()->updatesOn(true);
		}
		success = true;
	}
	else
	{
		QDir::setCurrent(CurDirP);
		m_Doc->DoDrawing = true;
		m_Doc->scMW()->setScriptRunning(false);
		m_Doc->view()->updatesOn(true);
		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
	}
	if (interactive)
		m_Doc->setLoading(false);
	//CB If we have a gui we must refresh it if we have used the progressbar
	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
	{
		if ((showProgress) && (!interactive))
			m_Doc->view()->DrawNew();
	}
	return success;
}
Пример #7
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();
    }
}
Пример #8
0
void FDialogPreview::GenPreview(QString name)
{
	QPixmap pm;
	QString Buffer = "";
	updtPix();
	if (name.isEmpty())
		return;
	QFileInfo fi = QFileInfo(name);
	if (fi.isDir())
		return;
	int w = pixmap()->width();
	int h = pixmap()->height();
	bool mode = false;
	QString ext = fi.suffix().toLower();
	QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::IMAGESIMGFRAME, 1));
 	QStringList formats = formatD.split("|");
	formats.append("pat");
	
	QStringList allFormatsV = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
	if (ext.isEmpty())
		ext = getImageType(name);
	if (formats.contains(ext.toUtf8()))
	{
		ScImage im;
		//No doc to send data anyway, so no doc to get into scimage.
		CMSettings cms(0, "", Intent_Perceptual);
		cms.allowColorManagement(false);
		if (im.loadPicture(name, 1, cms, ScImage::Thumbnail, 72, &mode))
		{
			int ix,iy;
			if ((im.imgInfo.exifDataValid) && (!im.imgInfo.exifInfo.thumbnail.isNull()))
			{
				ix = im.imgInfo.exifInfo.width;
				iy = im.imgInfo.exifInfo.height;
			}
			else
			{
				ix = im.width();
				iy = im.height();
			}
			int xres = im.imgInfo.xres;
			int yres = im.imgInfo.yres;
			QString tmp = "";
			QString tmp2 = "";
			QImage im2 = im.scaled(w - 5, h - 44, Qt::KeepAspectRatio, Qt::SmoothTransformation);
			QPainter p;
			QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
			// Qt4 FIXME imho should be better
			pm = *pixmap();
			p.begin(&pm);
			p.fillRect(0, 0, w, h-44, b);
			p.fillRect(0, h-44, w, 44, QColor(255, 255, 255));
			p.drawImage((w - im2.width()) / 2, (h - 44 - im2.height()) / 2, im2);
			p.drawText(2, h-29, tr("Size:")+" "+tmp.setNum(ix)+" x "+tmp2.setNum(iy));
			p.drawText(2, h-17, tr("Resolution:")+" "+tmp.setNum(xres)+" x "+tmp2.setNum(yres)+" "+ tr("DPI"));
			QString cSpace;
			if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (im.imgInfo.type != ImageType7))
				cSpace = tr("Unknown");
			else
				cSpace=colorSpaceText(im.imgInfo.colorspace);
			p.drawText(2, h-5, tr("Colorspace:")+" "+cSpace);
			p.end();
			setPixmap(pm);
			repaint();
		}
	}
	else if (allFormatsV.contains(ext.toUtf8()))
	{
		FileLoader *fileLoader = new FileLoader(name);
		int testResult = fileLoader->TestFile();
		delete fileLoader;
		if ((testResult != -1) && (testResult >= FORMATID_ODGIMPORT))
		{
			const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
			if( fmt )
			{
				QImage im = fmt->readThumbnail(name);
				if (!im.isNull())
				{
					QString desc = tr("Size:")+" ";
					desc += value2String(im.text("XSize").toDouble(), PrefsManager::instance()->appPrefs.docSetupPrefs.docUnitIndex, true, true);
					desc += " x ";
					desc += value2String(im.text("YSize").toDouble(), PrefsManager::instance()->appPrefs.docSetupPrefs.docUnitIndex, true, true);
					im = im.scaled(w - 5, h - 21, Qt::KeepAspectRatio, Qt::SmoothTransformation);
					QPainter p;
					QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
					pm = *pixmap();
					p.begin(&pm);
					p.fillRect(0, 0, w, h-21, b);
					p.fillRect(0, h-21, w, 21, QColor(255, 255, 255));
					p.drawImage((w - im.width()) / 2, (h - 21 - im.height()) / 2, im);
					p.drawText(2, h-5, desc);
					p.end();
					setPixmap(pm);
					repaint();
				}
			}
		}
	}
	else if (ext.toUtf8() == "sml")
	{
		QPixmap pmi;
		QByteArray cf;
		if (loadRawText(name, cf))
		{
			QString f = QString::fromUtf8(cf.data());
			StencilReader *pre = new StencilReader();
			pmi = pre->createPreview(f);
			QImage im = pmi.toImage();
			im = im.scaled(w - 5, h - 21, Qt::KeepAspectRatio, Qt::SmoothTransformation);
			QPainter p;
			QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
			pm = *pixmap();
			p.begin(&pm);
			p.fillRect(0, 0, w, h-21, b);
			p.fillRect(0, h-21, w, 21, QColor(255, 255, 255));
			p.drawImage((w - im.width()) / 2, (h - 21 - im.height()) / 2, im);
			QString desc = tr("Size:")+QString(" %1 x %2").arg(im.width()).arg(im.height());
			p.drawText(2, h-5, desc);
			p.end();
			setPixmap(pm);
			repaint();
			delete pre;
		}
	}
	else if (ext.toUtf8() == "shape")
	{
		QByteArray cf;
		if (loadRawText(name, cf))
		{
			QString f = QString::fromUtf8(cf.data());
			StencilReader *pre = new StencilReader();
			QString f2 = pre->createShape(f);
			ScPreview *pre2 = new ScPreview();
			QImage im = pre2->createPreview(f2);
			im = im.scaled(w - 5, h - 21, Qt::KeepAspectRatio, Qt::SmoothTransformation);
			QPainter p;
			QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
			pm = *pixmap();
			p.begin(&pm);
			p.fillRect(0, 0, w, h-21, b);
			p.fillRect(0, h-21, w, 21, QColor(255, 255, 255));
			p.drawImage((w - im.width()) / 2, (h - 21 - im.height()) / 2, im);
			QString desc = tr("Size:")+QString(" %1 x %2").arg(im.width()).arg(im.height());
			p.drawText(2, h-5, desc);
			p.end();
			setPixmap(pm);
			repaint();
			delete pre;
			delete pre2;
		}
	}
	else if (ext.toUtf8() == "sce")
	{
		QByteArray cf;
		if (loadRawText(name, cf))
		{
			QString f;
			if (cf.left(16) == "<SCRIBUSELEMUTF8")
				f = QString::fromUtf8(cf.data());
			else
				f = cf.data();
			ScPreview *pre = new ScPreview();
			QImage im = pre->createPreview(f);
			im = im.scaled(w - 5, h - 21, Qt::KeepAspectRatio, Qt::SmoothTransformation);
			QPainter p;
			QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
			pm = *pixmap();
			p.begin(&pm);
			p.fillRect(0, 0, w, h-21, b);
			p.fillRect(0, h-21, w, 21, QColor(255, 255, 255));
			p.drawImage((w - im.width()) / 2, (h - 21 - im.height()) / 2, im);
			QString desc = tr("Size:")+QString(" %1 x %2").arg(im.width()).arg(im.height());
			p.drawText(2, h-5, desc);
			p.end();
			setPixmap(pm);
			repaint();
			delete pre;
		}
	}
	else
	{
		ScSlaInfoReader slaInfos;
		if (slaInfos.readInfos(name))
		{
			QString Title = tr("Title:")+" ";
			QString ti2 = slaInfos.title();
			if (ti2.isEmpty())
				ti2= tr("No Title");
			Title += ti2+"\n";
			QString Author = tr("Author:")+" ";
			QString au2 = slaInfos.author();
			if (au2.isEmpty())
				au2 = tr("Unknown");
			Author += au2+"\n";
			QString Format =  tr("File Format:")+" ";
			QString fm2 = slaInfos.format();
			if (fm2.isEmpty())
				fm2 = tr("Unknown");
			Format += fm2;
			setText( tr("Scribus Document")+"\n\n"+Title+Author+Format);
		}
		else  if ((ext == "txt") || (ext == "html") || (ext == "xml"))
		{
			if (loadText(name, &Buffer))
				setText(Buffer.left(200));
		}
	}
}