<commit_before>//
//  PDFAnnotationController.swift
//  Pods
//
//  Created by <NAME> on 6/22/16.
//
//

import Foundation

public enum PDFAnnotationType {
    case none
    case pen
    case text
    case highlighter
}

open class PDFAnnotationController: UIViewController {
    
    var document: PDFDocument!
    var annotations: PDFAnnotationStore = PDFAnnotationStore()
    var currentPage: PDFPageContentView?
    var pageView: PDFPageContent?
    var lastPoint: CGPoint?
    var annotationType: PDFAnnotationType = .none
    
    var currentAnnotation: PDFAnnotation?
    
    //MARK: - Bar button items
    lazy var penButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("pen"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedPen(_:))
    )
    
    lazy var highlighterButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("highlighter"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedHighlighter(_:))
    )
    
    lazy var textButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("text-symbol"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedText(_:))
    )
    
    lazy var undoButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("undo"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedUndo(_:))
    )
    
    //MARK: - Init
    public init(document: PDFDocument) {
        
        self.document = document
        
        super.init(nibName: nil, bundle: nil)
        
        self.setupUI()
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        self.view.isUserInteractionEnabled = self.annotationType != .none
        self.view.isOpaque = false
        self.view.backgroundColor = UIColor.clear
    }
    
    
    //MARK: - Annotation handling
    open func showAnnotations(_ contentView: PDFPageContentView) {
        
        self.currentPage = contentView
        let page = contentView.page
        
        self.pageView = contentView.contentView
        
        let annotations = self.annotations.annotationsForPage(page)
        for annot in annotations {
            self.pageView?.addSubview(annot.mutableView())
        }
    }
    
    open func startAnnotation(_ type: PDFAnnotationType) {
        
        self.finishAnnotation()
        self.annotationType = type
        
        if type == .pen { self.currentAnnotation = PDFPathAnnotation() }
        else if type == .highlighter { self.currentAnnotation = PDFHighlighterAnnotation() }
        else if type == .text { self.currentAnnotation = PDFTextAnnotation() }
        
        self.view.isUserInteractionEnabled = self.annotationType != .none
        
        if let annotation = self.currentAnnotation {
            self.pageView?.addSubview(annotation.mutableView())
        }
    }
    
    open func finishAnnotation() {
        
        guard let annotation = self.currentAnnotation else { return }
        guard let currentPage = self.currentPage else { return }<commit_msg>startAnnotation func uses a switch statement<commit_after>//
//  PDFAnnotationController.swift
//  Pods
//
//  Created by <NAME> on 6/22/16.
//
//

import Foundation

public enum PDFAnnotationType {
    case none
    case pen
    case text
    case highlighter
}

open class PDFAnnotationController: UIViewController {
    
    var document: PDFDocument!
    var annotations: PDFAnnotationStore = PDFAnnotationStore()
    var currentPage: PDFPageContentView?
    var pageView: PDFPageContent?
    var lastPoint: CGPoint?
    var annotationType: PDFAnnotationType = .none
    
    var currentAnnotation: PDFAnnotation?
    
    //MARK: - Bar button items
    lazy var penButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("pen"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedPen(_:))
    )
    
    lazy var highlighterButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("highlighter"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedHighlighter(_:))
    )
    
    lazy var textButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("text-symbol"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedText(_:))
    )
    
    lazy var undoButton: PDFBarButton = PDFBarButton(
        image: UIImage.bundledImage("undo"),
        toggled: false,
        target: self,
        action: #selector(PDFAnnotationController.selectedUndo(_:))
    )
    
    //MARK: - Init
    public init(document: PDFDocument) {
        
        self.document = document
        
        super.init(nibName: nil, bundle: nil)
        
        self.setupUI()
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        self.view.isUserInteractionEnabled = self.annotationType != .none
        self.view.isOpaque = false
        self.view.backgroundColor = UIColor.clear
    }
    
    
    //MARK: - Annotation handling
    open func showAnnotations(_ contentView: PDFPageContentView) {
        
        self.currentPage = contentView
        let page = contentView.page
        
        self.pageView = contentView.contentView
        
        let annotations = self.annotations.annotationsForPage(page)
        for annot in annotations {
            self.pageView?.addSubview(annot.mutableView())
        }
    }
    
    open func startAnnotation(_ type: PDFAnnotationType) {
        
        self.finishAnnotation()
        self.annotationType = type
        
        switch type {
        case .pen:
            self.currentAnnotation = PDFPathAnnotation()
        case .highlighter:
            self.currentAnnotation = PDFHighlighterAnnotation()
        case .text:
            self.currentAnnotation = PDFTextAnnotation()
        case .none:
            break
        }
        
        self.view.isUserInteractionEnabled = self.annotationType != .none
        
        if let annotation = self.currentAnnotation {
            self.pageView?.addSubview(annotation.mutableView())
        }
    }
    
    open func finishAnnotation() {
        
        guard let annotation = self.currentAnnotation else { return }
        guard let currentPage = self.currentPage else { return }
{'fraction_non_alphanumeric': 0.0857185450208706, 'fraction_numerical': 0.0014907573047107932, 'mean_word_length': 2.250484496124031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5446419', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1814, 'n_words': 417}