Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
127 changes: 66 additions & 61 deletions src/Foundation/NSMutableAttributedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,108 +33,113 @@

using CoreText;

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

namespace Foundation {

public partial class NSMutableAttributedString {

/// <param name="str">C# string.</param>
/// <param name="attributes">CoreText attributes to be applied to the string.</param>
/// <summary>Creates an NSMutableAttributedString from a C# string and applies the specified CoreText attributes to the entire string.</summary>
/// <remarks>
/// </remarks>
public NSMutableAttributedString (string str, CTStringAttributes attributes)
: this (str, attributes is null ? null : attributes.Dictionary)
/// <summary>
/// Creates an NSMutableAttributedString from a C# string and applies the specified CoreText attributes to the entire string.
/// </summary>
/// <param name="str">The string content.</param>
/// <param name="attributes">CoreText attributes to be applied to the string.</param>
public NSMutableAttributedString (string str, CTStringAttributes? attributes)
: this (str, attributes?.Dictionary)
{
}

/// <param name="attributes">To be added.</param>
/// <param name="range">Range to which the attribute will be applied.</param>
/// <summary>Sets the attributes for the specified ranges. Any previous attributes in that range are replaces with the new values.</summary>
/// <remarks>
/// </remarks>
/// <summary>
/// Sets the attributes for the specified range. Any previous attributes in that range are replaced with the new values.
/// </summary>
/// <param name="attributes">The attributes to set.</param>
/// <param name="range">The range to which the attributes will be applied.</param>
public void SetAttributes (NSDictionary attributes, NSRange range)
{
if (attributes is null)
throw new ArgumentNullException ("attributes");
ArgumentNullException.ThrowIfNull (attributes);

LowLevelSetAttributes (attributes.Handle, range);
GC.KeepAlive (attributes);
}

/// <summary>
/// Sets the attributes for the specified range. Any previous attributes in that range are replaced with the new values.
/// </summary>
/// <param name="attrs">CoreText attributes to be set on the string.</param>
/// <param name="range">Range to which the attribute will be applied.</param>
/// <summary>Sets the attributes for the specified ranges. Any previous attributes in that range are replaces with the new values.</summary>
/// <remarks>
/// </remarks>
/// <param name="range">The range to which the attributes will be applied.</param>
public void SetAttributes (CTStringAttributes attrs, NSRange range)
{
SetAttributes (attrs is null ? null : attrs.Dictionary, range);
ArgumentNullException.ThrowIfNull (attrs);

SetAttributes (attrs.Dictionary, range);
}

/// <summary>
/// Adds attributes to the specified range of characters in the string.
/// </summary>
/// <param name="attrs">The CoreText attributes to add.</param>
/// <param name="range">Range to which the attribute will be applied.</param>
/// <summary>Adds an attribute and its value to the specified range of characters in the string.</summary>
/// <remarks>
/// </remarks>
/// <param name="range">The range to which the attributes will be applied.</param>
public void AddAttributes (CTStringAttributes attrs, NSRange range)
{
AddAttributes (attrs is null ? null : attrs.Dictionary, range);
ArgumentNullException.ThrowIfNull (attrs);

AddAttributes (attrs.Dictionary, range);
}

/// <param name="first">To be added.</param>
/// <param name="rest">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
/// <summary>
/// Appends an attributed string and additional objects to the end of the receiver.
/// </summary>
/// <param name="first">The first attributed string to append.</param>
/// <param name="rest">Additional objects to append. Can be <see cref="NSAttributedString"/>, <see cref="string"/>, or other objects whose <see cref="object.ToString"/> method will be called.</param>
public void Append (NSAttributedString first, params object [] rest)
{
Append (first);
foreach (var obj in rest) {
if (obj is NSAttributedString)
Append ((NSAttributedString) obj);
else if (obj is string)
Append (new NSAttributedString ((string) obj));
if (obj is NSAttributedString nsAttributedString)
Append (nsAttributedString);
else if (obj is string str)
Append (new NSAttributedString (str));
else
Append (new NSAttributedString (obj.ToString ()));
Append (new NSAttributedString (obj.ToString () ?? ""));

}
}
#if !MONOMAC
/// <param name="str">To be added.</param>
/// <param name="attributes">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
public NSMutableAttributedString (string str, UIStringAttributes attributes)
: this (str, attributes is not null ? attributes.Dictionary : null)
/// <summary>
/// Creates an NSMutableAttributedString from a string with UIKit attributes.
/// </summary>
/// <param name="str">The string content.</param>
/// <param name="attributes">UIKit attributes to be applied to the string.</param>
public NSMutableAttributedString (string str, UIStringAttributes? attributes)
: this (str, attributes?.Dictionary)
{
}

/// <param name="str">To be added.</param>
/// <param name="font">To be added.</param>
/// <param name="foregroundColor">To be added.</param>
/// <param name="backgroundColor">To be added.</param>
/// <param name="strokeColor">To be added.</param>
/// <param name="paragraphStyle">To be added.</param>
/// <param name="ligatures">To be added.</param>
/// <param name="kerning">To be added.</param>
/// <param name="underlineStyle">To be added.</param>
/// <param name="shadow">To be added.</param>
/// <param name="strokeWidth">To be added.</param>
/// <param name="strikethroughStyle">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
/// <summary>
/// Creates an NSMutableAttributedString from a string with individual UIKit styling attributes.
/// </summary>
/// <param name="str">The string content.</param>
/// <param name="font">The font to apply to the string.</param>
/// <param name="foregroundColor">The foreground (text) color.</param>
/// <param name="backgroundColor">The background color.</param>
/// <param name="strokeColor">The stroke color for outlined text.</param>
/// <param name="paragraphStyle">The paragraph style to apply.</param>
/// <param name="ligatures">The ligature type to use.</param>
/// <param name="kerning">The kerning value to apply.</param>
/// <param name="underlineStyle">The underline style to apply.</param>
/// <param name="shadow">The shadow effect to apply.</param>
/// <param name="strokeWidth">The stroke width for outlined text.</param>
/// <param name="strikethroughStyle">The strikethrough style to apply.</param>
public NSMutableAttributedString (string str,
UIFont font = null,
UIColor foregroundColor = null,
UIColor backgroundColor = null,
UIColor strokeColor = null,
NSParagraphStyle paragraphStyle = null,
UIFont? font = null,
UIColor? foregroundColor = null,
UIColor? backgroundColor = null,
UIColor? strokeColor = null,
NSParagraphStyle? paragraphStyle = null,
NSLigatureType ligatures = NSLigatureType.Default,
float kerning = 0,
NSUnderlineStyle underlineStyle = NSUnderlineStyle.None,
NSShadow shadow = null,
NSShadow? shadow = null,
float strokeWidth = 0,
NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None)
: this (str, ToDictionary (font, foregroundColor, backgroundColor, strokeColor, paragraphStyle, ligatures, kerning, underlineStyle, shadow, strokeWidth, strikethroughStyle))
Expand Down
29 changes: 17 additions & 12 deletions src/Foundation/NSMutableAttributedString.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@
using UIKit;
using CoreText;

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

namespace Foundation {

public partial class NSMutableAttributedString {
/// <param name="attrs">To be added.</param>
/// <param name="range">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
/// <summary>
/// Sets the attributes for the specified range. Any previous attributes in that range are replaced with the new values.
/// </summary>
/// <param name="attrs">The UIKit attributes to set.</param>
/// <param name="range">The range to which the attributes will be applied.</param>
public void SetAttributes (UIStringAttributes attrs, NSRange range)
{
SetAttributes (attrs is null ? null : attrs.Dictionary, range);
ArgumentNullException.ThrowIfNull (attrs);

SetAttributes (attrs.Dictionary, range);
}

/// <param name="attrs">To be added.</param>
/// <param name="range">To be added.</param>
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
/// <summary>
/// Adds attributes to the specified range of characters in the string.
/// </summary>
/// <param name="attrs">The UIKit attributes to add.</param>
/// <param name="range">The range to which the attributes will be applied.</param>
public void AddAttributes (UIStringAttributes attrs, NSRange range)
{
AddAttributes (attrs is null ? null : attrs.Dictionary, range);
ArgumentNullException.ThrowIfNull (attrs);

AddAttributes (attrs.Dictionary, range);
}

}
Expand Down
Loading