KMPreferenceCommon.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. //
  2. // KMPreferenceCommon.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/1/16.
  6. //
  7. import Foundation
  8. // general
  9. public let KMUserNameKey = "SKUserName"
  10. public let KMReopenLastOpenFilesKey = "SKReopenLastOpenFiles"
  11. public let KMOpenDocumentInTabKey = "KMOpenDocumentInTab"
  12. public let KMInitialWindowSizeOptionKey = "SKInitialWindowSizeOption"
  13. public let KMOpenContentsPaneOnlyForTOCKey = "SKOpenContentsPaneOnlyForTOC"
  14. public let KMRememberSnapshotsKey = "SKRememberSnapshots"
  15. public let KMDefaultPDFDisplaySettingsKey = "SKDefaultPDFDisplaySettings"
  16. public let KMDefaultFullScreenPDFDisplaySettingsKey = "SKDefaultFullScreenPDFDisplaySettings"
  17. public let KMAutoSaveSkimNotesKey = "SKAutoSaveSkimNotes"
  18. public let KMSnapshotsOnTopKey = "SKSnapshotsOnTop"
  19. public let KMSavePasswordOptionKey = "SKSavePasswordOption"
  20. // display
  21. public let KMThumbnailSizeKey = "SKThumbnailSize"
  22. public let KMSnapshotThumbnailSizeKey = "SKSnapshotThumbnailSize"
  23. public let KMTableFontSizeKey = "SKTableFontSize"
  24. public let KMGreekingThresholdKey = "SKGreekingThreshold"
  25. public let KMShouldAntiAliasKey = "SKShouldAntiAlias"
  26. public let KMBackgroundColorKey = "SKBackgroundColor"
  27. public let KMFullScreenBackgroundColorKey = "SKFullScreenBackgroundColor"
  28. public let KMReadingBarColorKey = "SKReadingBarColor"
  29. public let KMReadingBarInvertKey = "SKReadingBarInvert"
  30. // note
  31. public let KMFreeTextNoteColorKey = "SKFreeTextNoteColor"
  32. public let KMAnchoredNoteColorKey = "SKAnchoredNoteColor"
  33. public let KMLineNoteColorKey = "SKLineNoteColor"
  34. public let KMLineNoteInteriorColorKey = "SKLineNoteInteriorColor"
  35. public let KMCircleNoteColorKey = "SKCircleNoteColor"
  36. public let KMCircleNoteInteriorColorKey = "SKCircleNoteInteriorColor"
  37. public let KMSquareNoteColorKey = "SKSquareNoteColor"
  38. public let KMSquareNoteInteriorColorKey = "SKSquareNoteInteriorColor"
  39. public let KMHighlightNoteColorKey = "SKHighlightNoteColor"
  40. public let KMUnderlineNoteColorKey = "SKUnderlineNoteColor"
  41. public let KMStrikeOutNoteColorKey = "SKStrikeOutNoteColor"
  42. public let KMInkNoteColorKey = "SKInkNoteColor"
  43. // font
  44. public let KMFreeTextNoteFontNameKey = "SKFreeTextNoteFontName"
  45. public let KMFreeTextNoteFontSizeKey = "SKFreeTextNoteFontSize"
  46. public let KMFreeTextNoteAlignmentKey = "SKFreeTextNoteAlignment"
  47. public let KMAnchoredNoteFontNameKey = "SKAnchoredNoteFontName"
  48. public let KMAnchoredNoteFontSizeKey = "SKAnchoredNoteFontSize"
  49. // line style
  50. public let KMFreeTextNoteLineStyleKey = "SKFreeTextNoteLineStyle"
  51. public let KMFreeTextNoteLineWidthKey = "SKFreeTextNoteLineWidth"
  52. public let KMFreeTextNoteDashPatternKey = "SKFreeTextNoteDashPattern"
  53. public let KMCircleNoteLineStyleKey = "SKCircleNoteLineStyle"
  54. public let KMCircleNoteLineWidthKey = "SKCircleNoteLineWidth"
  55. public let KMCircleNoteDashPatternhKey = "SKCircleNoteDashPattern"
  56. public let KMSquareNoteLineStyleKey = "SKSquareNoteLineStyle"
  57. public let KMSquareNoteLineWidthKey = "SKSquareNoteLineWidth"
  58. public let KMSquareNoteDashPatternKey = "SKSquareNoteDashPattern"
  59. public let KMLineNoteLineStyleKey = "SKLineNoteLineStyle"
  60. public let KMLineNoteLineWidthKey = "SKLineNoteLineWidth"
  61. public let KMLineNoteDashPatternKey = "SKLineNoteDashPattern"
  62. public let KMLineNoteStartLineStyleKey = "SKLineNoteStartLineStyle"
  63. public let KMLineNoteEndLineStyleKey = "SKLineNoteEndLineStyle"
  64. public let KMInkNoteLineStyleKey = "SKInkNoteLineStyle"
  65. public let KMInkNoteLineWidthKey = "SKInkNoteLineWidth"
  66. public let KMInkNoteDashPatternKey = "SKInkNoteDashPattern"
  67. func KMPreferenceKeyToCKey(pKey: KMPreferenceKey) -> String? {
  68. // freeText
  69. if pKey == KMPreference.freeTextNoteLineWidthKey {
  70. return CFreeTextNoteLineWidthKey
  71. } else if pKey == KMPreference.freeTextNoteLineStyleKey {
  72. return CFreeTextNoteLineStyleKey
  73. } else if pKey == KMPreference.freeTextNoteDashPatternKey {
  74. return CFreeTextNoteDashPatternKey
  75. }
  76. // Line
  77. else if pKey == KMPreference.lineNoteLineWidthKey {
  78. return CLineNoteLineWidthKey
  79. } else if pKey == KMPreference.lineNoteLineStyleKey {
  80. return CLineNoteLineStyleKey
  81. } else if pKey == KMPreference.lineNoteDashPatternKey {
  82. return CLineNoteDashPatternKey
  83. } else if pKey == KMPreference.lineNoteStartLineStyleKey {
  84. return CLineNoteStartLineStyleKey
  85. } else if pKey == KMPreference.lineNoteEndLineStyleKey {
  86. return CLineNoteEndLineStyleKey
  87. }
  88. // freehand
  89. else if pKey == KMPreference.inkNoteLineWidthKey {
  90. return CInkNoteLineWidthKey
  91. } else if pKey == KMPreference.inkNoteLineStyleKey {
  92. return CInkNoteLineStyleKey
  93. } else if pKey == KMPreference.inkNoteDashPatternKey {
  94. return CInkNoteDashPatternKey
  95. }
  96. // circle
  97. else if pKey == KMPreference.circleNoteLineWidthKey {
  98. return CCircleNoteLineWidthKey
  99. } else if pKey == KMPreference.circleNoteLineStyleKey {
  100. return CCircleNoteLineStyleKey
  101. } else if pKey == KMPreference.circleNoteDashPatternKey {
  102. return CCircleNoteDashPatternKey
  103. }
  104. // rect
  105. else if pKey == KMPreference.squareNoteLineWidthKey {
  106. return CSquareNoteLineWidthKey
  107. } else if pKey == KMPreference.squareNoteLineStyleKey {
  108. return CSquareNoteLineStyleKey
  109. } else if pKey == KMPreference.squareNoteDashPatternKey {
  110. return CSquareNoteDashPatternKey
  111. }
  112. return nil
  113. }
  114. // MARK: - NSUserDefault key 与 偏好设置 key 相互转换
  115. func KMPreferenceKeyToUDKey(pKey: KMPreferenceKey) -> String? {
  116. // general
  117. if pKey == KMPreference.generalAuthorNameKey {
  118. return KMUserNameKey
  119. } else if pKey == KMPreference.openLastUnclosedDocumentWhenAppStartKey {
  120. return KMReopenLastOpenFilesKey
  121. } else if pKey == KMPreference.openDocumentTypeKey {
  122. return KMOpenDocumentInTabKey
  123. } else if pKey == KMPreference.openFileTypeKey {
  124. return KMInitialWindowSizeOptionKey
  125. } else if pKey == KMPreference.showLeftSideBarKey {
  126. return KMOpenContentsPaneOnlyForTOCKey
  127. } else if pKey == KMPreference.rememberSnapshotKey {
  128. return KMRememberSnapshotsKey
  129. } else if pKey == KMPreference.autoSaveNoteBackupKey {
  130. return KMAutoSaveSkimNotesKey
  131. } else if pKey == KMPreference.keepSnapshotWindowToTopKey {
  132. return KMSnapshotsOnTopKey
  133. } else if pKey == KMPreference.savePasswordTypeKey {
  134. return KMSavePasswordOptionKey
  135. }
  136. // display
  137. else if pKey == KMPreference.thumbPageSizeKey {
  138. return KMThumbnailSizeKey
  139. } else if pKey == KMPreference.thumbSnapshotSizeKey {
  140. return KMSnapshotThumbnailSizeKey
  141. } else if pKey == KMPreference.outlineFontSizeKey {
  142. return KMTableFontSizeKey
  143. } else if pKey == KMPreference.greekThresholdKey {
  144. return KMGreekingThresholdKey
  145. } else if pKey == KMPreference.antiAliasTextKey {
  146. return KMShouldAntiAliasKey
  147. } else if pKey == KMPreference.displayBackgroundNormalColorKey {
  148. return KMBackgroundColorKey
  149. } else if pKey == KMPreference.displayBackgroundFullScreenColorKey {
  150. return KMFullScreenBackgroundColorKey
  151. } else if pKey == KMPreference.readBarColorKey {
  152. return KMReadingBarColorKey
  153. } else if pKey == KMPreference.invertBarKey {
  154. return KMReadingBarInvertKey
  155. }
  156. // note
  157. else if pKey == KMPreference.markupColorTextKey {
  158. return KMFreeTextNoteColorKey
  159. } else if pKey == KMPreference.markupColorNoteKey {
  160. return KMAnchoredNoteColorKey
  161. } else if pKey == KMPreference.markupColorLineKey {
  162. return KMLineNoteColorKey
  163. }
  164. // else if pKey == KMPreference.markup
  165. else if pKey == KMPreference.markupColorCircleBorderKey {
  166. return KMCircleNoteColorKey
  167. } else if pKey == KMPreference.markupColorCircleFillKey {
  168. return KMCircleNoteInteriorColorKey
  169. } else if pKey == KMPreference.markupColorRectangleBorderKey {
  170. return KMSquareNoteColorKey
  171. } else if pKey == KMPreference.markupColorRectangleFillKey {
  172. return KMSquareNoteInteriorColorKey
  173. } else if pKey == KMPreference.markupColorHighlightKey {
  174. return KMHighlightNoteColorKey
  175. } else if pKey == KMPreference.markupColorUnderlineKey {
  176. return KMUnderlineNoteColorKey
  177. } else if pKey == KMPreference.markupColorStrikthroughKey {
  178. return KMStrikeOutNoteColorKey
  179. } else if pKey == KMPreference.markupColorPenKey {
  180. return KMInkNoteColorKey
  181. }
  182. // font
  183. else if pKey == KMPreference.markupFontTextStringKey {
  184. return KMFreeTextNoteFontNameKey
  185. } else if pKey == KMPreference.markupTextFontSizeKey {
  186. return KMFreeTextNoteFontSizeKey
  187. } else if pKey == KMPreference.markupFontTextAligmentKey {
  188. return KMFreeTextNoteAlignmentKey
  189. } else if pKey == KMPreference.markupFontNoteStringKey {
  190. return KMAnchoredNoteFontNameKey
  191. } else if pKey == KMPreference.markupNoteFontSizeKey {
  192. return KMAnchoredNoteFontSizeKey
  193. }
  194. // line style
  195. else if pKey == KMPreference.freeTextNoteLineStyleKey {
  196. return KMFreeTextNoteLineStyleKey
  197. } else if pKey == KMPreference.freeTextNoteLineWidthKey {
  198. return KMFreeTextNoteLineWidthKey
  199. } else if pKey == KMPreference.freeTextNoteDashPatternKey {
  200. return KMFreeTextNoteDashPatternKey
  201. }
  202. else if pKey == KMPreference.circleNoteLineStyleKey {
  203. return KMCircleNoteLineStyleKey
  204. } else if pKey == KMPreference.circleNoteLineWidthKey {
  205. return KMCircleNoteLineWidthKey
  206. } else if pKey == KMPreference.circleNoteDashPatternKey {
  207. return KMCircleNoteDashPatternhKey
  208. }
  209. else if pKey == KMPreference.squareNoteLineStyleKey {
  210. return KMSquareNoteLineStyleKey
  211. } else if pKey == KMPreference.squareNoteLineWidthKey {
  212. return KMSquareNoteLineWidthKey
  213. } else if pKey == KMPreference.squareNoteDashPatternKey {
  214. return KMSquareNoteDashPatternKey
  215. }
  216. else if pKey == KMPreference.lineNoteLineStyleKey {
  217. return KMLineNoteLineStyleKey
  218. } else if pKey == KMPreference.lineNoteLineWidthKey {
  219. return KMLineNoteLineWidthKey
  220. } else if pKey == KMPreference.lineNoteDashPatternKey {
  221. return KMLineNoteDashPatternKey
  222. } else if pKey == KMPreference.lineNoteStartLineStyleKey {
  223. return KMLineNoteStartLineStyleKey
  224. } else if pKey == KMPreference.lineNoteEndLineStyleKey {
  225. return KMLineNoteEndLineStyleKey
  226. }
  227. else if pKey == KMPreference.inkNoteLineStyleKey {
  228. return KMInkNoteLineStyleKey
  229. } else if pKey == KMPreference.inkNoteLineWidthKey {
  230. return KMInkNoteLineWidthKey
  231. } else if pKey == KMPreference.inkNoteDashPatternKey {
  232. return KMInkNoteDashPatternKey
  233. }
  234. return nil
  235. }
  236. //public let KMLineNoteInteriorColorKey = "SKLineNoteInteriorColor"
  237. func KMPreferenceKeyFromUDKey(udKey: String) -> KMPreferenceKey? {
  238. // general
  239. if udKey == KMUserNameKey {
  240. return KMPreference.generalAuthorNameKey
  241. } else if udKey == KMReopenLastOpenFilesKey {
  242. return KMPreference.openLastUnclosedDocumentWhenAppStartKey
  243. } else if udKey == KMOpenDocumentInTabKey {
  244. return KMPreference.openDocumentTypeKey
  245. } else if udKey == KMInitialWindowSizeOptionKey {
  246. return KMPreference.openFileTypeKey
  247. } else if udKey == KMOpenContentsPaneOnlyForTOCKey {
  248. return KMPreference.showLeftSideBarKey
  249. } else if udKey == KMRememberSnapshotsKey {
  250. return KMPreference.rememberSnapshotKey
  251. } else if udKey == KMAutoSaveSkimNotesKey {
  252. return KMPreference.autoSaveNoteBackupKey
  253. } else if udKey == KMSnapshotsOnTopKey {
  254. return KMPreference.keepSnapshotWindowToTopKey
  255. } else if udKey == KMSavePasswordOptionKey {
  256. return KMPreference.savePasswordTypeKey
  257. }
  258. // display
  259. else if udKey == KMThumbnailSizeKey {
  260. return KMPreference.thumbPageSizeKey
  261. } else if udKey == KMSnapshotThumbnailSizeKey {
  262. return KMPreference.thumbSnapshotSizeKey
  263. } else if udKey == KMTableFontSizeKey {
  264. return KMPreference.outlineFontSizeKey
  265. } else if udKey == KMGreekingThresholdKey {
  266. return KMPreference.greekThresholdKey
  267. } else if udKey == KMShouldAntiAliasKey {
  268. return KMPreference.antiAliasTextKey
  269. } else if udKey == KMBackgroundColorKey {
  270. return KMPreference.displayBackgroundNormalColorKey
  271. } else if udKey == KMFullScreenBackgroundColorKey {
  272. return KMPreference.displayBackgroundFullScreenColorKey
  273. } else if udKey == KMReadingBarColorKey {
  274. return KMPreference.readBarColorKey
  275. } else if udKey == KMReadingBarInvertKey {
  276. return KMPreference.invertBarKey
  277. }
  278. // note
  279. else if udKey == KMFreeTextNoteColorKey {
  280. return KMPreference.markupColorTextKey
  281. } else if udKey == KMAnchoredNoteColorKey {
  282. return KMPreference.markupColorNoteKey
  283. } else if udKey == KMLineNoteColorKey {
  284. return KMPreference.markupColorLineKey
  285. } else if udKey == KMCircleNoteColorKey {
  286. return KMPreference.markupColorCircleBorderKey
  287. } else if udKey == KMCircleNoteInteriorColorKey {
  288. return KMPreference.markupColorCircleFillKey
  289. } else if udKey == KMSquareNoteColorKey {
  290. return KMPreference.markupColorRectangleBorderKey
  291. } else if udKey == KMSquareNoteInteriorColorKey {
  292. return KMPreference.markupColorRectangleFillKey
  293. } else if udKey == KMHighlightNoteColorKey {
  294. return KMPreference.markupColorHighlightKey
  295. } else if udKey == KMUnderlineNoteColorKey {
  296. return KMPreference.markupColorUnderlineKey
  297. } else if udKey == KMStrikeOutNoteColorKey {
  298. return KMPreference.markupColorStrikthroughKey
  299. } else if udKey == KMInkNoteColorKey {
  300. return KMPreference.markupColorPenKey
  301. }
  302. // font
  303. else if udKey == KMFreeTextNoteFontNameKey {
  304. return KMPreference.markupFontTextStringKey
  305. } else if udKey == KMFreeTextNoteFontSizeKey {
  306. return KMPreference.markupTextFontSizeKey
  307. } else if udKey == KMFreeTextNoteAlignmentKey {
  308. return KMPreference.markupFontTextAligmentKey
  309. } else if udKey == KMAnchoredNoteFontNameKey {
  310. return KMPreference.markupFontNoteStringKey
  311. } else if udKey == KMAnchoredNoteFontSizeKey {
  312. return KMPreference.markupNoteFontSizeKey
  313. }
  314. // line style
  315. else if udKey == KMFreeTextNoteLineStyleKey {
  316. return KMPreference.freeTextNoteLineStyleKey
  317. } else if udKey == KMFreeTextNoteLineWidthKey {
  318. return KMPreference.freeTextNoteLineWidthKey
  319. } else if udKey == KMFreeTextNoteDashPatternKey {
  320. return KMPreference.freeTextNoteDashPatternKey
  321. }
  322. else if udKey == KMCircleNoteLineStyleKey {
  323. return KMPreference.circleNoteLineStyleKey
  324. } else if udKey == KMCircleNoteLineWidthKey {
  325. return KMPreference.circleNoteLineWidthKey
  326. } else if udKey == KMCircleNoteDashPatternhKey {
  327. return KMPreference.circleNoteDashPatternKey
  328. }
  329. else if udKey == KMSquareNoteLineStyleKey {
  330. return KMPreference.squareNoteLineStyleKey
  331. } else if udKey == KMSquareNoteLineWidthKey {
  332. return KMPreference.squareNoteLineWidthKey
  333. } else if udKey == KMSquareNoteDashPatternKey {
  334. return KMPreference.squareNoteDashPatternKey
  335. }
  336. else if udKey == KMLineNoteLineStyleKey {
  337. return KMPreference.lineNoteLineStyleKey
  338. } else if udKey == KMLineNoteLineWidthKey {
  339. return KMPreference.lineNoteLineWidthKey
  340. } else if udKey == KMLineNoteDashPatternKey {
  341. return KMPreference.lineNoteDashPatternKey
  342. } else if udKey == KMLineNoteStartLineStyleKey {
  343. return KMPreference.lineNoteStartLineStyleKey
  344. } else if udKey == KMLineNoteEndLineStyleKey {
  345. return KMPreference.lineNoteEndLineStyleKey
  346. }
  347. else if udKey == KMInkNoteLineStyleKey {
  348. return KMPreference.inkNoteLineStyleKey
  349. } else if udKey == KMInkNoteLineWidthKey {
  350. return KMPreference.inkNoteLineWidthKey
  351. } else if udKey == KMInkNoteDashPatternKey {
  352. return KMPreference.inkNoteDashPatternKey
  353. }
  354. return nil
  355. }