[HarfBuzz] Simplifying the hb-shape.cc example

Deron Kazmaier deron at pagestream.org
Fri Jan 6 09:00:02 PST 2012


I've been where you are! I have a set of hb unicode functions I wrote up 
because I did not want to depend on glib or icu either for my test 
program. It is a handful of simple functions and a rather large file of 
data, and might not work for you, but if you want I am happy to send 
them to you (about 210k uncompressed). I also wrote a small (rather 
ugly) program that parses the unicode data files to generate the tables 
it uses.

Also, it is possible to get simple strings of right-to-left to work, if 
you use the functions to determine the primary script and direction of 
the run. No mixed rtl/ltr, but at least arabic/hebrew would work (It 
does for me at least). Others could probably help you tweak it to be 
more complete. (get_script and get_bidi are calls from my unicode 
functions above).


     run_script = HB_SCRIPT_UNKNOWN;
     run_direction = HB_DIRECTION_UNKNOWN;

Roughly for each character:

             if (run_script == HB_SCRIPT_UNKNOWN)
             {
                 script = get_script(character);
                 if ((script != HB_SCRIPT_COMMON) && (script != 
HB_SCRIPT_INHERITED) && (script != HB_SCRIPT_UNKNOWN)) run_script = script;
             }

             if (run_direction == HB_DIRECTION_UNKNOWN)
             {
                 direction = get_bidi(character);
                 if (direction == UNICODE_BIDI_STRONG_LTR) run_direction 
= HB_DIRECTION_LTR;
                 else if (direction == UNICODE_BIDI_STRONG_RTL) 
run_direction = HB_DIRECTION_RTL;
             }

and then

     if (run_direction != HB_DIRECTION_UNKNOWN) hb_buffer_set_direction 
(buffer, run_direction);
     if (run_script != HB_SCRIPT_UNKNOWN) hb_buffer_set_script (buffer, 
run_script);


Deron



On 1/6/12 3:33 AM, Nicolas Rougier wrote:
>
>
> Thanks for the explanation but now I'm a bit lost...
> I thought that harfbuzz could work alone for shaping but from what you 
> suggest (I need to try), I would need either glib or ICU, is that 
> right ? But if I have to depend on ICU, I could as well use it 
> directly for shaping and layout, no ?
>
>
> Nicolas
>
>
> On Jan 6, 2012, at 10:46 , Kenichi Ishibashi wrote:
>
>> I took a look at your code and noticed that you don't call 
>> hb_buffer_set_unicode_funcs(). Since both HAVE_GLIB and HAVE_ICU are 
>> not defined, _hb_unicode_funcs_nil is used as default. It won't work 
>> for many cases(including ligatures). You need to implement your 
>> custom hb_unicode_funcs_t or use existing 
>> functions(hb_{glib,icu}_unicode_funcs).
>>
>> I think using ICU is a handy way if you can depend on ICU. hb-icu.cc 
>> contains two 'gint' variables, but you can just remove 'g' from them 
>> (Someone already sent a patch, IIRC).
>>
>> Thanks,
>>
>> On Fri, Jan 6, 2012 at 5:09 PM, Nicolas Rougier 
>> <Nicolas.Rougier at inria.fr <mailto:Nicolas.Rougier at inria.fr>> wrote:
>>
>>
>>     Thanks, this was certainly an error but it did not fix the problem.
>>
>>     Nicolas
>>
>>
>>     On Jan 6, 2012, at 9:00 , Kenichi Ishibashi wrote:
>>
>>>     You may want to define "HAVE_OT" if you use your custom makefile
>>>     (see configure.ac <http://configure.ac/>).
>>>
>>>     On Fri, Jan 6, 2012 at 4:40 PM, Nicolas Rougier
>>>     <Nicolas.Rougier at inria.fr <mailto:Nicolas.Rougier at inria.fr>> wrote:
>>>
>>>
>>>         Thanks for the quick answer. I will try to investigate a bit
>>>         further to see if there are any errors.
>>>         If anyone on the list can test the code and report results,
>>>         that might be helpful as well.
>>>
>>>         I'm attaching the Makefile I used to compile (removed all
>>>         glib stuff, maybe this where the error is):
>>>
>>>         Nicolas
>>>
>>>         Makefile
>>>         ======
>>>
>>>         PLATFORM                = $(shell uname)
>>>         CC                              = g++
>>>         CFLAGS                  = -Wall `freetype-config --cflags`
>>>         LIBS                    = `freetype-config --libs`
>>>
>>>         SOURCES = main.cc \
>>>                hb-blob.cc hb-buffer.cc hb-common.cc
>>>         hb-fallback-shape.cc hb-font.cc  \
>>>            hb-ft.cc hb-ot-layout.cc hb-ot-map.cc
>>>         hb-ot-shape-complex-arabic.cc   \
>>>            hb-ot-shape-complex-indic.cc  hb-ot-shape-complex-misc.cc
>>>         hb-shape.cc \
>>>            hb-ot-shape-normalize.cc hb-ot-shape.cc hb-ot-tag.cc
>>>         hb-unicode.cc
>>>
>>>         HEADERS = \
>>>            hb-buffer-private.hh hb-fallback-shape-private.hh
>>>         hb-font-private.hh      \
>>>            hb-ot-shape-complex-arabic-table.hh
>>>         hb-ot-shape-complex-indic-table.hh    \
>>>            hb-ot-shape-complex-private.hh hb-mutex-private.hh
>>>         hb-object-private.hh   \
>>>            hb-open-file-private.hh hb-open-type-private.hh
>>>         hb-ot-head-table.hh       \
>>>            hb-ot-hhea-table.hh hb-ot-hmtx-table.hh
>>>         hb-ot-layout-common-private.hh    \
>>>            hb-ot-layout-gpos-table.hh hb-ot-layout-gsub-table.hh
>>>         hb-unicode.h        \
>>>                hb-ot-layout-gsubgpos-private.hh
>>>         hb-ot-layout-private.hh hb-shape.h       \
>>>                hb-ot-map-private.hh hb-ot-maxp-table.hh
>>>         hb-ot-name-table.hh hb-blob.h    \
>>>            hb-private.hh hb-unicode-private.hh hb.h hb-buffer.h
>>>         hb-version.h hb-ot.h \
>>>            hb-common.h hb-font.h hb-ft.h hb-ot-layout.h
>>>         hb-ot-shape.h hb-ot-tag.h
>>>
>>>         OBJECTS :=  $(SOURCES:.cc=.o)
>>>
>>>         all: main
>>>
>>>         main: $(OBJECTS)
>>>                $(CC) $(OBJECTS) $(LIBS) -o $@
>>>
>>>         %.o : %.cc
>>>                @echo "$@..."
>>>                @$(CC) -c $(CFLAGS) $< -o $@
>>>
>>>         clean:
>>>                @-rm -f glut-main
>>>                @-rm -f $(OBJECTS)
>>>
>>>         distclean: clean
>>>                @-rm -f *~
>>>
>>>
>>>
>>>         On Jan 5, 2012, at 23:07 , Behdad Esfahbod wrote:
>>>
>>>         > 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 );
>>>         >> }
>>>         >>
>>>

-- 
Happy Trails,
Deron Kazmaier   deron at dogstarkennel.com
KD0AYO	Western South Dakota
Dog Star Kennel http://www.dogstarkennel.com
--- Racing AKC Sepp-Star Seppala Siberian Husky Sled Dogs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/harfbuzz/attachments/20120106/82f90d51/attachment.html>


More information about the HarfBuzz mailing list