[MFC] CRichEditCtrl how to set codepage for Unicode?

G

Guest

In MFC, CRichEditCtrl contrl, I want to set the codepage for the control to
Unicode.

I used the following method to set codepage for it (only for ANSI or BIG5,
etc, not unicode). How should I change codepage to Unicode?

[Step 1]
Get the default character format. GetDefaultCharFormat(CHARFORMAT2& _cf)

[Step 2]
Modify received character format.

[Step 2.1]
Modify bCharSet, szFaceName, and dwMask member variables in _cf.

For the bCharSet, it should be one of the value of lfCharSet in LOGFONT
structure.
lfCharSet may be ANSI_CHARSET, CHINESEBIG5_CHARSET, TURKISH_CHARSET, etc.
I cannot find a value for Unicode.

[Step 3]
Set back to RichEdit Control. SetDefaultCharFormat(CHARFORMAT2& _cf).
 
M

Mihai N.

In MFC, CRichEditCtrl contrl, I want to set the codepage for the control to
Unicode. ....
Get the default character format. GetDefaultCharFormat(CHARFORMAT2& _cf)
Modify received character format.
Modify bCharSet, szFaceName, and dwMask member variables in _cf.
What you are changing for the font is the charset, not codepage.
See http://www.mihai-nita.net/20060806a.shtml

If you need Unicode support in the RTF control, the control itself should be
Unicode (the class should be RichEdit20W, not RichEdit20A).
See here: http://www.mihai-nita.net/20050709b.shtml
 
M

Mihai N.

Do you know which font is suitable for Unicode?

There is no font covering all the Unicode ranges.

But Windows does a good job in selecting a font, and will even mix
various fonts to cover all your text.
Depending on what you want to do this might be enough, or not.

In general, you cannot properly select a font if you don't know the language
of the text. Knowing the Unicode value is not enough.
Example: the same Kanji is present in Chinese Simplified, Traditional and
Japanese. But a Japanese font cannot be used for Chinese Traditional, for
example.
 
T

Tamas Demjen

In general, you cannot properly select a font if you don't know the language
of the text.

That's probably true with Asian languages. However, there are clearly
non-Unicode fonts that contain 256 characters at best, and there are
Unicode ones, covering all the Central and Eastern European languages,
Russian, Greek, etc.

Typically most of the Microsoft-provided TrueType fonts that come with
the OS are Unicode. That's Arial, Courier New, Tahoma, Times New Roman
at the minimum.

The US and European Windows don't have the Asian package installed by
default, but you can always choose to install it later. Many of the
fonts I have will never show Japanese characters, but the built-in
Microsoft fonts will do, after installing the Asian package.

Tom
 
M

Mihai N.

My interpretation of the "Do you know which font is suitable for Unicode?"
question was Do you know which font can cover all the Unicode ranges?"
not "Do you know a Unicode font?"

I could have ask for more clarification and waste another day,
or restate the question as I understand it, which I did
("There is no font covering all the Unicode ranges.") and answer.

If I got the question wrong, Kevin can ask again.
But the answer to the question (as I understand it) is correct.

That's probably true with Asian languages. However, there are clearly
non-Unicode fonts that contain 256 characters at best, and there are
Unicode ones, covering all the Central and Eastern European languages,
Russian, Greek, etc. ....
Typically most of the Microsoft-provided TrueType fonts that come with
the OS are Unicode. That's Arial, Courier New, Tahoma, Times New Roman
at the minimum.

What makes a font unicode is not support for more than one script, or more
than 256 characters, but the presence of one of the Unicode cmap table
formats (see http://www.microsoft.com/typography/otspec/cmap.htm)

The US and European Windows don't have the Asian package installed by
default, but you can always choose to install it later. Many of the
fonts I have will never show Japanese characters, but the built-in
Microsoft fonts will do, after installing the Asian package.

Some of the MS fonts show Japanese after installing Asian support
not because the MS fonts are smarter, or Unicode, but because adding Asian
support also adds the proper font linking entries in the registry.
It can be done with your fonts too, if you are not afraid to play
with the registry (see HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\FontLink\SystemLink)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top