-1
如何使用Freetype2庫獲取由真實類型字體支持的字形或代碼點列表?如何在C++中使用Freetype2獲得真實類型字體支持的代碼點列表
如何使用Freetype2庫獲取由真實類型字體支持的字形或代碼點列表?如何在C++中使用Freetype2獲得真實類型字體支持的代碼點列表
Freetype提供了兩個功能來完成此任務。第一個是FT_Get_First_Char(FT_Face face, FT_UInt * agindex)。
該函數將返回字體支持的第一個字符的代碼。它還會將由agindex指向的變量設置爲字形在字體中的索引。請注意,如果它設置爲0,這意味着字體中沒有其他字符。
您需要的下一個功能是 FT_Get_Next_Char(FT_Face face, FT_ULong char_code, FT_UInt * agindex)。這將讓你通過返回它的值來獲取字體中下一個可用的字符。請注意,就像FT_Get_First_Char一樣,當它返回最終的字形時,它也會將agindex設置爲零。
所以現在的工作示例:
// 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.
在我的代碼我使用FT_Load_Glyph(ftFace,glyphIndex,FT_LOAD_DEFAULT)和FT_Render_Glyph(ftFace->字形,FT_RENDER_MODE_NORMAL),似乎從你輸入什麼不同,它確實工作,所以它讓我想知道。 – Zebrafish
我在想什麼,所有的downvotes。 – Zebrafish