HI There.
I'd like to introduce how to use custom font file at native app , wearable profile, like gear S2 watch application.
Few days ago, I felt desperate since I could't find any answer about what I want to get.
NO documents, NO articles about how to use custom font at text widget including label.
But, Finally I can get a solution from my best friends, hwang and kim, I really thanks to them.
Here is the solution what you might look for.
There are 2 ways
If you want to apply custom font to evas_text,
1. copy font file to proper path in app path like a $APP_INSTALL_DIR\res\font\custom.ttf
2. set font file full path to evas_text
#define FONT "/opt/usr/apps/org.example.watchapplication/res/font/" Evas *e; e = evas_object_evas_get(ad->win); ad->text = evas_object_text_add(e); evas_object_text_font_set(ad->text, FONT"Organo.ttf", 20); evas_object_color_set(ad->text, 255, 255, 255, 255); evas_object_move(ad->text, 40, 220); evas_object_resize(ad->text, width, 200); evas_object_show(ad->text);
or,
If you use FontConfig, then load font file or directory at initial time. and use font family name
static bool app_create(int width, int height, void *data) { /* Hook to take necessary actions before main event loop starts Initialize UI resources and application's data If this function returns true, the main loop of application starts If this function returns false, the application is terminated */ appdata_s *ad = data; FcConfigAppFontAddFile(NULL, (const FcChar8 *) FONT"Organo.ttf"); create_base_gui(ad, width, height); //FcConfigAppFontAddDir(NULL, (const FcChar8 *)FONT); return true; }
evas_object_text_font_set(ad->text, "Organo", 20); // use font family name
If you want to apply custom font to evas_textblock, then you MUST load font file at initial time by FontConfig ( FcConfigAppFontAddFile or FcConfigAppFontAddDirs )
because, textblock does not support set font api.
and then, use font family name at textblock style
Evas *e; e = evas_object_evas_get(ad->win); Evas_Textblock_Style *st; ad->watch_text = evas_object_textblock_add(e); st = evas_textblock_style_new(); evas_textblock_style_set(st, "DEFAULT='font=Organo font_size=15 color=#252525 wrap=mixed'"); evas_object_textblock_style_set(ad->watch_text, st); evas_object_move(ad->watch_text, 100, 310); evas_object_resize(ad->watch_text, width, 200); evas_object_show(ad->watch_text); evas_textblock_style_free(st);
When I test it which use load custom font file by FontConfig API and apply font family name to mark up to elm_label,
It was not working , I don't know why.
If somebody knows how to apply custom font to elm_label , plz, give me a hint.
Thanks to All.
Hope you to enjoy Tizen.