IMImagemeter.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // IMImagemeter.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 22/03/2019.
  6. // Copyright © 2019 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class IMImagemeterCodable: NSObject {
  25. struct imagemeterAnnotation: Codable {
  26. struct coordinates: Codable {
  27. let x: Double
  28. let y: Double
  29. }
  30. struct end_pt: Codable {
  31. let end_pt: coordinates
  32. enum CodingKeys : String, CodingKey {
  33. case end_pt = "end-pt"
  34. }
  35. }
  36. struct audio_recording: Codable {
  37. let recording_filename: String
  38. let recording_duration_msecs: Double
  39. enum CodingKeys : String, CodingKey {
  40. case recording_filename = "recording-filename"
  41. case recording_duration_msecs = "recording-duration-msecs"
  42. }
  43. }
  44. struct capture_timestamp: Codable {
  45. let year: Int
  46. let month: Int
  47. let day: Int
  48. let hour: Int
  49. let minutes: Int
  50. let seconds: Int
  51. }
  52. struct image: Codable {
  53. let title: String
  54. let filename: String
  55. let annotated_image_filename: String
  56. let rotation: Int
  57. enum CodingKeys : String, CodingKey {
  58. case title
  59. case filename
  60. case annotated_image_filename = "annotated-image-filename"
  61. case rotation
  62. }
  63. }
  64. struct export_image_cache: Codable {
  65. let width: Double
  66. let height: Double
  67. let file_format: String
  68. let with_hardware_antialiasing: Bool
  69. let with_watermark: Bool
  70. let with_image_title: Bool
  71. enum CodingKeys : String, CodingKey {
  72. case width
  73. case height
  74. case file_format = "file-format"
  75. case with_hardware_antialiasing = "with-hardware-antialiasing"
  76. case with_watermark = "with-watermark"
  77. case with_image_title = "with-image-title"
  78. }
  79. }
  80. struct elements: Codable {
  81. let id: Int
  82. let class_: String
  83. let center: coordinates
  84. let width: Double
  85. let arrows: [end_pt]
  86. let text: String
  87. let audio_recording: audio_recording
  88. let show_border: Bool
  89. let show_arrows: Bool
  90. let fill_background: Bool
  91. enum CodingKeys : String, CodingKey {
  92. case id
  93. case class_ = "class"
  94. case center
  95. case width
  96. case arrows
  97. case text
  98. case audio_recording = "audio-recording"
  99. case show_border = "show-border"
  100. case show_arrows = "show-arrows"
  101. case fill_background = "fill-background"
  102. }
  103. }
  104. struct thumbnails: Codable {
  105. let filename: String
  106. let width: Int
  107. let height: Int
  108. }
  109. let is_example_image: Bool
  110. let version: Int
  111. let capture_timestamp: capture_timestamp
  112. let image: image
  113. let export_image_cache: [export_image_cache]
  114. let elements: [elements]
  115. let id: String
  116. let thumbnails: [thumbnails]
  117. let last_modification: Int
  118. enum CodingKeys : String, CodingKey {
  119. case is_example_image = "is-example-image"
  120. case version
  121. case capture_timestamp = "capture-timestamp"
  122. case image
  123. case export_image_cache = "export-image-cache"
  124. case elements
  125. case id
  126. case thumbnails
  127. case last_modification = "last-modification"
  128. }
  129. }
  130. @objc static let sharedInstance: IMImagemeterCodable = {
  131. let instance = IMImagemeterCodable()
  132. return instance
  133. }()
  134. func decoderAnnotetion(_ annotation: Data) -> imagemeterAnnotation? {
  135. let jsonDecoder = JSONDecoder.init()
  136. do {
  137. let decode = try jsonDecoder.decode(imagemeterAnnotation.self, from: annotation)
  138. return decode
  139. } catch let error {
  140. print("Serious internal error in decoding metadata ("+error.localizedDescription+")")
  141. return nil
  142. }
  143. }
  144. }