简体   繁体   中英

How to get a list of code points supported by a true type font with Freetype2 in C++

如何使用Freetype2库获取真字体支持的字形或代码点列表?

Freetype provides two functions to accomplish this task. The first is FT_Get_First_Char(FT_Face face, FT_UInt * agindex) .

This function will return the code for the first character supported by the font. It will also set the variable pointed to by agindex to the index the glyph has in the font. Note that if it is set to 0, that means there are no additional characters in the font.

The next function you need is FT_Get_Next_Char(FT_Face face, FT_ULong char_code, FT_UInt * agindex) . This will let you grab the next available character in the font by returning its value. Note that like FT_Get_First_Char, this will also set agindex to zero when it returns the final glyph.

So now for a working example:

    // Load freetype library before hand.
FT_Face face;

// Load the face by whatever means you feel are best.

FT_UInt index;
FT_ULong c = FT_Get_First_Char(face, &index);

while (index) {
    std::cout << "Supported Code: " << c << std::endl;

    // Load character glyph.
    FT_Load_Char(face, c, FT_LOAD_RENDER);

    // You can now access the glyph with:
    // face->glyph;

    // Now grab the next charecter.
    c = FT_Get_Next_Char(face, c, &index);
}

// Make sure to clean up your mess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM