[docs] Don’t use FreeType in the simple example

Also make the code actually compile.

Fixes https://github.com/harfbuzz/harfbuzz/issues/2106
This commit is contained in:
Khaled Hosny 2020-12-27 00:22:31 +02:00 committed by Behdad Esfahbod
parent bfe4bbfc05
commit 4136ecf741
1 changed files with 18 additions and 13 deletions

View File

@ -216,6 +216,7 @@
</orderedlist> </orderedlist>
<programlisting language="C"> <programlisting language="C">
#include &lt;hb.h&gt; #include &lt;hb.h&gt;
hb_buffer_t *buf; hb_buffer_t *buf;
buf = hb_buffer_create(); buf = hb_buffer_create();
hb_buffer_add_utf8(buf, text, -1, 0, -1); hb_buffer_add_utf8(buf, text, -1, 0, -1);
@ -235,15 +236,14 @@
<orderedlist numeration="arabic"> <orderedlist numeration="arabic">
<listitem override="3"> <listitem override="3">
<para> <para>
Create a face and a font, using FreeType for now. Create a face and a font from a font file.
</para> </para>
</listitem> </listitem>
</orderedlist> </orderedlist>
<programlisting language="C"> <programlisting language="C">
#include &lt;hb-ft.h&gt; hb_blob_t *blob = hb_blob_create_from_file(filename);
FT_New_Face(ft_library, font_path, index, &amp;face); hb_face_t *face = hb_face_create(blob, 0);
FT_Set_Char_Size(face, 0, 1000, 0, 0); hb_font_t *font = hb_font_create(face);
hb_font_t *font = hb_ft_font_create(face);
</programlisting> </programlisting>
<orderedlist numeration="arabic"> <orderedlist numeration="arabic">
<listitem override="4"> <listitem override="4">
@ -263,6 +263,7 @@
</listitem> </listitem>
</orderedlist> </orderedlist>
<programlisting language="C"> <programlisting language="C">
unsigned int glyph_count;
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &amp;glyph_count); hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &amp;glyph_count);
hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &amp;glyph_count); hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &amp;glyph_count);
</programlisting> </programlisting>
@ -274,13 +275,15 @@
</listitem> </listitem>
</orderedlist> </orderedlist>
<programlisting language="C"> <programlisting language="C">
for (i = 0; i &lt; glyph_count; ++i) { hb_position_t cursor_x = 0;
glyphid = glyph_info[i].codepoint; hb_position_t cursor_y = 0;
x_offset = glyph_pos[i].x_offset / 64.0; for (unsigned int i = 0; i &lt; glyph_count; i++) {
y_offset = glyph_pos[i].y_offset / 64.0; hb_codepoint_t glyphid = glyph_info[i].codepoint;
x_advance = glyph_pos[i].x_advance / 64.0; hb_position_t x_offset = glyph_pos[i].x_offset;
y_advance = glyph_pos[i].y_advance / 64.0; hb_position_t y_offset = glyph_pos[i].y_offset;
draw_glyph(glyphid, cursor_x + x_offset, cursor_y + 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_x += x_advance;
cursor_y += y_advance; cursor_y += y_advance;
} }
@ -294,7 +297,9 @@
</orderedlist> </orderedlist>
<programlisting language="C"> <programlisting language="C">
hb_buffer_destroy(buf); hb_buffer_destroy(buf);
hb_font_destroy(hb_ft_font); hb_font_destroy(font);
hb_face_destroy(face);
hb_blob_destroy(blob);
</programlisting> </programlisting>
<para> <para>