android - 如何从Windows Phone中获取字体文件

标签 android windows-phone-8 fonts xamarin.forms

我正在 Xamarin 平台中创建库,我需要获取设备(android、iOS 和 windows)字体文件。 在 android 中,我可以从 /system/fonts 文件夹中获取字体文件。

安卓:

string[] fontfiles = System.IO.Directory.GetFiles("/system/fonts");

谁能分享您从 Windows 设备获取字体文件的想法?

提前致谢。

萨西。

最佳答案

How to get font file from windows phone

Windows Phone 无法获取系统字体文件,但可以获取系统字体。引用ptallett's blog , 请执行以下步骤:

  1. 为了在 UWP 中获取系统字体,我们必须使用 DirectX,将这些 NuGet 包安装到您的项目中:

    • SharpDX
    • SharpDX.Direct2D1
  2. GetFontFiles() 将返回所有系统字体。

    public class GetFont : FontDemo.IGetFont
    {
        public string[] GetFontFiles()
        {
            var fontList = new List<string>();
            var factory = new SharpDX.DirectWrite.Factory();
            var fontCollection = factory.GetSystemFontCollection(false);
            var familyCount = fontCollection.FontFamilyCount;
    
            for (int i = 0; i < familyCount; i++)
            {
                var fontFamily = fontCollection.GetFontFamily(i);
                var familyNames = fontFamily.FamilyNames;
                int index;
    
                if (!familyNames.FindLocaleName(CultureInfo.CurrentCulture.Name, out index))
                {
                    if (!familyNames.FindLocaleName("en-us", out index))
                    {
                        index = 0;
                    }
                }
                string name = familyNames.GetString(index);
                fontList.Add(name);
            }
            return fontList.ToArray();
        }
    }
    
  3. 使用 DependencyService在您的 PCL 中获取结果:

    string[] fontfiles = DependencyService.Get<IGetFont>().GetFontFiles();
    

关于android - 如何从Windows Phone中获取字体文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47897933/

相关文章:

c# - Windows Phone 8.1 中后台任务显示对话框的问题

c# - 我们可以在 Windows Phone 8 的应用程序中以编程方式获取已安装应用程序的列表吗?

PDF 低级 : Text Rendering

html - 更改 Bootstrap 中下拉菜单的字体样式?

java - PrintedPdfDocument bmp 转 pdf

java - Whatsapp 如何快速检测到我使用同一应用程序新添加的号码?

xna - Windows Phone 8 SDK 博客公告和 XNA 混淆

php - tFPDF 添加多种 DejaVu 字体

android - 将 Google 表格自动化为 strings.xml 以进行本地化

java - Android 字符串 utf-8 在布局中有效,但在 java 代码中无效