문제

I'm writing a text writer in C++, which I'll have a string of a phrase and display the appropriate bitmap font for each char value.

For now, it's working for the regular characters, but I'm getting weird values for accents and other characters such as À, Á, Â, Ã, etc

I'm doing this:

int charToPrint = 'a';
//use this value to figure which bitmap font to display

The bitmap font does have these characters, but on this line I'm not getting the values I'm supposed to get, such as: 195 for Ã, 199 for Ç, etc...

I tried changing my project's character set from Multi Byte to Unicode, but I don't think that does anything for the char->int conversion...

How can I get this conversion with chars?

Edit: I'm using Visual Studio 2012, Windows 7, and it's an OpenGL application with a bitmap font. I've mapped the positions/width/height of each character, according to it's char value, so the character a is at the position 97 of my bitmap font (plus width accounted for).

To draw, I just need to figure the position based on the char code.

I have a string of a phrase I want to display, and I loop through each character, figure the charCode, and call my draw function.

For these characters with accents, I'm getting negative values, so my draw function doesn't do anything (there's no position -30 for Ç for example). I need to figure how to get these values properly and send to the draw function.

도움이 되었습니까?

해결책

Use Unicode, it is year 2013 already :) The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets

You will use wchar_t as a type and UTF-16 / UTF-32 encoding. That will make your code supporting not only "irregular" characters but many more "irregular" characters :) (there is no such a thing as regular characters).

Example

wchar_t c = L'Á';
printf("char: %lc encoding: %d\n", c, c);

c = 0xc1; 
printf("char: %lc encoding: %d\n", c, c);

Output

char: Á encoding: 193
char: Á encoding: 193
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top