]> O.S.I.I.S - jp/vkvg.git/commitdiff
remove strlen from _font_cache_create_text_run
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 1 Mar 2022 14:48:46 +0000 (15:48 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 1 Mar 2022 14:48:46 +0000 (15:48 +0100)
src/vkvg_fonts.c
tests/common/test.c

index 43a401d8932bd2487316cd55d9d6d55f151d5602..f887005e9f0069c25a5a4afcc3ca49dc00216b4e 100644 (file)
@@ -603,6 +603,8 @@ void _font_cache_text_extents (VkvgContext ctx, const char* text, int length, vk
 
        _font_cache_destroy_text_run (&tr);
 }
+//text is expected as utf8 encoded
+//if length is < 0, text must be null terminated, else it contains glyph count
 void _font_cache_create_text_run (VkvgContext ctx, const char* text, int length, VkvgText textRun) {
 
        _update_current_font (ctx);
@@ -620,36 +622,33 @@ void _font_cache_create_text_run (VkvgContext ctx, const char* text, int length,
        textRun->hbBuf = _get_hb_buffer (ctx->currentFontSize, text,  length);
        textRun->glyphs = hb_buffer_get_glyph_positions  (textRun->hbBuf, &textRun->glyph_count);
 #else
-       int textByteLength = strlen (text);
-       if (textByteLength > 0) {
-               setlocale(LC_ALL, "");//TODO:move this elsewhere
-               size_t wsize;
-               if (length < 0)
-                       wsize = mbstowcs(NULL, text, 0);
-               else
-                       wsize = (size_t)length;
-               wchar_t *tmp = (wchar_t*)malloc((wsize+1) * sizeof (wchar_t));
-               textRun->glyph_count = mbstowcs (tmp, text, wsize);
-               textRun->glyphs = (vkvg_glyph_info_t*)malloc(textRun->glyph_count * sizeof (vkvg_glyph_info_t));
-               for (unsigned int i=0; i<textRun->glyph_count; i++) {
+
+       size_t wsize;
+       if (length < 0)
+               wsize = mbstowcs(NULL, text, 0);
+       else
+               wsize = (size_t)length;
+       wchar_t *tmp = (wchar_t*)malloc((wsize+1) * sizeof (wchar_t));
+       textRun->glyph_count = mbstowcs (tmp, text, wsize);
+       textRun->glyphs = (vkvg_glyph_info_t*)malloc(textRun->glyph_count * sizeof (vkvg_glyph_info_t));
+       for (unsigned int i=0; i<textRun->glyph_count; i++) {
 #ifdef VKVG_USE_FREETYPE
-                       uint32_t gindex = FT_Get_Char_Index (textRun->font->face, tmp[i]);
+               uint32_t gindex = FT_Get_Char_Index (textRun->font->face, tmp[i]);
 #else
-                       uint32_t gindex = stbtt_FindGlyphIndex (&textRun->fontId->stbInfo, tmp[i]);
+               uint32_t gindex = stbtt_FindGlyphIndex (&textRun->fontId->stbInfo, tmp[i]);
 #endif
-                       _char_ref* cr = textRun->font->charLookup[gindex];
-                       if (cr==NULL)
-                               cr = _prepare_char (textRun->dev, textRun, gindex);
-                       textRun->glyphs[i].codepoint = gindex;
-                       textRun->glyphs[i].x_advance = cr->advance.x;
-                       textRun->glyphs[i].y_advance = cr->advance.y;
-                       textRun->glyphs[i].x_offset      = 0;
-                       textRun->glyphs[i].y_offset      = 0;
-                       /*textRun->glyphs[i].x_offset    = cr->bmpDiff.x;
-                       textRun->glyphs[i].y_offset      = cr->bmpDiff.y;*/
-               }
-               free (tmp);
+               _char_ref* cr = textRun->font->charLookup[gindex];
+               if (cr==NULL)
+                       cr = _prepare_char (textRun->dev, textRun, gindex);
+               textRun->glyphs[i].codepoint = gindex;
+               textRun->glyphs[i].x_advance = cr->advance.x;
+               textRun->glyphs[i].y_advance = cr->advance.y;
+               textRun->glyphs[i].x_offset      = 0;
+               textRun->glyphs[i].y_offset      = 0;
+               /*textRun->glyphs[i].x_offset    = cr->bmpDiff.x;
+               textRun->glyphs[i].y_offset      = cr->bmpDiff.y;*/
        }
+       free (tmp);
 #endif
        
        UNLOCK_FONTCACHE (ctx->dev)
index f5f1b089fc1667e028d67aca842bf35c86cbee86..c60e2c7ffeb805cb28c78a55a467e0f1a3b671d5 100644 (file)
@@ -1,5 +1,6 @@
 #include "test.h"
-#include "string.h"
+#include <locale.h>
+#include <string.h>
 
 #if defined(_WIN32) || defined(_WIN64)
 int gettimeofday(struct timeval * tp, void * tzp)
@@ -405,6 +406,7 @@ void _print_debug_stats () {
 #endif
 
 void perform_test (void(*testfunc)(void), const char *testName, int argc, char* argv[]) {
+       setlocale(LC_ALL, "");
        //dumpLayerExts();
        _parse_args (argc, argv);