0

I init FreeType as following:

if (FT_Init_FreeType(&ft)) { printf("couldn't init freetype\n"); exit(1); } std::string fontPath = "D:/fonts/newscycle-bold.ttf"; if (FT_New_Face(ft, fontPath.c_str(), 0, &face)) { printf("couldn't open font\n"); exit(1); } FT_Select_Charmap(face, ft_encoding_unicode); FT_Set_Pixel_Sizes(face, 0, size); g = face->glyph; // declaration like FT_GlyphSlot g; 

I get glyphs as following:

 // load the w_char into the face object if (FT_Load_Char(face, c, FT_LOAD_RENDER)) printf("freetype is unable to load char: %c\n", c); // this runs if error was occured 

And I use wchar_t* and wchar_t types.

But I see following: enter image description here

1
  • 2
    What did you expect to see? Could it be inferred from the code you have posted? Commented Mar 6, 2014 at 19:56

4 Answers 4

1

I had the same problem with unicode characters and at the end I found that the problem was the conversion from UTF8 string to UTF16 (wstring). I was using mbstowcs function to do the conversion, but symbols like '€' are not converted as expected. The way it works ok for me is with the new C++11 std::wstring_convert class. Try this:

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert; const std::wstring wideText = convert.from_bytes(_text); 

Now pass the wideText string to FreeType.

Sign up to request clarification or add additional context in comments.

Comments

1

I guess for initializing a string with wide chars, you need to initialize them like this:

wchar_t c = L'آ'; wchar_t w = _T('آ'); wchar_t *s = L"Hآ文"; wchar_t *q = _T("Hآ文"); 

but if you are loading the string at run-time, you must convert the string to ut16 or utf-32, either by saving the string file as utf-16 or utf-32 file in some text editors or by converting your utf-8 formatted string to utf-16 formatted string with a function.

Comments

0

It's probably too late, but I had the same issue. The reason is that you are using the wrong function to load the character/glyph.

All you have to do is to replace FT_Load_Char by FT_Load_Glyph.

Comments

0

It could also be that your font doesn't have the Glyphs you try to show.

I had the same problem with japanese chars 'あえいおう' and searched for days - only to find out that my font did only contain ASCII character set and some western sets, but no asian sets.

If the Glyph is not within the font, it gets replaced by either ...

  • ... an empty square (see your screenshot), or ...
  • ... a square with a centered 2-lined hexadecimal glyph-id

Example: Image: rendered 'あえいおう' + 1 errornous glyph

The font I used for this example contains japanese character sets, but doesn't contain Thai/Vietnamese sets, so that's why japanese chars are shown, whereas Thai/Vietnamese chars aren't. (Though I don't know why it's sometimes a square with glyph-id, and sometimes without it)

If you see that square, you'll know that the glyph with the borderd glyph-id simply doesn't exist in your font file. You have to use a unicode font.

For testing purposes you might want to use the Arial Unicode from standard windows fonts.

To get ARIALUNI.TTF (Arial Unicode):

  1. Open Start-Menu (Windows-key) and type: font
  2. Open "Show installed fonts"
  3. In Fonts window search (F3) for Arial Uni
  4. Look for Arial Unicode MS Standard
  5. Drag and Drop it e.g. to Desktop (or to any other place)

Use that font for unicode text.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.