[HarfBuzz] I got hb/ft working but I don't know how
Eduardo Castineyra
eduardo at brainstorm.es
Tue Oct 1 08:00:44 PDT 2013
Hi,
I just coded my first working Windows example with harfbuzz (code
attached). I got my first thai characters to be shaped into glyphs (at
least I got the same output as hb-shape). But I don't really feel like I
understood anything:
1) What is a blob and how come I didn't need to know what it is?
2) I created a hb_ft_font and passed it to the shaper but, shouldn't I
also call hb_ft_font_set_funcs in order to use hb-ft as font instance?
3) How does harfbuzz manage to get the GSUB/GPOS tables of the fonts if
everything I provided was a FT_Face? I don't see anything related to
those tables in hb-ft, and AFAIK FT2 does not provide tools to extract
those tables. Is it opening the font file by itself?
4) What is get_ft_library for? Should I be calling it instead of
FT_Init_FreeType?
Thanks!
-------------- next part --------------
#include <string.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <hb.h>
#include <assert.h>
#include <hb-ft.h>
#define MAX_CHARS 2048
int loadUcsFile(char* filename, uint16_t* buf){
FILE* fp;
fp = fopen (filename, "r");
int count = fread(buf, sizeof(uint16_t), MAX_CHARS, fp);
buf[count] = (uint16_t)0;
fclose(fp);
return count;
}
void loadFTFace(char* filename, FT_Face& ft_face){
FT_Library ft_library;
assert(!FT_Init_FreeType(&ft_library));
/* Load our fonts */
assert(!FT_New_Face(ft_library, "C:/Windows/fonts/leelawad.ttf", 0, &ft_face));
assert(!FT_Set_Char_Size(ft_face, 0, 50*64, 72, 72 ));
FT_Set_Charmap(ft_face, 0);
//FT_Done_FreeType(ft_library);
}
void printGlyphs(hb_glyph_info_t *glyph_info,
hb_glyph_position_t *glyph_pos,
unsigned int glyph_count){
for (int i = 0; i < glyph_count; i++){
printf("[%4x] Adv(%4d, %4d) Ofs(%4d, %4d)\n", glyph_info[i].codepoint,
glyph_pos[i].x_advance,
glyph_pos[i].y_advance,
glyph_pos[i].x_offset,
glyph_pos[i].y_offset);
}
}
int main (int argc, char **argv){
uint16_t buf[MAX_CHARS];
int count = loadUcsFile("line.txt", buf);
FT_Face ft_face;
hb_font_t *hb_ft_font;
loadFTFace("C:/Windows/fonts/leelawad.ttf", ft_face);
hb_ft_font = hb_ft_font_create(ft_face, NULL);
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
hb_buffer_set_script(buffer, HB_SCRIPT_THAI);
hb_buffer_set_language(buffer, hb_language_from_string("th", strlen("th"))); // see hb-ot-tag.cc
// hb_buffer_guess_segment_properties(buffer);
hb_buffer_add_utf16(buffer, buf, count, 0, count);
hb_shape(hb_ft_font, buffer, NULL, 0);
unsigned int glyph_count;
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buffer, &glyph_count);
hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buffer, &glyph_count);
printGlyphs(glyph_info, glyph_pos, glyph_count);
hb_buffer_destroy (buffer);
}
More information about the HarfBuzz
mailing list