July 13th, 2007, 07:26 AM
#1
DrawText : Output letters overlaps
Hi
I try to draw a text using gdi function DrawText, the letters overlaps when the size of the font is too small (3 points)?
Code:
//FONT
CFont font;
LOGFONT lgFont;
memset(&lgFont, 0, sizeof(LOGFONT));
lgFont.lfCharSet = DEFAULT_CHARSET;
lgFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lgFont.lfItalic = fontStyle & FontStyleItalic;//IsItalic(m_strFontStyle);
lgFont.lfOrientation = 0;
lgFont.lfStrikeOut = FALSE;
lgFont.lfUnderline = FALSE;
lgFont.lfOutPrecision = OUT_SCREEN_OUTLINE_PRECIS;
lgFont.lfQuality = ANTIALIASED_QUALITY | PROOF_QUALITY;
strcpy(lgFont.lfFaceName ,m_strFont);
lgFont.lfHeight = -fFontSize;//MulDiv(fFontSize, pDC->GetDeviceCaps(LOGPIXELSY), 96);
lgFont.lfWeight = (fontStyle & FontStyleBold)?FW_BOLD:FW_REGULAR;//GetBoldWeightNew(m_strFontStyle);
lgFont.lfEscapement = 0;
font.CreateFontIndirect(&lgFont);
{
int nBkMode = emfDC.SetBkMode(TRANSPARENT);
int nGraphicMode = emfDC.SetGraphicsMode(GM_ADVANCED);
int nMapMode = emfDC.SetMapMode( MM_TEXT);
CFont* pOldFont = emfDC.SelectObject(&font);
emfDC.DrawTextEx(sText,rcDest,uFormat,NULL);
rcDest.OffsetRect(0,-nY);
emfDC.SetTextColor(oldColor);
emfDC.SelectObject(pOldFont);
nGraphicMode = emfDC.SetGraphicsMode(nGraphicMode);
nMapMode = emfDC.SetMapMode( nMapMode);
nBkMode = emfDC.SetBkMode(nBkMode);
}
I attached a jpeg showing the output.
thank you
Attached Images
July 13th, 2007, 08:43 AM
#2
Re: DrawText : Output letters overlaps
After doing some tests the problem is due to the length of the string being rendered and the size of the font;
I repalced the DrawText with a TextOut and I get the same behaviour?
Any Idea
Attached Images
Last edited by khaldoun KASSEM; July 13th, 2007 at 09:22 AM .
July 13th, 2007, 09:23 AM
#3
Re: DrawText : Output letters overlaps
If you are using the above code from other place other than OnPaint or OnDraw you have to first erase the previous background and then apply fresh drawing or text output. If you don't paint the background you'll see some garbage.
When OnPaint is called it previously calls another function (possibly OnEraseBkground) and thus the background is erased and then new drawing takes place in OnPaint handler. Same goes for OnDraw.
The advice: Do your drawings in the above mentioned functions.
EDIT: After re-reading the post I am not sure if what I have stated is your problem or not.
Last edited by miteshpandey; July 13th, 2007 at 09:27 AM .
If there is no love sun won't shine
July 13th, 2007, 09:35 AM
#4
Re: DrawText : Output letters overlaps
the problem is not in erasing background or not, its really in renderring text, I have it when printing my text...
July 13th, 2007, 09:43 AM
#5
Re: DrawText : Output letters overlaps
Maybe the problem is due to this specific font (face name) that you are using. Try using other fonts (face names)
If there is no love sun won't shine
July 13th, 2007, 10:01 AM
#6
Re: DrawText : Output letters overlaps
Another thing I had in mind is:
What are u using for lfPitchAndFamily
May be FIXED_PITCH is causing all this which maybe the default (not sure) if you have not assigned the lfPitchAndFamily
If there is no love sun won't shine
July 13th, 2007, 10:21 AM
#7
Re: DrawText : Output letters overlaps
Thank you,
Maybe the problem is due to this specific font (face name) that you are using. Try using other fonts (face names)
I tried many font face, I have the same problem;
What are u using for lfPitchAndFamily
after your comment, I tested all possibilities, the output is the same
Its very strange I just have it when the font size is very small (2,3,4)points
July 16th, 2007, 09:12 AM
#8
Re: DrawText : Output letters overlaps
An exemple wich reproduce the behaviour of the DrawText function...
EDIT
Finaly the problem is in the DrawText Function, because the TextOut is working...
Thank you
Attached Files
Last edited by khaldoun KASSEM; July 16th, 2007 at 10:23 AM .
Reason: Adding some clarifications
August 8th, 2007, 05:06 AM
#9
Re: DrawText : Output letters overlaps
Hi
No solution for the moment
I am trying to use GetCharWidth to get char widths and ExttextOut to render the text. (Exemple found on the web from Feng Yuang).
when using the GetCharWidth(hDC,0,255,nCharWidth) we get just for 256 chars, what can i do to get unicode or multibyte chars widths?
thank you
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width