Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2005, 01:49 AM
Authorized User
 
Join Date: Jul 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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....







Similar Threads
Thread Thread Starter Forum Replies Last Post
Font Problem :( surendran Flash (all versions) 1 November 1st, 2006 02:09 AM
Font printing problem harini19 Java Basics 1 July 17th, 2006 08:04 AM
how to get font ,color,font size of text in win32 satishsatao Visual C++ 0 April 5th, 2006 05:05 AM
Font problem in php ksunil Beginning PHP 0 January 30th, 2006 07:13 AM
font-size problem in CSS crmpicco CSS Cascading Style Sheets 2 August 22nd, 2005 09:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.