Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetTextCharacterExtra

0 views
Skip to first unread message

TOB

unread,
Oct 13, 2008, 4:51:00 PM10/13/08
to
//Why does DrawText sometimes overlap characters
//Thank you,
//Tim

pDC->SetMapMode(MM_HIMETRIC);
pDC->SetTextCharacterExtra(85);
CFont* def_font = pDC->SelectObject(&font);
CRect r;

CString strName="1884-1922"; //does not print '-'
r.SetRect(200,-2000,8000,-3000);
pDC->DrawText(strName,r,DT_CENTER);

strName="ABCDEFG";
r.SetRect(200,-3000,8000,-4000);
pDC->DrawText(strName,r,DT_CENTER);

strName="1884X1922";//the X gets printed over the 4
r.SetRect(200,-4000,8000,-5000);
pDC->DrawText(strName,r,DT_CENTER);

strName="1884 1922";
r.SetRect(200,-5000,8000,-6000);
pDC->DrawText(strName,r,DT_CENTER);

strName="1a2b3c1A2B3C4X";
r.SetRect(200,-6000,8000,-7000);
pDC->DrawText(strName,r,DT_CENTER);

Alex Blekhman

unread,
Oct 15, 2008, 9:42:32 AM10/15/08
to
"TOB" wrote:
> //Why does DrawText sometimes overlap characters
> //Thank you,
> //Tim
>
> pDC->SetMapMode(MM_HIMETRIC);
> pDC->SetTextCharacterExtra(85);
> CFont* def_font = pDC->SelectObject(&font);
> CRect r;
>
> CString strName="1884-1922"; //does not print '-'
> r.SetRect(200,-2000,8000,-3000);
> pDC->DrawText(strName,r,DT_CENTER);
>
> [...]

Do you have enough space for the text? For MM_HIMETRIC mode a
logical unit equals to 0.01 mm. You give 7800 logical units for
the text string, it is 78 mm. This is pretty much space, but
didn't say what the size of a font.

HTH
Alex


TOB

unread,
Oct 15, 2008, 7:22:00 PM10/15/08
to
I just used the default font.
ignore the line 'CFont* def_font = pDC->SelectObject(&font);' not needed
I think it might be my display driver.
I got the same code to work on some computers and others fail.

Thank ,
Tim

Alex Blekhman

unread,
Oct 16, 2008, 5:30:11 AM10/16/08
to
"TOB" wrote:
> I think it might be my display driver.
> I got the same code to work on some computers and others fail.

This functionality is too basic in order to ascribe the problem to
a display driver bug. Of course, everything is possible, but as a
first step I'd suggest you to reproduce the problem with minimal
standalone application.

Alex


TOB

unread,
Oct 16, 2008, 11:23:00 AM10/16/08
to
You can reproduce it my creating a new Project. And replacing the
CNewView::OnDraw() with:

void CNewView::OnDraw(CDC* pDC)
{
pDC->SetMapMode(MM_HIMETRIC);
pDC->SetTextCharacterExtra(85);
CRect r;

CString strName="1884-1922"; //does not print '-'
r.SetRect(200,-2000,8000,-3000);
pDC->DrawText(strName,r,DT_CENTER);

strName="ABCDEFG";
r.SetRect(200,-3000,8000,-4000);
pDC->DrawText(strName,r,DT_CENTER);

strName="1884X1922";//the X gets printed over the 4
r.SetRect(200,-4000,8000,-5000);
pDC->DrawText(strName,r,DT_CENTER);

strName="1884 1922";
r.SetRect(200,-5000,8000,-6000);
pDC->DrawText(strName,r,DT_CENTER);

strName="1a2b3c1A2B3C4X";
r.SetRect(200,-6000,8000,-7000);
pDC->DrawText(strName,r,DT_CENTER);
}

Thank you,
Tim

Alex Blekhman

unread,
Oct 16, 2008, 12:19:20 PM10/16/08
to
"TOB" wrote:
> You can reproduce it my creating a new Project. And replacing
> the CNewView::OnDraw() with:
> [...]

I succeeded to reproduce it on my system, too. I don't know what
exactly causes the problem, but these changes apparently fix it:

> void CNewView::OnDraw(CDC* pDC)
> {
> pDC->SetMapMode(MM_HIMETRIC);
> pDC->SetTextCharacterExtra(85);

pDC->SetTextAlign(TA_CENTER);

> CRect r;
>
> CString strName="1884-1922"; //does not print '-'
> r.SetRect(200,-2000,8000,-3000);

pDC->ExtTextOut(r.CenterPoint().x, r.top, 0, r, strName, NULL);
...

HTH
Alex


TOB

unread,
Oct 16, 2008, 12:37:01 PM10/16/08
to
Thank Alex
Yes, that fixed it on my system also.

Thanks again,
Tim


"Alex Blekhman" wrote:

> ....
>
> HTH
> Alex
>
>
>

0 new messages