[HarfBuzz] Simplifying the hb-shape.cc example
Behdad Esfahbod
behdad at behdad.org
Thu Jan 5 14:07:39 PST 2012
On 01/05/2012 04:44 PM, Nicolas Rougier wrote:
>
> Hi,
>
> I've been trying to simplify the hb-shape.c example from the util directory in order to remove any glib dependencies and come up with source below ( ~50 lines) but it does not seem to work (no ligature for fi):
>
> $ hb-shape DejaVuSans.ttf "fi"
> <fi=0+1290>
>
> $ main DejaVuSans.ttf "fi"
> <f=0+721|i=2+569>
>
>
> Did I do something wrong ?
The code looks fine. I'm out of ideas. Can you recompile harfbuzz with glib
and test the same code?
behdad
>
> Nicolas
>
>
> main.cc
> ======
>
> #include <stdio.h>
> #include <ft2build.h>
> #include FT_FREETYPE_H
> #include "hb-ft.h"
>
> int main( int argc, char **argv )
> {
> const char *text = "fi";
> char glyph_name[30];
> size_t i;
>
> FT_Library library;
> FT_Face face;
> FT_Init_FreeType( &library );
> FT_New_Face( library, "./DejaVuSans.ttf", 0, &face );
> FT_Set_Char_Size( face, (int)(32*64), 0, 72, 72 );
>
> hb_font_t * font = hb_ft_font_create( face, 0 );
> hb_ft_font_set_funcs( font );
>
> hb_buffer_t * buffer = hb_buffer_create( );
> hb_buffer_set_direction( buffer, HB_DIRECTION_LTR );
> hb_buffer_add_utf8( buffer, text, strlen(text), 0, strlen(text) );
> hb_shape( font, buffer, NULL, 0 );
> unsigned int num_glyphs = hb_buffer_get_length (buffer);
> hb_glyph_info_t* glyphs = hb_buffer_get_glyph_infos( buffer, 0 );
> hb_glyph_position_t *pos = hb_buffer_get_glyph_positions( buffer, 0 );
> hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL);
>
> for( i=0; i<num_glyphs; ++i )
> {
> if( i ) printf( "|" );
> else printf( "<" );
> if (!FT_Get_Glyph_Name( face, glyphs[i].codepoint, glyph_name, sizeof (glyph_name) ))
> printf( "%s", glyph_name );
> else
> printf( "%u", info->codepoint );
> printf( "=%u", info->cluster );
> if (pos->x_offset || pos->y_offset) {
> printf("@");
> if (pos->x_offset) printf ("%d", pos->x_offset);
> if (pos->y_offset) printf (",%d", pos->y_offset);
> }
> if (pos->x_advance || pos->y_advance) {
> printf ("+");
> if (pos->x_advance) printf ("%d", pos->x_advance);
> if (pos->y_advance) printf (",%d", pos->y_advance);
> }
> ++pos; ++info;
> }
> printf( ">\n" );
>
> hb_font_destroy(font);
> FT_Done_Face( face );
> FT_Done_FreeType( library );
> }
>
>
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
More information about the HarfBuzz
mailing list