[HarfBuzz] question about Mongolian text render

aron aronsoyol at gmail.com
Fri Nov 28 00:28:01 PST 2014


Hi
I use the latest version of HarfBuzz as a static library in VisualStudio,
The Mongolian string can't be rendered as I expected in my program
but rendered correctly in sh-view.exe. Could anyone tell me where is wrong
in my program.

I found that the vaule -- glyph_info[i].codepoint is less than real glyph
index, the difference is always 87 in my case.What is the correct way to
get glyph index?

​void HBDrawText(HDC dc, int x, int y)
{
const char * fontFilePath  = "./MongolianWhite.ttf";
const wchar_t * text   = L"ᠺᠣᠮᠫᠢᠦ᠋ᠲ᠋ᠧᠷ";//Mongolian string for render


FT_Library ft_library;
FT_Face ft_face;

FT_Init_FreeType(&ft_library); /* initialize library */
FT_New_Face(ft_library, fontFilePath, 0, &ft_face); /* create face object */
FT_Set_Pixel_Sizes(ft_face, 0, 40); /* set character size */

hb_font_t * font = hb_ft_font_create(ft_face, NULL);
hb_buffer_t * buffer= hb_buffer_create();;

//
//set buffer
//
hb_buffer_add_utf16(buffer, (uint16_t *)text, lstrlen(text), 0, -1);
hb_buffer_set_direction(buffer, HB_DIRECTION_TTB); /* or LTR */
hb_buffer_set_script(buffer, HB_SCRIPT_MONGOLIAN); /* see hb-unicode.h */
hb_buffer_guess_segment_properties(buffer);
//
//
//
hb_shape(font, buffer, NULL, 0);

int  glyph_count = hb_buffer_get_length(buffer);
hb_glyph_info_t * glyph_info = hb_buffer_get_glyph_infos(buffer, 0);

WCHAR dbg_info[6];
int pen_x = x;
int yBaseLine = y;
int glyphPosX = 0;
int glyphPosY = 0;

for (int i = 0; i < glyph_count; ++i)
{
FT_UInt glyph_index  = glyph_info[i].codepoint;
FT_Load_Glyph(ft_face, glyph_index, FT_LOAD_DEFAULT);
 wsprintf(dbg_info, L"%d,", glyph_index + 87);//*why + 87?*
OutputDebugString(dbg_info);

/* convert to an anti-aliased bitmap */
FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_NORMAL);

FreeTypeDrawBitmap(dc, &ft_face->glyph->bitmap, pen_x +
ft_face->glyph->bitmap_left,
yBaseLine - ft_face->glyph->bitmap_top);
pen_x += ft_face->glyph->advance.x >> 6;
}
hb_buffer_destroy(buffer);
hb_font_destroy(font);
FT_Done_Face(ft_face);
FT_Done_FreeType(ft_library);
}

this is the glyph index list generated by this program(incorrect).
769,660,566,487,675,490,705
hb-shape' s output(correct) is:
 [769|660|566|484|678|492|705]


-- 
Aron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/harfbuzz/attachments/20141128/5ceaf536/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QQ截图20141128154130.png
Type: image/png
Size: 26794 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/harfbuzz/attachments/20141128/5ceaf536/attachment-0001.png>


More information about the HarfBuzz mailing list