Languages

Menu
Sites
Language
use custom font at native gear app

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. 

Edited by: hyogil kim on 05 Jan, 2016

Responses

7 Replies
Jeongsu Kim

You can use evas_font_path_global_append api.

Add directories that contains .ttf fonts using above api. Then you can custom fonts. Filename is uses as family name.

hyogil kim

Geart !! working now. Many Thanks !!! 

Dinal Jivani

Hello hyogil kim ,

how you get it worked ? can you please share a little code ,so that it can help other developer stuck in same issues.

pius lee

there are no api evas_font_path_global_append in tizen.

EFL have that but tizen don't have that.

I can't find evas_font_xxx functions in Any version of API document.

and also Document comment of Evas.h in SDK show it as internal functions.

why you suggest it? Tizen market don't block internal API??

Jeongsu Kim

1. I don't know when it is changed to internal api. But I just found it is not internal yet.

/**
 * @brief   Appends a font path to the list of font paths used by the application.
 * @since   1.9
 *
 * @if MOBILE @since_tizen 2.3
 * @elseif WEARABLE @since_tizen 2.3.1
 * @endif
 *
 * @param[in]   path  The new font path
 * @ingroup Evas_Font_Path_Group
 */
EAPI void                    evas_font_path_global_append(const char *path) EINA_ARG_NONNULL(1);

It is from the Evas.h in Tizen SDK 2.4 with wearable 2.3.1.

2. I think FcConfigAppFontAddFile or FcConfigAppFontAddDir is better because evas_font_path_global_append has a issue with font fallback.
 Evas can't show characters that is not in the font file.

3. But if you use font config api only, it will be broken when user change the font from the setting app. If user change the font, EFL will reinitialize the fontconfig internally and this clear user font or dir of fontconfig.
 So developer should run again when font changed detected using system settings api

4. So I think that api should be open to public. EFL should fix font fallback issue, too.

5. I posted this comment about 8 months ago. At that time, I didn't know the drawback of the api. I thought it is good enough because developer doesn't need to use fontconfig explictly.

I want to know why this api should not open to public?
Who decides this?
Why many features in EFL is not available in Tizen?
Then why Tizen uses EFL?
Why Tizen says that we use EFL?

If it is blocked by market, then why don't you request the market to open this api?

I don't know why Tizen limits the oppotunity of the developer.

Oleg Belousov

Hello!

I just can not get to work FcConfigAppFontAddFile(). This function returns "false". I have already tried different variants of the location of the file with the font - res/font, share/, share/font. Nothing helps!

I use Gear S3 (Tizen 2.3.1)

Shaswati Saha

I'm also trying to set custom font. As FcConfigAppFontAddFile() isn't working I was trying with evas_font_path_global_append(). Does the evas_font_path_global_append() function become deprecated?