2021-08-11 11:06:46 +03:00
|
|
|
//
|
2016-05-26 16:06:52 +03:00
|
|
|
// Unit tests for CTFont
|
|
|
|
//
|
|
|
|
// Authors:
|
|
|
|
// Sebastien Pouliot <sebastien@xamarin.com>
|
|
|
|
//
|
|
|
|
// Copyright 2015 Xamarin Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using CoreGraphics;
|
|
|
|
using CoreText;
|
|
|
|
using Foundation;
|
2020-06-26 21:02:44 +03:00
|
|
|
using ObjCRuntime;
|
2017-01-12 21:13:56 +03:00
|
|
|
#if MONOMAC
|
|
|
|
using AppKit;
|
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
using UIKit;
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.CoreText {
|
2022-11-10 19:59:26 +03:00
|
|
|
|
2016-05-26 16:06:52 +03:00
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
2019-08-07 20:07:42 +03:00
|
|
|
public class FontTest {
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CTFontCreateWithNameAndOptions ()
|
|
|
|
{
|
2022-11-10 19:59:26 +03:00
|
|
|
TestRuntime.AssertXcodeVersion (5, 0);
|
2016-07-16 01:10:30 +03:00
|
|
|
|
|
|
|
using (var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default)) {
|
|
|
|
Assert.That (font.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CTFontCreateWithFontDescriptorAndOptions ()
|
|
|
|
{
|
2022-11-10 19:59:26 +03:00
|
|
|
TestRuntime.AssertXcodeVersion (5, 0);
|
2016-07-16 01:10:30 +03:00
|
|
|
|
|
|
|
CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes () {
|
|
|
|
FamilyName = "Courier",
|
|
|
|
StyleName = "Bold",
|
|
|
|
Size = 16.0f
|
|
|
|
};
|
|
|
|
using (var fd = new CTFontDescriptor (fda))
|
|
|
|
using (var font = new CTFont (fd, 10, CTFontOptions.Default)) {
|
|
|
|
Assert.That (font.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetCascadeList ()
|
|
|
|
{
|
2022-11-10 19:59:26 +03:00
|
|
|
TestRuntime.AssertXcodeVersion (5, 0);
|
2016-07-16 01:10:30 +03:00
|
|
|
|
|
|
|
using (var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default)) {
|
|
|
|
Assert.NotNull (font.GetDefaultCascadeList (null), "null");
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetLocalizedName ()
|
|
|
|
{
|
2016-07-16 01:10:30 +03:00
|
|
|
TestRuntime.AssertXcodeVersion (5, 0);
|
|
|
|
|
|
|
|
using (var font = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default)) {
|
|
|
|
Assert.NotNull (font.GetLocalizedName (CTFontNameKey.Copyright), "1");
|
|
|
|
|
|
|
|
// We need to check if we are using english as our main language since this is the known case
|
|
|
|
// that the following code works. It fails with spanish for example but it is a false positive
|
|
|
|
// because the localized name for this font Full option does not have a spanish representation
|
|
|
|
var language = NSLocale.PreferredLanguages [0];
|
|
|
|
if (language == "en") {
|
|
|
|
string str;
|
|
|
|
Assert.NotNull (font.GetLocalizedName (CTFontNameKey.Full, out str), "2");
|
|
|
|
Assert.NotNull (str, "out str");
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetGlyphsForCharacters_35048 ()
|
|
|
|
{
|
|
|
|
using (var font = CGFont.CreateWithFontName ("AppleColorEmoji"))
|
|
|
|
using (var ctfont = font.ToCTFont ((nfloat) 10.0)) {
|
2022-11-10 19:59:26 +03:00
|
|
|
ushort [] gid = new ushort [2];
|
2016-05-26 16:06:52 +03:00
|
|
|
Assert.True (ctfont.GetGlyphsForCharacters ("\ud83d\ude00".ToCharArray (), gid), "GetGlyphsForCharacters");
|
|
|
|
Assert.That (gid [0], Is.Not.EqualTo (0), "0");
|
|
|
|
Assert.That (gid [1], Is.EqualTo (0), "1");
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 20:07:42 +03:00
|
|
|
|
|
|
|
[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");
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 15:41:14 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CTFontCopyNameForGlyph ()
|
|
|
|
{
|
|
|
|
TestRuntime.AssertXcodeVersion (12, 0);
|
|
|
|
|
|
|
|
using (var ctfont = new CTFont ("HoeflerText-Regular", 10, CTFontOptions.Default))
|
|
|
|
Assert.That (ctfont.GetGlyphName ((ushort) 65), Is.EqualTo ("asciicircum"), "1");
|
|
|
|
|
|
|
|
using (var font = CGFont.CreateWithFontName ("AppleColorEmoji"))
|
|
|
|
using (var ctfont = font.ToCTFont ((nfloat) 10.0))
|
|
|
|
Assert.Null (ctfont.GetGlyphName ('\ud83d'), "2");
|
|
|
|
}
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|