]> O.S.I.I.S - jp/vkvg.git/commitdiff
harfbuzz: detect script with unicode funcs testing first glyph
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 2 Mar 2022 09:08:23 +0000 (10:08 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 2 Mar 2022 09:08:23 +0000 (10:08 +0100)
src/vkvg_fonts.c

index f887005e9f0069c25a5a4afcc3ca49dc00216b4e..7370050f539858a91c84d7f09bfa03dcd11cee8b 100644 (file)
@@ -544,18 +544,20 @@ void _update_current_font (VkvgContext ctx) {
 hb_buffer_t * _get_hb_buffer (_vkvg_font_t* font, const char* text, int length) {
        hb_buffer_t *buf = hb_buffer_create();
 
-       const char *lng  = "fr";
        hb_script_t script = HB_SCRIPT_LATIN;
-       script = hb_script_from_string (text, length);
+       hb_unicode_funcs_t* ucfunc = hb_unicode_funcs_get_default ();
+       wchar_t firstChar = 0;
+       if (mbstowcs (&firstChar, text, 1))
+               script = hb_unicode_script (ucfunc, firstChar);
 
        hb_direction_t dir = hb_script_get_horizontal_direction(script);
-       //dir = HB_DIRECTION_TTB;
        hb_buffer_set_direction (buf, dir);
        hb_buffer_set_script    (buf, script);
-       hb_buffer_set_language  (buf, hb_language_from_string (lng, (int)strlen(lng)));
+       //hb_buffer_set_language        (buf, hb_language_from_string (lng, (int)strlen(lng)));
        hb_buffer_add_utf8              (buf, text, length, 0, length);
 
        hb_shape (font->hb_font, buf, NULL, 0);
+
        return buf;
 }
 #endif