public static void test_renderer_long()
{
NOPackage lPackage=NOPackage.readPackageFromFile("../../examples/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;
byte[] lBuffer = new byte [lBufferLength];
NiXPS.memset(lBuffer,0,lBufferLength);
lPage.renderToImage(lBuffer,300,300,1,0);
// delete[] lBuffer;
}
NOPackage.destroyPackage(ref lPackage);
}
public static void test_renderer_totiff()
{
string pIn="../../examples/testfiles/catalog.xps";
string pOut="../../examples/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;
byte[] lBuffer = new byte [lBufferLength];
NiXPS.memset(lBuffer,0,lBufferLength);
lPage.renderToImage(lBuffer,lOutSize,lOutSize,1,0);
NiXPS.NOUtility_write_tiff(lBuffer,System.Text.Encoding.UTF8.GetBytes(pOut),lOutSize,lOutSize);
// delete[] lBuffer;
NOPackage.destroyPackage(ref lPackage);
}
public static void test_create_glyphs_via_NOX()
{
string pOut="../../examples/output/create_glyphs_via_NOX.xps";
// new destination document
NOPackage lPackage=NOPackage.createPackage(1,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
string lURI;
{
NOPackage lDummyPackage=NOPackage.readPackageFromFile("../../examples/testfiles/vdp.xps");
{
NOFontVector lFonts = new NOFontVector(lDummyPackage);
lDummyPackage.getDocument(0).getPage(0).getFonts(lFonts);
NOFont lFont=lPage.addFont(lFonts.elementAt(0));
lURI=lFont.getPartName();
}
NOPackage.destroyPackage(ref lDummyPackage);
}
// create a glyphs section in the canvas
NOXGlyphs lGlyphs=lCanvas.createGlyphs(0);
lGlyphs.intialize(10.0,("/"+lURI),50.0,50.0);
lGlyphs.setFill("#FF0000FF");
lGlyphs.setUnicodeString("abcdefghijklmnopqrstuvwxyz");
// write out and close
lPackage.writePackageToFile(pOut);
NOPackage.destroyPackage(ref lPackage);
}
public static void test_moveObjectsAndRenderToImage()
{
string pOut="../../examples/output/moveObjectsAndRenderToImage.tiff";
NOPackage lPackage=NOPackage.readPackageFromFile("../../examples/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,1);
NiXPS.UInt32RectC lRect;
lRect.mTop=157;
lRect.mLeft=59;
lRect.mBottom=299;
lRect.mRight=538;
lPage.selectMarquee(ref lRect,600,400,0);
NOSelection lSelection=lPage.getCopyOfSelection();
double lPageSizeX=0;
double lPageSizeY=0;
lPage.getPageSize(ref lPageSizeX, ref 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,1);
NOPackage.destroyPackage(ref lPackage);
}
public static void test_calculateBoundingBox()
{
NOPackage lPackage=NOPackage.readPackageFromFile("../../examples/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;
byte[] lBuffer = new byte [lBufferLength];
NiXPS.memset(lBuffer,0,lBufferLength);
lPage.renderToImage(lBuffer,10,10,1,0);
UInt32 lObjectID = lPage.findObjectAt(417,194,960,720);
lPage.clearSelection();
lPage.setSelection(lObjectID,1);
NOSelection lSelectedObjects = lPage.getCopyOfSelection();
NiXPS.doubleRectC lRect;
lRect=lPage.getBoundingBox(lSelectedObjects.getSelectedObject(0).mID);
System.Console.Out.WriteLine( "[" + String.Format("{0:0.##}",lRect.mTop) + "," + String.Format("{0:0.##}",lRect.mBottom) + "," + String.Format("{0:0.##}",lRect.mLeft) + "," + String.Format("{0:0.##}",lRect.mRight) + "]" );
// delete[] lBuffer;
}
}
public static void test_interleave_pages()
{
string pIn="../../examples/testfiles/Office2007_Powerpoint_Drawing_Fills_Texture.xps";
string pOut="../../examples/output/interleave_pages.xps";
string file_terms="../../examples/testfiles/vdp.xps";
string file_input=pIn;
string 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(1,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(ref lOutput);
NOPackage.destroyPackage(ref lInput);
NOPackage.destroyPackage(ref lTerms);
}
public static 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("../../examples/testfiles/angledtext.xps");
NODocument lDocument = lPackage.getDocument(0);
NOPage lPage = lDocument.getPage(0);
byte[] lBuffer = new byte [125 * 162 * 3];
lPage.renderToImage(lBuffer, 125, 162, 0, 0);
NiXPS.doubleRectC lRect1;
lRect1.mLeft = 346;
lRect1.mTop = 409;
lRect1.mBottom = 357;
lRect1.mRight = 361;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
lRect1.mBottom = 328;
lRect1.mRight = 369;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
// 297,404 . 431,203
// should select entire text
lRect1.mLeft = 297;
lRect1.mTop = 404;
lRect1.mBottom = 203;
lRect1.mRight = 431;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
// 366,324 . 378,275
// "n isocele"
lRect1.mLeft = 366;
lRect1.mTop = 324;
lRect1.mBottom = 275;
lRect1.mRight = 378;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
// 376,291 . 416,157
// "eles triangle, nearly."
lRect1.mLeft = 376;
lRect1.mTop = 291;
lRect1.mBottom = 157;
lRect1.mRight = 416;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
// 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(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
}
public static void test_textareaselect2()
{
NOPackage lPackage=NOPackage.readPackageFromFile("../../examples/testfiles/0inDashArray.xps");
NODocument lDocument = lPackage.getDocument(0);
NOPage lPage = lDocument.getPage(0);
byte[] lBuffer = new byte [125 * 162 * 3];
lPage.renderToImage(lBuffer, 125, 162, 0, 0);
NiXPS.doubleRectC lRect1;
// 101,193 . 168,240
lRect1.mLeft = 101;
lRect1.mTop = 193;
lRect1.mBottom = 240;
lRect1.mRight = 168;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
// 184,194 . 78,254
lRect1.mLeft = 184;
lRect1.mTop = 194;
lRect1.mBottom = 254;
lRect1.mRight = 78;
lPage.selectTextMarquee(ref lRect1);
{
NiXPSObjects.NOTextSelection lTextSelection = lPage.getTextSelection();
UInt32 i = 0; for (; i < lTextSelection.getNumberOfSelections(); i++)
{
NiXPSObjects.NOString lString = lTextSelection.getSelectedTextPart(i);
string lstring = lString.getUTF8String();
System.Console.Out.WriteLine( lstring );
}
}
}
public static void test_replace_text()
{
string pIn="../../examples/testfiles/template.xps";
string pOut="../../examples/output/replace_text.xps";
NOPackage lPackage=NOPackage.readPackageFromFile(pIn);
NODocument lDoc=lPackage.getDocument(0);
{
NOFontVector lFonts = new NOFontVector(lPackage);
lDoc.searchAndReplaceText("TAG_TO", "Other Text", lFonts, 1);
if (lFonts.size()>0)
{
if (lFonts.elementAt(0).replaceWithFile("../../examples/testfiles/Arial.ttf")==0)
return;
}
}
{
NOFontVector lFonts = new NOFontVector(lPackage);
lDoc.searchAndReplaceText("TAG_TO", "Other Text", lFonts, 0);
}
lPackage.writePackageToFile(pOut);
NOPackage.destroyPackage(ref lPackage);
}
public static void test_open_drawrectangle_save()
{
string pIn="../../examples/testfiles/Office2007_Powerpoint_Drawing_Fills_Texture.xps";
string pOut="../../examples/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("M 100,100 L 200,100 L 200,200 L 100,200 Z");
// color: ARGB - so full red, transparant overlay
lPath.setFill("#99FF0000");
// write the XPS file out
lPackage.writePackageToFile(pOut);
NOPackage.destroyPackage(ref lPackage);
}