/
EmbeddedFontLoader.cs
41 lines (37 loc) · 1.02 KB
/
EmbeddedFontLoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.IO;
using ElmSharp;
using TApplication = Tizen.Applications.Application;
namespace Xamarin.Forms.Platform.Tizen
{
public class EmbeddedFontLoader : IEmbeddedFontLoader, IRegisterable
{
const string _fontCacheFolderName = "fonts";
public DirectoryInfo FontCacheDirectory { get; private set; }
public EmbeddedFontLoader()
{
FontCacheDirectory = Directory.CreateDirectory(Path.Combine(TApplication.Current.DirectoryInfo.Data, _fontCacheFolderName));
Utility.AppendGlobalFontPath(FontCacheDirectory.FullName);
}
public (bool success, string filePath) LoadFont(EmbeddedFont font)
{
var filePath = Path.Combine(FontCacheDirectory.FullName, font.FontName);
if (File.Exists(filePath))
return (true, filePath);
try
{
using (var fileStream = File.Create(filePath))
{
font.ResourceStream.CopyTo(fileStream);
}
return (true, filePath);
}
catch (Exception ex)
{
Log.Error(ex.Message);
File.Delete(filePath);
}
return (false, null);
}
}
}