From a45fd083b575c8f02a347af154f1f7f52729edd5 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 7 Aug 2019 13:07:42 -0400 Subject: [PATCH] [coretext] Update for Xcode 11 beta 5 (#6731) Beta 4 added some new API and constants Beta 5 removed `CTFontManagerCopyRegisteredFontDescriptors` from all OS but iOS --- src/CoreText/CTEnums.cs | 1 + src/CoreText/CTFont.cs | 25 +++++++++++++++++ src/CoreText/CTFontManager.cs | 7 +++-- src/CoreText/CTGlyphInfo.cs | 10 +++++++ src/coretext.cs | 8 ++++++ tests/monotouch-test/CoreText/FontTest.cs | 26 +++++++++++++++++- .../monotouch-test/CoreText/GlyphInfoTest.cs | 27 +++++++++++++++++++ tests/xtro-sharpie/iOS-CoreText.todo | 4 --- tests/xtro-sharpie/macOS-CoreText.todo | 5 ---- tests/xtro-sharpie/tvOS-CoreText.todo | 5 ---- tests/xtro-sharpie/watchOS-CoreText.todo | 5 ---- 11 files changed, 101 insertions(+), 22 deletions(-) create mode 100644 tests/monotouch-test/CoreText/GlyphInfoTest.cs delete mode 100644 tests/xtro-sharpie/iOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/macOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/tvOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/watchOS-CoreText.todo diff --git a/src/CoreText/CTEnums.cs b/src/CoreText/CTEnums.cs index c14f79bbad..b53fc50cae 100644 --- a/src/CoreText/CTEnums.cs +++ b/src/CoreText/CTEnums.cs @@ -48,5 +48,6 @@ namespace CoreText { InsufficientInfo = 303, CancelledByUser = 304, DuplicatedName = 305, + InvalidFilePath = 306, } } diff --git a/src/CoreText/CTFont.cs b/src/CoreText/CTFont.cs index fa89d7a249..0adf9b9800 100644 --- a/src/CoreText/CTFont.cs +++ b/src/CoreText/CTFont.cs @@ -1712,6 +1712,31 @@ namespace CoreText { return CreateFont (CTFontCreateForString (handle, v.Handle, range)); } + [iOS (13,0), Mac (10,15), TV (13,0), Watch (6,0)] + [DllImport (Constants.CoreTextLibrary)] + static extern /* CTFontRef */ IntPtr CTFontCreateForStringWithLanguage ( + /* CTFontRef */ IntPtr currentFont, + /* CFStringRef */ IntPtr @string, + NSRange range, + /* CFStringRef _Nullable */ IntPtr language); + + [iOS (13,0), Mac (10,15), TV (13,0), Watch (6,0)] + public CTFont ForString (string value, NSRange range, string language) + { + if (value == null) + throw new ArgumentNullException (nameof (value)); + + var v = NSString.CreateNative (value); + var l = NSString.CreateNative (language); + try { + return CreateFont (CTFontCreateForStringWithLanguage (handle, v, range, l)); + } + finally { + NSString.ReleaseNative (l); + NSString.ReleaseNative (v); + } + } + #endregion #region Font Accessors diff --git a/src/CoreText/CTFontManager.cs b/src/CoreText/CTFontManager.cs index 0ffad3810b..06be334c20 100644 --- a/src/CoreText/CTFontManager.cs +++ b/src/CoreText/CTFontManager.cs @@ -401,17 +401,20 @@ namespace CoreText { } } - [Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)] +#if __IOS__ + [iOS (13,0)] [DllImport (Constants.CoreTextLibrary)] static extern /* CFArrayRef */ IntPtr CTFontManagerCopyRegisteredFontDescriptors (CTFontManagerScope scope, bool enabled); - [Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)] + [iOS (13,0)] + [NoWatch][NoTV][NoMac] public static CTFontDescriptor[] GetRegisteredFontDescriptors (CTFontManagerScope scope, bool enabled) { var p = CTFontManagerCopyRegisteredFontDescriptors (scope, enabled); // Copy/Create rule - we must release the CFArrayRef return ArrayFromHandle (p, releaseAfterUse: true); } +#endif // [Watch (2,0), TV (9,0), Mac (10,7), iOS (7,0)] [DllImport (Constants.CoreTextLibrary)] diff --git a/src/CoreText/CTGlyphInfo.cs b/src/CoreText/CTGlyphInfo.cs index 4ba5b2d03d..d27cb046ab 100644 --- a/src/CoreText/CTGlyphInfo.cs +++ b/src/CoreText/CTGlyphInfo.cs @@ -156,6 +156,16 @@ namespace CoreText { public CTCharacterCollection CharacterCollection { get {return CTGlyphInfoGetCharacterCollection (handle);} } + + [DllImport (Constants.CoreTextLibrary)] + [iOS (13,0), Mac (10,15), TV (13,0), Watch (6,0)] + static extern ushort /* CGGlyph */ CTGlyphInfoGetGlyph (IntPtr /* CTGlyphInfoRef */ glyphInfo); + + [iOS (13,0), Mac (10,15), TV (13,0), Watch (6,0)] + public CGGlyph GetGlyph () + { + return CTGlyphInfoGetGlyph (handle); + } #endregion public override string ToString () diff --git a/src/coretext.cs b/src/coretext.cs index dc7a8c1e19..112bdf6471 100644 --- a/src/coretext.cs +++ b/src/coretext.cs @@ -49,6 +49,14 @@ namespace CoreText { [Field ("kCTFontFeatureSelectorSettingKey")] NSString Setting { get; } + + [iOS (13,0), Mac (10,15), TV (13,0), Watch (6,0)] + [Field ("kCTFontFeatureSampleTextKey")] + NSString SampleText { get; } + + [iOS (13,0), Mac (10,15), TV (13,0), Watch (6,0)] + [Field ("kCTFontFeatureTooltipTextKey")] + NSString TooltipText { get; } } [Static] diff --git a/tests/monotouch-test/CoreText/FontTest.cs b/tests/monotouch-test/CoreText/FontTest.cs index 26df7895e6..bc08064039 100644 --- a/tests/monotouch-test/CoreText/FontTest.cs +++ b/tests/monotouch-test/CoreText/FontTest.cs @@ -39,7 +39,7 @@ namespace MonoTouchFixtures.CoreText { [TestFixture] [Preserve (AllMembers = true)] - public class A_FontTest { + public class FontTest { [Test] public void CTFontCreateWithNameAndOptions () @@ -108,5 +108,29 @@ namespace MonoTouchFixtures.CoreText { Assert.That (gid [1], Is.EqualTo (0), "1"); } } + + [Test] + public void CTFontCreateForString () + { + TestRuntime.AssertXcodeVersion (5, 0); + + using (var f1 = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default)) + using (var f2 = f1.ForString ("xamarin", new NSRange (0, 3))) { + Assert.That (f2.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle"); + } + } + + [Test] + public void CTFontCreateForStringWithLanguage () + { + TestRuntime.AssertXcodeVersion (11, 0); + + using (var f1 = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default)) { + using (var f2 = f1.ForString ("xamarin", new NSRange (0, 3), null)) + Assert.That (f2.Handle, Is.Not.EqualTo (IntPtr.Zero), "f2"); + using (var f3 = f1.ForString ("xamarin", new NSRange (0, 3), "FR")) + Assert.That (f3.Handle, Is.Not.EqualTo (IntPtr.Zero), "f3"); + } + } } } diff --git a/tests/monotouch-test/CoreText/GlyphInfoTest.cs b/tests/monotouch-test/CoreText/GlyphInfoTest.cs new file mode 100644 index 0000000000..34d97e1c8c --- /dev/null +++ b/tests/monotouch-test/CoreText/GlyphInfoTest.cs @@ -0,0 +1,27 @@ +using System; + +using CoreText; +using Foundation; + +using NUnit.Framework; + +namespace MonoTouchFixtures.CoreText { + + [TestFixture] + [Preserve (AllMembers = true)] + public class GlyphInfoTest { + + [Test] + public void GlyphInfo () + { + using (var f = new CTFont ("ArialMY", 24)) + using (var g = new CTGlyphInfo (64, f, "Foo")) { + Assert.That (g.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle"); + + if (TestRuntime.CheckXcodeVersion (11,0)) { + Assert.That (g.GetGlyph (), Is.EqualTo (64), "GetGlyph"); + } + } + } + } +} diff --git a/tests/xtro-sharpie/iOS-CoreText.todo b/tests/xtro-sharpie/iOS-CoreText.todo deleted file mode 100644 index 190e509c4a..0000000000 --- a/tests/xtro-sharpie/iOS-CoreText.todo +++ /dev/null @@ -1,4 +0,0 @@ -!missing-field! kCTFontFeatureSampleTextKey not bound -!missing-field! kCTFontFeatureTooltipTextKey not bound -!missing-pinvoke! CTFontCreateForStringWithLanguage is not bound -!missing-pinvoke! CTGlyphInfoGetGlyph is not bound diff --git a/tests/xtro-sharpie/macOS-CoreText.todo b/tests/xtro-sharpie/macOS-CoreText.todo deleted file mode 100644 index c9149344d2..0000000000 --- a/tests/xtro-sharpie/macOS-CoreText.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-field! kCTFontFeatureSampleTextKey not bound -!missing-field! kCTFontFeatureTooltipTextKey not bound -!missing-pinvoke! CTFontCreateForStringWithLanguage is not bound -!missing-pinvoke! CTGlyphInfoGetGlyph is not bound -!unknown-pinvoke! CTFontManagerCopyRegisteredFontDescriptors bound diff --git a/tests/xtro-sharpie/tvOS-CoreText.todo b/tests/xtro-sharpie/tvOS-CoreText.todo deleted file mode 100644 index c9149344d2..0000000000 --- a/tests/xtro-sharpie/tvOS-CoreText.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-field! kCTFontFeatureSampleTextKey not bound -!missing-field! kCTFontFeatureTooltipTextKey not bound -!missing-pinvoke! CTFontCreateForStringWithLanguage is not bound -!missing-pinvoke! CTGlyphInfoGetGlyph is not bound -!unknown-pinvoke! CTFontManagerCopyRegisteredFontDescriptors bound diff --git a/tests/xtro-sharpie/watchOS-CoreText.todo b/tests/xtro-sharpie/watchOS-CoreText.todo deleted file mode 100644 index c9149344d2..0000000000 --- a/tests/xtro-sharpie/watchOS-CoreText.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-field! kCTFontFeatureSampleTextKey not bound -!missing-field! kCTFontFeatureTooltipTextKey not bound -!missing-pinvoke! CTFontCreateForStringWithLanguage is not bound -!missing-pinvoke! CTGlyphInfoGetGlyph is not bound -!unknown-pinvoke! CTFontManagerCopyRegisteredFontDescriptors bound