CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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 Attached Images

  2. #2
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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 Attached Images
    Last edited by khaldoun KASSEM; July 13th, 2007 at 09:22 AM.

  3. #3
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    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

  4. #4
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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...

  5. #5
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    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

  6. #6
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    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

  7. #7
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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

  8. #8
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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 Attached Files
    Last edited by khaldoun KASSEM; July 16th, 2007 at 10:23 AM. Reason: Adding some clarifications

  9. #9
    Join Date
    May 2002
    Location
    France, Toulouse
    Posts
    156

    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
  •  





Click Here to Expand Forum to Full Width

Featured