2016-05-26 16:06:52 +03:00
|
|
|
//
|
|
|
|
// Unit tests for CTStringAttributes
|
|
|
|
//
|
|
|
|
// Authors:
|
|
|
|
// Marek Safar (marek.safar@gmail.com)
|
|
|
|
//
|
|
|
|
// Copyright 2012 Xamarin Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using Foundation;
|
2017-01-12 21:13:56 +03:00
|
|
|
#if MONOMAC
|
|
|
|
using AppKit;
|
|
|
|
using UIColor = AppKit.NSColor;
|
|
|
|
#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 CoreGraphics;
|
|
|
|
using CoreText;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.CoreText
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class StringAttributesTests
|
|
|
|
{
|
2017-01-12 21:13:56 +03:00
|
|
|
#if !MONOMAC // No UIGraphics on mac
|
2016-05-26 16:06:52 +03:00
|
|
|
[Test]
|
|
|
|
public void SimpleValuesSet ()
|
|
|
|
{
|
|
|
|
var sa = new CTStringAttributes ();
|
|
|
|
sa.ForegroundColor = UIColor.Blue.CGColor;
|
|
|
|
sa.Font = new CTFont ("Georgia-BoldItalic", 24);
|
|
|
|
sa.UnderlineStyle = CTUnderlineStyle.Double; // It does not seem to do anything
|
|
|
|
sa.UnderlineColor = UIColor.Blue.CGColor;
|
|
|
|
sa.UnderlineStyleModifiers = CTUnderlineStyleModifiers.PatternDashDotDot;
|
|
|
|
|
2018-07-03 18:12:42 +03:00
|
|
|
Assert.IsNull (sa.BaselineClass, "#0");
|
|
|
|
sa.BaselineClass = CTBaselineClass.IdeographicHigh;
|
|
|
|
Assert.AreEqual (CTBaselineClass.IdeographicHigh, sa.BaselineClass, "#1");
|
2016-05-26 16:06:52 +03:00
|
|
|
|
2018-07-03 18:12:42 +03:00
|
|
|
sa.SetBaselineInfo (CTBaselineClass.Roman, 13);
|
|
|
|
sa.SetBaselineInfo (CTBaselineClass.IdeographicHigh, 3);
|
|
|
|
sa.SetWritingDirection (CTWritingDirection.LeftToRight);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
2019-07-15 20:06:56 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (11, 0))
|
|
|
|
sa.TrackingAdjustment = 1.0f;
|
|
|
|
|
2020-05-28 17:35:09 +03:00
|
|
|
var size = new CGSize (300, 300);
|
2016-05-26 16:06:52 +03:00
|
|
|
UIGraphics.BeginImageContext (size);
|
|
|
|
var gctx = UIGraphics.GetCurrentContext ();
|
|
|
|
|
|
|
|
gctx.SetFillColor (UIColor.Green.CGColor);
|
|
|
|
|
|
|
|
var attributedString = new NSAttributedString ("Test_ME~`", sa);
|
|
|
|
|
|
|
|
using (var textLine = new CTLine (attributedString)) {
|
|
|
|
textLine.Draw (gctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
UIGraphics.EndImageContext ();
|
|
|
|
}
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-07-05 23:49:59 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BackgroundColor ()
|
|
|
|
{
|
|
|
|
var sa = new CTStringAttributes ();
|
2018-07-03 18:13:55 +03:00
|
|
|
Assert.DoesNotThrow (() => { sa.BackgroundColor = TestRuntime.GetCGColor (UIColor.Blue); }, "#0");
|
2016-07-05 23:49:59 +03:00
|
|
|
Assert.DoesNotThrow (() => { var x = sa.BackgroundColor; }, "#1");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HorizontalInVerticalForms ()
|
|
|
|
{
|
|
|
|
var sa = new CTStringAttributes ();
|
|
|
|
Assert.DoesNotThrow (() => { sa.HorizontalInVerticalForms = 1; }, "#0");
|
|
|
|
Assert.DoesNotThrow (() => { var x = sa.HorizontalInVerticalForms; }, "#1");
|
|
|
|
}
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|