コード例 #1
0
EStatusCode TiffSpecialsTest::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status; 
	TIFFUsageParameters TIFFParameters;

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TiffSpecialsTest.PDF"),ePDFVersion13,LogConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TiffSpecialsTestLog.txt")));
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	


		// multipage Tiff
		for(int i=0;i<4 && (PDFHummus::eSuccess == status);++i)
		{
			TIFFParameters.PageIndex = i;
			PDFFormXObject* imageFormXObject = pdfWriter.CreateFormXObjectFromTIFFFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/multipage.tif"),TIFFParameters);
			if(!imageFormXObject)
			{
				cout<<"failed to create image form XObject from file, for file "<<"multipage.tif page "<<i<<"\n";
				status = PDFHummus::eFailure;
			}
			else
				status = CreatePageForImageAndRelease(pdfWriter,imageFormXObject);
		}

		if(status != PDFHummus::eSuccess)
			break;

		// Black and White mask
		status = CreateBlackAndWhiteMaskImage(inTestConfiguration,pdfWriter);
		if(status != PDFHummus::eSuccess)
			break;

		//Create BiLevel grayscales
		status = CreateBiLevelGrayScales(inTestConfiguration,pdfWriter);
		if(status != PDFHummus::eSuccess)
			break;

		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;
}
コード例 #2
0
EStatusCode ImagesAndFormsForwardReferenceTest::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status; 

	do
	{

		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"ImagesAndFormsForwardReferenceTest.PDF"),ePDFVersion13);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start PDF\n";
			break;
		}	

		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));

		PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(page);
		if(NULL == pageContentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
		}



		// continue page drawing size the image to 500,400
		pageContentContext->q();
		pageContentContext->cm(500,0,0,400,0,0);
		
		ObjectIDType imageXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddImageXObjectMapping(imageXObjectID));

		// optionally i can also add the necessary PDF Procsets. i'll just add all that might be relevant
		page->GetResourcesDictionary().AddProcsetResource(KProcsetImageB);
		page->GetResourcesDictionary().AddProcsetResource(KProcsetImageC);
		page->GetResourcesDictionary().AddProcsetResource(KProcsetImageI);

		pageContentContext->Q();

		// continue page drawing size the image to 500,400
		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,400);
		ObjectIDType formXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(formXObjectID));
		pageContentContext->Q();

#ifndef NO_TIFF
		pageContentContext->q();
		ObjectIDType tiffFormXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(tiffFormXObjectID));
		pageContentContext->Q();
#endif
        
		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,100,500);
		ObjectIDType simpleFormXObjectID = pdfWriter.GetObjectsContext().GetInDirectObjectsRegistry().AllocateNewObjectID();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(simpleFormXObjectID));
		pageContentContext->Q();

		status = pdfWriter.EndPageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context\n";
			break;
		}

		status = pdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page\n";
			break;
		}


		// Create image xobject  
		PDFImageXObject* imageXObject  = pdfWriter.CreateImageXObjectFromJPGFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG"),imageXObjectID);
		if(!imageXObject)
		{
			cout<<"failed to create image XObject from file\n";
			status = PDFHummus::eFailure;
			break;
		}

		// now create form xobject
		PDFFormXObject*  formXObject = pdfWriter.CreateFormXObjectFromJPGFile(
            RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG"),formXObjectID);
		if(!formXObject)
		{
			cout<<"failed to create form XObject from file\n";
			status = PDFHummus::eFailure;
			break;
		}

#ifndef NO_TIFF
		PDFFormXObject* tiffFormXObject = pdfWriter.CreateFormXObjectFromTIFFFile(
            RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/jim___ah.tif"),tiffFormXObjectID);
		if(!tiffFormXObject)
		{
			cout<<"failed to create image form XObject from file, for file\n";
			status = PDFHummus::eFailure;
			break;
		}
		delete tiffFormXObject;
#endif

		delete imageXObject;
		delete formXObject;


		// define an xobject form to draw a 200X100 points red rectangle
		PDFFormXObject* xobjectForm = pdfWriter.StartFormXObject(PDFRectangle(0,0,200,100),simpleFormXObjectID);

		XObjectContentContext* xobjectContentContext = xobjectForm->GetContentContext();
		xobjectContentContext->q();
		xobjectContentContext->k(0,100,100,0);
		xobjectContentContext->re(0,0,200,100);
		xobjectContentContext->f();
		xobjectContentContext->Q();

		status = pdfWriter.EndFormXObjectAndRelease(xobjectForm);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write XObject form\n";
			break;
		}


		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;		
}
コード例 #3
0
EStatusCode TiffSpecialsTest::CreateBiLevelGrayScales(const TestConfiguration& inTestConfiguration,PDFWriter& inpdfWriter)
{
	EStatusCode status = PDFHummus::eSuccess;
	TIFFUsageParameters TIFFParameters;
    
    string scWJim = RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/jim___cg.tif");

	do
	{

		// GrayScale regular
		PDFFormXObject* imageGrayScale = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim);
		if(!imageGrayScale)
		{
			cout<<"failed to create image form XObject from file, grayscale for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// GrayScale Green
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(0,255,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(255,255,255);
		PDFFormXObject* imageGrayScaleGreen = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleGreen)
		{
			cout<<"failed to create image form XObject from file, green n white for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}


		// grayscale cyan magenta
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(255,255,0,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(0,0,0,0);
		PDFFormXObject* imageGrayScaleCyanMagenta = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleCyanMagenta)
		{
			cout<<"failed to create image form XObject from file, cyan magenta n white for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// grayscale green vs red
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(0,255,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(255,0,0);
		PDFFormXObject* imageGrayScaleGreenVSRed = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleGreenVSRed)
		{
			cout<<"failed to create image form XObject from file, green n red for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// grayscale cyan vs magenta
		TIFFParameters.GrayscaleTreatment.AsColorMap = true;
		TIFFParameters.GrayscaleTreatment.OneColor = CMYKRGBColor(255,0,0,0);
		TIFFParameters.GrayscaleTreatment.ZeroColor = CMYKRGBColor(0,255,0,0);
		PDFFormXObject* imageGrayScaleCyanVSMagenta = inpdfWriter.CreateFormXObjectFromTIFFFile(scWJim,TIFFParameters);
		if(!imageGrayScaleCyanVSMagenta)
		{
			cout<<"failed to create image form XObject from file, cyan n magenta for file "<<scWJim;
			status = PDFHummus::eFailure;
			break;
		}

		// start page
		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));

		PageContentContext* pageContentContext = inpdfWriter.StartPageContentContext(page);
		if(NULL == pageContentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
		}

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScale->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleGreen->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36*2,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleCyanMagenta->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,842 - 195.12*2);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleGreenVSRed->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36,842 - 195.12*2);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageGrayScaleCyanVSMagenta->GetObjectID()));
		pageContentContext->Q();

		delete imageGrayScale;
		delete imageGrayScaleGreen;
		delete imageGrayScaleCyanMagenta;
		delete imageGrayScaleGreenVSRed;
		delete imageGrayScaleCyanVSMagenta;

		status = inpdfWriter.EndPageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context, for bilevel grayscale images\n";
			break;
		}

		status = inpdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page, for bilevel grayscale images\n";
			break;
		}
	}while(false);

	return status;
}
コード例 #4
0
EStatusCode TiffSpecialsTest::CreateBlackAndWhiteMaskImage(const TestConfiguration& inTestConfiguration,PDFWriter& inpdfWriter)
{
    string scJimBW = RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/tiff/jim___ah.tif");

	EStatusCode status = PDFHummus::eSuccess;
	TIFFUsageParameters TIFFParameters;

	do
	{
		PDFFormXObject* imageBW = inpdfWriter.CreateFormXObjectFromTIFFFile(scJimBW);
		if(!imageBW)
		{
			cout<<"failed to create image BW, for file "<<scJimBW<<"\n";
			status = PDFHummus::eFailure;
			break;
		}

		TIFFParameters.BWTreatment.AsImageMask = true;
		TIFFParameters.BWTreatment.OneColor = CMYKRGBColor(255,128,0);
		PDFFormXObject* imageBWMask = inpdfWriter.CreateFormXObjectFromTIFFFile(scJimBW,TIFFParameters);
		if(!imageBWMask)
		{
			cout<<"failed to create image mask BW, for file "<<scJimBW<<"\n";
			status = PDFHummus::eFailure;
			break;
		}

		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));

		PageContentContext* pageContentContext = inpdfWriter.StartPageContentContext(page);
		if(NULL == pageContentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
		}

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,0,842 - 195.12);
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageBW->GetObjectID()));
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(1,0,0,1,159.36,842 - 195.12);
		pageContentContext->rg(0,0,1);
		pageContentContext->re(0,0,159.36,195.12);
		pageContentContext->f();
		pageContentContext->Do(page->GetResourcesDictionary().AddFormXObjectMapping(imageBWMask->GetObjectID()));
		pageContentContext->Q();

		delete imageBW;
		delete imageBWMask;

		status = inpdfWriter.EndPageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to end page content context, for Image BWs test\n";
			break;
		}

		status = inpdfWriter.WritePageAndRelease(page);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to write page, for image BWs test\n";
			break;
		}
	}while(false);

	return status;
}