void test_renderer_long()
{
NOPackage *lPackage=NOPackage::readPackageFromFile("testfiles/Office2007_Powerpoint_Drawing_Fills_Texture.xps");
NODocument lDoc=lPackage->getDocument(0);
UInt32 lCount=0; for(;lCount < lDoc.getNumberOfPages();lCount++)
{
NOPage lPage=lDoc.getPage(lCount);
UInt32 lBufferLength = 300 * 300 * 3;
UInt8 *lBuffer = new UInt8[lBufferLength];
memset(lBuffer,0,lBufferLength);
lPage.renderToImage(lBuffer,300,300,true,false);
delete [] lBuffer;
}
NOPackage::destroyPackage(lPackage);
}
void test_renderer_totiff()
{
const char *pIn="testfiles/catalog.xps";
const char *pOut="output/renderer_totiff.tiff";
NOPackage *lPackage=NOPackage::readPackageFromFile(pIn);
NODocument lDoc=lPackage->getDocument(0);
UInt32 lOutSize=1000;
NOPage lPage=lDoc.getPage(0);
UInt32 lBufferLength = lOutSize * lOutSize * 3;
UInt8 *lBuffer = new UInt8[lBufferLength];
memset(lBuffer,0,lBufferLength);
lPage.renderToImage(lBuffer,lOutSize,lOutSize,true,false);
NOUtility_write_tiff(lBuffer,const_cast(pOut),lOutSize,lOutSize);
delete [] lBuffer;
NOPackage::destroyPackage(lPackage);
}
void test_create_glyphs_via_NOX()
{
const char *pOut="output/create_glyphs_via_NOX.xps";
// new destination document
NOPackage *lPackage=NOPackage::createPackage(true,pOut);
// create a new page in the destination doc
NOPage lPage=lPackage->getDocument(0).createPage();
// create fixed page
NOXFixedPage lContent=lPage.createFixedPage();
lContent.intialize(300,500);
// create a canvas
NOXCanvas lCanvas=lContent.createCanvas(0);
lCanvas.intialize();
// now, get some font
UTF8String lURI;
{
NOPackage *lDummyPackage=NOPackage::readPackageFromFile("testfiles/vdp.xps");
{
NOFontVector lFonts(*lDummyPackage);
lDummyPackage->getDocument(0).getPage(0).getFonts(lFonts);
NOFont lFont=lPage.addFont(lFonts.elementAt(0));
lURI=lFont.getPartName();
}
NOPackage::destroyPackage(lDummyPackage);
}
// create a glyphs section in the canvas
NOXGlyphs lGlyphs=lCanvas.createGlyphs(0);
lGlyphs.intialize(10.0,(NOString)((UTF8String)"/"+lURI),50.0,50.0);
lGlyphs.setFill((NOString)"#FF0000FF");
lGlyphs.setUnicodeString((NOString)"abcdefghijklmnopqrstuvwxyz");
// write out and close
lPackage->writePackageToFile(pOut);
NOPackage::destroyPackage(lPackage);
}
void test_moveObjectsAndRenderToImage()
{
const char *pOut="output/moveObjectsAndRenderToImage.tiff";
NOPackage *lPackage=NOPackage::readPackageFromFile("testfiles/0inDashArray.xps");
NODocument lDocument = lPackage->getDocument(0);
NOPage lPage = lDocument.getPage(0);
// render first to make sure we have bounding boxes
lPage.renderToTiff(pOut,1000,1000,300,true);
NCommon::UInt32Rect lRect;
lRect.mTop=157;
lRect.mLeft=59;
lRect.mBottom=299;
lRect.mRight=538;
lPage.selectMarquee(lRect,600,400,false);
NOSelection lSelection=lPage.getCopyOfSelection();
double lPageSizeX=0;
double lPageSizeY=0;
lPage.getPageSize(&lPageSizeX, &lPageSizeY);
UInt32 lNumberOfSelectedObjects = lSelection.getNumberOfSelectedObjects();
UInt32 j = 0; for (; j < lNumberOfSelectedObjects; j++)
lPage.moveObject(lSelection.getSelectedObject(j).mID,100*lPageSizeX/600,100*lPageSizeY/400);
lPage.renderToTiff(pOut,1000,1000,300,true);
NOPackage::destroyPackage(lPackage);
}
void test_calculateBoundingBox()
{
NOPackage *lPackage=NOPackage::readPackageFromFile("testfiles/SkewedText.xps");
NODocument lDoc=lPackage->getDocument(0);
UInt32 lCount=0; for(;lCount < lDoc.getNumberOfPages();lCount++)
{
NOPage lPage=lDoc.getPage(0);
UInt32 lBufferLength = 10 * 10 * 3;
UInt8 *lBuffer = new UInt8[lBufferLength];
memset(lBuffer,0,lBufferLength);
lPage.renderToImage(lBuffer,10,10,true,false);
UInt32 lObjectID = lPage.findObjectAt(417,194,960,720);
lPage.clearSelection();
lPage.setSelection(lObjectID,true);
NOSelection lSelectedObjects = lPage.getCopyOfSelection();
NCommon::doubleRect lRect;
lRect=lPage.getBoundingBox(lSelectedObjects.getSelectedObject(0).mID);
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << "[" << double(lRect.mTop) << "," << double(lRect.mBottom) << "," << double(lRect.mLeft) << "," << double(lRect.mRight) << "]" << "";
delete [] lBuffer;
}
}
void test_interleave_pages()
{
const char *pIn="testfiles/Office2007_Powerpoint_Drawing_Fills_Texture.xps";
const char *pOut="output/interleave_pages.xps";
const char *file_terms="testfiles/vdp.xps";
const char *file_input=pIn;
const char *file_output=pOut;
// open terms, get handler to terms page
NOPackage *lTerms=NOPackage::readPackageFromFile(file_terms);
NOPage lTermsPage=lTerms->getDocument(0).getPage(0);
// open input, get handle to the doc inside
NOPackage *lInput=NOPackage::readPackageFromFile(file_input);
NODocument lInputDoc=lInput->getDocument(0);
// create output, 1 doc, get handle to doc inside
NOPackage *lOutput=NOPackage::createPackage(true,pOut);
NODocument lOutputDoc=lOutput->getDocument(0);
// loop over the pages in lInputDoct, interleave with lTermspage
// and put this in the lOutputDoc
UInt32 i=0; for (;i < lInputDoc.getNumberOfPages();i++)
{
lOutputDoc.insertPage(lInputDoc.getPage(i),2*i);
lOutputDoc.insertPage(lTermsPage,2*i+1);
}
lOutput->writePackageToFile(file_output);
NOPackage::destroyPackage(lOutput);
NOPackage::destroyPackage(lInput);
NOPackage::destroyPackage(lTerms);
}
void test_textareaselect1()
{
// bounding box selectTextMarquee: [ 346,409 -> 361,357];
// selected characters: 5 -> 15
// bounding box selectTextMarquee: [ 346,409 -> 369,328];
// selected characters: 6 -> 21
NOPackage *lPackage=NOPackage::readPackageFromFile("testfiles/angledtext.xps");
NODocument lDocument = lPackage->getDocument(0);
NOPage lPage = lDocument.getPage(0);
UInt8 *lBuffer = new UInt8[125 * 162 * 3];
lPage.renderToImage(lBuffer, 125, 162, false, false);
doubleRect lRect1;
lRect1.mLeft = 346;
lRect1.mTop = 409;
lRect1.mBottom = 357;
lRect1.mRight = 361;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
lRect1.mBottom = 328;
lRect1.mRight = 369;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
// 297,404 -> 431,203
// should select entire text
lRect1.mLeft = 297;
lRect1.mTop = 404;
lRect1.mBottom = 203;
lRect1.mRight = 431;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
// 366,324 -> 378,275
// "n isocele"
lRect1.mLeft = 366;
lRect1.mTop = 324;
lRect1.mBottom = 275;
lRect1.mRight = 378;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
// 376,291 -> 416,157
// "eles triangle, nearly."
lRect1.mLeft = 376;
lRect1.mTop = 291;
lRect1.mBottom = 157;
lRect1.mRight = 416;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
// 367,324 -> 343,221
// ---> should be "is object will be an", because the end is above the finishing line and not underneath of it
lRect1.mLeft = 367;
lRect1.mTop = 324;
lRect1.mBottom = 221;
lRect1.mRight = 343;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
}
void test_textareaselect2()
{
NOPackage *lPackage=NOPackage::readPackageFromFile("testfiles/0inDashArray.xps");
NODocument lDocument = lPackage->getDocument(0);
NOPage lPage = lDocument.getPage(0);
UInt8 *lBuffer = new UInt8[125 * 162 * 3];
lPage.renderToImage(lBuffer, 125, 162, false, false);
doubleRect lRect1;
// 101,193 -> 168,240
lRect1.mLeft = 101;
lRect1.mTop = 193;
lRect1.mBottom = 240;
lRect1.mRight = 168;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
// 184,194 -> 78,254
lRect1.mLeft = 184;
lRect1.mTop = 194;
lRect1.mBottom = 254;
lRect1.mRight = 78;
lPage.selectTextMarquee(lRect1);
{
NiXPSObjects::NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects::NOString lString = lTextSelection.getSelectedTextPart(i);
NCommon::UTF8String lUTF8String = lString.getUTF8String();
std::cout << lUTF8String << std::endl;
}
}
}
void test_replace_text()
{
const char *pIn="testfiles/template.xps";
const char *pOut="output/replace_text.xps";
NOPackage *lPackage=NOPackage::readPackageFromFile(pIn);
NODocument lDoc=lPackage->getDocument(0);
{
NOFontVector lFonts(*lPackage);
lDoc.searchAndReplaceText("TAG_TO", "Other Text", lFonts, true);
if (lFonts.size()>0)
{
if (lFonts.elementAt(0).replaceWithFile("testfiles/Arial.ttf")==0)
return;
}
}
{
NOFontVector lFonts(*lPackage);
lDoc.searchAndReplaceText("TAG_TO", "Other Text", lFonts, false);
}
lPackage->writePackageToFile(pOut);
NOPackage::destroyPackage(lPackage);
}
void test_open_drawrectangle_save()
{
const char *pIn="testfiles/Office2007_Powerpoint_Drawing_Fills_Texture.xps";
const char *pOut="output/open_drawrectangle_save.xps";
NOPackage *lPackage = NOPackage::readPackageFromFile(pIn);
// get first page
NOPage lPage = lPackage->getDocument(0).getPage(0);
// get content stream
NOXFixedPage lContent = lPage.getFixedPage();
// append a rectangle
// a rectangle is a path, we will add this in a seperate canvas (group)
// and we will put this canvas at the end of the stack, so it will be displayed on top
NOXPath lPath=lContent.createCanvas(lContent.getNumCanvas()).createPath(0);
lPath.intialize();
// geometry: (100,100)-(200,200)
lPath.setData((NOString)"M 100,100 L 200,100 L 200,200 L 100,200 Z");
// color: ARGB - so full red, transparant overlay
lPath.setFill((NOString)"#99FF0000");
// write the XPS file out
lPackage->writePackageToFile(pOut);
NOPackage::destroyPackage(lPackage);
}