Beispiel #1
0
        public static Blob ToHarfBuzzBlob(this SKStreamAsset asset)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }

            var size = asset.Length;

            Blob blob;

            var memoryBase = asset.GetMemoryBase();

            if (memoryBase != IntPtr.Zero)
            {
                blob = new Blob(memoryBase, size, MemoryMode.ReadOnly, () => asset.Dispose());
            }
            else
            {
                var ptr = Marshal.AllocCoTaskMem(size);
                asset.Read(ptr, size);
                blob = new Blob(ptr, size, MemoryMode.ReadOnly, () => Marshal.FreeCoTaskMem(ptr));
            }

            blob.MakeImmutable();

            return(blob);
        }
Beispiel #2
0
        private static Blob GetHarfBuzzBlob(SKStreamAsset asset)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }

            Blob blob;

            var size       = asset.Length;
            var memoryBase = asset.GetMemoryBase();

            if (memoryBase != IntPtr.Zero)
            {
                // the underlying stream is really a mamory block
                // so save on copying and just use that directly
                blob = new Blob(memoryBase, size, MemoryMode.ReadOnly, () => asset.Dispose());
            }
            else
            {
                // this could be a forward-only stream, so we must copy
                var ptr = Marshal.AllocCoTaskMem(size);
                asset.Read(ptr, size);
                blob = new Blob(ptr, size, MemoryMode.ReadOnly, () => Marshal.FreeCoTaskMem(ptr));
            }

            // make immutable for performance?
            blob.MakeImmutable();

            return(blob);
        }