예제 #1
0
        public void Should_Initialize_With_Location_And_Filename()
        {
            var source = new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf#MyFont");

            var fontFamilyKey = new FontFamilyKey(source);

            Assert.Equal(new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf"), fontFamilyKey.Source);
        }
        private static FontCollection CreateFontCollection(FontFamilyKey key)
        {
            var assets = FontFamilyLoader.LoadFontAssets(key);

            var fontLoader = new DWriteResourceFontLoader(Direct2D1Platform.DirectWriteFactory, assets);

            return(new FontCollection(Direct2D1Platform.DirectWriteFactory, fontLoader, fontLoader.Key));
        }
예제 #3
0
        private static SharpDX.DirectWrite.FontCollection CreateFontCollection(FontFamilyKey key)
        {
            var assets = FontFamilyLoader.LoadFontAssets(key);

            var fontLoader = new DWriteResourceFontLoader(s_factory, assets);

            return(new SharpDX.DirectWrite.FontCollection(s_factory, fontLoader, fontLoader.Key));
        }
예제 #4
0
        public void Should_Initialize_With_Location()
        {
            var source = new Uri("resm:Avalonia.Visuals.UnitTests#MyFont");

            var fontFamilyKey = new FontFamilyKey(source);

            Assert.Equal(new Uri("resm:Avalonia.Visuals.UnitTests"), fontFamilyKey.Location);

            Assert.Null(fontFamilyKey.FileName);
        }
        public void Should_Parse_FontFamily_With_Resource_Filename()
        {
            var source = new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf#MyFont");

            var key = new FontFamilyKey(source);

            var fontFamily = FontFamily.Parse(source.OriginalString);

            Assert.Equal("MyFont", fontFamily.Name);

            Assert.Equal(key, fontFamily.Key);
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
        /// </summary>
        /// <param name="baseUri">Specifies the base uri that is used to resolve font family assets.</param>
        /// <param name="name">The name of the <see cref="T:Avalonia.Media.FontFamily" />.</param>
        /// <exception cref="T:System.ArgumentException">Base uri must be an absolute uri.</exception>
        public FontFamily(Uri?baseUri, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var fontFamilySegment = GetFontFamilyIdentifier(name);

            if (fontFamilySegment.Source != null)
            {
                if (baseUri != null && !baseUri.IsAbsoluteUri)
                {
                    throw new ArgumentException("Base uri must be an absolute uri.", nameof(baseUri));
                }

                Key = new FontFamilyKey(fontFamilySegment.Source, baseUri);
            }

            FamilyNames = new FamilyNameCollection(fontFamilySegment.Name);
        }
예제 #7
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
 /// </summary>
 /// <param name="name">The name of the <see cref="T:Avalonia.Media.FontFamily" />.</param>
 /// <param name="source">The source of font resources.</param>
 public FontFamily(string name, Uri source) : this(name)
 {
     Key = new FontFamilyKey(source);
 }
예제 #8
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
 /// </summary>
 /// <param name="name">The name of the <see cref="T:Avalonia.Media.FontFamily" />.</param>
 /// <param name="source">The source of font resources.</param>
 /// <param name="baseUri"></param>
 public FontFamily(string name, Uri source, Uri baseUri = null) : this(name)
 {
     Key = new FontFamilyKey(source, baseUri);
 }