[HarfBuzz] harfbuzz documentation

Werner LEMBERG wl at gnu.org
Sun Jun 24 14:51:35 PDT 2012


>> Yes, here's a much simpler thing:
>> 
>>   https://github.com/anoek/ex-sdl-cairo-freetype-harfbuzz
> 
> Nice, thanks!

I had to patch the package with the attached diff (which also contains
some beautifications).  Could someone tell me whether the changes are
correct?  The output looks identical, but...


    Werner


======================================================================


diff --git a/Makefile b/Makefile
index 77ef439..6dc1ca9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,21 @@
-CC=gcc
-CFLAGS=--std=c99 -g -Wall --pedantic `freetype-config --cflags`
-LDFLAGS=`icu-config --ldflags`
-LIBS=-lcairo -lSDL -lharfbuzz `freetype-config --libs`
+CC = gcc
+CFLAGS = \
+  --std=c99 \
+  -g \
+  -Wall \
+  --pedantic \
+  `pkg-config freetype2 --cflags` \
+  `pkg-config glib-2.0 --cflags` \
+  `pkg-config harfbuzz --cflags` \
+  `pkg-config cairo-ft --cflags` \
+  `pkg-config SDL_image --cflags`
+LDFLAGS = `icu-config --ldflags`
+LIBS= \
+  `pkg-config freetype2 --libs` \
+  `pkg-config harfbuzz --libs` \
+  `pkg-config glib-2.0 --libs` \
+  `pkg-config cairo-ft --libs` \
+  `pkg-config SDL_image --libs`
 
 all: ex-sdl-cairo-freetype-harfbuzz
 
diff --git a/ex-sdl-cairo-freetype-harfbuzz.c b/ex-sdl-cairo-freetype-harfbuzz.c
index eadbef0..bfdb1b7 100644
--- a/ex-sdl-cairo-freetype-harfbuzz.c
+++ b/ex-sdl-cairo-freetype-harfbuzz.c
@@ -2,22 +2,21 @@
 #include <stdio.h>
 #include <assert.h>
 
-#include <SDL/SDL.h>
-#include <SDL/SDL_image.h>
+#include <SDL.h>
+#include <SDL_image.h>
 
 #include <ft2build.h>
 #include FT_FREETYPE_H
-#include <freetype/ftadvanc.h>
-#include <freetype/ftsnames.h>
-#include <freetype/tttables.h>
+#include FT_ADVANCES_H
+#include FT_SFNT_NAMES_H
+#include FT_TRUETYPE_TABLES_H
 
-#include <harfbuzz/hb.h>
-#include <harfbuzz/hb-ft.h>
-#include <harfbuzz/hb-buffer.h>
-#include <harfbuzz/hb-icu.h> /* Alternatively you can use hb-glib.h */
+#include <hb.h>
+#include <hb-ft.h>
+#include <hb-glib.h>
 
-#include <cairo/cairo.h>
-#include <cairo/cairo-ft.h>
+#include <cairo.h>
+#include <cairo-ft.h>
 
 const char *texts[3] = {
     "This is some english text",
@@ -144,23 +143,22 @@ int main () {
         for (int i=0; i < 3; ++i) {
             x = 0;
             /* Create a buffer for harfbuzz to use */
-            hb_buffer_t *buf = hb_buffer_create(0);
+            hb_buffer_t *buf = hb_buffer_create();
 
-            //alternatively you can use hb_buffer_set_unicode_funcs(buf, hb_glib_get_unicode_funcs());
-            hb_buffer_set_unicode_funcs(buf, hb_icu_get_unicode_funcs());
+            hb_buffer_set_unicode_funcs(buf, hb_glib_get_unicode_funcs());
             hb_buffer_set_direction(buf, text_directions[i]); /* or LTR */
             hb_buffer_set_script(buf, scripts[i]); /* see hb-unicode.h */
-            hb_buffer_set_language(buf, hb_language_from_string(languages[i]));
+            hb_buffer_set_language(buf, hb_language_from_string(languages[i], 2));
 
             /* Layout the text */
             hb_buffer_add_utf8(buf, texts[i], strlen(texts[i]), 0, strlen(texts[i]));
-            hb_shape(hb_ft_font[i], hb_ft_face[i], buf, NULL, 0);
+            hb_shape(hb_ft_font[i], buf, NULL, 0);
 
 
             /* Hand the layout to cairo to render */
-            int                  glyph_count  = hb_buffer_get_length(buf);
-            hb_glyph_info_t     *glyph_info   = hb_buffer_get_glyph_infos(buf);
-            hb_glyph_position_t *glyph_pos    = hb_buffer_get_glyph_positions(buf);
+            unsigned int         glyph_count  = hb_buffer_get_length(buf);
+            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);
             cairo_glyph_t       *cairo_glyphs = malloc(sizeof(cairo_glyph_t) * glyph_count);
             for (int i=0; i < glyph_count; ++i) {
                 cairo_glyphs[i].index = glyph_info[i].codepoint;



More information about the HarfBuzz mailing list