}
free (f->sizes);
free(f->fontFile);
- for (uint32_t j = 0; j < f->fcNamesCount; j++)
- free (f->fcNames[j]);
- if (f->fcNamesCount > 0)
- free (f->fcNames);
+ for (uint32_t j = 0; j < f->namesCount; j++)
+ free (f->names[j]);
+ if (f->namesCount > 0)
+ free (f->names);
}
free(cache->fonts);
dev->fontCache->stagingX += bmpWidth;
return cr;
}
-void _select_font_path (VkvgContext ctx, const char* fontFile){
- ctx->currentFont = NULL;
+void _font_add_name (_vkvg_font_identity_t* font, const char* name, int nameLength) {
+ if (++font->namesCount == 1)
+ font->names = (char**) malloc (sizeof(char*));
+ else
+ font->names = (char**) realloc (font->names, font->namesCount * sizeof(char*));
+
+ font->names[font->namesCount-1] = (char*)calloc(nameLength, sizeof (char));
+ strcpy (font->names[font->namesCount-1], name);
+}
+void _add_new_font_identity (VkvgContext ctx, const char* fontFile, const char* name){
+ _font_cache_t* cache = (_font_cache_t*)ctx->pSurf->dev->fontCache;
+ if (++cache->fontsCount == 1)
+ cache->fonts = (_vkvg_font_identity_t*) malloc (cache->fontsCount * sizeof(_vkvg_font_identity_t));
+ else
+ cache->fonts = (_vkvg_font_identity_t*) realloc (cache->fonts, cache->fontsCount * sizeof(_vkvg_font_identity_t));
+ _vkvg_font_identity_t nf = {0};
+
+ int fflength = strlen (fontFile) + 1;
+ nf.fontFile = (char*)malloc (fflength * sizeof(char));
+ strcpy (nf.fontFile, fontFile);
+ _font_add_name (&nf, name, fflength);
+
+ cache->fonts[cache->fontsCount-1] = nf;
}
//select current font for context
void _select_font_face (VkvgContext ctx, const char* name){
ctx->currentFont = NULL;
ctx->currentFontSize = NULL;
}
-void _font_add_fc_name (_vkvg_font_identity_t* font, const char* fcname, int nameLength) {
- if (++font->fcNamesCount == 1)
- font->fcNames = (char**) malloc (sizeof(char*));
- else
- font->fcNames = (char**) realloc (font->fcNames, font->fcNamesCount * sizeof(char*));
-
- font->fcNames[font->fcNamesCount-1] = (char*)calloc(nameLength, sizeof (char));
- strcpy (font->fcNames[font->fcNamesCount-1], fcname);
-}
_vkvg_font_t* _find_or_create_font_size (VkvgContext ctx, _vkvg_font_identity_t* font, FT_F26Dot6 charSize) {
for (uint32_t i = 0; i < font->sizeCount; ++i) {
if (font->sizes[i].charSize == charSize)
font->sizes = (_vkvg_font_t*) realloc (font->sizes, font->sizeCount * sizeof(_vkvg_font_t));
_vkvg_font_t newSize = {.charSize = charSize};
- FT_CHECK_RESULT(FT_New_Face(cache->library, font->fontFile, 0, &newSize.face));
+ FT_CHECK_RESULT(FT_New_Face (cache->library, font->fontFile, 0, &newSize.face));
FT_CHECK_RESULT(FT_Set_Char_Size(newSize.face, 0, newSize.charSize, dev->hdpi, dev->vdpi ));
#ifdef VKVG_USE_HARFBUZZ
_vkvg_font_identity_t* _tryFindFontByName (VkvgContext ctx){
_font_cache_t* cache = (_font_cache_t*)ctx->pSurf->dev->fontCache;
for (int i = 0; i < cache->fontsCount; ++i) {
- for (uint32_t j = 0; j < cache->fonts[i].fcNamesCount; j++) {
- if (strcmp (cache->fonts[i].fcNames[j], ctx->selectedFontName) == 0)
+ for (uint32_t j = 0; j < cache->fonts[i].namesCount; j++) {
+ if (strcmp (cache->fonts[i].names[j], ctx->selectedFontName) == 0)
return &cache->fonts[i];
}
}
for (int i = 0; i < cache->fontsCount; ++i) {
if (strcmp (cache->fonts[i].fontFile, fontFile) == 0) {
int fflength = strlen(fontFile) + 1;
- _font_add_fc_name (&cache->fonts[i], ctx->selectedFontName, fflength);
+ _font_add_name (&cache->fonts[i], ctx->selectedFontName, fflength);
resolvedFont = &cache->fonts[i];
break;;
}
}
if (!resolvedFont) {
//if not found, create a new vkvg_font
- cache->fontsCount++;
-
- if (cache->fontsCount == 1)
- cache->fonts = (_vkvg_font_identity_t*) malloc (cache->fontsCount * sizeof(_vkvg_font_identity_t));
- else
- cache->fonts = (_vkvg_font_identity_t*) realloc (cache->fonts, cache->fontsCount * sizeof(_vkvg_font_identity_t));
-
- _vkvg_font_identity_t nf = {0};
-
- int fflength = strlen(fontFile) + 1;
- nf.fontFile = (char*)malloc (fflength * sizeof(char));
- strcpy (nf.fontFile, fontFile);
- _font_add_fc_name (&nf, ctx->selectedFontName, fflength);
-
- cache->fonts[cache->fontsCount-1] = nf;
+ _add_new_font_identity(cache, fontFile, ctx->selectedFontName);
resolvedFont = &cache->fonts[cache->fontsCount-1];
}
}
if (ctx->selectedFontName[0] == 0)
_select_font_face (ctx, "sans");
- ctx->currentFont = _find_or_create_font (ctx);
- ctx->currentFontSize = _find_or_create_font_size (ctx, ctx->currentFont, ctx->selectedCharSize);
+ ctx->currentFont = _find_or_create_font (ctx);
+ ctx->currentFontSize = _find_or_create_font_size (ctx, ctx->currentFont, ctx->selectedCharSize);
}
}
#else
int textByteLength = strlen (text);
if (textByteLength > 0) {
+ setlocale(LC_ALL, "");
size_t wsize = mbstowcs(NULL, text, 0);
wchar_t *tmp = (wchar_t*)malloc((wsize+1) * sizeof (wchar_t));
textRun->glyph_count = mbstowcs (tmp, text, wsize);
/* Font identification structure */
typedef struct {
- char** fcNames; /* Resolved Input names to this font by fontConfig */
- uint32_t fcNamesCount; /* Count of resolved names by fontConfig */
- char* fontFile; /* Font file full path*/
- uint32_t sizeCount; /* available font size loaded */
- _vkvg_font_t* sizes; /* loaded font size array */
+ char** names; /* Resolved Input names to this font by fontConfig */
+ uint32_t namesCount; /* Count of resolved names by fontConfig */
+ char* fontFile; /* Font file full path*/
+ uint32_t sizeCount; /* available font size loaded */
+ _vkvg_font_t* sizes; /* loaded font size array */
}_vkvg_font_identity_t;
// Font cache global structure, entry point for all font related operations.
void _destroy_font_cache (VkvgDevice dev);
//Select current font for context from font name, create new font entry in cache if required
void _select_font_face (VkvgContext ctx, const char* name);
-void _select_font_path (VkvgContext ctx, const char* fontFile);
+void _add_new_font_identity (VkvgContext ctx, const char* fontFile, const char *name);
//Draw text
void _show_text (VkvgContext ctx, const char* text);
//Get text dimmensions
print_boxed (ctx, "ANOTHER ONE TO CHECK..", 50,80,20);
vkvg_destroy (ctx);
}
+void font_file_path () {
+ VkvgContext ctx = vkvg_create(surf);
+
+ vkvg_set_source_rgb (ctx, 0, 0, 0);
+ vkvg_paint (ctx);
+ vkvg_set_source_rgb (ctx, 1, 1, 1);
+ vkvg_load_font_from_path (ctx, "data/DancingScript-Regular.ttf", "droid");
+ print_boxed (ctx, "This is a test string!", 50,20,12);
+ print_boxed (ctx, "This is a test string!", 50,50,20);
+ print_boxed (ctx, "ANOTHER ONE TO CHECK..", 50,80,20);
+ print_boxed (ctx, "this is another string to check if ligature are well set", 10,120,20);
+ vkvg_destroy (ctx);
+}
+
void random_size () {
VkvgContext ctx = vkvg_create(surf);
vkvg_clear(ctx);
no_test_size = true;
//vkvg_log_level = VKVG_LOG_INFO;
PERFORM_TEST (simple_text, argc, argv);
+ PERFORM_TEST (font_file_path, argc, argv);
PERFORM_TEST (single_font_and_size, argc, argv);
PERFORM_TEST (random_size, argc, argv);
PERFORM_TEST (random_font_and_size, argc, argv);