KMPreferenceCommon.swift 17 KB

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