Esempio n. 1
0
        public unsafe void ReleaseDataWasInvokedOnlyAfterTheTypefaceWasFinished()
        {
            if (IsMac)
            {
                throw new SkipException("macOS does not release the data when the typeface is disposed.");
            }

            var path  = Path.Combine(PathToFonts, "Distortable.ttf");
            var bytes = File.ReadAllBytes(path);

            var released = false;

            fixed(byte *b = bytes)
            {
                var data = SKData.Create((IntPtr)b, bytes.Length, (addr, ctx) => released = true);

                var typeface = SKTypeface.FromData(data);

                Assert.Equal("Distortable", typeface.FamilyName);

                data.Dispose();
                Assert.False(released, "The SKDataReleaseDelegate was called too soon.");

                typeface.Dispose();
                Assert.True(released, "The SKDataReleaseDelegate was not called at all.");
            }
        }
Esempio n. 2
0
        public unsafe bool Register(ResourceFile file, out string familyName)
        {
            if (file.IsNone)
            {
                throw new ArgumentException("file is none.", nameof(file));
            }
            using var stream = file.GetStream();

            SKTypeface tf;

            if (stream.CanSeek && stream.Length <= int.MaxValue)
            {
                var size = (int)stream.Length;
                using var data = SKData.Create(size);
                stream.Read(new Span <byte>((void *)data.Data, size));
                tf = SKTypeface.FromData(data, 0);
            }
            else
            {
                using var data = SKData.Create(stream);
                tf             = SKTypeface.FromData(data, 0);
            }
            familyName = tf.FamilyName;
            return(_dic.TryAdd(tf.FamilyName, tf));
        }
Esempio n. 3
0
        public unsafe void FromDataReturnsDifferentObject()
        {
            using var data = SKData.Create(Path.Combine(PathToFonts, "Roboto2-Regular_NoEmbed.ttf"));

            using var tf1 = SKTypeface.FromData(data);
            using var tf2 = SKTypeface.FromData(data);

            Assert.NotSame(tf1, tf2);
        }
Esempio n. 4
0
        public void CanReadData()
        {
            var bytes = File.ReadAllBytes(Path.Combine(PathToFonts, "Distortable.ttf"));

            using (var data = SKData.CreateCopy(bytes))
                using (var typeface = SKTypeface.FromData(data))
                {
                    Assert.NotNull(typeface);
                }
        }
Esempio n. 5
0
 private void initFonts()
 {
     fonts.forEach(s =>
     {
         var buf  = App.LoadData($"fonts/{s}");
         var data = SKData.CreateCopy(buf);
         faces[s] = SKTypeface.FromData(data);
         data.Dispose();
     });
 }
Esempio n. 6
0
 public CustomTypefaceProvider(SKData data, int index = 0)
 {
     Typeface   = SKTypeface.FromData(data, index);
     FamilyName = Typeface.FamilyName;
 }
Esempio n. 7
0
 /// <summary>
 /// Load a font from a file
 /// </summary>
 /// <param name="fileName">The path to the input file</param>
 /// <returns>The loaded font</returns>
 public static SKTypeface LoadFont(string fileName)
 {
     using (var stream = File.OpenRead(fileName))
         using (var data = SKData.Create(stream))
             return(SKTypeface.FromData(data));
 }