Пример #1
0
    public void CanLoadFonts(string fontName, string assetName)
    {
        var fontWeight = FontWeight.Regular;
        var registrar  = new FontRegistrar(fontLoader: null);

        registrar.Register("dokdo_regular.ttf", "myalias");
        var manager  = new FontManager(registrar);
        var actual   = manager.GetTypeface(Font.OfSize(fontName, 12, fontWeight));
        var expected = Typeface.Create(Typeface.CreateFromAsset(Application.Context.Assets, assetName), (int)fontWeight, italic: false);

        Assert.True(expected.Equals(actual));
    }
Пример #2
0
    public void CanLoadEmbeddedFont()
    {
        var fontName   = "FooBarFont";
        var fontWeight = FontWeight.Regular;
        var registrar  = new FontRegistrar(new EmbeddedFontLoader());

        registrar.Register("dokdo_regular.ttf", fontName, GetType().Assembly);
        var manager     = new FontManager(registrar);
        var actual      = manager.GetTypeface(Font.OfSize(fontName, 12, fontWeight));
        var defaultFont = Typeface.Create(Typeface.Create(fontName, TypefaceStyle.Normal), (int)fontWeight, italic: false);

        Assert.False(defaultFont.Equals(actual));
    }
Пример #3
0
    public void CanLoadEmbeddedFont()
    {
        // skip on older androids for now
        // https://github.com/dotnet/maui/issues/5903
        if (!OperatingSystem.IsAndroidVersionAtLeast(28))
        {
            return;
        }

        var fontName   = "FooBarFont";
        var fontWeight = FontWeight.Regular;
        var fontStyle  = TypefaceStyle.Normal;
        var fontSlant  = false;

        var registrar = new FontRegistrar(new EmbeddedFontLoader());

        registrar.Register("dokdo_regular.ttf", fontName, GetType().Assembly);
        var manager = new FontManager(registrar);
        var actual  = manager.GetTypeface(Font.OfSize(fontName, 12, fontWeight));

        Assert.NotEqual(Typeface.Default, actual);

        Typeface expected;
        var      expectedTypeface = Typeface.Create(fontName, TypefaceStyle.Normal);

        if (OperatingSystem.IsAndroidVersionAtLeast(28))
        {
            expected = Typeface.Create(expectedTypeface, (int)fontWeight, italic: fontSlant);
        }
        else
        {
            expected = Typeface.Create(expectedTypeface, fontStyle);
        }

        Assert.NotEqual(Typeface.Default, expected);

        Assert.False(expected.Equals(actual));
    }
Пример #4
0
        public MainWindow()
        {
            InitializeComponent();

            var font = ToFontFamily("pack://application:,,,/Fonts/#Font Awesome 5 Free Solid");

            var window = new Window()
            {
                Content = new TextBlock()
                {
                    Text       = "\uf007;",
                    FontFamily = font,
                    Margin     = new System.Windows.Thickness(10, 10, 10, 10)
                }
            };

            window.Show();

            FontRegistrar.Register(new ExportFontAttribute("FontAwesome5_Solid.otf"), typeof(MainWindow).Assembly);

            Forms.Init();
            LoadApplication(new BugReport.App());
        }
Пример #5
0
    public void CanLoadFonts(string fontName, string assetName)
    {
        // skip on older androids for now
        // https://github.com/dotnet/maui/issues/5903
        if (!OperatingSystem.IsAndroidVersionAtLeast(28))
        {
            return;
        }

        var fontWeight = FontWeight.Regular;
        var fontStyle  = TypefaceStyle.Normal;
        var fontSlant  = false;

        Typeface expected;
        var      expectedTypeface = Typeface.CreateFromAsset(Application.Context.Assets, assetName);

        if (OperatingSystem.IsAndroidVersionAtLeast(28))
        {
            expected = Typeface.Create(expectedTypeface, (int)fontWeight, fontSlant);
        }
        else
        {
            expected = Typeface.Create(expectedTypeface, fontStyle);
        }

        Assert.NotEqual(Typeface.Default, expected);

        var registrar = new FontRegistrar(fontLoader: null);

        registrar.Register("dokdo_regular.ttf", "myalias");
        var manager = new FontManager(registrar);
        var actual  = manager.GetTypeface(Font.OfSize(fontName, 12, fontWeight));

        Assert.NotEqual(Typeface.Default, actual);

        Assert.True(expected.Equals(actual));
    }