Unicode troubles in FreeType
Asked Answered
J

2

6

So, I've got an implementation that parses an xml that, among other things, positions and strings of Wikipedia's main page. The parsing is done with rapidxml after which the strings are converted from UTF-8 to UTF-32 by http://utfcpp.sourceforge.net/. The UTF-32 code is then used in freetype's:

unsigned long c = FT_Get_Char_Index(face,*p);
FT_Load_Glyph(face,c,FT_LOAD_RENDER);

where *p is the UTF-32 char code. This glyph is then rendered in OpenGL.

Now, I can't seem to get cryllic characters to work, nor any chinese or japanese or viet, I am sure that *p corresponds to the correct code, and I would be thankful for any pointers I can get.

For these fonts Microsofts arial.ttf is used, from the Arch linux package and from what I've seen in fontviewing programs, it should contain the characters that I want.

Jerold answered 16/7, 2012 at 9:12 Comment(0)
F
8

Two things to suggest:

First, have you called FT_Select_Charmap to specify you're using a Unicode encoding?

FT_Select_Charmap(face , ft_encoding_unicode);

Second, not all Arial fonts have all characters, and some font viewers (on Windows, anyway) can mislead by automatically substituting glyphs from different faces. Try ArialUni.ttf if you can find it.

Finding answered 16/7, 2012 at 9:56 Comment(9)
Thank you for your suggestions! Using FT_Select_Charmap did not produce any different results, I'm guessing that unicode is freetype's default? Is there any free font that contains the characters that I'm looking for that you can recommend?Jerold
Re. fonts, I'd start here : en.wikipedia.org/wiki/Unicode_typeface - and one other thing to check is to breakpoint before calling FT_Get_Char_Index and checking exactly what code point you're passing. There could be a bug could be in your use of rapidxml or utfcpp...Finding
Freetype's default encoding depends on the font you're using, and a few other things. I'd recommend specifying the encoding explicitly.Finding
Well, I do get a char with the code 0x43f which should be п (a cryllic character) and then FT_Get_Char_Index(face, *p) returns 0, which is ‘undefined character code’ according to Freetype docs. This time i'm using FreeMono.ttf which should contain cryllic. I have selected the unicode charmap during initilization.Jerold
Can you try and build a minimal example that fails? FT_Library library; FT_Face face; FT_Init_FreeType( &library ); FT_New_Face( library, "monofont.ttf", 0, &face ); FT_Get_Char_Index(face, 0x43f); - but check error returns in each case!Finding
I commited my own answer to this, thanks for the help, it led me to the error. And yes, that minimal build worked.Jerold
@JonathanGustafsson Where is your own answer?Auger
@Auger It was deleted as it wasn't really helpful : " there was an error in how I handled the FT_Faces after parsing, as there are many different fonts on the wikipedia main page".Finding
@JonathanGustafsson Ok, thank you for your quick answer! Did you ever get it fixed? I'm facing the same issue right now with Arial fonts. It works if I use FTGL, but I'm having issues directly against FreeType.Auger
H
2

Do not forget to set the font size right after loading the face.

FT_Error err =  FT_Set_Pixel_Sizes(face, (width), (height));
Hustle answered 19/6, 2017 at 22:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.