[HarfBuzz] An example, another variation of anoek/ex-sdl-cairo-freetype-harfbuzz

Werner LEMBERG wl at gnu.org
Fri Jan 4 22:22:16 PST 2013


> Here:
> 
> https://github.com/lxnt/ex-sdl-freetype-harfbuzz
> 
> Is a variant that does not depend on Cairo, glib or ICU.

Very nice!

> The origin at
> https://github.com/anoek/ex-sdl-cairo-freetype-harfbuzz has a nasty
> bug in that it tries to set font point size with a double instead of
> Freetype's 26.6 fixed point. With Cairo it works because Cairo
> itself resets the point size at first frame drawn.  When one
> disables Cairo, well, it takes some head-scratching.

:-)

Below is a patch for ex-sdl-cairo-freetype-harfbuzz (including the
point size fix) which makes the compilation more standard, so to say.


    Werner


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


diff --git a/Makefile b/Makefile
index 2b2ea26..8be656e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,18 @@
-CC=gcc
-CFLAGS=--std=c99 -g -O2 -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 harfbuzz --cflags` \
+  `pkg-config cairo --cflags` \
+  `pkg-config sdl --cflags`
+LIBS= \
+  `pkg-config freetype2 --libs` \
+  `pkg-config harfbuzz --libs` \
+  `pkg-config cairo --libs` \
+  `pkg-config sdl --libs`
 
 all: ex-sdl-cairo-freetype-harfbuzz
 
diff --git a/ex-sdl-cairo-freetype-harfbuzz.c b/ex-sdl-cairo-freetype-harfbuzz.c
index fbb3a3a..d334371 100644
--- a/ex-sdl-cairo-freetype-harfbuzz.c
+++ b/ex-sdl-cairo-freetype-harfbuzz.c
@@ -2,21 +2,20 @@
 #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-icu.h> /* Alternatively you can use hb-glib.h */
+#include <hb.h>
+#include <hb-ft.h>
 
-#include <cairo/cairo.h>
-#include <cairo/cairo-ft.h>
+#include <cairo.h>
+#include <cairo-ft.h>
 
 #define NUM_EXAMPLES 3
 
@@ -63,12 +62,11 @@ int main () {
     /* Load our fonts */
     FT_Face ft_face[NUM_EXAMPLES];
     assert(!FT_New_Face(ft_library, "fonts/DejaVuSerif.ttf", 0, &ft_face[ENGLISH]));
-    assert(!FT_Set_Char_Size(ft_face[ENGLISH], 0, ptSize, device_hdpi, device_vdpi ));
-    //assert(!FT_New_Face(ft_library, "fonts/lateef.ttf", 0, &ft_face[ARABIC]));
+    assert(!FT_Set_Char_Size(ft_face[ENGLISH], 0, ptSize * 64, device_hdpi, device_vdpi ));
     assert(!FT_New_Face(ft_library, "fonts/amiri-0.104/amiri-regular.ttf", 0, &ft_face[ARABIC]));
-    assert(!FT_Set_Char_Size(ft_face[ARABIC], 0, ptSize, device_hdpi, device_vdpi ));
+    assert(!FT_Set_Char_Size(ft_face[ARABIC], 0, ptSize * 64, device_hdpi, device_vdpi ));
     assert(!FT_New_Face(ft_library, "fonts/fireflysung-1.3.0/fireflysung.ttf", 0, &ft_face[CHINESE]));
-    assert(!FT_Set_Char_Size(ft_face[CHINESE], 0, ptSize, device_hdpi, device_vdpi ));
+    assert(!FT_Set_Char_Size(ft_face[CHINESE], 0, ptSize * 64, device_hdpi, device_vdpi ));
 
     /* Get our cairo font structs */
     cairo_font_face_t *cairo_ft_face[NUM_EXAMPLES];
@@ -147,8 +145,6 @@ int main () {
             /* Create a buffer for harfbuzz to use */
             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_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], strlen(languages[i])));



More information about the HarfBuzz mailing list