2016-05-26 16:06:52 +03:00
|
|
|
//
|
|
|
|
// Unit tests for CGPDFInfo
|
|
|
|
//
|
|
|
|
// Authors:
|
|
|
|
// Rolf Bjarne Kvinge <rolf@xamarin.com>
|
|
|
|
//
|
|
|
|
// Copyright 2012-2014 Xamarin Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using Foundation;
|
2018-01-26 19:17:46 +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 CoreGraphics;
|
|
|
|
#else
|
|
|
|
using MonoTouch.CoreGraphics;
|
|
|
|
using MonoTouch.Foundation;
|
2018-01-26 19:17:46 +03:00
|
|
|
using MonoTouch.ObjCRuntime;
|
2016-05-26 16:06:52 +03:00
|
|
|
using MonoTouch.UIKit;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using RectangleF=CoreGraphics.CGRect;
|
|
|
|
using SizeF=CoreGraphics.CGSize;
|
|
|
|
using PointF=CoreGraphics.CGPoint;
|
|
|
|
#else
|
|
|
|
using nfloat=global::System.Single;
|
|
|
|
using nint=global::System.Int32;
|
|
|
|
using nuint=global::System.UInt32;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.CoreGraphics {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class PDFInfoTest {
|
|
|
|
|
|
|
|
static public CGPDFInfo GetInfo ()
|
|
|
|
{
|
|
|
|
return new CGPDFInfo () {
|
|
|
|
AllowsCopying = true,
|
|
|
|
AllowsPrinting = true,
|
|
|
|
Author = "My Name",
|
|
|
|
Creator = "My Creator",
|
|
|
|
EncryptionKeyLength = 123,
|
|
|
|
Keywords = new string [] { "K1", "K2" },
|
|
|
|
OwnerPassword = "My OwnerPassword",
|
|
|
|
Subject = "My Subject",
|
|
|
|
Title = "My Title",
|
|
|
|
UserPassword = "My UserPassword",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-12 21:13:56 +03:00
|
|
|
#if !MONOMAC // Not on mac
|
2016-05-26 16:06:52 +03:00
|
|
|
[Test]
|
|
|
|
public void ToDictionary ()
|
|
|
|
{
|
2018-01-26 19:17:46 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (9,3))
|
|
|
|
Assert.Ignore ("Crash (at least on devices) with iOS 11.3 beta 1");
|
2016-05-26 16:06:52 +03:00
|
|
|
// Bug #8879
|
|
|
|
var info = GetInfo ();
|
|
|
|
UIGraphics.BeginPDFContext("file", RectangleF.Empty, info);
|
|
|
|
}
|
[CoreGraphics] Implement CoreGraphics bindings for Xcode 9. (#2812)
* [ios11-b1] CoreGraphics bindings
* Updated with feedback from Sebastien
* Fix build, optimize checks
* Add version information
* Address comments
* Tests
* Remove Apply code, add special code for typo
* [CoreGraphics] Add comma after last enum value.
* [CoreGraphics] No need to bind CGColorSpaceGetName.
* [CoreGraphics] Add new field in Xcode 9 beta 5.
* [CoreGraphics] Move kCGPDFContextAccessPermissions to the correct dictionary container and implement the corresponding manual code.
* [CoreGraphics] Adjust nullability acceptance based on new attributes for CGColorSpace.CreateCalibratedGray/RGB functions.
* [CoreGraphics] Bind CGColorSpaceCreateLab, introduced in Xcode 9 beta 5.
* [CoreGraphics] Adjust CGColorSpaceCreateWithICCData and CGColorSpaceCreateWithICCProfile bindings according to Xcode 9 beta 2.
Apple introduced CGColorSpaceCreateWithICCData in b1, and made
CGColorSpaceCreateWithICCProfile a typedef to CGColorSpaceCreateWithICCData.
Apple reversed the typedef in b2 (probably because it creates broken
executables when targetting earlier versions of macOS, since those executables
would use CGColorSpaceCreateWithICCData, which would not exist), and instead
made CGColorSpaceCreateWithICCProfile a normal deprecated method.
So copy this logic in our bindings: deprecate CreateICCProfile, and introduce
CreateICCProfile, with two overloads for NSData and CGDataProvider (since
that's what's accepted according to the documentation).
* [CoreGraphics] Add CGContextPDF constructors to make parity between different overloads.
There are two types of CGContextPDF constructors: the first argument is either
an NSUrl or a CGDataConsumer. Previously the NSUrl type had more overloads,
and also allowed a null CGRect for the second argument. With the overloads are
identical between the two types of CGContextPDF constructors.
Existing constructors:
CGContextPDF (NSUrl, CGRect, CGPDFInfo)
CGContextPDF (NSUrl, CGRect)
CGContextPDF (NSUrl, CGPDFInfo)
CGContextPDF (NSUrl)
CGContextPDF (CGDataConsumer, CGRect, CGPDFInfo)
Added constructors:
CGContextPDF (CGDataConsumer, CGRect)
CGContextPDF (CGDataConsumer, CGPDFInfo)
CGContextPDF (CGDataConsumer)
Additionally the code has been fixed to not throw NullReferenceExceptions if
null is passed for any of the values and instead pass on any null values to
the native `CGPDFContextCreate` method (since `CGPDFContextCreate`'s arguments
are all `__nullable`).
* [tests] Add and improve existing tests for new and some existing CoreGraphics API.
* Undo accidental whitespace noise.
* [tests] Remove random characters in assert message.
* [CoreGraphics] Improve argument exception messages in CGColorSpace according to review.
* [CoreGraphics] Use 'Icc' instead of 'ICC' for new API, and also make the change for XAMCORE_4_0.
* [CoreGraphics] Fix availability attribute for High Sierra.
* [tests] Update monotouch-test after API changes.
2017-10-02 13:02:41 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void ToDictionaryWithPermissions ()
|
|
|
|
{
|
|
|
|
TestRuntime.AssertXcodeVersion (9, 0);
|
|
|
|
|
|
|
|
var filename = Environment.GetFolderPath (Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
|
|
|
|
|
|
|
|
var info = GetInfo ();
|
|
|
|
info.AccessPermissions = CGPDFAccessPermissions.AllowsContentCopying;
|
|
|
|
|
|
|
|
using (var url = new NSUrl (filename)) {
|
|
|
|
using (var ctx = new CGContextPDF (url, new RectangleF (0, 0, 1000, 1000), info)) {
|
|
|
|
Assert.IsNotNull (ctx, "1");
|
|
|
|
}
|
|
|
|
using (var consumer = new CGDataConsumer (url)) {
|
|
|
|
using (var ctx = new CGContextPDF (consumer, new RectangleF (0, 0, 1000, 1000), info)) {
|
|
|
|
Assert.IsNotNull (ctx, "2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|