Reputation: 11
I am using harfbuzz hb_shape() fubction to get the final glyph index but I am getting the isolated glyph without any gsub applied on it if I comment the .hb_buffer_set_direction function.And if I don't comment it then I am getting glyph out of the arabic range. Can anyone help me how to fix it. And why it is hapeening? Below is sample code:-
FT_Library library;
FT_Face face;
FT_Error error;
char* fontfilepath;
fontfilepath = "D:/Amiri-Bold.ttf";
error = FT_Init_FreeType( &library );
error = FT_New_Face( library, fontfilepath, 0, &face );
hb_font_t* hb_font = hb_ft_font_create(face, NULL);
hb_buffer_t* hb_buffer = hb_buffer_create();
const uint16_t* textt = (const uint16_t*) tempdata;
hb_buffer_set_script(hb_buffer, HB_SCRIPT_ARABIC); // Set script to Arabic
hb_buffer_set_language(hb_buffer, hb_language_from_string("ara", -1));
hb_buffer_set_direction(hb_buffer, HB_DIRECTION_RTL); // Set direction to Right-To-Left for Arabic
hb_buffer_add_utf16(hb_buffer, textt, -1, 0, -1);
hb_shape(hb_font, hb_buffer, NULL, 0);
unsigned int glyph_count;
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(hb_buffer, &glyph_count);
// Now, glyph_info contains an array of glyph indexes
for (unsigned int ii = 0; ii < glyph_count; ii++) {
char str[7];
// Get the glyph index from FreeType directly
FT_UInt glyph_index;// = FT_Get_Char_Index(face, glyph_info[ii].codepoint);
glyph_index = FT_Get_Char_Index(face, glyph_info[ii].codepoint);
sprintf(str, "%04X", glyph_index);
vContentStream->PutBlock((CBytePtr)/*"0037"*/str, 4);
}
Upvotes: 1
Views: 12