EStatusCode HighLevelContentContext::Run(const TestConfiguration& inTestConfiguration)
{
	EStatusCode status = eSuccess;
	PDFWriter pdfWriter;

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"HighLevelContentContext.PDF"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,
                                                     RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"HighLevelContentContext.log")));
		if(status != eSuccess)
		{
			cout<<"Failed to start file\n";
			break;
		}

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

		AbstractContentContext::TextOptions textOptions(pdfWriter.GetFontForFile(
																			RelativeURLToLocalPath(
                                                                            inTestConfiguration.mSampleFileBase,
                                                                            "TestMaterials/fonts/arial.ttf")),
																			14,
																			AbstractContentContext::eGray,
																			0);
		AbstractContentContext::GraphicOptions pathFillOptions(AbstractContentContext::eFill,
																AbstractContentContext::eCMYK,
																0xFF000000);
		AbstractContentContext::GraphicOptions pathStrokeOptions(AbstractContentContext::eStroke,
																AbstractContentContext::eRGB,
																AbstractContentContext::ColorValueForName("DarkMagenta"),
																4);

		DoubleAndDoublePairList pathPoints;

		// draw path
		pathPoints.push_back(DoubleAndDoublePair(75,640));
		pathPoints.push_back(DoubleAndDoublePair(149,800));
		pathPoints.push_back(DoubleAndDoublePair(225,640));
		cxt->DrawPath(pathPoints,pathFillOptions);
		pathPoints.clear();
		pathPoints.push_back(DoubleAndDoublePair(75,540));
		pathPoints.push_back(DoubleAndDoublePair(110,440));
		pathPoints.push_back(DoubleAndDoublePair(149,540));
		pathPoints.push_back(DoubleAndDoublePair(188,440));
		pathPoints.push_back(DoubleAndDoublePair(223,540));
		cxt->DrawPath(pathPoints,pathStrokeOptions);

		// draw square
		cxt->DrawSquare(375,640,120,pathFillOptions);
		cxt->DrawSquare(375,440,120,pathStrokeOptions);

		// draw rectangle
		cxt->DrawRectangle(375,220,50,160,pathFillOptions);
		cxt->DrawRectangle(375,10,50,160,pathStrokeOptions);

		// draw circle
		cxt->DrawCircle(149,300,80,pathFillOptions);
		cxt->DrawCircle(149,90,80,pathStrokeOptions);

		// wrote text (writing labels for each of the shapes)
		cxt->WriteText(75,805,"Paths",textOptions);
		cxt->WriteText(375,805,"Squares",textOptions);
		cxt->WriteText(375,400,"Rectangles",textOptions);
		cxt->WriteText(75,400,"Circles",textOptions);

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

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


		status = pdfWriter.EndPDF();
		if(status != eSuccess)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to end pdf\n";
			break;
		}

	}while(false);


	return status;
}
EStatusCode TestMeasurementsTest::Run(const TestConfiguration& inTestConfiguration)
{
	EStatusCode status = eSuccess;
	PDFWriter pdfWriter;

	do
	{
		status = pdfWriter.StartPDF(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TextMeasurementsTest.PDF"),
                                    ePDFVersion13,
                                    LogConfiguration(true,true,
                                                     RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TextMeasurementsTest.log")));
		if(status != eSuccess)
		{
			cout<<"Failed to start file\n";
			break;
		}

		PDFPage* page = new PDFPage();
		page->SetMediaBox(PDFRectangle(0,0,595,842));
		
		PageContentContext* cxt = pdfWriter.StartPageContentContext(page);
		PDFUsedFont* arialFont = pdfWriter.GetFontForFile(
                                                     RelativeURLToLocalPath(
                                                                            inTestConfiguration.mSampleFileBase,
                                                                            "TestMaterials/fonts/arial.ttf"));
		if(!arialFont)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to create font for arial font\n";
			break;
		}

		AbstractContentContext::GraphicOptions pathStrokeOptions(AbstractContentContext::eStroke,
																AbstractContentContext::eRGB,
																AbstractContentContext::ColorValueForName("DarkMagenta"),
																4);
		AbstractContentContext::TextOptions textOptions(arialFont,
														14,
														AbstractContentContext::eGray,
														0);

		PDFUsedFont::TextMeasures textDimensions = arialFont->CalculateTextDimensions("Hello World",14);

		cxt->WriteText(10,100,"Hello World",textOptions);
		DoubleAndDoublePairList pathPoints;
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMin,98+textDimensions.yMin));
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMax,98+textDimensions.yMin));
		cxt->DrawPath(pathPoints,pathStrokeOptions);
		pathPoints.clear();
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMin,102+textDimensions.yMax));
		pathPoints.push_back(DoubleAndDoublePair(10+textDimensions.xMax,102+textDimensions.yMax));
		cxt->DrawPath(pathPoints,pathStrokeOptions);

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

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


		status = pdfWriter.EndPDF();
		if(status != eSuccess)
		{
			status = PDFHummus::eFailure;
			cout<<"Failed to end pdf\n";
			break;
		}

	}while(false);


	return status;
}
Пример #3
0
EStatusCode RotatedPagesPDF::Run(const TestConfiguration& inTestConfiguration)
{
	LogConfiguration logConfiguration(true,true,RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPagesLog.txt"));
	EStatusCode status; 

	do
	{
		// PDF Page rotation writing

		PDFWriter pdfWriter;
		status = pdfWriter.StartPDF(
			RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPages.pdf"),
			ePDFVersion13,logConfiguration);

		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start RotatedPages.pdf\n";
			break;
		}	

		AbstractContentContext::TextOptions textOptions(pdfWriter.GetFontForFile(
																			RelativeURLToLocalPath(
                                                                            inTestConfiguration.mSampleFileBase,
                                                                            "TestMaterials/fonts/arial.ttf")),
																			14,
																			AbstractContentContext::eGray,
																			0);

		for(int i=0;i<6 && PDFHummus::eSuccess == status;++i)
		{
			PDFPage page;
			page.SetMediaBox(PDFRectangle(0,0,595,842));

			page.SetRotate(33);
			if ( page.GetRotate().second != 0 )
			{
				status = PDFHummus::eFailure;
				cout<<"Failed to reject invalid rotation\n";
				break;
			}
			
			page.SetRotate(i*90);
		
			std::ostringstream s;
			s << "Page rotated by " << i*90 << " degrees.";

			PageContentContext* cxt = pdfWriter.StartPageContentContext(&page);
			cxt->WriteText(75,805,s.str(),textOptions);
			status = pdfWriter.EndPageContentContext(cxt);
			if(status != eSuccess)
			{
				status = PDFHummus::eFailure;
				cout<<"Failed to end content context\n";
				break;
			}

			status = pdfWriter.WritePage(&page);
			if(status != PDFHummus::eSuccess)
				cout<<"failed to write page "<<i<<"\n";
		}

		status = pdfWriter.EndPDF();
		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end RotatedPages.pdf\n";
			break;
		}


		// PDF page rotation copy
        
		status = pdfWriter.StartPDF(
			RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPagesCopy.pdf"),
			ePDFVersion13);

		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed to start RotatedPagesCopy.pdf\n";
			break;
		}
        
		EStatusCodeAndObjectIDTypeList result;
        
        // append pages
		result = pdfWriter.AppendPDFPagesFromPDF(
			RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPages.pdf"),
			PDFPageRange());

		if(result.first != PDFHummus::eSuccess)
		{
			cout<<"failed to append pages from RotatedPages.pdf\n";
			status = result.first;
			break;
		}
        
		status = pdfWriter.EndPDF();

		if(status != PDFHummus::eSuccess)
		{
			cout<<"failed in end RotatedPagesCopy.pdf\n";
			break;
		}

		// PDF Page rotation parsing

		InputFile pdfFile;
		PDFParser pdfParser;

		status = pdfFile.OpenFile(
			RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"RotatedPagesCopy.pdf"));

		if(status != PDFHummus::eSuccess)
		{
			cout<<"unable to open file RotatedPagesCopy.pdf for reading.\n";
			break;
		}

		status = pdfParser.StartPDFParsing(pdfFile.GetInputStream());
		if(status != PDFHummus::eSuccess)
		{
			cout<<"unable to parse input file";
			break;
		}

		if(pdfParser.GetPagesCount() != 6)
		{
			cout<<"expecting 6 pages, got "<<pdfParser.GetPagesCount()<<"\n";
			status = PDFHummus::eFailure;
			break;
		}

		for(unsigned long i=0;i<pdfParser.GetPagesCount() && PDFHummus::eSuccess == status;++i)
		{
			RefCountPtr<PDFDictionary> page = pdfParser.ParsePage(i);
			if (!page)
			{
				cout << i << ". page parsing failed\n";
				status = PDFHummus::eFailure;
				break;
			}

			PDFPageInput input( &pdfParser, page );
			if ( input.GetRotate() != i*90 )
			{
				cout<< i << ". page has invalid rotation\n";
				status = PDFHummus::eFailure;
				break;
			}
		}

	}while(false);
	return status;
}