1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // KMSearchMode.swift
- // PDF Reader Pro
- //
- // Created by lxy on 2022/12/9.
- //
- import Cocoa
- class KMSearchMode: NSObject {
- var selection : CPDFSelection = CPDFSelection()
- var attributedString : NSMutableAttributedString = NSMutableAttributedString()
- var selectionPageIndex : UInt = 0
- var datas : [KMSearchMode] = []
- var select: Bool = false
- var hover: Bool = false
-
- func fetchSelection(document: CPDFDocument?) -> CPDFSelection? {
- guard let doc = document else {
- return nil
- }
- if self.selectionPageIndex < 0 || self.selectionPageIndex >= doc.pageCount {
- return nil
- }
- guard let page = document?.page(at: self.selectionPageIndex) else {
- return nil
- }
- return CPDFSelection(page: page, rect: self.selection.bounds)
- }
-
- class func sortSearchResult(results:[KMSearchMode]) ->[KMSearchMode] {
- var sortResult : [KMSearchMode] = []
- var pageIndexs : [UInt] = []
- for mode in results {
- pageIndexs.append(mode.selectionPageIndex)
- }
- if Set(pageIndexs).count != pageIndexs.count {
- pageIndexs = Array(Set(pageIndexs))
- }
- pageIndexs = pageIndexs.sorted()
- for index in pageIndexs {
- var indexs : [KMSearchMode] = []
- for result in results {
- if result.selectionPageIndex == index {
- indexs.append(result)
- }
- }
- var s : KMSearchMode = KMSearchMode()
- s.datas = indexs
- s.selectionPageIndex = index
- sortResult.append(s)
- }
- return sortResult
- }
- }
|