Re: Problem in Drawing Text with different Fonts & Charset

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 08/27/04


Date: Fri, 27 Aug 2004 03:21:11 -0400


(a) did you verify that CreateFont actually succeeded?
        VERIFY(newFont.CreateFont(...));
would be a good start. Also, although you say you are selecting the HFONT, you actually
are selecting the CFont *. The code shown should not compile; the correct code should be
        CFont * oldFont = CurDC.SelectObject(&newFont);

(b) Why are you calling GetDC? This should only be done in the OnPaint handler, which
already declares a DC for your use, CPaintDC dc(this); But if you need a DC, the correct
format is to do CClientDC dc(this);, not your own GetDC/ReleaseDC.

I've never used any iconographic font, so I'm not sure how to create one. Someone else
will have to jump in with advice on that. I know that the basic Arial font does not have
any glyphs, but the font "Arial Unicode MS" has a huge number of glyphs. But since you do
not verify the font creation worked, there is no way to tell what any of this code means.
But the presence of the GetDC is deeply suspicious, and I suspect you have additional
problems you need to address.

Also, read my essay on using SaveDC/RestoreDC, on my MVP Tips site, to avoid using more
and more variables to hold saved state.
                                joe

On Fri, 27 Aug 2004 11:47:21 +0800, "Marco Hung" <marco@xmlhk.com> wrote:

>Dear all,
>
>I'm working in a program which will draw some string with both chinese and
>English character in the Window.
>
>I try to use CreateFont() to create a HFONT with Fonts "Arial" and CharSet
>"CHINESEBIG5_CHARSET" and then select the HFONT to the current DC. However
>the text drawing out isn't in Font "Arial" (It seems to be "Times New Roman"
>instead).
>
>After that, I try to use other available fonts on my platform, but the same
>outpur again. No matter what font I'm using, it give the same output!!!
>
>Does anyone know Why and how to fix it?
>
>Here I attached part of my code.
>
>.
>.
>.
>CDC CurDC = GetDC();
>CFont newFont;
>newFont.CreateFont(20, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
> 0, CHINESEBIG5_CHARSET, OUT_DEFAULT_PRECIS,
> CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
> DEFAULT_PITCH, _T("Arial")); // <- No matter what
>font I use, the program will "Times New Roman" to print text!
>CFont oldFont = CurDC.SelectObject(newFont);
>
>// Draw the Text in Screen
>
>CurDC.SelectObject(oldFont );
>ReleaseDC(CurDC);
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: Text Stretching with a text box.
    ... font size by selecting the text as with any other text or by selecting just ... [MVP] ... Operating System: ...
    (microsoft.public.mac.office.word)
  • Re: show new font and color on screen?
    ... Sorry if this is too obvious, but you'd be surprised:-) Are you selecting ... Bob Jones ... [MVP] ... I go to "Format, font, choose font, but the screen stays the same. ...
    (microsoft.public.word.docmanagement)
  • Re: Uncheck "List font names in their font" option in 2007
    ... The option is nowhere in the user interface anymore. ... Patrick Schmid [OneNote MVP] ... Customize Office 2007: http://pschmid.net/office2007/customize ... My font list has been displaying in the typeface since day ...
    (microsoft.public.word.customization.menustoolbars)
  • Re: Word 2008 Performance
    ... "Blew up Offfice 2008 after saving the Entourage database and reinstalled it." ... Office:Mac MVP ... For the duplicates, launch /Applications/Font Book. ... The application will lkist all your active font. ...
    (microsoft.public.mac.office.word)
  • Re: Strange printing problem in WD2003
    ... Highlight the text, Format - Font. ... MVP Microsoft [Publisher] ... I'm using Word 2003 with XP Home and an Epsom inkjet printer - ...
    (microsoft.public.word.docmanagement)