コード例 #1
0
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;
}
コード例 #2
0
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;
}