Font Problem
Hi all,
Iam using Keith Rule's CMemDc class & I have changed it according to my requirement.Iam posting that class also here.
Now Iam zooming my View using "SetWorldTransform" call.
My problem now is when I change the zoom factor to below or above 100,the Fonts are not smooth.
The following are my codes:
//Creating Font like this in "MyView" constructor.Don't want to use FixedFonts.
m_oFont.CreatePointFont(120, _T("Courier New"));
LOGFONT oLogfont;
m_oFont.GetLogFont(&oLogfont);
//OnPrepareDc looks like this.
void MyView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
pDC->SetMapMode(MM_TEXT);
SetGraphicsMode(pDC->GetSafeHdc(), GM_ADVANCED);
pDC->SelectObject(&m_oFont);
pDC->GetTextMetrics(&m_TextMetrics);
XFORM xForm;
xForm.eM11 = 0.01 * m_iZoomFactor;
xForm.eM21 = 0;
xForm.eDx = 0;
xForm.eM12 = 0;
xForm.eM22 = 0.01 * m_iZoomFactor;
xForm.eDy = 0;
pDC->GetTextMetrics(&m_textMetrics);
SetWorldTransform(pDC->GetSafeHdc(), &xForm);
CScrollView::OnPrepareDC(pDC, pInfo);
}
//My "OnDraw" looks like this.
void MyView::OnDraw(CDC* pDC)
{
CpagesDoc* pDoc = GetDocument();
CSize sizeTotal;
//default scrollsizes to 80 chars X 80 lines.
sizeTotal.cx = 80;
sizeTotal.cy = 80;
//Client Rectangle Size.
CRect rect;
GetClientRect(&rect);
//Creating a temporary Dc.
C_TempDc tempDC(pDC,m_oFont,&rect);
int pageWidth = 800;
int pageHeight = 800;
//int pageGap = 5;
int pageNumber =3;
SIZE size;
size.cx = 1000;
size.cy = (pageHeight*3)+100;
//First Page
tempDC->Rectangle(CRect(0,0,pageWidth,pageHeight));
tempDC->TextOut(5,10,"This is the first line on the FirstPage");
sizeTotal.cx *= MulDiv(m_textMetrics.tmAveCharWidth, m_iZoomFactor, 100);
sizeTotal.cy *= MulDiv(m_textMetrics.tmHeight, m_iZoomFactor, 100);
SetScrollSizes(MM_TEXT, sizeTotal);
}
//Keith Rule's Memory Buffer
#ifndef C_TEMPDC_H
#define C_TEMPDC_H
class C_TempDc : public CDC
{
public:
C_TempDc(CDC* pDC,CFont & font,const CRect* pRect = NULL): CDC()
{
ASSERT(pDC != NULL);
//Initialising.
m_pDC = pDC;
m_oldBitmap = NULL;
m_oldFont= NULL;
//Getting ClipBox Rectangle.
pDC->GetClipBox(&m_clipRect);
//Client Rectangle.
m_clientRect = *pRect;
pDC->DPtoLP(&m_clientRect);
// Create a Memory DC
CreateCompatibleDC(pDC);
//pDC->LPtoDP(&m_rect);
m_bitmap.CreateCompatibleBitmap(pDC,m_clientRect.W idth(),m_clientRect.Height());
pDC->LPtoDP(&m_clientRect);
m_oldBitmap = SelectObject(&m_bitmap);
///Selecting the Font.
m_oldFont = SelectObject(&font);
SetMapMode(pDC->GetMapMode());
pDC->DPtoLP(&m_clientRect);
SetWindowOrg(m_clientRect.left,m_clientRect.top);
// Fill background
FillSolidRect(m_clientRect, pDC->GetBkColor());
}
~C_TempDc()
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_clipRect.left,m_clipRect.top,m_clipRect. Width(), m_clipRect.Height(),
this, m_clipRect.left,m_clipRect.top, SRCCOPY);
//Swap back the original bitmap & font.
SelectObject(m_oldBitmap);
SelectObject(m_oldFont);
}
C_TempDc* operator->()
{
return this;
}
operator C_TempDc*()
{
return this;
}
private:
CBitmap m_bitmap;
CBitmap* m_oldBitmap;
CFont* m_oldFont;
CDC* m_pDC;
CRect m_clientRect;
CRect m_clipRect;
};
#endif//C_TEMPDC_H
Hope someone can Help....
|