Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/CoreText/CTFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTAdaptiveImageProviding> __Nullable */ IntPtr provider);

/// <summary>Computes metrics that clients performing their own typesetting of an adaptive image glyph need.</summary>
/// <returns>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).</returns>
/// <param name="provider">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.</param>
#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<CTAdaptiveImageProviding> __Nullable */ IntPtr provider,
/* CGPoint */ CGPoint point,
/* CGContexRef */ IntPtr context);

/// <summary>Draws the image for an adaptive image glyph at the given point.</summary>
/// <param name="provider">The adaptive image provider used during the rendering.</param>
/// <param name="point">The adaptive image glyph is rendered relative to this point.</param>
/// <param name="context">The <see cref="CoreGraphics.CGBitmapContext" /> where the adaptive image glyph is drawn.</param>
#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;
Expand Down
64 changes: 64 additions & 0 deletions src/CoreText/CTFontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/CoreText/CTStringAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICTAdaptiveImageProviding> (h, owns: false);
}
set {
Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.AdaptiveImageProvider!, value);
}
}
#endif
}
}
18 changes: 18 additions & 0 deletions src/coretext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//

using System;

using CoreGraphics;
using Foundation;
using ObjCRuntime;

Expand Down Expand Up @@ -444,11 +446,27 @@ 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)]
[MacCatalyst (13, 1)]
[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);
}
}
5 changes: 5 additions & 0 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33247,6 +33247,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)
Expand Down Expand Up @@ -63831,6 +63832,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
Expand All @@ -63845,6 +63847,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
Expand All @@ -63854,6 +63857,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
Expand Down Expand Up @@ -79533,6 +79537,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
Expand Down
36 changes: 36 additions & 0 deletions tests/monotouch-test/CoreText/FontTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
26 changes: 26 additions & 0 deletions tests/monotouch-test/CoreText/StringAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreText.todo

This file was deleted.

6 changes: 0 additions & 6 deletions tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreText.todo

This file was deleted.

6 changes: 0 additions & 6 deletions tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreText.todo

This file was deleted.

5 changes: 0 additions & 5 deletions tests/xtro-sharpie/iOS-CoreText.todo
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions tests/xtro-sharpie/macOS-CoreText.todo
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions tests/xtro-sharpie/tvOS-CoreText.todo
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions tests/xtro-sharpie/watchOS-CoreText.todo
Original file line number Diff line number Diff line change
@@ -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