diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/Example/ISSUE_TEMPLATE.md b/Example/ISSUE_TEMPLATE.md old mode 100644 new mode 100755 diff --git a/Example/Podfile b/Example/Podfile old mode 100644 new mode 100755 diff --git a/Example/Podfile.lock b/Example/Podfile.lock old mode 100644 new mode 100755 diff --git a/Example/Pods/Local Podspecs/UXMPDFKit.podspec.json b/Example/Pods/Local Podspecs/UXMPDFKit.podspec.json old mode 100644 new mode 100755 diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock old mode 100644 new mode 100755 diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index 28222e8..b20b6c2 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -491,8 +491,11 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 1010; TargetAttributes = { + 806AC9F20336348B8F1E6138E470491D = { + LastSwiftMigration = 1010; + }; D7C77B95095598F2FFA1E9456D29905E = { LastSwiftMigration = 0820; }; @@ -680,7 +683,8 @@ PRODUCT_NAME = UXMPDFKit; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -713,7 +717,8 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -767,14 +772,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -851,14 +864,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/UXMPDFKit.xcscheme b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/UXMPDFKit.xcscheme old mode 100644 new mode 100755 index a2f2807..7d60637 --- a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/UXMPDFKit.xcscheme +++ b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/UXMPDFKit.xcscheme @@ -1,6 +1,6 @@ + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/UXMPDFKit/AppDelegate.swift b/Example/UXMPDFKit/AppDelegate.swift old mode 100644 new mode 100755 index dea5111..81f97ec --- a/Example/UXMPDFKit/AppDelegate.swift +++ b/Example/UXMPDFKit/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { let dirPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) print("App Path: \(dirPaths)") diff --git a/Example/UXMPDFKit/Base.lproj/LaunchScreen.xib b/Example/UXMPDFKit/Base.lproj/LaunchScreen.xib old mode 100644 new mode 100755 diff --git a/Example/UXMPDFKit/Base.lproj/Main.storyboard b/Example/UXMPDFKit/Base.lproj/Main.storyboard old mode 100644 new mode 100755 diff --git a/Example/UXMPDFKit/ExampleViewController.swift b/Example/UXMPDFKit/ExampleViewController.swift old mode 100644 new mode 100755 diff --git a/Example/UXMPDFKit/Info.plist b/Example/UXMPDFKit/Info.plist old mode 100644 new mode 100755 diff --git a/Example/UXMPDFKit/ViewController.swift b/Example/UXMPDFKit/ViewController.swift old mode 100644 new mode 100755 diff --git a/Example/UXMPDFKit/sample.pdf b/Example/UXMPDFKit/sample.pdf old mode 100644 new mode 100755 diff --git a/Example/UXMPDFKit/sample3.pdf b/Example/UXMPDFKit/sample3.pdf old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Package.swift b/Package.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/.gitkeep b/Pod/Classes/.gitkeep old mode 100644 new mode 100755 diff --git a/Pod/Classes/Annotations/PDFAnnotation.swift b/Pod/Classes/Annotations/PDFAnnotation.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Annotations/PDFAnnotationController.swift b/Pod/Classes/Annotations/PDFAnnotationController.swift old mode 100644 new mode 100755 index e0cd2b0..c213454 --- a/Pod/Classes/Annotations/PDFAnnotationController.swift +++ b/Pod/Classes/Annotations/PDFAnnotationController.swift @@ -18,7 +18,7 @@ open class PDFAnnotationController: UIViewController { var document: PDFDocument! /// Store containing all annotations for document - var annotations = PDFAnnotationStore() + private (set) open var annotations = PDFAnnotationStore() /// References to pages within view var allPages = [PDFPageContentView]() @@ -119,7 +119,8 @@ open class PDFAnnotationController: UIViewController { view.isOpaque = false view.backgroundColor = UIColor.clear - self.loadButtons(for: self.annotationTypes) + loadButtons(for: self.annotationTypes) + undoButton.isEnabled = (annotations.annotations.count > 0) } //MARK: - Annotation handling @@ -136,7 +137,7 @@ open class PDFAnnotationController: UIViewController { for annotation in annotationsForPage { let view = annotation.mutableView() contentView.contentView.addSubview(view) - contentView.contentView.bringSubview(toFront: view) + contentView.contentView.bringSubviewToFront(view) } } @@ -145,13 +146,16 @@ open class PDFAnnotationController: UIViewController { annotationType = type view.isUserInteractionEnabled = annotationType != nil + undoButton.isEnabled = (annotationType != nil || annotations.annotations.count > 0) } open func finishAnnotation() { annotationType = .none addCurrentAnnotationToStore() + view.isUserInteractionEnabled = false + undoButton.isEnabled = (annotations.annotations.count > 0) } //MARK: - Bar button actions @@ -176,9 +180,15 @@ open class PDFAnnotationController: UIViewController { } @IBAction func selectedUndo(_ button: PDFBarButton) { + //keep track of what kind of annotation we're adding + let currentAnnotationType = annotationType + //finish and undo it finishAnnotation() undo() + + //then start a new annotation of the same type + startAnnotation(currentAnnotationType) } func select(annotation: PDFAnnotation?) { @@ -188,7 +198,7 @@ open class PDFAnnotationController: UIViewController { } func loadButtons(for annotations: [PDFAnnotation.Type]) { - self.buttons = self.annotationTypes.flatMap { + self.buttons = self.annotationTypes.compactMap { if let annotation = $0 as? PDFAnnotationButtonable.Type { return PDFAnnotationBarButton( @@ -231,7 +241,13 @@ open class PDFAnnotationController: UIViewController { //MARK: - Touches methods to pass to annotation open override func touchesBegan(_ touches: Set, with event: UIEvent?) { - guard let touch = touches.first else { return } + // We only allow one-finger touches to start annotations, as otherwise + // when you are pen-editing then try to zoom, one of your fingers will draw instead of zooming + // This is a HACK, as IDEALLY the two-finger pinch would zoom while still in + // annotation editing mode, but for the life of me I could not get that to go, forwarding + // events/touches to pretty much anything. + guard let touch = touches.first, event?.allTouches?.count == 1 + else { return } let page = annotationDelegate?.annotationWillStart(touch: touch) @@ -252,14 +268,16 @@ open class PDFAnnotationController: UIViewController { open override func touchesMoved(_ touches: Set, with event: UIEvent?) { - guard let touch = touches.first else { return } + guard let touch = touches.first, event?.allTouches?.count == 1 + else { return } let point = touch.location(in: pageView) currentAnnotation?.touchMoved(touch, point: point) } open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - guard let touch = touches.first else { return } + guard let touch = touches.first, event?.allTouches?.count == 1 + else { return } let point = touch.location(in: pageView) currentAnnotation?.touchEnded(touch, point: point) diff --git a/Pod/Classes/Annotations/PDFAnnotationStore.swift b/Pod/Classes/Annotations/PDFAnnotationStore.swift old mode 100644 new mode 100755 index c35058b..bcf5257 --- a/Pod/Classes/Annotations/PDFAnnotationStore.swift +++ b/Pod/Classes/Annotations/PDFAnnotationStore.swift @@ -17,7 +17,7 @@ public protocol PDFAnnotationStoreDelegate { open class PDFAnnotationStore: NSObject, NSCoding { - var annotations: [PDFAnnotation] = [] + private (set) open var annotations: [PDFAnnotation] = [] var delegate: PDFAnnotationStoreDelegate? diff --git a/Pod/Classes/Annotations/PDFPathAnnotation.swift b/Pod/Classes/Annotations/PDFPathAnnotation.swift old mode 100644 new mode 100755 index 1e37507..346d140 --- a/Pod/Classes/Annotations/PDFPathAnnotation.swift +++ b/Pod/Classes/Annotations/PDFPathAnnotation.swift @@ -65,6 +65,7 @@ open class PDFPathAnnotation: NSObject, NSCoding { func drawRect(_ frame: CGRect, point: CGPoint = CGPoint.zero) { self.incrementalImage?.draw(at: point) + self.path.lineWidth = self.lineWidth self.color.setStroke() self.path.stroke() } diff --git a/Pod/Classes/Annotations/PDFTextAnnotation.swift b/Pod/Classes/Annotations/PDFTextAnnotation.swift old mode 100644 new mode 100755 index 32d95dd..eab0f4c --- a/Pod/Classes/Annotations/PDFTextAnnotation.swift +++ b/Pod/Classes/Annotations/PDFTextAnnotation.swift @@ -95,15 +95,15 @@ extension PDFTextAnnotation: PDFAnnotation { paragraphStyle.alignment = NSTextAlignment.left let attributes: [String:AnyObject] = [ - NSFontAttributeName: font, - NSForegroundColorAttributeName: UIColor.black, - NSParagraphStyleAttributeName: paragraphStyle + convertFromNSAttributedStringKey(NSAttributedString.Key.font): font, + convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor): UIColor.black, + convertFromNSAttributedStringKey(NSAttributedString.Key.paragraphStyle): paragraphStyle ] - let size = nsText.size(attributes: attributes) + let size = nsText.size(withAttributes: convertToOptionalNSAttributedStringKeyDictionary(attributes)) let textRect = CGRect(origin: rect.origin, size: size) - nsText.draw(in: textRect, withAttributes: attributes) + nsText.draw(in: textRect, withAttributes: convertToOptionalNSAttributedStringKeyDictionary(attributes)) UIGraphicsPopContext() } @@ -209,7 +209,7 @@ class PDFTextAnnotationView: ResizableView, PDFAnnotationView { self.addSubview(textView) } - func menuActionEdit(_ sender: Any!) { + @objc func menuActionEdit(_ sender: Any!) { self.delegate?.resizableViewDidSelectAction(view: self, action: "edit") self.isLocked = true @@ -225,3 +225,14 @@ class PDFTextAnnotationView: ResizableView, PDFAnnotationView { return super.canPerformAction(action, withSender: sender) } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromNSAttributedStringKey(_ input: NSAttributedString.Key) -> String { + return input.rawValue +} + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? { + guard let input = input else { return nil } + return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)}) +} diff --git a/Pod/Classes/Extensions/CGPoint.swift b/Pod/Classes/Extensions/CGPoint.swift old mode 100644 new mode 100755 index 5dded27..de51470 --- a/Pod/Classes/Extensions/CGPoint.swift +++ b/Pod/Classes/Extensions/CGPoint.swift @@ -19,8 +19,8 @@ extension CGPoint { func rect(from point: CGPoint) -> CGRect { return CGRect(x: min(self.x, point.x), y: min(self.y, point.y), - width: fabs(self.x - point.x), - height: fabs(self.y - point.y)) + width: abs(self.x - point.x), + height: abs(self.y - point.y)) } /// Get the distance between two points diff --git a/Pod/Classes/Extensions/CGRect.swift b/Pod/Classes/Extensions/CGRect.swift old mode 100644 new mode 100755 index 94b9c25..8a8f2ae --- a/Pod/Classes/Extensions/CGRect.swift +++ b/Pod/Classes/Extensions/CGRect.swift @@ -55,8 +55,8 @@ extension CGRect { return CGRect( x: minX, y: minY, - width: fabs(maxX - minX), - height: fabs(maxY - minY) + width: abs(maxX - minX), + height: abs(maxY - minY) ) } } diff --git a/Pod/Classes/Extensions/UIColor.swift b/Pod/Classes/Extensions/UIColor.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Extensions/UIImage.swift b/Pod/Classes/Extensions/UIImage.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Extensions/UIViewController.swift b/Pod/Classes/Extensions/UIViewController.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Form/PDFArray.swift b/Pod/Classes/Form/PDFArray.swift old mode 100644 new mode 100755 index 25bb87f..de00551 --- a/Pod/Classes/Form/PDFArray.swift +++ b/Pod/Classes/Form/PDFArray.swift @@ -163,7 +163,7 @@ internal class PDFArray: PDFObject { extension PDFArray: NSCopying { func copy(with zone: NSZone?) -> Any { - return type(of: self).init(arrayRef: arr) + return Swift.type(of: self).init(arrayRef: arr) } } diff --git a/Pod/Classes/Form/PDFDictionary.swift b/Pod/Classes/Form/PDFDictionary.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Form/PDFFormButtonField.swift b/Pod/Classes/Form/PDFFormButtonField.swift old mode 100644 new mode 100755 index 82a4d93..1a96165 --- a/Pod/Classes/Form/PDFFormButtonField.swift +++ b/Pod/Classes/Form/PDFFormButtonField.swift @@ -66,7 +66,7 @@ open class PDFFormButtonField: PDFFormField { addSubview(button) } - func buttonPressed() { + @objc func buttonPressed() { value = (isSelected ? "" : exportValue) as AnyObject? delegate?.formFieldValueChanged(self) } @@ -91,7 +91,7 @@ open class PDFFormButtonField: PDFFormField { frame.origin.x += self.frame.origin.x frame.origin.y += self.frame.origin.y - let state = isSelected ? UIControlState.selected : UIControlState.normal + let state = isSelected ? UIControl.State.selected : UIControl.State.normal var title: NSString = "" let titleColor = button.titleColor(for: state) ?? UIColor.black let font: UIFont = button.titleLabel!.font @@ -106,13 +106,24 @@ open class PDFFormButtonField: PDFFormField { paragraphStyle.alignment = NSTextAlignment.center let attributes: [String:AnyObject] = [ - NSFontAttributeName: font, - NSForegroundColorAttributeName: titleColor, - NSParagraphStyleAttributeName: paragraphStyle + convertFromNSAttributedStringKey(NSAttributedString.Key.font): font, + convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor): titleColor, + convertFromNSAttributedStringKey(NSAttributedString.Key.paragraphStyle): paragraphStyle ] - title.draw(in: frame, withAttributes: attributes) + title.draw(in: frame, withAttributes: convertToOptionalNSAttributedStringKeyDictionary(attributes)) UIGraphicsPopContext() } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromNSAttributedStringKey(_ input: NSAttributedString.Key) -> String { + return input.rawValue +} + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? { + guard let input = input else { return nil } + return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)}) +} diff --git a/Pod/Classes/Form/PDFFormField.swift b/Pod/Classes/Form/PDFFormField.swift old mode 100644 new mode 100755 index e89a565..85a4dd9 --- a/Pod/Classes/Form/PDFFormField.swift +++ b/Pod/Classes/Form/PDFFormField.swift @@ -32,7 +32,7 @@ open class PDFFormFieldObject { let flags: [PDFFormFlag] if let flagsObj = dict["Ff"] as? NSNumber { - flags = self.determineFlags(UInt(flagsObj)) + flags = self.determineFlags(UInt(truncating: flagsObj)) } else { flags = [] diff --git a/Pod/Classes/Form/PDFFormPageView.swift b/Pod/Classes/Form/PDFFormPageView.swift old mode 100644 new mode 100755 index 9e3b729..b633df8 --- a/Pod/Classes/Form/PDFFormPageView.swift +++ b/Pod/Classes/Form/PDFFormPageView.swift @@ -60,7 +60,7 @@ open class PDFFormPage: NSObject { contentView.viewDidZoom = { scale in formView.updateWithZoom(scale) } - contentView.sendSubview(toBack: formView) + contentView.sendSubviewToBack(formView) } func createFormField(_ dict: PDFDictionary) { diff --git a/Pod/Classes/Form/PDFFormSignatureField.swift b/Pod/Classes/Form/PDFFormSignatureField.swift old mode 100644 new mode 100755 index e7a013c..4b24e84 --- a/Pod/Classes/Form/PDFFormSignatureField.swift +++ b/Pod/Classes/Form/PDFFormSignatureField.swift @@ -17,10 +17,10 @@ open class PDFFormSignatureField: PDFFormField { lazy fileprivate var signButton: UIButton = { var button = UIButton(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)) - button.setTitle("Tap To Sign", for: UIControlState()) + button.setTitle("Tap To Sign", for: UIControl.State()) button.tintColor = UIColor.black button.titleLabel?.font = UIFont.systemFont(ofSize: 14.0) - button.setTitleColor(UIColor.black, for: UIControlState()) + button.setTitleColor(UIColor.black, for: UIControl.State()) button.addTarget(self, action: #selector(PDFFormSignatureField.addSignature), for: .touchUpInside) button.isUserInteractionEnabled = true button.isExclusiveTouch = true @@ -48,7 +48,7 @@ open class PDFFormSignatureField: PDFFormField { addSubview(signImage) addSubview(signButton) - bringSubview(toFront: signButton) + bringSubviewToFront(signButton) } required public init?(coder aDecoder: NSCoder) { @@ -61,7 +61,7 @@ open class PDFFormSignatureField: PDFFormField { } } - func addSignature() { + @objc func addSignature() { let vc = PDFFormSignatureViewController() vc.delegate = self diff --git a/Pod/Classes/Form/PDFFormTextField.swift b/Pod/Classes/Form/PDFFormTextField.swift old mode 100644 new mode 100755 index bb4040a..5ba47d6 --- a/Pod/Classes/Form/PDFFormTextField.swift +++ b/Pod/Classes/Form/PDFFormTextField.swift @@ -59,7 +59,7 @@ open class PDFFormTextField: PDFFormField { textView.autoresizingMask = [.flexibleWidth, .flexibleHeight] textView.delegate = self textView.isScrollEnabled = true - textView.textContainerInset = UIEdgeInsetsMake(4, 4, 4, 4) + textView.textContainerInset = UIEdgeInsets.init(top: 4, left: 4, bottom: 4, right: 4) let fontSize = fontSizeForRect(frame) < 13.0 ? fontSizeForRect(frame) : 13.0 textView.font = UIFont.systemFont(ofSize: fontSize) } @@ -118,15 +118,14 @@ open class PDFFormTextField: PDFFormField { fatalError() } - /// UGLY - (text as NSString!).draw(in: frame, withAttributes: [ - NSFontAttributeName: font - ]) + (text as NSString).draw(in: frame, withAttributes: convertToOptionalNSAttributedStringKeyDictionary([ + convertFromNSAttributedStringKey(NSAttributedString.Key.font): font + ])) } } extension PDFFormTextField: UITextFieldDelegate { - func textChanged() { + @objc func textChanged() { value = text as AnyObject? delegate?.formFieldValueChanged(self) } @@ -153,3 +152,14 @@ extension PDFFormTextField: UITextViewDelegate { return false } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? { + guard let input = input else { return nil } + return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)}) +} + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromNSAttributedStringKey(_ input: NSAttributedString.Key) -> String { + return input.rawValue +} diff --git a/Pod/Classes/Form/PDFFormViewController.swift b/Pod/Classes/Form/PDFFormViewController.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Form/PDFObjectParser.swift b/Pod/Classes/Form/PDFObjectParser.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Form/PDFToggleButton.swift b/Pod/Classes/Form/PDFToggleButton.swift old mode 100644 new mode 100755 index 45a944c..557615c --- a/Pod/Classes/Form/PDFToggleButton.swift +++ b/Pod/Classes/Form/PDFToggleButton.swift @@ -28,7 +28,7 @@ class PDFToggleButton: UIButton { titleLabel?.font = UIFont(name: "ZapfDingbatsITC", size: 10) } - func buttonTapped() { + @objc func buttonTapped() { self.isSelected = !self.isSelected } } diff --git a/Pod/Classes/Model/PDFAction.swift b/Pod/Classes/Model/PDFAction.swift old mode 100644 new mode 100755 index dfa7fcb..a530208 --- a/Pod/Classes/Model/PDFAction.swift +++ b/Pod/Classes/Model/PDFAction.swift @@ -9,7 +9,7 @@ import Foundation open class PDFAction { - open static func fromPDFDictionary(_ sourceDictionary: CGPDFDictionaryRef, documentReference: CGPDFDocument) -> PDFAction? { + public static func fromPDFDictionary(_ sourceDictionary: CGPDFDictionaryRef, documentReference: CGPDFDocument) -> PDFAction? { var action: PDFAction? var destinationName: CGPDFStringRef? = nil var destinationString: UnsafePointer? = nil diff --git a/Pod/Classes/Model/PDFActionGoTo.swift b/Pod/Classes/Model/PDFActionGoTo.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Model/PDFActionURL.swift b/Pod/Classes/Model/PDFActionURL.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/CGPDFDocument.swift b/Pod/Classes/Renderer/CGPDFDocument.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFDocument.swift b/Pod/Classes/Renderer/PDFDocument.swift old mode 100644 new mode 100755 index 82b9704..1aa7dd8 --- a/Pod/Classes/Renderer/PDFDocument.swift +++ b/Pod/Classes/Renderer/PDFDocument.swift @@ -205,16 +205,16 @@ open class PDFDocument: NSObject, NSCoding { return ProcessInfo.processInfo.globallyUniqueString } - open static func documentsPath() -> String { + public static func documentsPath() -> String { return NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] } - open static func applicationPath() -> String { + public static func applicationPath() -> String { let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) return (paths.first! as NSString).deletingLastPathComponent } - open static func applicationSupportPath() -> String { + public static func applicationSupportPath() -> String { let fileManager = FileManager() let pathURL = try! fileManager.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true) return pathURL.path diff --git a/Pod/Classes/Renderer/PDFDocumentLink.swift b/Pod/Classes/Renderer/PDFDocumentLink.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFPageContent.swift b/Pod/Classes/Renderer/PDFPageContent.swift old mode 100644 new mode 100755 index 9272dd7..48ba64a --- a/Pod/Classes/Renderer/PDFPageContent.swift +++ b/Pod/Classes/Renderer/PDFPageContent.swift @@ -85,7 +85,7 @@ public class PDFPageContent: UIView { autoresizesSubviews = false isUserInteractionEnabled = true contentMode = .redraw - autoresizingMask = UIViewAutoresizing() + autoresizingMask = UIView.AutoresizingMask() backgroundColor = UIColor.clear buildAnnotationLinksList() @@ -115,7 +115,7 @@ public class PDFPageContent: UIView { highlight.autoresizesSubviews = false highlight.isUserInteractionEnabled = false highlight.contentMode = .redraw - highlight.autoresizingMask = UIViewAutoresizing() + highlight.autoresizingMask = UIView.AutoresizingMask() highlight.backgroundColor = color addSubview(highlight) diff --git a/Pod/Classes/Renderer/PDFPageContentView.swift b/Pod/Classes/Renderer/PDFPageContentView.swift old mode 100644 new mode 100755 index 1ea7967..99c57a8 --- a/Pod/Classes/Renderer/PDFPageContentView.swift +++ b/Pod/Classes/Renderer/PDFPageContentView.swift @@ -72,12 +72,12 @@ open class PDFPageContentView: UIScrollView, UIScrollViewDelegate { NotificationCenter.default.addObserver( self, selector: #selector(PDFPageContentView.keyboardWillShowNotification(_:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver( self, selector: #selector(PDFPageContentView.keyboardWillHideNotification(_:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil ) @@ -106,8 +106,8 @@ open class PDFPageContentView: UIScrollView, UIScrollViewDelegate { } deinit { - NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil) - NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil) + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) self.removeObserver(self, forKeyPath: "frame") } @@ -147,7 +147,7 @@ open class PDFPageContentView: UIScrollView, UIScrollViewDelegate { self.zoomReset() } - open func processSingleTap(_ recognizer: UITapGestureRecognizer) { + @objc open func processSingleTap(_ recognizer: UITapGestureRecognizer) { if let action = contentView.processSingleTap(recognizer) as? PDFAction { contentDelegate?.contentView(self, didSelect: action) } @@ -159,7 +159,7 @@ open class PDFPageContentView: UIScrollView, UIScrollViewDelegate { } } - open func processDoubleTap(_ recognizer: UITapGestureRecognizer) { + @objc open func processDoubleTap(_ recognizer: UITapGestureRecognizer) { contentDelegate?.contentView(self, doubleTapped: recognizer) } @@ -218,18 +218,18 @@ open class PDFPageContentView: UIScrollView, UIScrollViewDelegate { viewDidZoom?(scrollView.zoomScale) } - func keyboardWillShowNotification(_ notification: Notification) { + @objc func keyboardWillShowNotification(_ notification: Notification) { updateBottomLayoutConstraintWithNotification(notification, show: true) } - func keyboardWillHideNotification(_ notification: Notification) { + @objc func keyboardWillHideNotification(_ notification: Notification) { updateBottomLayoutConstraintWithNotification(notification, show: false) } func updateBottomLayoutConstraintWithNotification(_ notification: Notification, show:Bool) { let userInfo = (notification as NSNotification).userInfo! - let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue + let keyboardEndFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue let convertedKeyboardEndFrame = self.convert(keyboardEndFrame, from: self.window) let height: CGFloat @@ -239,7 +239,7 @@ open class PDFPageContentView: UIScrollView, UIScrollViewDelegate { height = 0 } - contentInset = UIEdgeInsetsMake(0, 0, height, 0) + contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: height, right: 0) } diff --git a/Pod/Classes/Renderer/PDFPageScrubber.swift b/Pod/Classes/Renderer/PDFPageScrubber.swift old mode 100644 new mode 100755 index 46fe01c..80ca75e --- a/Pod/Classes/Renderer/PDFPageScrubber.swift +++ b/Pod/Classes/Renderer/PDFPageScrubber.swift @@ -70,7 +70,7 @@ open class PDFPageScrubber: UIToolbar { let pageNumberLabel = UILabel(frame: textRect) pageNumberLabel.autoresizesSubviews = false - pageNumberLabel.autoresizingMask = UIViewAutoresizing() + pageNumberLabel.autoresizingMask = UIView.AutoresizingMask() pageNumberLabel.textAlignment = .center pageNumberLabel.backgroundColor = UIColor.clear pageNumberLabel.textColor = UIColor.darkText @@ -245,7 +245,7 @@ open class PDFPageScrubber: UIToolbar { } } - func trackTimerFired(_ timer: Timer) { + @objc func trackTimerFired(_ timer: Timer) { trackTimer?.invalidate() trackTimer = nil if scrubber.tag != document.currentPage { @@ -253,7 +253,7 @@ open class PDFPageScrubber: UIToolbar { } } - func enableTimerFired(_ timer: Timer) { + @objc func enableTimerFired(_ timer: Timer) { enableTimer?.invalidate() enableTimer = nil scrubber.isUserInteractionEnabled = true @@ -292,7 +292,7 @@ open class PDFPageScrubber: UIToolbar { return page + 1 } - func scrubberTouchDown(_ scrubber: PDFPageScrubberTrackControl) { + @objc func scrubberTouchDown(_ scrubber: PDFPageScrubberTrackControl) { let page = scrubberPageNumber(scrubber) if page != document.currentPage { @@ -304,7 +304,7 @@ open class PDFPageScrubber: UIToolbar { scrubber.tag = page } - func scrubberTouchUp(_ scrubber: PDFPageScrubberTrackControl) { + @objc func scrubberTouchUp(_ scrubber: PDFPageScrubberTrackControl) { if trackTimer != nil { trackTimer?.invalidate() trackTimer = nil @@ -319,7 +319,7 @@ open class PDFPageScrubber: UIToolbar { scrubber.tag = 0 } - func scrubberValueChanged(_ scrubber: PDFPageScrubberTrackControl) { + @objc func scrubberValueChanged(_ scrubber: PDFPageScrubberTrackControl) { let page = self.scrubberPageNumber(scrubber) if page != scrubber.tag { updatePageNumberText(page) diff --git a/Pod/Classes/Renderer/PDFPageScrubberThumb.swift b/Pod/Classes/Renderer/PDFPageScrubberThumb.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFPageScrubberTrackControl.swift b/Pod/Classes/Renderer/PDFPageScrubberTrackControl.swift old mode 100644 new mode 100755 index 38840f3..3c1aa32 --- a/Pod/Classes/Renderer/PDFPageScrubberTrackControl.swift +++ b/Pod/Classes/Renderer/PDFPageScrubberTrackControl.swift @@ -17,7 +17,7 @@ internal class PDFPageScrubberTrackControl: UIControl { autoresizesSubviews = false isUserInteractionEnabled = true contentMode = .redraw - autoresizingMask = UIViewAutoresizing() + autoresizingMask = UIView.AutoresizingMask() backgroundColor = UIColor.clear isExclusiveTouch = true } diff --git a/Pod/Classes/Renderer/PDFPageTileLayer.swift b/Pod/Classes/Renderer/PDFPageTileLayer.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFRenderer.swift b/Pod/Classes/Renderer/PDFRenderer.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFSinglePageCell.swift b/Pod/Classes/Renderer/PDFSinglePageCell.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFSinglePageViewer.swift b/Pod/Classes/Renderer/PDFSinglePageViewer.swift old mode 100644 new mode 100755 index 4676ae1..42441ac --- a/Pod/Classes/Renderer/PDFSinglePageViewer.swift +++ b/Pod/Classes/Renderer/PDFSinglePageViewer.swift @@ -32,7 +32,7 @@ open class PDFSinglePageViewer: UICollectionView { var internalPage: Int = 0 - var scrollDirection: UICollectionViewScrollDirection { + var scrollDirection: UICollectionView.ScrollDirection { let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout return flowLayout.scrollDirection } diff --git a/Pod/Classes/Renderer/PDFSnapshotCache.swift b/Pod/Classes/Renderer/PDFSnapshotCache.swift old mode 100644 new mode 100755 index b928243..2790091 --- a/Pod/Classes/Renderer/PDFSnapshotCache.swift +++ b/Pod/Classes/Renderer/PDFSnapshotCache.swift @@ -65,7 +65,7 @@ open class PDFQueue { renderQueue.addOperation(thumbRender) } - open static func fetchPage(_ document: PDFDocument, page: Int, size: CGSize, completion:((PDFSnapshot) -> Void)?) { + public static func fetchPage(_ document: PDFDocument, page: Int, size: CGSize, completion:((PDFSnapshot) -> Void)?) { self.sharedQueue.fetchPage(document, page: page, size: size, completion:completion) } } diff --git a/Pod/Classes/Renderer/PDFThumbnailView.swift b/Pod/Classes/Renderer/PDFThumbnailView.swift old mode 100644 new mode 100755 index 5c31902..0a11156 --- a/Pod/Classes/Renderer/PDFThumbnailView.swift +++ b/Pod/Classes/Renderer/PDFThumbnailView.swift @@ -15,7 +15,7 @@ internal class PDFThumbnailView: UIView { imageView = UIImageView() imageView.autoresizesSubviews = false imageView.isUserInteractionEnabled = false - imageView.autoresizingMask = UIViewAutoresizing() + imageView.autoresizingMask = UIView.AutoresizingMask() imageView.translatesAutoresizingMaskIntoConstraints = false imageView.contentMode = .scaleAspectFit @@ -27,7 +27,7 @@ internal class PDFThumbnailView: UIView { autoresizesSubviews = false isUserInteractionEnabled = false contentMode = .redraw - autoresizingMask = UIViewAutoresizing() + autoresizingMask = UIView.AutoresizingMask() backgroundColor = UIColor.clear var constraints = NSLayoutConstraint.constraints(withVisualFormat: "H:[image]|", options: .alignAllLastBaseline, metrics: nil, views: [ "superview": self, "image": imageView ]) diff --git a/Pod/Classes/Renderer/PDFThumbnailViewCell.swift b/Pod/Classes/Renderer/PDFThumbnailViewCell.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/Renderer/PDFThumbnailViewController.swift b/Pod/Classes/Renderer/PDFThumbnailViewController.swift old mode 100644 new mode 100755 index 4e41301..44a8d2e --- a/Pod/Classes/Renderer/PDFThumbnailViewController.swift +++ b/Pod/Classes/Renderer/PDFThumbnailViewController.swift @@ -20,7 +20,7 @@ open class PDFThumbnailViewController: UIViewController { private var flowLayout: UICollectionViewFlowLayout { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .vertical - layout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20) + layout.sectionInset = UIEdgeInsets.init(top: 20, left: 20, bottom: 20, right: 20) layout.minimumLineSpacing = 0.0 layout.minimumInteritemSpacing = 0.0 return layout diff --git a/Pod/Classes/Renderer/PDFViewController.swift b/Pod/Classes/Renderer/PDFViewController.swift old mode 100644 new mode 100755 index 3e13528..fe5c381 --- a/Pod/Classes/Renderer/PDFViewController.swift +++ b/Pod/Classes/Renderer/PDFViewController.swift @@ -39,8 +39,10 @@ open class PDFViewController: UIViewController { /// A boolean value that determines if view controller is displayed as modal open var isPresentingInModal: Bool = false + open var modalDoneButtonTouched: (() -> ())? + /// The scroll direction of the reader - open var scrollDirection: UICollectionViewScrollDirection = .horizontal + open var scrollDirection: UICollectionView.ScrollDirection = .horizontal /// A reference to the document that is being displayed var document: PDFDocument! @@ -52,6 +54,14 @@ open class PDFViewController: UIViewController { /// The default action brings up a UIActivityViewController open lazy var shareBarButtonAction: () -> () = { self.showActivitySheet() } + /// A closure that defines what happens on viewWillDisappear. + /// The default is to assign the annotations out of the annotationController into + /// the document, then call document.save() + open lazy var autoSaveAction: (PDFDocument, PDFAnnotationController) -> () = { document, annotationController in + document.annotations = annotationController.annotations + document.save() + } + /// A reference to the collection view handling page presentation var collectionView: PDFSinglePageViewer! @@ -75,6 +85,9 @@ open class PDFViewController: UIViewController { public init(document: PDFDocument) { super.init(nibName: nil, bundle: nil) self.document = document + self.modalDoneButtonTouched = { [unowned self] in + self.dismiss(animated: true, completion: nil) + } } /** @@ -160,15 +173,14 @@ open class PDFViewController: UIViewController { super.viewWillDisappear(animated) self.annotationController.finishAnnotation() - self.document.annotations = self.annotationController.annotations - self.document.save() + autoSaveAction(self.document, self.annotationController) } open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) coordinator.animate(alongsideTransition: { (context) in - self.collectionView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, self.bottomLayoutGuide.length, 0) + self.collectionView.contentInset = UIEdgeInsets(top: self.topLayoutGuide.length, left: 0, bottom: self.bottomLayoutGuide.length, right: 0) self.collectionView.collectionViewLayout.invalidateLayout() self.pageScrubber.sizeToFit() }, completion: { (context) in @@ -198,13 +210,23 @@ open class PDFViewController: UIViewController { open func rightBarButtons() -> [UIBarButtonItem] { if (signatureMode) { - var buttons = self.navigationItem.rightBarButtonItems! + var buttons = self.navigationItem.rightBarButtonItems ?? [] // undo button buttons.append(annotationController.undoButton) - // draw button - buttons.append(annotationController.buttons[1]); + // find the draw button (hopefully you added that thing huh?) + if let penButton = annotationController.buttons.filter({ (button: PDFBarButton) -> Bool in + if let annotationButton = button as? PDFAnnotationBarButton { + return annotationButton.annotationType == PDFPenAnnotation.self + } + return false + }).first { + buttons.append(penButton); + } + else { + assert(false, "Used 'signatureMode' of true, but did NOT provide the PDFPenAnnotationBarButton as an annotation! No Sign button for you!") + } return buttons } @@ -252,7 +274,7 @@ open class PDFViewController: UIViewController { return buttons } - func toggleAnnotations(_ button: PDFBarButton) { + @objc func toggleAnnotations(_ button: PDFBarButton) { showingAnnotations = !showingAnnotations reloadBarButtons() } @@ -286,7 +308,7 @@ open class PDFViewController: UIViewController { present(activityVC, animated: true, completion: nil) } - func showThumbnailView() { + @objc func showThumbnailView() { let vc = PDFThumbnailViewController(document: document) vc.delegate = self let nvc = UINavigationController(rootViewController: vc) @@ -321,12 +343,12 @@ open class PDFViewController: UIViewController { self.toggleBars() } - func shareDocument() { + @objc func shareDocument() { self.shareBarButtonAction() } - func dismissModal() { - dismiss(animated: true, completion: nil) + @objc func dismissModal() { + modalDoneButtonTouched?() } } diff --git a/Pod/Classes/TextParser/PDFTextParser.swift b/Pod/Classes/TextParser/PDFTextParser.swift old mode 100644 new mode 100755 diff --git a/Pod/Classes/View/PDFBarButton.swift b/Pod/Classes/View/PDFBarButton.swift old mode 100644 new mode 100755 index 9a49462..bcacd21 --- a/Pod/Classes/View/PDFBarButton.swift +++ b/Pod/Classes/View/PDFBarButton.swift @@ -40,7 +40,7 @@ open class PDFBarButton: UIBarButtonItem { self.block = block button.addTarget(self, action: #selector(PDFBarButton.tapped), for: .touchUpInside) - button.setImage(image?.withRenderingMode(.alwaysTemplate), for: UIControlState()) + button.setImage(image?.withRenderingMode(.alwaysTemplate), for: UIControl.State()) } open func toggle(_ state: Bool) { @@ -57,7 +57,7 @@ open class PDFBarButton: UIBarButtonItem { } } - func tapped() { + @objc func tapped() { let _ = self.target?.perform(self.action, with: self) self.block?(self) } diff --git a/Pod/Classes/View/ResizeableView.swift b/Pod/Classes/View/ResizeableView.swift old mode 100644 new mode 100755 index cced88a..219cde9 --- a/Pod/Classes/View/ResizeableView.swift +++ b/Pod/Classes/View/ResizeableView.swift @@ -41,7 +41,7 @@ open class ResizableView: UIView { var touchStart: CGPoint? var minWidth: CGFloat = 48.0 var minHeight: CGFloat = 48.0 - var anchorPoint: ResizableViewAnchorPoint? + var resizableViewAnchorPoint: ResizableViewAnchorPoint? var delegate: ResizableViewDelegate? var preventsPositionOutsideSuperview: Bool = true var isLocked = false { @@ -73,7 +73,7 @@ open class ResizableView: UIView { } var isResizing: Bool { get { - guard let anchorPoint = self.anchorPoint else { return false } + guard let anchorPoint = self.resizableViewAnchorPoint else { return false } return anchorPoint.adjustsH != 0.0 || anchorPoint.adjustsW != 0.0 || anchorPoint.adjustsX != 0.0 @@ -184,7 +184,7 @@ open class ResizableView: UIView { self.delegate?.resizableViewDidBeginEditing(view: self) self.borderView.isHidden = false - self.anchorPoint = self.anchorPoint(touch: touch.location(in: self)) + self.resizableViewAnchorPoint = self.anchorPoint(touch: touch.location(in: self)) self.touchStart = touch.location(in: self.superview) if !self.isResizing { @@ -235,7 +235,7 @@ open class ResizableView: UIView { guard let superview = self.superview, let touchStart = self.touchStart, - let anchorPoint = self.anchorPoint else { return } + let anchorPoint = self.resizableViewAnchorPoint else { return } // (1) Update the touch point if we're outside the superview. if self.preventsPositionOutsideSuperview { @@ -344,7 +344,7 @@ open class ResizableView: UIView { self.resignFirstResponder() } - func menuActionDelete(_ sender: Any!) { + @objc func menuActionDelete(_ sender: Any!) { self.delegate?.resizableViewDidSelectAction(view: self, action: "delete") } diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/UXMPDFKit.podspec b/UXMPDFKit.podspec old mode 100644 new mode 100755 index 6767ff3..840fe83 --- a/UXMPDFKit.podspec +++ b/UXMPDFKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "UXMPDFKit" - s.version = "0.7.2" + s.version = "0.7.3" s.summary = "A fully functioning PDF reader written completely in Swift" s.homepage = "https://github.com/uxmstudio/UXMPDFKit"