示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        private void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args)
        {
            //Get the font name
            string fontName = args.FontName.Split(',')[0];

            //Get the font style
            PdfFontStyle fontStyle = args.FontStyle;

            SKTypefaceStyle sKFontStyle = SKTypefaceStyle.Normal;

            if (fontStyle != PdfFontStyle.Regular)
            {
                if (fontStyle == PdfFontStyle.Bold)
                {
                    sKFontStyle = SKTypefaceStyle.Bold;
                }
                else if (fontStyle == PdfFontStyle.Italic)
                {
                    sKFontStyle = SKTypefaceStyle.Italic;
                }
                else if (fontStyle == (PdfFontStyle.Italic | PdfFontStyle.Bold))
                {
                    sKFontStyle = SKTypefaceStyle.BoldItalic;
                }
            }

            SKTypeface    typeface       = SKTypeface.FromFamilyName(fontName, sKFontStyle);
            SKStreamAsset typeFaceStream = typeface.OpenStream();
            MemoryStream  memoryStream   = null;

            if (typeFaceStream != null && typeFaceStream.Length > 0)
            {
                //Create fontData from type face stream.
                byte[] fontData = new byte[typeFaceStream.Length - 1];
                typeFaceStream.Read(fontData, typeFaceStream.Length);
                typeFaceStream.Dispose();
                //Create the new memory stream from font data.
                memoryStream = new MemoryStream(fontData);
            }
            //set the font stream to the event args.
            args.FontStream = memoryStream;
        }