From: Jean-Philippe Bruyère Date: Tue, 1 Mar 2022 14:48:46 +0000 (+0100) Subject: remove strlen from _font_cache_create_text_run X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=311d063ec511bc1cc0fc719d0fe08a6b0685b53c;p=jp%2Fvkvg.git remove strlen from _font_cache_create_text_run --- diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c index 43a401d..f887005 100644 --- a/src/vkvg_fonts.c +++ b/src/vkvg_fonts.c @@ -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; iglyph_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; iglyph_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) diff --git a/tests/common/test.c b/tests/common/test.c index f5f1b08..c60e2c7 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -1,5 +1,6 @@ #include "test.h" -#include "string.h" +#include +#include #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);