From 4136ecf74149c533f9a31e039d67e9a234e1f9ce Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 27 Dec 2020 00:22:31 +0200 Subject: [PATCH] =?UTF-8?q?[docs]=20Don=E2=80=99t=20use=20FreeType=20in=20?= =?UTF-8?q?the=20simple=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also make the code actually compile. Fixes https://github.com/harfbuzz/harfbuzz/issues/2106 --- docs/usermanual-getting-started.xml | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/docs/usermanual-getting-started.xml b/docs/usermanual-getting-started.xml index 1f26df8d8..b3bdb3488 100644 --- a/docs/usermanual-getting-started.xml +++ b/docs/usermanual-getting-started.xml @@ -216,6 +216,7 @@ #include <hb.h> + hb_buffer_t *buf; buf = hb_buffer_create(); hb_buffer_add_utf8(buf, text, -1, 0, -1); @@ -235,15 +236,14 @@ - Create a face and a font, using FreeType for now. + Create a face and a font from a font file. - #include <hb-ft.h> - FT_New_Face(ft_library, font_path, index, &face); - FT_Set_Char_Size(face, 0, 1000, 0, 0); - hb_font_t *font = hb_ft_font_create(face); + hb_blob_t *blob = hb_blob_create_from_file(filename); + hb_face_t *face = hb_face_create(blob, 0); + hb_font_t *font = hb_font_create(face); @@ -263,6 +263,7 @@ + unsigned int glyph_count; hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count); hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count); @@ -274,13 +275,15 @@ - for (i = 0; i < glyph_count; ++i) { - glyphid = glyph_info[i].codepoint; - x_offset = glyph_pos[i].x_offset / 64.0; - y_offset = glyph_pos[i].y_offset / 64.0; - x_advance = glyph_pos[i].x_advance / 64.0; - y_advance = glyph_pos[i].y_advance / 64.0; - draw_glyph(glyphid, cursor_x + x_offset, cursor_y + y_offset); + hb_position_t cursor_x = 0; + hb_position_t cursor_y = 0; + for (unsigned int i = 0; i < glyph_count; i++) { + hb_codepoint_t glyphid = glyph_info[i].codepoint; + hb_position_t x_offset = glyph_pos[i].x_offset; + hb_position_t y_offset = glyph_pos[i].y_offset; + hb_position_t x_advance = glyph_pos[i].x_advance; + hb_position_t y_advance = glyph_pos[i].y_advance; + /* draw_glyph(glyphid, cursor_x + x_offset, cursor_y + y_offset); */ cursor_x += x_advance; cursor_y += y_advance; } @@ -294,7 +297,9 @@ hb_buffer_destroy(buf); - hb_font_destroy(hb_ft_font); + hb_font_destroy(font); + hb_face_destroy(face); + hb_blob_destroy(blob);