Example #1
0
        public (bool success, string filePath) LoadFont(EmbeddedFont font)
        {
            var tmpdir = Path.Combine(Path.GetTempPath(), System.Reflection.Assembly.GetEntryAssembly().GetName().Name, "Fonts");

            Directory.CreateDirectory(tmpdir);
            var filePath = Path.Combine(tmpdir, 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)
            {
                Debug.WriteLine(ex);
                File.Delete(filePath);
            }
            return(false, null);
        }
Example #2
0
        public (bool success, string filePath) LoadFont(EmbeddedFont font)
        {
            var filePath = IOPath.Combine(FontCacheDirectory.FullName, font.FontName);

            if (File.Exists(filePath))
            {
                return(true, filePath);
            }
            try
            {
                using (var fileStream = File.Create(filePath))
                {
                    font.ResourceStream.CopyTo(fileStream);
                }

                if (DotnetUtil.TizenAPIVersion > 5)
                {
                    FontExtensions.FontReinit();
                }

                return(true, filePath);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                File.Delete(filePath);
            }
            return(false, null);
        }
Example #3
0
 public (bool success, string filePath) LoadFont(EmbeddedFont font)
 {
     try
     {
         var data     = NSData.FromStream(font.ResourceStream);
         var provider = new CGDataProvider(data);
         var cGFont   = CGFont.CreateFromProvider(provider);
         var name     = cGFont.PostScriptName;
         if (CTFontManager.RegisterGraphicsFont(cGFont, out var error))
         {
             return(true, name);
         }
         else                 //Lets check if the font is already registered
         {
             var uiFont = NSFont.FromFontName(name, 10);
             if (uiFont != null)
             {
                 return(true, name);
             }
         }
         Debug.WriteLine(error.Description);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
     return(false, null);
 }
Example #4
0
        public (bool success, string filePath) LoadFont(EmbeddedFont font)
        {
            try
            {
                var data = NSData.FromStream(font.ResourceStream);

                var provider = new CGDataProvider(data);
                var cGFont   = CGFont.CreateFromProvider(provider);
                if (CTFontManager.RegisterGraphicsFont(cGFont, out var error))
                {
                    return(true, null);
                }
                Debug.WriteLine(error.Description);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(false, null);
        }
        public (bool success, string filePath) LoadFont(EmbeddedFont font)
        {
            try
            {
                var t      = ApplicationData.Current.LocalFolder.CreateFolderAsync(_fontCacheFolderName, CreationCollisionOption.OpenIfExists);
                var tmpdir = t.AsTask().Result;

                var    file     = tmpdir.TryGetItemAsync(font.FontName).AsTask().Result;
                string filePath = "";
                if (file != null)
                {
                    filePath = file.Path;
                    return(true, CleanseFilePath(filePath));
                }

                try
                {
                    var f = tmpdir.CreateFileAsync(font.FontName).AsTask().Result;
                    filePath = f.Path;
                    using (var fileStream = File.Open(f.Path, FileMode.Open))
                    {
                        font.ResourceStream.CopyTo(fileStream);
                    }
                    return(true, CleanseFilePath(filePath));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    File.Delete(filePath);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            return(false, null);
        }
        public (bool success, string filePath) LoadFont(EmbeddedFont font)
        {
            var tmpdir   = Path.GetTempPath();
            var filePath = Path.Combine(tmpdir, 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)
            {
                Debug.WriteLine(ex);
                File.Delete(filePath);
            }
            return(false, null);
        }
Example #7
0
 public string?LoadFont(EmbeddedFont font) => null;
Example #8
0
 public static EmbeddedFont FontName(this EmbeddedFont font, string name)
 {
     font.FontName = name;
     return(font);
 }
Example #9
0
 public static EmbeddedFont ResourceStream(this EmbeddedFont font, Stream resource)
 {
     font.ResourceStream = resource;
     return(font);
 }
 public (bool success, string?filePath) LoadFont(EmbeddedFont font) => (false, null);