From 2969672a44ee364582c60c2308e35806cfc05ff8 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 11 Jul 2024 12:20:35 +0200 Subject: [PATCH 1/6] [CoreText] Implement Xcode 16.0 beta 1, beta 2 and beta 3 changes. Note: there were no changes in beta 2 or beta 3. --- src/CoreText/CTFont.cs | 62 ++++++++++++++++++ src/CoreText/CTFontManager.cs | 64 +++++++++++++++++++ src/CoreText/CTStringAttributes.cs | 17 +++++ src/coretext.cs | 18 ++++++ .../Documentation.KnownFailures.txt | 5 ++ tests/monotouch-test/CoreText/FontTest.cs | 36 +++++++++++ .../CoreText/StringAttributes.cs | 26 ++++++++ .../common-CoreText.ignore | 1 - .../api-annotations-dotnet/iOS-CoreText.todo | 6 -- .../macOS-CoreText.todo | 6 -- .../api-annotations-dotnet/tvOS-CoreText.todo | 6 -- tests/xtro-sharpie/iOS-CoreText.todo | 5 -- tests/xtro-sharpie/macOS-CoreText.todo | 5 -- tests/xtro-sharpie/tvOS-CoreText.todo | 5 -- tests/xtro-sharpie/watchOS-CoreText.todo | 5 -- 15 files changed, 228 insertions(+), 39 deletions(-) delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo diff --git a/src/CoreText/CTFont.cs b/src/CoreText/CTFont.cs index 1f521a6b4f0d..94706027ee35 100644 --- a/src/CoreText/CTFont.cs +++ b/src/CoreText/CTFont.cs @@ -2668,6 +2668,68 @@ public CTFontTable [] GetAvailableTables (CTFontTableOptions options) } #endregion + +#if NET + [SupportedOSPlatform ("ios18.0")] + [SupportedOSPlatform ("maccatalyst18.0")] + [SupportedOSPlatform ("macos15.0")] + [SupportedOSPlatform ("tvos18.0")] +#else + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] +#endif + [DllImport (Constants.CoreTextLibrary)] + extern static /* CGRect */ CGRect CTFontGetTypographicBoundsForAdaptiveImageProvider ( + /* CTFontRef */ IntPtr font, + /* id __Nullable */ IntPtr provider); + + /// Computes metrics that clients performing their own typesetting of an adaptive image glyph need. + /// The typographic bounds in points expressed as a rectangle, where the rectangle's Width property corresponds to the advance width, the rectangle's Bottom property corresponds to the ascent (above the baseline), and Top property corresponds to the descent (below the baseline). + /// The adaptive image provider used during the computation. If null, then default results will be returned, on the assumption that an image is not yet available. +#if NET + [SupportedOSPlatform ("ios18.0")] + [SupportedOSPlatform ("maccatalyst18.0")] + [SupportedOSPlatform ("macos15.0")] + [SupportedOSPlatform ("tvos18.0")] +#else + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] +#endif + public CGRect GetTypographicBoundsForAdaptiveImageProvider (ICTAdaptiveImageProviding? provider) + { + return CTFontGetTypographicBoundsForAdaptiveImageProvider (Handle, provider.GetHandle ()); + } + +#if NET + [SupportedOSPlatform ("ios18.0")] + [SupportedOSPlatform ("maccatalyst18.0")] + [SupportedOSPlatform ("macos15.0")] + [SupportedOSPlatform ("tvos18.0")] +#else + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] +#endif + [DllImport (Constants.CoreTextLibrary)] + extern static void CTFontDrawImageFromAdaptiveImageProviderAtPoint ( + /* CTFontRef */ IntPtr font, + /* id __Nullable */ IntPtr provider, + /* CGPoint */ CGPoint point, + /* CGContexRef */ IntPtr context); + + /// Draws the image for an adaptive image glyph at the given point. + /// The adaptive image provider used during the rendering. + /// The adaptive image glyph is rendered relative to this point. + /// The where the adaptive image glyph is drawn. +#if NET + [SupportedOSPlatform ("ios18.0")] + [SupportedOSPlatform ("maccatalyst18.0")] + [SupportedOSPlatform ("macos15.0")] + [SupportedOSPlatform ("tvos18.0")] +#else + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] +#endif + public void DrawImage (ICTAdaptiveImageProviding provider, CGPoint point, CGContext context) + { + CTFontDrawImageFromAdaptiveImageProviderAtPoint (Handle, provider.GetNonNullHandle (nameof (provider)), point, context.GetNonNullHandle (nameof (context))); + } + public override string? ToString () { return FullName; diff --git a/src/CoreText/CTFontManager.cs b/src/CoreText/CTFontManager.cs index 9d349437918d..56a9658ef6cd 100644 --- a/src/CoreText/CTFontManager.cs +++ b/src/CoreText/CTFontManager.cs @@ -442,9 +442,41 @@ public static CTFontDescriptor [] GetFonts (NSUrl url) } } +#if NET + [SupportedOSPlatform ("macos")] + [SupportedOSPlatform ("tvos")] + [SupportedOSPlatform ("ios")] + [SupportedOSPlatform ("maccatalyst")] + [ObsoletedOSPlatform ("macos15.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [ObsoletedOSPlatform ("tvos18.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [ObsoletedOSPlatform ("ios18.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [ObsoletedOSPlatform ("maccatalyst18.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] +#else + [Deprecated (PlatformName.iOS, 18, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.TvOS, 18, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.WatchOS, 11, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] +#endif [DllImport (Constants.CoreTextLibrary)] unsafe static extern byte CTFontManagerRegisterGraphicsFont (IntPtr cgfont, IntPtr* error); +#if NET + [SupportedOSPlatform ("macos")] + [SupportedOSPlatform ("tvos")] + [SupportedOSPlatform ("ios")] + [SupportedOSPlatform ("maccatalyst")] + [ObsoletedOSPlatform ("macos15.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [ObsoletedOSPlatform ("tvos18.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [ObsoletedOSPlatform ("ios18.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [ObsoletedOSPlatform ("maccatalyst18.0", "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] +#else + [Deprecated (PlatformName.iOS, 18, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.TvOS, 18, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] + [Deprecated (PlatformName.WatchOS, 11, 0, message: "Use 'CreateFontDescriptors' or 'RegisterFontsForUrl' instead.")] +#endif public static bool RegisterGraphicsFont (CGFont font, [NotNullWhen (true)] out NSError? error) { if (font is null) @@ -466,9 +498,41 @@ public static bool RegisterGraphicsFont (CGFont font, [NotNullWhen (true)] out N return ret; } +#if NET + [SupportedOSPlatform ("macos")] + [SupportedOSPlatform ("tvos")] + [SupportedOSPlatform ("ios")] + [SupportedOSPlatform ("maccatalyst")] + [ObsoletedOSPlatform ("macos15.0")] + [ObsoletedOSPlatform ("tvos18.0")] + [ObsoletedOSPlatform ("ios18.0")] + [ObsoletedOSPlatform ("maccatalyst18.0")] +#else + [Deprecated (PlatformName.iOS, 18, 0)] + [Deprecated (PlatformName.MacCatalyst, 18, 0)] + [Deprecated (PlatformName.TvOS, 18, 0)] + [Deprecated (PlatformName.MacOSX, 15, 0)] + [Deprecated (PlatformName.WatchOS, 11, 0)] +#endif [DllImport (Constants.CoreTextLibrary)] unsafe static extern byte CTFontManagerUnregisterGraphicsFont (IntPtr cgfont, IntPtr* error); +#if NET + [SupportedOSPlatform ("macos")] + [SupportedOSPlatform ("tvos")] + [SupportedOSPlatform ("ios")] + [SupportedOSPlatform ("maccatalyst")] + [ObsoletedOSPlatform ("macos15.0")] + [ObsoletedOSPlatform ("tvos18.0")] + [ObsoletedOSPlatform ("ios18.0")] + [ObsoletedOSPlatform ("maccatalyst18.0")] +#else + [Deprecated (PlatformName.iOS, 18, 0)] + [Deprecated (PlatformName.MacCatalyst, 18, 0)] + [Deprecated (PlatformName.TvOS, 18, 0)] + [Deprecated (PlatformName.MacOSX, 15, 0)] + [Deprecated (PlatformName.WatchOS, 11, 0)] +#endif public static bool UnregisterGraphicsFont (CGFont font, out NSError? error) { if (font is null) diff --git a/src/CoreText/CTStringAttributes.cs b/src/CoreText/CTStringAttributes.cs index bf16f2b64347..9cdc7e25ce0f 100644 --- a/src/CoreText/CTStringAttributes.cs +++ b/src/CoreText/CTStringAttributes.cs @@ -424,5 +424,22 @@ public void SetWritingDirection (params CTWritingDirection [] writingDirections) CFMutableDictionary.SetValue (Dictionary.Handle, CTStringAttributeKey.WritingDirection.GetHandle (), array); GC.KeepAlive (numbers); // make sure the numbers aren't freed until we're done with them } + +#if NET + [SupportedOSPlatform ("ios18.0")] + [SupportedOSPlatform ("maccatalyst18.0")] + [SupportedOSPlatform ("macos15.0")] + [SupportedOSPlatform ("tvos18.0")] + // The attribute value must be an object conforming to the CTAdaptiveImageProviding protocol. + public ICTAdaptiveImageProviding? AdaptiveImageProvider { + get { + var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.AdaptiveImageProvider.GetHandle ()); + return Runtime.GetINativeObject (h, owns: false); + } + set { + Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.AdaptiveImageProvider!, value); + } + } +#endif } } diff --git a/src/coretext.cs b/src/coretext.cs index ae417afd281b..9381e67ec013 100644 --- a/src/coretext.cs +++ b/src/coretext.cs @@ -8,6 +8,8 @@ // using System; + +using CoreGraphics; using Foundation; using ObjCRuntime; @@ -444,6 +446,13 @@ interface CTStringAttributeKey { [Field ("kCTWritingDirectionAttributeName")] NSString WritingDirection { get; } + + [Field ("kCTRubyAnnotationAttributeName")] + NSString RubyAnnotation { get; } + + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] + [Field ("kCTAdaptiveImageProviderAttributeName")] + NSString AdaptiveImageProvider { get; } #endif [Watch (6, 0), TV (13, 0), iOS (13, 0)] @@ -451,4 +460,13 @@ interface CTStringAttributeKey { [Field ("kCTTrackingAttributeName")] NSString TrackingAttributeName { get; } } + + [Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)] + [Protocol (BackwardsCompatibleCodeGeneration = false)] + interface CTAdaptiveImageProviding { + [Abstract] + [Export ("imageForProposedSize:scaleFactor:imageOffset:imageSize:")] + [return: NullAllowed] + CGImage GetImage (CGSize proposedSize, nfloat scaleFactor, out CGPoint imageOffset, out CGSize imageSize); + } } diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index af9bc49c35a3..3cd68b7f8be7 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -33012,6 +33012,7 @@ M:CoreText.CTTypesetter.SuggestLineBreak(System.Int32,System.Double,System.Doubl M:CoreText.CTTypesetter.SuggestLineBreak(System.Int32,System.Double) M:CoreText.CTTypesetterOptions.#ctor M:CoreText.CTTypesetterOptions.#ctor(Foundation.NSDictionary) +M:CoreText.ICTAdaptiveImageProviding.GetImage(CoreGraphics.CGSize,System.Runtime.InteropServices.NFloat,CoreGraphics.CGPoint@,CoreGraphics.CGSize@) M:CoreVideo.CVBuffer.GetAttachment(Foundation.NSString,CoreVideo.CVAttachmentMode@) M:CoreVideo.CVBuffer.GetAttachment``1(Foundation.NSString,CoreVideo.CVAttachmentMode@) M:CoreVideo.CVBuffer.GetAttachments(CoreVideo.CVAttachmentMode) @@ -63382,6 +63383,7 @@ P:CoreText.CTRun.StringRange P:CoreText.CTRun.TextMatrix P:CoreText.CTRunDelegate.Operations P:CoreText.CTRunDelegateOperations.Handle +P:CoreText.CTStringAttributeKey.AdaptiveImageProvider P:CoreText.CTStringAttributeKey.BackgroundColor P:CoreText.CTStringAttributeKey.BaselineClass P:CoreText.CTStringAttributeKey.BaselineInfo @@ -63396,6 +63398,7 @@ P:CoreText.CTStringAttributeKey.HorizontalInVerticalForms P:CoreText.CTStringAttributeKey.KerningAdjustment P:CoreText.CTStringAttributeKey.LigatureFormation P:CoreText.CTStringAttributeKey.ParagraphStyle +P:CoreText.CTStringAttributeKey.RubyAnnotation P:CoreText.CTStringAttributeKey.RunDelegate P:CoreText.CTStringAttributeKey.StrokeColor P:CoreText.CTStringAttributeKey.StrokeWidth @@ -63405,6 +63408,7 @@ P:CoreText.CTStringAttributeKey.UnderlineColor P:CoreText.CTStringAttributeKey.UnderlineStyle P:CoreText.CTStringAttributeKey.VerticalForms P:CoreText.CTStringAttributeKey.WritingDirection +P:CoreText.CTStringAttributes.AdaptiveImageProvider P:CoreText.CTStringAttributes.BackgroundColor P:CoreText.CTStringAttributes.BaselineClass P:CoreText.CTStringAttributes.BaselineOffset @@ -78985,6 +78989,7 @@ T:CoreText.CTUnderlineStyle T:CoreText.CTUnderlineStyleModifiers T:CoreText.CTWritingDirection T:CoreText.FontFeatureGroup +T:CoreText.ICTAdaptiveImageProviding T:CoreVideo.CVDisplayLink T:CoreVideo.CVDisplayLink.DisplayLinkOutputCallback T:CoreVideo.CVFillExtendedPixelsCallBack diff --git a/tests/monotouch-test/CoreText/FontTest.cs b/tests/monotouch-test/CoreText/FontTest.cs index 7a1191f97939..1e761bd8d170 100644 --- a/tests/monotouch-test/CoreText/FontTest.cs +++ b/tests/monotouch-test/CoreText/FontTest.cs @@ -129,5 +129,41 @@ public void CTFontCopyNameForGlyph () using (var ctfont = font.ToCTFont ((nfloat) 10.0)) Assert.Null (ctfont.GetGlyphName ('\ud83d'), "2"); } + + [Test] + public void DrawImage () + { + TestRuntime.AssertXcodeVersion (16, 0); + + using var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default); + using var provider = new AdaptiveImageProvider (); + using var space = CGColorSpace.CreateDeviceRGB (); + using var context = new CGBitmapContext (null, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast); + font.DrawImage (provider, CGPoint.Empty, context); + Assert.AreEqual (1, provider.Count, "#Count"); + } + + [Test] + public void GetTypographicBoundsForAdaptiveImageProvider () + { + TestRuntime.AssertXcodeVersion (16, 0); + + using var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default); + using var provider = new AdaptiveImageProvider (); + var bounds = font.GetTypographicBoundsForAdaptiveImageProvider (provider); + Assert.AreEqual (CGRect.Empty, bounds, "Bounds"); + Assert.AreEqual (1, provider.Count, "#Count"); + } + + class AdaptiveImageProvider : NSObject, ICTAdaptiveImageProviding { + public int Count; + public CGImage? GetImage (CGSize proposedSize, nfloat scaleFactor, out CGPoint imageOffset, out CGSize imageSize) + { + imageOffset = default (CGPoint); + imageSize = default (CGSize); + Count++; + return null; + } + } } } diff --git a/tests/monotouch-test/CoreText/StringAttributes.cs b/tests/monotouch-test/CoreText/StringAttributes.cs index b93b54f9437b..dc96dc39d9be 100644 --- a/tests/monotouch-test/CoreText/StringAttributes.cs +++ b/tests/monotouch-test/CoreText/StringAttributes.cs @@ -49,6 +49,10 @@ public void SimpleValuesSet () if (TestRuntime.CheckXcodeVersion (11, 0)) sa.TrackingAdjustment = 1.0f; + AdaptiveImageProvider? provider = null; + if (TestRuntime.CheckXcodeVersion (16, 0)) + sa.AdaptiveImageProvider = provider = new AdaptiveImageProvider (); + var size = new CGSize (300, 300); UIGraphics.BeginImageContext (size); var gctx = UIGraphics.GetCurrentContext (); @@ -61,6 +65,17 @@ public void SimpleValuesSet () textLine.Draw (gctx); } + if (TestRuntime.CheckXcodeVersion (16, 0)) + Assert.AreEqual (0, provider!.Count, "AdaptiveImageProvider #0"); + + attributedString = new NSAttributedString ("🙈`", sa); + using (var textLine = new CTLine (attributedString)) { + textLine.Draw (gctx); + } + + if (TestRuntime.CheckXcodeVersion (16, 0)) + Assert.AreEqual (1, provider!.Count, "AdaptiveImageProvider #1"); + UIGraphics.EndImageContext (); } #endif @@ -81,4 +96,15 @@ public void HorizontalInVerticalForms () Assert.DoesNotThrow (() => { var x = sa.HorizontalInVerticalForms; }, "#1"); } } + + class AdaptiveImageProvider : NSObject, ICTAdaptiveImageProviding { + public int Count; + public CGImage? GetImage (CGSize proposedSize, nfloat scaleFactor, out CGPoint imageOffset, out CGSize imageSize) + { + imageOffset = default (CGPoint); + imageSize = default (CGSize); + Count++; + return null; + } + } } diff --git a/tests/xtro-sharpie/api-annotations-dotnet/common-CoreText.ignore b/tests/xtro-sharpie/api-annotations-dotnet/common-CoreText.ignore index 58153965d318..32312d209095 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/common-CoreText.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/common-CoreText.ignore @@ -10,7 +10,6 @@ !missing-field! kCTFontOpenTypeFeatureTag not bound !missing-field! kCTFontOpenTypeFeatureValue not bound !missing-field! kCTLanguageAttributeName not bound -!missing-field! kCTRubyAnnotationAttributeName not bound !missing-field! kCTRubyAnnotationScaleToFitAttributeName not bound !missing-field! kCTRubyAnnotationSizeFactorAttributeName not bound !missing-field! kCTFontOpticalSizeAttribute not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo deleted file mode 100644 index 9cd31ac34b8a..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo +++ /dev/null @@ -1,6 +0,0 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo deleted file mode 100644 index 9cd31ac34b8a..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo +++ /dev/null @@ -1,6 +0,0 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo deleted file mode 100644 index 9cd31ac34b8a..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo +++ /dev/null @@ -1,6 +0,0 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound diff --git a/tests/xtro-sharpie/iOS-CoreText.todo b/tests/xtro-sharpie/iOS-CoreText.todo index 9cd31ac34b8a..97d5b47fd79a 100644 --- a/tests/xtro-sharpie/iOS-CoreText.todo +++ b/tests/xtro-sharpie/iOS-CoreText.todo @@ -1,6 +1 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute !missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound diff --git a/tests/xtro-sharpie/macOS-CoreText.todo b/tests/xtro-sharpie/macOS-CoreText.todo index 9cd31ac34b8a..97d5b47fd79a 100644 --- a/tests/xtro-sharpie/macOS-CoreText.todo +++ b/tests/xtro-sharpie/macOS-CoreText.todo @@ -1,6 +1 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute !missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound diff --git a/tests/xtro-sharpie/tvOS-CoreText.todo b/tests/xtro-sharpie/tvOS-CoreText.todo index 9cd31ac34b8a..97d5b47fd79a 100644 --- a/tests/xtro-sharpie/tvOS-CoreText.todo +++ b/tests/xtro-sharpie/tvOS-CoreText.todo @@ -1,6 +1 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute !missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound diff --git a/tests/xtro-sharpie/watchOS-CoreText.todo b/tests/xtro-sharpie/watchOS-CoreText.todo index 9cd31ac34b8a..97d5b47fd79a 100644 --- a/tests/xtro-sharpie/watchOS-CoreText.todo +++ b/tests/xtro-sharpie/watchOS-CoreText.todo @@ -1,6 +1 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute !missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound From ab468199560daceaaba7f434a3649a2dd16bdeda Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 12 Aug 2024 16:11:36 +0200 Subject: [PATCH 2/6] [CoreText] Update to beta 5. --- src/CoreText/CTFont.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/CoreText/CTFont.cs b/src/CoreText/CTFont.cs index 94706027ee35..e181853edba3 100644 --- a/src/CoreText/CTFont.cs +++ b/src/CoreText/CTFont.cs @@ -2730,6 +2730,37 @@ public void DrawImage (ICTAdaptiveImageProviding provider, CGPoint point, CGCont CTFontDrawImageFromAdaptiveImageProviderAtPoint (Handle, provider.GetNonNullHandle (nameof (provider)), point, context.GetNonNullHandle (nameof (context))); } +#if NET + [SupportedOSPlatform ("ios13.0")] + [SupportedOSPlatform ("maccatalyst")] + [SupportedOSPlatform ("macos10.15")] + [SupportedOSPlatform ("tvos13.0")] +#else + [Watch (6, 0), TV (13, 0), Mac (10, 15), iOS (13, 0), MacCatalyst (13, 0)] +#endif + [DllImport (Constants.CoreTextLibrary)] + extern static byte CTFontHasTable ( + /* CTFontRef */ IntPtr font, + /* CTFontTableTag */ CTFontTable tag); + + /// Checks whether a table is present in a font. + /// The table identifier to check for. + /// Whether the table is present in the font or not. + /// The check behaves as if was specified. +#if NET + [SupportedOSPlatform ("ios13.0")] + [SupportedOSPlatform ("maccatalyst")] + [SupportedOSPlatform ("macos10.15")] + [SupportedOSPlatform ("tvos13.0")] +#else + [Watch (6, 0), TV (13, 0), Mac (10, 15), iOS (13, 0), MacCatalyst (13, 0)] +#endif + public bool HasTable (CTFontTable tag) + { + return CTFontHasTable (GetCheckedHandle (), tag) != 0; + } + + public override string? ToString () { return FullName; From c2635d7266fdcf0423fb2fc5443e850bbdfc872d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 12 Aug 2024 17:25:20 +0200 Subject: [PATCH 3/6] Misc test fixes. --- src/CoreText/CTFont.cs | 8 ++++---- tests/monotouch-test/CoreText/FontTest.cs | 4 +++- tests/monotouch-test/CoreText/StringAttributes.cs | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/CoreText/CTFont.cs b/src/CoreText/CTFont.cs index e181853edba3..b6b0bacc164d 100644 --- a/src/CoreText/CTFont.cs +++ b/src/CoreText/CTFont.cs @@ -2733,10 +2733,10 @@ public void DrawImage (ICTAdaptiveImageProviding provider, CGPoint point, CGCont #if NET [SupportedOSPlatform ("ios13.0")] [SupportedOSPlatform ("maccatalyst")] - [SupportedOSPlatform ("macos10.15")] + [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("tvos13.0")] #else - [Watch (6, 0), TV (13, 0), Mac (10, 15), iOS (13, 0), MacCatalyst (13, 0)] + [Watch (6, 0), TV (13, 0), iOS (13, 0), MacCatalyst (13, 0)] #endif [DllImport (Constants.CoreTextLibrary)] extern static byte CTFontHasTable ( @@ -2750,10 +2750,10 @@ extern static byte CTFontHasTable ( #if NET [SupportedOSPlatform ("ios13.0")] [SupportedOSPlatform ("maccatalyst")] - [SupportedOSPlatform ("macos10.15")] + [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("tvos13.0")] #else - [Watch (6, 0), TV (13, 0), Mac (10, 15), iOS (13, 0), MacCatalyst (13, 0)] + [Watch (6, 0), TV (13, 0), iOS (13, 0), MacCatalyst (13, 0)] #endif public bool HasTable (CTFontTable tag) { diff --git a/tests/monotouch-test/CoreText/FontTest.cs b/tests/monotouch-test/CoreText/FontTest.cs index 1e761bd8d170..085dde52a88b 100644 --- a/tests/monotouch-test/CoreText/FontTest.cs +++ b/tests/monotouch-test/CoreText/FontTest.cs @@ -32,6 +32,8 @@ public void CTFontCreateWithNameAndOptions () using (var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default)) { Assert.That (font.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle"); + if (TestRuntime.CheckXcodeVersion (11, 0)) + Assert.That (font.HasTable (CTFontTable.ScalableVectorGraphics), Is.EqualTo (false), "HasTable"); } } @@ -151,7 +153,7 @@ public void GetTypographicBoundsForAdaptiveImageProvider () using var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default); using var provider = new AdaptiveImageProvider (); var bounds = font.GetTypographicBoundsForAdaptiveImageProvider (provider); - Assert.AreEqual (CGRect.Empty, bounds, "Bounds"); + Assert.AreEqual (new CGRect (0, -3.90625, 13, 16.40625), bounds, "Bounds"); Assert.AreEqual (1, provider.Count, "#Count"); } diff --git a/tests/monotouch-test/CoreText/StringAttributes.cs b/tests/monotouch-test/CoreText/StringAttributes.cs index dc96dc39d9be..049196ae4455 100644 --- a/tests/monotouch-test/CoreText/StringAttributes.cs +++ b/tests/monotouch-test/CoreText/StringAttributes.cs @@ -50,8 +50,10 @@ public void SimpleValuesSet () sa.TrackingAdjustment = 1.0f; AdaptiveImageProvider? provider = null; +#if NET if (TestRuntime.CheckXcodeVersion (16, 0)) sa.AdaptiveImageProvider = provider = new AdaptiveImageProvider (); +#endif var size = new CGSize (300, 300); UIGraphics.BeginImageContext (size); @@ -65,6 +67,7 @@ public void SimpleValuesSet () textLine.Draw (gctx); } +#if NET if (TestRuntime.CheckXcodeVersion (16, 0)) Assert.AreEqual (0, provider!.Count, "AdaptiveImageProvider #0"); @@ -75,6 +78,7 @@ public void SimpleValuesSet () if (TestRuntime.CheckXcodeVersion (16, 0)) Assert.AreEqual (1, provider!.Count, "AdaptiveImageProvider #1"); +#endif UIGraphics.EndImageContext (); } From f592d522004ce6ef423ee0bdf5282587b8d1a308 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 12 Aug 2024 19:57:33 +0200 Subject: [PATCH 4/6] A few more APIs --- src/CoreText/CTFontDescriptor.cs | 11 +++++++++++ src/CoreText/CTFontManager.cs | 2 +- src/coretext.cs | 4 ++++ tests/cecil-tests/Documentation.KnownFailures.txt | 2 ++ .../api-annotations-dotnet/MacCatalyst-CoreText.todo | 9 --------- .../api-annotations-dotnet/iOS-CoreText.ignore | 2 -- .../api-annotations-dotnet/iOS-CoreText.todo | 7 ------- .../api-annotations-dotnet/macOS-CoreText.todo | 7 ------- .../api-annotations-dotnet/tvOS-CoreText.todo | 7 ------- 9 files changed, 18 insertions(+), 33 deletions(-) delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreText.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.ignore delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo diff --git a/src/CoreText/CTFontDescriptor.cs b/src/CoreText/CTFontDescriptor.cs index 066de79318d4..b61e862f5b0e 100644 --- a/src/CoreText/CTFontDescriptor.cs +++ b/src/CoreText/CTFontDescriptor.cs @@ -401,6 +401,17 @@ public bool Enabled { } } #endif // !XAMCORE_5_0 + +#if NET && (__IOS__ || __MACCATALYST__) + [SupportedOSPlatform ("ios13.0")] + [UnsupportedOSPlatform ("tvos")] + [SupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("macos")] + public string? RegistrationUserInfo { + get { return Adapter.GetStringValue (Dictionary, CTFontDescriptorAttributeKey.RegistrationUserInfo); } + set { Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.RegistrationUserInfo!, value); } + } +#endif } #if NET diff --git a/src/CoreText/CTFontManager.cs b/src/CoreText/CTFontManager.cs index 56a9658ef6cd..2dd5c5e0e300 100644 --- a/src/CoreText/CTFontManager.cs +++ b/src/CoreText/CTFontManager.cs @@ -60,7 +60,7 @@ public enum CTFontManagerScope : uint { #endif Persistent = 2, #if NET - [SupportedOSPlatform ("maccatalyst")] + [UnsupportedOSPlatform ("maccatalyst")] [SupportedOSPlatform ("macos")] [UnsupportedOSPlatform ("ios")] [UnsupportedOSPlatform ("tvos")] diff --git a/src/coretext.cs b/src/coretext.cs index 9381e67ec013..aadb0a85e75a 100644 --- a/src/coretext.cs +++ b/src/coretext.cs @@ -226,6 +226,10 @@ interface CTFontDescriptorAttributeKey { [Field ("kCTFontEnabledAttribute")] NSString Enabled { get; } + + [iOS (13, 0), NoTV, NoWatch, MacCatalyst (13, 1), NoMac] + [Field ("kCTFontRegistrationUserInfoAttribute")] + NSString RegistrationUserInfo { get; } } /// A class whose static properties can be used as keys for the used by . diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index 9a960685ff1e..e28284ba95ea 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -63656,6 +63656,7 @@ P:CoreText.CTFontDescriptorAttributeKey.Matrix P:CoreText.CTFontDescriptorAttributeKey.Name P:CoreText.CTFontDescriptorAttributeKey.Priority P:CoreText.CTFontDescriptorAttributeKey.RegistrationScope +P:CoreText.CTFontDescriptorAttributeKey.RegistrationUserInfo P:CoreText.CTFontDescriptorAttributeKey.Size P:CoreText.CTFontDescriptorAttributeKey.StyleName P:CoreText.CTFontDescriptorAttributeKey.Traits @@ -63679,6 +63680,7 @@ P:CoreText.CTFontDescriptorAttributes.Matrix P:CoreText.CTFontDescriptorAttributes.Name P:CoreText.CTFontDescriptorAttributes.Priority P:CoreText.CTFontDescriptorAttributes.RegistrationScope +P:CoreText.CTFontDescriptorAttributes.RegistrationUserInfo P:CoreText.CTFontDescriptorAttributes.Size P:CoreText.CTFontDescriptorAttributes.StyleName P:CoreText.CTFontDescriptorAttributes.Traits diff --git a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreText.todo deleted file mode 100644 index 91b6072439a6..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreText.todo +++ /dev/null @@ -1,9 +0,0 @@ -!missing-field! kCTFontRegistrationUserInfoAttribute not bound -!extra-enum-value! Managed value 3 for CTFontManagerScope.Session is available for the current platform while the value in the native header is not -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound -!missing-pinvoke! CTFontHasTable is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.ignore b/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.ignore deleted file mode 100644 index beb8a39d8595..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.ignore +++ /dev/null @@ -1,2 +0,0 @@ -## related (only usage) to unbound `CTFontManagerRegisterFontDescriptors` p/invoke -!missing-field! kCTFontRegistrationUserInfoAttribute not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo deleted file mode 100644 index cbac7e0e1100..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo +++ /dev/null @@ -1,7 +0,0 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound -!missing-pinvoke! CTFontHasTable is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo deleted file mode 100644 index cbac7e0e1100..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo +++ /dev/null @@ -1,7 +0,0 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound -!missing-pinvoke! CTFontHasTable is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo b/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo deleted file mode 100644 index cbac7e0e1100..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo +++ /dev/null @@ -1,7 +0,0 @@ -!deprecated-attribute-missing! CTFontManagerRegisterGraphicsFont missing a [Deprecated] attribute -!deprecated-attribute-missing! CTFontManagerUnregisterGraphicsFont missing a [Deprecated] attribute -!missing-field! kCTAdaptiveImageProviderAttributeName not bound -!missing-pinvoke! CTFontDrawImageFromAdaptiveImageProviderAtPoint is not bound -!missing-pinvoke! CTFontGetTypographicBoundsForAdaptiveImageProvider is not bound -!missing-protocol! CTAdaptiveImageProviding not bound -!missing-pinvoke! CTFontHasTable is not bound From 3ce87a357bbd17aeedba9ea9815e9a00c103c79b Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 14 Aug 2024 15:57:54 +0200 Subject: [PATCH 5/6] Fix test --- tests/monotouch-test/CoreText/FontTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/monotouch-test/CoreText/FontTest.cs b/tests/monotouch-test/CoreText/FontTest.cs index 085dde52a88b..a94a58dd3184 100644 --- a/tests/monotouch-test/CoreText/FontTest.cs +++ b/tests/monotouch-test/CoreText/FontTest.cs @@ -154,7 +154,7 @@ public void GetTypographicBoundsForAdaptiveImageProvider () using var provider = new AdaptiveImageProvider (); var bounds = font.GetTypographicBoundsForAdaptiveImageProvider (provider); Assert.AreEqual (new CGRect (0, -3.90625, 13, 16.40625), bounds, "Bounds"); - Assert.AreEqual (1, provider.Count, "#Count"); + Assert.AreEqual (0, provider.Count, "#Count"); } class AdaptiveImageProvider : NSObject, ICTAdaptiveImageProviding { From cc5695fbd52f2d18420fcb181d8f09d0dca4b02a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 19 Aug 2024 17:35:50 +0200 Subject: [PATCH 6/6] Exclude test from watchOS. --- tests/monotouch-test/CoreText/FontTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/monotouch-test/CoreText/FontTest.cs b/tests/monotouch-test/CoreText/FontTest.cs index a94a58dd3184..3bfa4e33506f 100644 --- a/tests/monotouch-test/CoreText/FontTest.cs +++ b/tests/monotouch-test/CoreText/FontTest.cs @@ -145,6 +145,7 @@ public void DrawImage () Assert.AreEqual (1, provider.Count, "#Count"); } +#if !__WATCHOS__ [Test] public void GetTypographicBoundsForAdaptiveImageProvider () { @@ -156,6 +157,7 @@ public void GetTypographicBoundsForAdaptiveImageProvider () Assert.AreEqual (new CGRect (0, -3.90625, 13, 16.40625), bounds, "Bounds"); Assert.AreEqual (0, provider.Count, "#Count"); } +#endif // !__WATCHOS__ class AdaptiveImageProvider : NSObject, ICTAdaptiveImageProviding { public int Count;