Ejemplo n.º 1
0
        public Font(Xamarin.Forms.NamedSize namedSize, FontStyle style = 0)
        {
            UIFont uiFont = UIFont.SystemFontOfSize((float)Xamarin.Forms.Device.GetNamedSize(namedSize, typeof(Xamarin.Forms.Label)));
            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = uiFont.FamilyName,
                Size       = (float)uiFont.PointSize
            };

            uiFont.Dispose();

            if ((style & FontStyle.Bold) != 0)
            {
                fda.StyleName = "Bold";
            }
            else if ((style & FontStyle.Italic) != 0)
            {
                fda.StyleName = "Italic";
            }

            CTFontDescriptor fd = new CTFontDescriptor(fda);

            nativeFont = new CTFont(fd, 0);
            fd.Dispose();
        }
Ejemplo n.º 2
0
        public void WithFeature()
        {
#if __TVOS__
            var fontName = "Gujarati Sangam MN";
#else
            var fontName = "HoeflerText-Regular";
#endif

            using (var font = new CTFont(fontName, 10)) {
                var  f1        = font.GetFeatures();
                var  ligatures = f1.Where(l => l.FeatureGroup == FontFeatureGroup.Ligatures).First();
                bool rare      = ligatures.Selectors.Cast <CTFontFeatureLigatures> ().Any(l => l.Feature == CTFontFeatureLigatures.Selector.RareLigaturesOn);
                Assert.That(rare, Is.True, "RareLigaturesOn available");
                Assert.That(font.GetFeatureSettings(), Is.Empty, "No custom settings");
            }

            using (var fd = new CTFontDescriptor(fontName, 20))
                using (var rare_on_fd = fd.WithFeature(CTFontFeatureLigatures.Selector.RareLigaturesOn))
                    using (var font = new CTFont(rare_on_fd, 13)) {
                        var set_feature = font.GetFeatureSettings()[0];

                        Assert.That(set_feature.FeatureGroup, Is.EqualTo(FontFeatureGroup.Ligatures), "#1");
                        Assert.That(set_feature.FeatureWeak, Is.EqualTo((int)CTFontFeatureLigatures.Selector.RareLigaturesOn), "#2");
                    }
        }
Ejemplo n.º 3
0
        public Font(int size, FontStyle style = 0)
        {
            UIFont uiFont = UIFont.SystemFontOfSize(size);
            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = uiFont.FamilyName,
                Size       = (float)uiFont.PointSize
            };

            uiFont.Dispose();

            if ((style & FontStyle.Bold) != 0)
            {
                fda.StyleName = "Bold";
            }
            else if ((style & FontStyle.Italic) != 0)
            {
                fda.StyleName = "Italic";
            }

            CTFontDescriptor fd = new CTFontDescriptor(fda);

            nativeFont = new CTFont(fd, 0);
            fd.Dispose();
        }
Ejemplo n.º 4
0
        static CTFont CTFontWithFamilyName(string family, CTFontSymbolicTraits straits, float size, float weight)
        {
            var bold   = Math.Abs(weight - CTFontWeight.Bold) < 0.01f;
            var traits = new NSMutableDictionary();

            if (Math.Abs(weight) > 0.01 && !bold)
            {
                traits[CTFontTraitKey.Weight] = NSNumber.FromFloat(weight);
            }

            if (bold)
            {
                straits |= CTFontSymbolicTraits.Bold;
            }

            if (0 != (straits & (CTFontSymbolicTraits.Bold | CTFontSymbolicTraits.Italic)))
            {
                traits[CTFontTraitKey.Symbolic] = NSNumber.FromUInt32((UInt32)straits);
            }

            var attrs = new NSMutableDictionary();

            attrs[CTFontDescriptorAttributeKey.FamilyName] = (NSString)family;
            attrs[CTFontDescriptorAttributeKey.Traits]     = traits;

            var desc = new CTFontDescriptor(new CTFontDescriptorAttributes(attrs));
            var font = new CTFont(desc, size);

            return(font);
        }
Ejemplo n.º 5
0
        public static CTFontDescriptor GetFontDescriptor(MACaptionAppearanceDomain domain, ref MACaptionAppearanceBehavior behavior, MACaptionAppearanceFontStyle fontStyle)
        {
            nint b  = (int)behavior;
            var  rv = new CTFontDescriptor(MACaptionAppearanceCopyFontDescriptorForStyle((int)domain, ref b, (int)fontStyle), owns: true);

            behavior = (MACaptionAppearanceBehavior)(int)b;
            return(rv);
        }
Ejemplo n.º 6
0
        public static CTFont GetCtFont(this UIFont font)
        {
            var fda = new CTFontDescriptorAttributes
            {
                FamilyName = font.FamilyName,
                Size       = (float)font.PointSize,
                StyleName  = font.FontDescriptor.Face
            };
            var fd = new CTFontDescriptor(fda);

            return(new CTFont(fd, 0));
        }
Ejemplo n.º 7
0
        public void CTFontCreateWithFontDescriptorAndOptions()
        {
            TestRuntime.AssertXcodeVersion(5, 0);

            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = "Courier",
                StyleName  = "Bold",
                Size       = 16.0f
            };

            using (var fd = new CTFontDescriptor(fda))
                using (var font = new CTFont(fd, 10, CTFontOptions.Default)) {
                    Assert.That(font.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                }
        }
Ejemplo n.º 8
0
        public void RegisterFontDescriptors_NoCallback()
        {
            TestRuntime.AssertXcodeVersion(11, 1);              // Introduced in iOS 13.0, but with a bug that makes it crash. Apple fixed it for iOS 13.1
            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = "Courier",
                StyleName  = "Bold",
                Size       = 16.0f
            };

            using (CTFontDescriptor fd = new CTFontDescriptor(fda)) {
                var array = new [] { fd };
                CTFontManager.RegisterFontDescriptors(array, CTFontManagerScope.Process, true, null);
                CTFontManager.UnregisterFontDescriptors(array, CTFontManagerScope.Process, null);
            }
        }
Ejemplo n.º 9
0
        public void RegisterFontDescriptors_WithCallback()
        {
            TestRuntime.AssertXcodeVersion(11, 0);

            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = "Courier",
                StyleName  = "Bold",
                Size       = 16.0f
            };

            using (CTFontDescriptor fd = new CTFontDescriptor(fda)) {
                var array = new [] { fd };
                CTFontManager.RegisterFontDescriptors(array, CTFontManagerScope.Process, true, SuccessDone);
                CTFontManager.UnregisterFontDescriptors(array, CTFontManagerScope.Process, SuccessDone);
            }
        }
        private void CreateNativeFontFamily(string extendedName, FontCollection fontCollection, bool createDefaultIfNotExists)
        {
            RemoveSemiboldSuffix(extendedName, out string name);

            if (fontCollection != null)
            {
                if (fontCollection.nativeFontDescriptors.ContainsKey(name))
                {
                    nativeFontDescriptor = fontCollection.nativeFontDescriptors [name];
                }

                if (nativeFontDescriptor == null && createDefaultIfNotExists)
                {
                    nativeFontDescriptor = new CTFontDescriptor(SANS_SERIF, 0);
                }
            }
            else
            {
                nativeFontDescriptor = new CTFontDescriptor(name, 0);

                if (nativeFontDescriptor == null && createDefaultIfNotExists)
                {
                    nativeFontDescriptor = new CTFontDescriptor(SANS_SERIF, 0);
                }
            }

            if (nativeFontDescriptor == null)
            {
                throw new ArgumentException("name specifies a font that is not installed on the computer running the application.");
            }
            else
            {
                var attrs = nativeFontDescriptor.GetAttributes();
                familyName = attrs.FamilyName;
                // if the font description attributes do not contain a value for FamilyName then we
                // need to try and create the font to get the family name from the actual font.
                if (string.IsNullOrEmpty(familyName))
                {
                    var font = new CTFont(nativeFontDescriptor, 0);
                    familyName = font.FamilyName;                    // extendedName;
                }
            }
        }
Ejemplo n.º 11
0
        // http://stackoverflow.com/questions/9007991/monotouch-custom-font-with-attributes/9009161#9009161
        public void FromAttributes()
        {
            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = "Courier",
                StyleName  = "Bold",
                Size       = 16.0f
            };

            using (CTFontDescriptor fd = new CTFontDescriptor(fda))
                using (CTFont font = new CTFont(fd, 0)) {
                    // check that the created font match the descriptor's attributes
                    Assert.That(font.FamilyName, Is.EqualTo("Courier"), "FamilyName");
                    Assert.That(font.FullName, Is.EqualTo("Courier Bold"), "FullName");
                    Assert.That(font.Size, Is.EqualTo((nfloat)16), "Size");
                    // that changed in iOS 8.3, there's an undocumented flag + MonoSpace (make sense) + bold
                    Assert.True((font.SymbolicTraits & CTFontSymbolicTraits.Bold) != 0, "SymbolicTraits");
                }
        }
Ejemplo n.º 12
0
        private CTFontDescriptor getDescriptor(FontStyle style)
        {
            if (!style.HasFlag(FontStyle.Underline) && !style.HasFlag(FontStyle.Strikeout)) return null;

            NSMutableDictionary dict = new NSMutableDictionary();
            if (style.HasFlag(FontStyle.Underline))
            {
                NSString underline = UIStringAttributeKey.UnderlineStyle;
                dict[underline] = NSNumber.FromInt32((int)NSUnderlineStyle.Single);
            }
            if (style.HasFlag(FontStyle.Strikeout))
            {
                NSString strike = UIStringAttributeKey.StrikethroughStyle;
                dict[strike] = NSNumber.FromInt32((int)NSUnderlineStyle.Single);
            }
            CTFontDescriptorAttributes attrs = new CTFontDescriptorAttributes(dict);
            CTFontDescriptor desc = new CTFontDescriptor(attrs);
            return desc;
        }
Ejemplo n.º 13
0
 public void CTFontCreateWithFontDescriptorAndOptions()
 {
     // Apple documents CTFontCreateWithFontDescriptorAndOptions as availble since 3.2 but it does not work before 7.0 (e.g. 6.1)
     // it seems to be a known issue, http://stackoverflow.com/q/4419283 but I still left feedback to Apple to fix it
     try {
         CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
         {
             FamilyName = "Courier",
             StyleName  = "Bold",
             Size       = 16.0f
         };
         using (var fd = new CTFontDescriptor(fda))
             using (var font = new CTFont(fd, 10, CTFontOptions.Default)) {
                 Assert.That(font.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
             }
     }
     catch (EntryPointNotFoundException) {
         Assert.True(!UIDevice.CurrentDevice.CheckSystemVersion(7, 0), "< iOS 7.0");
     }
 }
Ejemplo n.º 14
0
        public void RequestFonts()
        {
            TestRuntime.AssertXcodeVersion(11, 0);
            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = "Courier",
                StyleName  = "Bold",
                Size       = 16.0f
            };

            using (CTFontDescriptor fd = new CTFontDescriptor(fda)) {
                Assert.Throws <ArgumentNullException> (() => CTFontManager.RequestFonts(new [] { fd }, null), "null");

                var callback = false;
                CTFontManager.RequestFonts(new [] { fd }, (unresolved) => {
                    Assert.That(unresolved.Length, Is.EqualTo(0), "all resolved");
                    callback = true;
                });
                Assert.True(callback, "callback");
            }
        }
Ejemplo n.º 15
0
        public Font(string name, int size, FontStyle style = 0)
        {
            CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
            {
                FamilyName = name,
                Size       = size
            };

            if ((style & FontStyle.Bold) != 0)
            {
                fda.StyleName = "Bold";
            }
            else if ((style & FontStyle.Italic) != 0)
            {
                fda.StyleName = "Italic";
            }

            CTFontDescriptor fd = new CTFontDescriptor(fda);

            nativeFont = new CTFont(fd, 0);
            fd.Dispose();
        }
Ejemplo n.º 16
0
        protected INativeObject GetINativeInstance(Type t)
        {
            var ctor = t.GetConstructor (Type.EmptyTypes);
            if ((ctor != null) && !ctor.IsAbstract)
                return ctor.Invoke (null) as INativeObject;

            if (!NativeObjectInterfaceType.IsAssignableFrom (t))
                throw new ArgumentException ("t");
            switch (t.Name) {
            case "CFAllocator":
                return CFAllocator.SystemDefault;
            case "CFBundle":
                var bundles = CFBundle.GetAll ();
                if (bundles.Length > 0)
                    return bundles [0];
                else
                    throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            case "CFNotificationCenter":
                return CFNotificationCenter.Darwin;
            case "CFReadStream":
            case "CFStream":
                CFReadStream readStream;
                CFWriteStream writeStream;
                CFStream.CreatePairWithSocketToHost ("www.google.com", 80, out readStream, out writeStream);
                return readStream;
            case "CFWriteStream":
                CFStream.CreatePairWithSocketToHost ("www.google.com", 80, out readStream, out writeStream);
                return writeStream;
            case "CFUrl":
                return CFUrl.FromFile ("/etc");
            case "AudioFile":
                var path = Path.GetFullPath ("1.caf");
                var af = AudioFile.Open (CFUrl.FromFile (path), AudioFilePermission.Read, AudioFileType.CAF);
                return af;
            case "CFHTTPMessage":
                return CFHTTPMessage.CreateEmpty (false);
            case "CGBitmapContext":
                byte[] data = new byte [400];
                using (CGColorSpace space = CGColorSpace.CreateDeviceRGB ()) {
                    return new CGBitmapContext (data, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast);
                }
            case "CGContextPDF":
                var filename = Environment.GetFolderPath (Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
                using (var url = new NSUrl (filename))
                    return new CGContextPDF (url);
            case "CGColorConverter":
                var cvt = new CGColorConverterTriple () {
                    Space = CGColorSpace.CreateGenericRgb (),
                    Intent = CGColorRenderingIntent.Default,
                    Transform = CGColorConverterTransformType.ApplySpace
                };
                return new CGColorConverter (null, cvt, cvt, cvt);
            case "CGDataConsumer":
                using (NSMutableData destData = new NSMutableData ()) {
                    return new CGDataConsumer (destData);
                }
            case "CGDataProvider":
                filename = "xamarin1.png";
                return new CGDataProvider (filename);
            case "CGFont":
                return CGFont.CreateWithFontName ("Courier New");
            case "CGPattern":
                return new CGPattern (
                    new RectangleF (0, 0, 16, 16),
                    CGAffineTransform.MakeIdentity (),
                    16, 16,
                    CGPatternTiling.NoDistortion,
                    true,
                    (cgc) => {});
            case "CMBufferQueue":
                return CMBufferQueue.CreateUnsorted (2);
            case "CTFont":
                CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes () {
                    FamilyName = "Courier",
                    StyleName = "Bold",
                    Size = 16.0f
                };
                using (var fd = new CTFontDescriptor (fda))
                    return new CTFont (fd, 10, CTFontOptions.Default);
            case "CTFontCollection":
                return new CTFontCollection (new CTFontCollectionOptions ());
            case "CTFontDescriptor":
                fda = new CTFontDescriptorAttributes ();
                return new CTFontDescriptor (fda);
            case "CTTextTab":
                return new CTTextTab (CTTextAlignment.Left, 2);
            case "CTTypesetter":
                return new CTTypesetter (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
            case "CTFrame":
                var framesetter = new CTFramesetter (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
                var bPath = UIBezierPath.FromRect (new RectangleF (0, 0, 3, 3));
                return framesetter.GetFrame (new NSRange (0, 0), bPath.CGPath, null);
            case "CTFramesetter":
                return new CTFramesetter (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
            case "CTGlyphInfo":
                return new CTGlyphInfo ("Zapfino", new CTFont ("Arial", 24), "Foo");
            case "CTLine":
                return new CTLine (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
            case "CGImageDestination":
                var storage = new NSMutableData ();
                return CGImageDestination.Create (new CGDataConsumer (storage), "public.png", 1);
            case "CGImageMetadataTag":
                using (NSString name = new NSString ("tagName"))
                using (var value = new NSString ("value"))
                    return new CGImageMetadataTag (CGImageMetadataTagNamespaces.Exif, CGImageMetadataTagPrefixes.Exif, name, CGImageMetadataType.Default, value);
            case "CGImageSource":
                filename = "xamarin1.png";
                return CGImageSource.FromUrl (NSUrl.FromFilename (filename));
            case "SecPolicy":
                return SecPolicy.CreateSslPolicy (false, null);
            case "SecIdentity":
                using (var options = NSDictionary.FromObjectAndKey (new NSString ("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var result = SecImportExport.ImportPkcs12 (farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                        throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    return new SecIdentity (array [0].LowlevelObjectForKey (SecImportExport.Identity.Handle));
                }
            case "SecTrust":
                X509Certificate x = new X509Certificate (mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy (true, "mail.google.com"))
                    return new SecTrust (x, policy);
            case "SslContext":
                return new SslContext (SslProtocolSide.Client, SslConnectionType.Stream);
            case "UIFontFeature":
                return new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers);
            case "NetworkReachability":
                return new NetworkReachability (IPAddress.Loopback, null);
            #if !__TVOS__
            case "VTCompressionSession":
            case "VTSession":
                return VTCompressionSession.Create (1024, 768, CMVideoCodecType.H264, (sourceFrame, status, flags, buffer) => { }, null, (CVPixelBufferAttributes) null);
            case "VTFrameSilo":
                return VTFrameSilo.Create ();
            case "VTMultiPassStorage":
                return VTMultiPassStorage.Create ();
            #endif
            case "CFString":
                return new CFString ("test");
            case "DispatchQueue":
                return new DispatchQueue ("com.example.subsystem.taskXYZ");
            case "DispatchGroup":
                return DispatchGroup.Create ();
            case "CGColorSpace":
                return CGColorSpace.CreateAcesCGLinear ();
            case "CGGradient":
                CGColor[] cArray = { UIColor.Black.CGColor, UIColor.Clear.CGColor, UIColor.Blue.CGColor };
                return new CGGradient (null, cArray);
            case "CGImage":
                filename = "xamarin1.png";
                using (var dp = new CGDataProvider (filename))
                    return CGImage.FromPNG (dp, null, false, CGColorRenderingIntent.Default);
            case "CGColor":
                return UIColor.Black.CGColor;
            case "CMClock":
                CMClockError ce;
                CMClock clock = CMClock.CreateAudioClock (out ce);
                if (ce == CMClockError.None)
                    return clock;
                throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            case "CMTimebase":
                clock = CMClock.CreateAudioClock (out ce);
                if (ce == CMClockError.None) {
                    return new CMTimebase (clock);
                }
                throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            case "CVPixelBufferPool":
                return new CVPixelBufferPool (
                    new CVPixelBufferPoolSettings (),
                    new CVPixelBufferAttributes (CVPixelFormatType.CV24RGB, 100, 50)
                );
            case "SecCertificate":
                using (var cdata = NSData.FromArray (mail_google_com))
                    return new SecCertificate (cdata);
            case "SecKey":
                SecKey private_key;
                SecKey public_key;
                using (var record = new SecRecord (SecKind.Key)) {
                    record.KeyType = SecKeyType.RSA;
                    record.KeySizeInBits = 512; // it's not a performance test :)
                    SecKey.GenerateKeyPair (record.ToDictionary (), out public_key, out private_key);
                    return private_key;
                }
            case "SecAccessControl":
                return new SecAccessControl (SecAccessible.WhenPasscodeSetThisDeviceOnly);
            default:
                throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            }
        }
Ejemplo n.º 17
0
        protected INativeObject GetINativeInstance(Type t)
        {
            var ctor = t.GetConstructor(Type.EmptyTypes);

            if ((ctor != null) && !ctor.IsAbstract)
            {
                return(ctor.Invoke(null) as INativeObject);
            }

            if (!NativeObjectInterfaceType.IsAssignableFrom(t))
            {
                throw new ArgumentException("t");
            }
            switch (t.Name)
            {
            case "CFAllocator":
                return(CFAllocator.SystemDefault);

            case "CFBundle":
                var bundles = CFBundle.GetAll();
                if (bundles.Length > 0)
                {
                    return(bundles [0]);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
                }

            case "CFNotificationCenter":
                return(CFNotificationCenter.Darwin);

            case "CFReadStream":
            case "CFStream":
                CFReadStream  readStream;
                CFWriteStream writeStream;
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(readStream);

            case "CFWriteStream":
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(writeStream);

            case "CFUrl":
                return(CFUrl.FromFile("/etc"));

            case "CFPropertyList":
                return(CFPropertyList.FromData(NSData.FromString("<string>data</string>")).PropertyList);

            case "DispatchData":
                return(DispatchData.FromByteBuffer(new byte [] { 1, 2, 3, 4 }));

            case "AudioFile":
                var path = Path.GetFullPath("1.caf");
                var af   = AudioFile.Open(CFUrl.FromFile(path), AudioFilePermission.Read, AudioFileType.CAF);
                return(af);

            case "CFHTTPMessage":
                return(CFHTTPMessage.CreateEmpty(false));

            case "CFMutableString":
                return(new CFMutableString("xamarin"));

            case "CGBitmapContext":
                byte[] data = new byte [400];
                using (CGColorSpace space = CGColorSpace.CreateDeviceRGB()) {
                    return(new CGBitmapContext(data, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast));
                }

            case "CGContextPDF":
                var filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
                using (var url = new NSUrl(filename))
                    return(new CGContextPDF(url));

            case "CGColorConversionInfo":
                var cci = new GColorConversionInfoTriple()
                {
                    Space     = CGColorSpace.CreateGenericRgb(),
                    Intent    = CGColorRenderingIntent.Default,
                    Transform = CGColorConversionInfoTransformType.ApplySpace
                };
                return(new CGColorConversionInfo((NSDictionary)null, cci, cci, cci));

            case "CGDataConsumer":
                using (NSMutableData destData = new NSMutableData()) {
                    return(new CGDataConsumer(destData));
                }

            case "CGDataProvider":
                filename = "xamarin1.png";
                return(new CGDataProvider(filename));

            case "CGFont":
                return(CGFont.CreateWithFontName("Courier New"));

            case "CGPattern":
                return(new CGPattern(
                           new RectangleF(0, 0, 16, 16),
                           CGAffineTransform.MakeIdentity(),
                           16, 16,
                           CGPatternTiling.NoDistortion,
                           true,
                           (cgc) => {}));

            case "CMBufferQueue":
                return(CMBufferQueue.CreateUnsorted(2));

            case "CTFont":
                CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
                {
                    FamilyName = "Courier",
                    StyleName  = "Bold",
                    Size       = 16.0f
                };
                using (var fd = new CTFontDescriptor(fda))
                    return(new CTFont(fd, 10));

            case "CTFontCollection":
                return(new CTFontCollection(new CTFontCollectionOptions()));

            case "CTFontDescriptor":
                fda = new CTFontDescriptorAttributes();
                return(new CTFontDescriptor(fda));

            case "CTTextTab":
                return(new CTTextTab(CTTextAlignment.Left, 2));

            case "CTTypesetter":
                return(new CTTypesetter(new NSAttributedString("Hello, world",
                                                               new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CTFrame":
                var framesetter = new CTFramesetter(new NSAttributedString("Hello, world",
                                                                           new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                }));
                var bPath = UIBezierPath.FromRect(new RectangleF(0, 0, 3, 3));
                return(framesetter.GetFrame(new NSRange(0, 0), bPath.CGPath, null));

            case "CTFramesetter":
                return(new CTFramesetter(new NSAttributedString("Hello, world",
                                                                new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CTGlyphInfo":
                return(new CTGlyphInfo("copyright", new CTFont("ArialMY", 24), "Foo"));

            case "CTLine":
                return(new CTLine(new NSAttributedString("Hello, world",
                                                         new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("ArialMT", 24)
                })));

            case "CGImageDestination":
                var storage = new NSMutableData();
                return(CGImageDestination.Create(new CGDataConsumer(storage), "public.png", 1));

            case "CGImageMetadataTag":
                using (NSString name = new NSString("tagName"))
                    using (var value = new NSString("value"))
                        return(new CGImageMetadataTag(CGImageMetadataTagNamespaces.Exif, CGImageMetadataTagPrefixes.Exif, name, CGImageMetadataType.Default, value));

            case "CGImageSource":
                filename = "xamarin1.png";
                return(CGImageSource.FromUrl(NSUrl.FromFilename(filename)));

            case "SecPolicy":
                return(SecPolicy.CreateSslPolicy(false, null));

            case "SecIdentity":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle)));
                }

            case "SecTrust":
                X509Certificate x = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust(x, policy));

            case "SslContext":
                return(new SslContext(SslProtocolSide.Client, SslConnectionType.Stream));

            case "UIFontFeature":
                return(new UIFontFeature(CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

            case "NetworkReachability":
                return(new NetworkReachability(IPAddress.Loopback, null));

            case "VTCompressionSession":
            case "VTSession":
                return(VTCompressionSession.Create(1024, 768, CMVideoCodecType.H264, (sourceFrame, status, flags, buffer) => { }, null, (CVPixelBufferAttributes)null));

            case "VTFrameSilo":
                return(VTFrameSilo.Create());

            case "VTMultiPassStorage":
                return(VTMultiPassStorage.Create());

            case "CFString":
                return(new CFString("test"));

            case "DispatchBlock":
                return(new DispatchBlock(() => { }));

            case "DispatchQueue":
                return(new DispatchQueue("com.example.subsystem.taskXYZ"));

            case "DispatchGroup":
                return(DispatchGroup.Create());

            case "CGColorSpace":
                return(CGColorSpace.CreateDeviceCmyk());

            case "CGGradient":
                CGColor[] cArray = { UIColor.Black.CGColor, UIColor.Clear.CGColor, UIColor.Blue.CGColor };
                return(new CGGradient(null, cArray));

            case "CGImage":
                filename = "xamarin1.png";
                using (var dp = new CGDataProvider(filename))
                    return(CGImage.FromPNG(dp, null, false, CGColorRenderingIntent.Default));

            case "CGColor":
                return(UIColor.Black.CGColor);

            case "CMClock":
                return(CMClock.HostTimeClock);

            case "CMTimebase":
                return(new CMTimebase(CMClock.HostTimeClock));

            case "CVPixelBufferPool":
                return(new CVPixelBufferPool(
                           new CVPixelBufferPoolSettings(),
                           new CVPixelBufferAttributes(CVPixelFormatType.CV24RGB, 100, 50)
                           ));

            case "SecCertificate":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate(cdata));

            case "SecCertificate2":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate2(new SecCertificate(cdata)));

            case "SecTrust2":
                X509Certificate x2 = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust2(new SecTrust(x2, policy)));

            case "SecIdentity2":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity2(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle))));
                }

            case "SecKey":
                SecKey private_key;
                SecKey public_key;
                using (var record = new SecRecord(SecKind.Key)) {
                    record.KeyType       = SecKeyType.RSA;
                    record.KeySizeInBits = 512;                     // it's not a performance test :)
                    SecKey.GenerateKeyPair(record.ToDictionary(), out public_key, out private_key);
                    return(private_key);
                }

            case "SecAccessControl":
                return(new SecAccessControl(SecAccessible.WhenPasscodeSetThisDeviceOnly));

            default:
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
            }
        }
Ejemplo n.º 18
0
		// Listing 2-7
		static CTFont CreateFont (CTFontDescriptor fontDescriptor, float size)
		{
			return new CTFont (fontDescriptor, size);
		}
Ejemplo n.º 19
0
        static bool IsFontInstalled(CTFontDescriptor descriptor)
        {
            var matching = descriptor.GetMatchingFontDescriptors((NSSet)null);

            return(matching != null && matching.Length > 0);
        }
        private void CreateNativeFontFamily(string name, FontCollection fontCollection, bool createDefaultIfNotExists)
        {
            if (fontCollection != null)
            {
                if (fontCollection.nativeFontDescriptors.ContainsKey (name))
                    nativeFontDescriptor = fontCollection.nativeFontDescriptors [name];

                if (nativeFontDescriptor == null && createDefaultIfNotExists)
                {
                    nativeFontDescriptor = new CTFontDescriptor (SANS_SERIF, 0);
                }
            }
            else
            {
                nativeFontDescriptor = new CTFontDescriptor (name, 0);

                if (nativeFontDescriptor == null && createDefaultIfNotExists)
                {
                    nativeFontDescriptor = new CTFontDescriptor (SANS_SERIF, 0);
                }
            }

            if (nativeFontDescriptor == null)
                throw new ArgumentException ("name specifies a font that is not installed on the computer running the application.");
            else
            {
                var attrs = nativeFontDescriptor.GetAttributes ();
                familyName = attrs.FamilyName;
                // if the font description attributes do not contain a value for FamilyName then we
                // need to try and create the font to get the family name from the actual font.
                if (string.IsNullOrEmpty (familyName))
                {
                    var font = new CTFont (nativeFontDescriptor, 0);
                    familyName = font.FamilyName;
                }
            }
        }