Hi again Thomas & Everyone, I started thinking that there should be some way to do clipping of text. It is not elegant, but I came up with a solution. Note, the font I am using has a height of 33 and the destination rectangle has a height of 23. This code has not been tweaked for error checking. I will explain what I did in code: //-------------------------------------------------- //If only partial line used, then draw into a temporary document of a clipped size and adjust the drawing such that it starts //adjusted and therefore clips the code drawn into the temporary PDF document. So:
//Open a temporary PDF document PdfDocument^ tempDocument = gcnew PdfSharp::Pdf::PdfDocument();
//Add a page PdfPage^ tempPage = tempDocument->AddPage();
//Make all measurements relative to 0,0 and setup a small rectangle for the size of the page to draw into. //Note that this will bypass the regular page sizes. "Frame" is a rectangle with its width and height set PdfRectangle^ pdfRect = gcnew PdfRectangle(XPoint(0, 0), XSize(Frame.Width(), Frame.Height())); //PDFSharp need the origin to be set to 0,0
//Set the size of the new page in the temporary document tempPage->MediaBox = pdfRect; //now set the rectangle as the whole page size
//Now get the graphics object from this newly sized temporary page XGraphics^ tempGraphicsDrawingObject = XGraphics::FromPdfPage(tempPage);
//Now draw the string into this page adjusting the height for the new height of the frame tempGraphicsDrawingObject->DrawString( outputString, m_fontObject, m_brush, 0, Frame.Height());
//And save to a temporary file tempDocument->Save("c:/temp/tempjunk.pdf");
//This is where we load the image object of the temporary PDF document. There must be a way to do //this somehow without saving and reloading the PDF document to disk. Anyone have any ideas? XImage^ xImage = XImage::FromFile("c:/temp/tempjunk.pdf");
//Now, go back to the original document and specify the rectangle where you want to insert the WHOLE temporary image into. XRect dRect = XRect(Frame.MinX(), Frame.MinY(), Frame.Width(), Frame.Height());
//Now draw in the image to the original document at the specified coordinates and thus we have clipping. m_graphicsDrawingObject->DrawImage(xImage, dRect); //,, xRect, XGraphicsUnit::Point);
//It is at this point I delete the temporary PDF file using our custom crossplatform function to do so (not shown). //--------------------------------------------------
And this is how text clipping can be done. Best Regards, George
|