Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ward <matt.ward@microsoft.com>2022-04-11 20:33:48 +0300
committerMatt Ward <ward.matt@gmail.com>2022-04-14 13:10:18 +0300
commite9aee053d0bab21b00fe0c85fc1a0c4f03d32542 (patch)
tree0882b55bb5200c38d0695b9345ccaa0b9fc97199
parent40ba4a4ef71f346fab445a40a064147eee1fdff0 (diff)
[Mac] Fix ArgumentNullException when drawing Chinese characters
The TextLayoutBackendHandler did not handle NSFont returning null when trying to get a different weight or size for an NSFont. System.ArgumentNullException: Value cannot be null. (Parameter 'value') at ObjCRuntime.ThrowHelper.ThrowArgumentNullException( String argumentName) in xamarin-macios/src/ObjCRuntime/ ThrowHelper.cs:line 28 at Foundation.NSMutableAttributedString.AddAttribute( NSString attributeName, NSObject value, NSRange range) in xamarin-macios/src/build/dotnet/macos/generated-sources/Foundation/ NSMutableAttributedString.g.cs:line 187 at Xwt.Mac.MacTextLayoutBackendHandler.LayoutInfo. AddAttributeInternal(TextAttribute attribute) in Xwt.XamMac/ Xwt.Mac/TextLayoutBackendHandler.cs:line 210 at Xwt.Mac.MacTextLayoutBackendHandler.LayoutInfo.AddAttribute( TextAttribute attribute) in Xwt.XamMac/Xwt.Mac/ TextLayoutBackendHandler.cs:line 125 at Xwt.Mac.MacTextLayoutBackendHandler.AddAttribute(Object backend, TextAttribute attribute) in Xwt.XamMac/Xwt.Mac/ TextLayoutBackendHandler.cs:line 405 at Xwt.Drawing.TextLayout.set_Markup(String value) Xwt.Drawing/ TextLayout.cs:line 260
-rw-r--r--Xwt.XamMac/Xwt.Mac/TextLayoutBackendHandler.cs10
1 files changed, 6 insertions, 4 deletions
diff --git a/Xwt.XamMac/Xwt.Mac/TextLayoutBackendHandler.cs b/Xwt.XamMac/Xwt.Mac/TextLayoutBackendHandler.cs
index c8fb79a8..ded27931 100644
--- a/Xwt.XamMac/Xwt.Mac/TextLayoutBackendHandler.cs
+++ b/Xwt.XamMac/Xwt.Mac/TextLayoutBackendHandler.cs
@@ -206,8 +206,9 @@ namespace Xwt.Mac
NSRange er;
// get the effective font to modify for the given range
var ft = TextStorage.GetAttribute (NSStringAttributeKey.Font, attribute.StartIndex, out er, r) as NSFont;
- ft = ft.WithWeight (xa.Weight);
- TextStorage.AddAttribute (NSStringAttributeKey.Font, ft, r);
+ ft = ft?.WithWeight (xa.Weight);
+ if (ft != null)
+ TextStorage.AddAttribute (NSStringAttributeKey.Font, ft, r);
}
else if (attribute is LinkTextAttribute)
{
@@ -225,8 +226,9 @@ namespace Xwt.Mac
var xa = (FontSizeTextAttribute)attribute;
NSRange er;
var ft = TextStorage.GetAttribute (NSStringAttributeKey.Font, attribute.StartIndex, out er, r) as NSFont;
- ft = ft.WithSize (xa.Size);
- TextStorage.AddAttribute (NSStringAttributeKey.Font, ft, r);
+ ft = ft?.WithSize (xa.Size);
+ if (ft != null)
+ TextStorage.AddAttribute (NSStringAttributeKey.Font, ft, r);
}
else if (attribute is FontTextAttribute)
{