How to set the custom font
You can add the font path via Elmsharp.Utility.AppendGlobalFontPath.
The parameter path
must be a directory in which the fonts to be added are present.
If you use only ElmSharp, you should make get the following code.
using ElmSharp;
using Tizen.Applications;
namespace ElmSharpNewFont
{
class Program : CoreUIApplication
{
protected override void OnCreate()
{
var window = new Window("NewFontWindow");
Utility.AppendGlobalFontPath(Application.Current.DirectoryInfo.Resource);
var layout = new Box(window)
{
WeightX = NamedHint.Expand,
WeightY = NamedHint.Expand,
BackgroundColor = Color.Black
};
window.AddResizeObject(layout);
layout.Show();
var label = new Label(layout)
{
AlignmentX = 0.5,
AlignmentY = 0.5,
WeightX = NamedHint.Expand,
WeightY = NamedHint.Expand,
Text = "안녕하세요.",
TextStyle = "DEFAULT='font=YiSunShinBold font_size=39'",
};
label.Show();
layout.PackEnd(label);
}
static void Main(string[] args)
{
var app = new Program();
app.Run(args);
}
}
}
Application.Current.DirectoryInfo.Resource is application's resource directory in which the YiSunShin-Bold.ttf
font is located
In the Label.TextStyle
, font=
part should be font name
not font family
.
YiSunShinBold
is the font name
and font family
is YiSunShin Bold
,
but you can see that it is written as font name
.
Note
The font name
is actually postscript name
in your TTF or OTF file.
In some cases, a custom font can't be set with postscript name
.
If your custom font is not applied with postscript name
, please try to set font family name
Tip
You can find postscript name
and font family name
from the font file with fc-query
in the font config installed shell.fc-query -f "%{postscriptname}\n" Font.ttf
fc-query -f "%{family}\n" Font.ttf
Of course, it can also be used with Xamarin.Forms.
using ElmSharp;
using Tizen.Applications;
namespace XamarinFormsNewFont
{
class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
{
protected override void OnCreate()
{
base.OnCreate();
Utility.AppendGlobalFontPath(Application.Current.DirectoryInfo.Resource);
LoadApplication(new App());
}
static void Main(string[] args)
{
var app = new Program();
global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
Tizen.Wearable.CircularUI.Forms.Renderer.FormsCircularUI.Init();
app.Run(args);
}
}
}
using Xamarin.Forms;
namespace XamarinFormsNewFont
{
public class App : Application
{
public App()
{
MainPage = new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
HorizontalTextAlignment = TextAlignment.Center,
FontFamily = "YiSunShinBold",
Text = "Welcome to Xamarin Forms!"
}
}
}
};
}
}
}
Similarly, you can call Utility.AppendGlobalFontPath
before the Label
is used.
Tip
You can find YiSunShin
font from here