Text drawn upside down
Hi,
I'm trying to play with OLE with Visual Studio 2005 and Windows Vista.
I've done a MFC project which renders methematical equations from
CStrings, and without any OLE stuff it works just fine. The formula is
parsed, each symbol is put into a global in-memory object tree, objets
are converted into CImages and then gradually mixed to obtain the final
result by using BitBlt(). I've just used standard Win32 APIs like
DrawText or LineTo.
Now I'm trying to implement all the OLE stuff which would allow my
application to be embedded in WordPad, for instance. Basically it works
EXCEPT that the text in the graphic displayed is drawn upside down ! Not
the lines I drawn with LineTo, for instance; but just what I passed to
DrawText()...
What should I do ? Before drawing the picture inside of the OLE view I
called SetWindowOrg/SetWindowExt/SetViewportExt to configure the DC. And
it seems to work "good enough" to return a well-sized rectangle with the
unstretched original picture... But how to avoid this Y-flip ? I'm a
little bit puzzled, since a call to pDC->TextOut("This is a test") after
having copied the problematic bitmap to the DC displays the text
*without* the flip !
As the equation members are not rendered directly in the OLE OnDraw
event handler (and as a result they don't share the OnDraw::pDC which is
affected by SetMapMode/SetWindowExt functions), should I modify my
drawing routines in order to change the viewport, the map mode and so on
when pictures are drawn in the context of the OLE server ? Since I want
also to keep the standalone MFC app, it would require to duplicate my
drawing code (one for the OLE server app, the other for the regular app)...
Here is my code :
BOOL CEquSrvrItem::OnDraw(CDC* pDC, CSize& rSize)
{
UNREFERENCED_PARAMETER(rSize);
CEquationsM?dialexieDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->SetMapMode(MM_ANISOTROPIC);
CSize DocSize;
if (pDoc->equation.getHiMetricSize(DocSize))
{
DocSize.cy = -DocSize.cy;
pDC->SetWindowOrg(0,0);
pDC->SetWindowExt(DocSize);
pDC->SetViewportExt(1, -1);
/* Drawing code here ! */
if (pDoc->equation.isDefined())
{
/* Get the bitmap */
CImage *pEquationImage = pDoc->equation.drawBitmap();
CDC* pEquationDC = CDC::FromHandle(pEquationImage->GetDC());
/* Copy the image */
pDC->BitBlt(0,
0,
DocSize.cx,
DocSize.cy,
pEquationDC,
0,
-DocSize.cy,
SRCCOPY); //DON'T WORK, TEXT DISPLAYED UPSIDE DOWN
/* Release the DC */
pEquationImage->ReleaseDC();
pDC->TextOutA(0, 0, "THIS IS A TEST", 15);//WORKS!
delete pEquationImage;
}
}
return TRUE;
}
Any hint greatly appreciated !
Best regards,
A.R.