KMPreferenceCommon.swift 17 KB

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