KMConvertImageWindowController.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // KMConvertImageWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. // 转档 转图片 窗口
  8. class KMConvertImageWindowController: KMConvertBaseWindowController {
  9. override func initDefaultValue() {
  10. super.initDefaultValue()
  11. self.titleLabel.stringValue = NSLocalizedString("PDF to Image", comment: "")
  12. }
  13. override func initSettingView() -> KMConvertSettingView? {
  14. return KMConvertImageSettingView.createFromNib()
  15. }
  16. override func initConvert() -> KMPDFConvert {
  17. return KMPDFConvertImage()
  18. }
  19. override var fileExtension: String {
  20. let settingView: KMConvertImageSettingView = self.settingView as! KMConvertImageSettingView
  21. if (settingView.selectedFormatIndex == 0 || settingView.selectedFormatIndex == 2) {
  22. return "zip"
  23. }
  24. return super.fileExtension
  25. }
  26. override func convertModelAppendParams(convert: KMPDFConvert) {
  27. let settingView: KMConvertImageSettingView = self.settingView as! KMConvertImageSettingView
  28. if (settingView.selectedFormatIndex == 0) {
  29. convert.convertType = .jpeg
  30. } else if (settingView.selectedFormatIndex == 1) {
  31. convert.convertType = .jpg
  32. } else if (settingView.selectedFormatIndex == 2) {
  33. convert.convertType = .png
  34. } else if (settingView.selectedFormatIndex == 3) {
  35. convert.convertType = .gif
  36. } else if (settingView.selectedFormatIndex == 4) {
  37. convert.convertType = .tiff
  38. } else if (settingView.selectedFormatIndex == 5) {
  39. convert.convertType = .tga
  40. } else if (settingView.selectedFormatIndex == 6) {
  41. convert.convertType = .bmp
  42. } else if (settingView.selectedFormatIndex == 7) {
  43. convert.convertType = .jp2
  44. } else {
  45. convert.convertType = .jpeg
  46. }
  47. var dpi: Int = 150
  48. if settingView.selectedResolutionIndex == 0 {
  49. dpi = 50
  50. } else if settingView.selectedResolutionIndex == 1 {
  51. dpi = 72
  52. } else if settingView.selectedResolutionIndex == 2 {
  53. dpi = 96
  54. } else if settingView.selectedResolutionIndex == 3 {
  55. dpi = 150
  56. } else if settingView.selectedResolutionIndex == 4 {
  57. dpi = 300
  58. } else if settingView.selectedResolutionIndex == 5 {
  59. dpi = 600
  60. } else {
  61. dpi = 150
  62. }
  63. if let _convert = convert as? KMPDFConvertImage {
  64. if (convert.convertType == .jpeg) {
  65. _convert.imageType = .JPEG
  66. _convert.imageDpi = dpi
  67. } else if (convert.convertType == .png) {
  68. _convert.imageType = .PNG
  69. _convert.imageDpi = dpi
  70. } else {
  71. _convert.imageDpi = 150
  72. }
  73. }
  74. }
  75. }