EStatusCode DCTDecodeFilterTest::CreateFileWithJPGImage(const TestConfiguration& inTestConfiguration,
                                                        const string& inTestFileName)
{
	PDFWriter pdfWriter;
	EStatusCode status;
    
	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,inTestFileName),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";
		}
        
		// draw a rectangle
		pageContentContext->q();
		pageContentContext->k(100,0,0,0);
		pageContentContext->re(500,0,100,100);
		pageContentContext->f();
		pageContentContext->Q();
        
		// pause stream to start writing the image
		status = pdfWriter.PausePageContentContext(pageContentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to pause page content context\n";
			break;
		}
        
		// Create image xobject from
		PDFImageXObject* imageXObject  = pdfWriter.CreateImageXObjectFromJPGFile(
                                                                                 RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/images/otherStage.JPG"));
		if(!imageXObject)
		{
			cout<<"failed to create image XObject from file\n";
			status = PDFHummus::eFailure;
			break;
		}
        
		// continue page drawing size the image to 500,400
		pageContentContext->q();
		pageContentContext->cm(500,0,0,400,0,0);
		pageContentContext->Do(page->GetResourcesDictionary().AddImageXObjectMapping(imageXObject));
		pageContentContext->Q();
        
		delete imageXObject;
        
		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;
		}
        
        
		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;
}
EStatusCode SimpleContentPageTest::Run(const TestConfiguration& inTestConfiguration)
{
	PDFWriter pdfWriter;
	EStatusCode status; 

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"SimpleContent.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* contentContext = pdfWriter.StartPageContentContext(page);
		if(NULL == contentContext)
		{
			status = PDFHummus::eFailure;
			cout<<"failed to create content context for page\n";
			break;
		}

		// draw a 100X100 points cyan square
		contentContext->q();
		contentContext->k(100,0,0,0);
		contentContext->re(100,500,100,100);
		contentContext->f();
		contentContext->Q();

		// force stream change
		status = pdfWriter.PausePageContentContext(contentContext);
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to pause page content context\n";
			break;
		}

		// draw a 200X100 points red rectangle
		contentContext->q();
		contentContext->k(0,100,100,0);
		contentContext->re(200,600,200,100);
		contentContext->f();
		contentContext->Q();

		// draw a gray line
		contentContext->q();
		contentContext->G(0.5);
		contentContext->w(3);
		contentContext->m(200,600);
		contentContext->l(400,400);
		contentContext->S();
		contentContext->Q();
		
		status = pdfWriter.EndPageContentContext(contentContext);
		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;
		}

		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end PDF\n";
			break;
		}
	}while(false);
	return status;
}
int main(int argc, char* argv[])
{
	PDFWriter pdfWriter;
	EStatusCode status;

	do
	{
		// Initial Setup for file,page and page content
		status = pdfWriter.StartPDF(scBasePath + "DrawingShapes.pdf",ePDFVersion13);
		if(status != eSuccess)
			break;

		PDFPage* pdfPage = new PDFPage();
		pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
		PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);

		// Start adding content to page

		// Draw a Line, stroke
		pageContentContext->q();
		pageContentContext->w(2);
		pageContentContext->K(0,0,1,0);

		pageContentContext->m(10,500);
		pageContentContext->l(30,700);
		pageContentContext->s();

		pageContentContext->Q();

		// Draw a Polygon, stroke
		pageContentContext->q();
		pageContentContext->w(2);
		pageContentContext->K(0,1,0,0);

		pageContentContext->m(40,500);
		pageContentContext->l(60,700);
		pageContentContext->l(160,700);
		pageContentContext->l(140,500);
		pageContentContext->s();

		pageContentContext->Q();

		// Draw a Rectangle, fill
		pageContentContext->q();
		pageContentContext->k(0,1,0,0);

		pageContentContext->re(200,400,100,300);
		pageContentContext->f();

		pageContentContext->Q();

		// Pausing content context, to allow form definition
		pdfWriter.PausePageContentContext(pageContentContext);

		// Create a form with a triangle pattern, RGB colorspace, fill
		PDFFormXObject* formXObject = pdfWriter.StartFormXObject(PDFRectangle(0,0,400,400));
		XObjectContentContext* xobjectContent = formXObject->GetContentContext();

		xobjectContent->rg(1,0,0);
		xobjectContent->m(0,0);
		xobjectContent->l(200,400);
		xobjectContent->l(400,0);
		xobjectContent->f();

		ObjectIDType formObjectID = formXObject->GetObjectID();
		status = pdfWriter.EndFormXObjectAndRelease(formXObject);
		if(status != eSuccess)
			break;

		// Place the form in multiple locations in the page
		string formNameInPage = pdfPage->GetResourcesDictionary().AddFormXObjectMapping(formObjectID);

		pageContentContext->q();
		pageContentContext->cm(0.5,0,0,0.5,120,100);
		pageContentContext->Do(formNameInPage);
		pageContentContext->Q();

		pageContentContext->q();
		pageContentContext->cm(0.2,0,0,0.2,350,100);
		pageContentContext->Do(formNameInPage);
		pageContentContext->Q();

		// End adding content to page

		// end page content, write page object and finalize PDF
		status = pdfWriter.EndPageContentContext(pageContentContext);
		if(status != eSuccess)
			break;

		status = pdfWriter.WritePageAndRelease(pdfPage);
		if(status != eSuccess)
			break;

		status = pdfWriter.EndPDF();
	}while(false);

	if(eSuccess == status)
		cout<<"Succeeded in creating PDF file\n";
	else
		cout<<"Failed in creating PDF file\n";

	return 0;
}