You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * Copyright 2012 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ZXDataMatrixVersion.h"
  17. @implementation ZXDataMatrixECBlocks
  18. - (id)initWithCodewords:(int)ecCodewords ecBlocks:(ZXDataMatrixECB *)ecBlocks {
  19. if (self = [super init]) {
  20. _ecCodewords = ecCodewords;
  21. _ecBlocks = @[ecBlocks];
  22. }
  23. return self;
  24. }
  25. - (id)initWithCodewords:(int)ecCodewords ecBlocks1:(ZXDataMatrixECB *)ecBlocks1 ecBlocks2:(ZXDataMatrixECB *)ecBlocks2 {
  26. if (self = [super init]) {
  27. _ecCodewords = ecCodewords;
  28. _ecBlocks = @[ecBlocks1, ecBlocks2];
  29. }
  30. return self;
  31. }
  32. @end
  33. @implementation ZXDataMatrixECB
  34. - (id)initWithCount:(int)count dataCodewords:(int)dataCodewords {
  35. if (self = [super init]) {
  36. _count = count;
  37. _dataCodewords = dataCodewords;
  38. }
  39. return self;
  40. }
  41. @end
  42. static NSArray *VERSIONS = nil;
  43. @implementation ZXDataMatrixVersion
  44. - (id)initWithVersionNumber:(int)versionNumber symbolSizeRows:(int)symbolSizeRows symbolSizeColumns:(int)symbolSizeColumns
  45. dataRegionSizeRows:(int)dataRegionSizeRows dataRegionSizeColumns:(int)dataRegionSizeColumns ecBlocks:(ZXDataMatrixECBlocks *)ecBlocks {
  46. if (self = [super init]) {
  47. _versionNumber = versionNumber;
  48. _symbolSizeRows = symbolSizeRows;
  49. _symbolSizeColumns = symbolSizeColumns;
  50. _dataRegionSizeRows = dataRegionSizeRows;
  51. _dataRegionSizeColumns = dataRegionSizeColumns;
  52. _ecBlocks = ecBlocks;
  53. int total = 0;
  54. int ecCodewords = ecBlocks.ecCodewords;
  55. NSArray *ecbArray = ecBlocks.ecBlocks;
  56. for (ZXDataMatrixECB *ecBlock in ecbArray) {
  57. total += ecBlock.count * (ecBlock.dataCodewords + ecCodewords);
  58. }
  59. _totalCodewords = total;
  60. }
  61. return self;
  62. }
  63. + (ZXDataMatrixVersion *)versionForDimensions:(int)numRows numColumns:(int)numColumns {
  64. if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
  65. return nil;
  66. }
  67. for (ZXDataMatrixVersion *version in VERSIONS) {
  68. if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns) {
  69. return version;
  70. }
  71. }
  72. return nil;
  73. }
  74. - (NSString *)description {
  75. return [@(self.versionNumber) stringValue];
  76. }
  77. /**
  78. * See ISO 16022:2006 5.5.1 Table 7
  79. */
  80. + (void)initialize {
  81. if ([self class] != [ZXDataMatrixVersion class]) return;
  82. VERSIONS = @[[[ZXDataMatrixVersion alloc] initWithVersionNumber:1
  83. symbolSizeRows:10
  84. symbolSizeColumns:10
  85. dataRegionSizeRows:8
  86. dataRegionSizeColumns:8
  87. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:5
  88. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:3]]],
  89. [[ZXDataMatrixVersion alloc] initWithVersionNumber:2
  90. symbolSizeRows:12
  91. symbolSizeColumns:12
  92. dataRegionSizeRows:10
  93. dataRegionSizeColumns:10
  94. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:7
  95. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:5]]],
  96. [[ZXDataMatrixVersion alloc] initWithVersionNumber:3
  97. symbolSizeRows:14
  98. symbolSizeColumns:14
  99. dataRegionSizeRows:12
  100. dataRegionSizeColumns:12
  101. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:10
  102. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:8]]],
  103. [[ZXDataMatrixVersion alloc] initWithVersionNumber:4
  104. symbolSizeRows:16
  105. symbolSizeColumns:16
  106. dataRegionSizeRows:14
  107. dataRegionSizeColumns:14
  108. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:12
  109. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:12]]],
  110. [[ZXDataMatrixVersion alloc] initWithVersionNumber:5
  111. symbolSizeRows:18
  112. symbolSizeColumns:18
  113. dataRegionSizeRows:16
  114. dataRegionSizeColumns:16
  115. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:14
  116. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:18]]],
  117. [[ZXDataMatrixVersion alloc] initWithVersionNumber:6
  118. symbolSizeRows:20
  119. symbolSizeColumns:20
  120. dataRegionSizeRows:18
  121. dataRegionSizeColumns:18
  122. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:18
  123. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:22]]],
  124. [[ZXDataMatrixVersion alloc] initWithVersionNumber:7
  125. symbolSizeRows:22
  126. symbolSizeColumns:22
  127. dataRegionSizeRows:20
  128. dataRegionSizeColumns:20
  129. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:20
  130. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:30]]],
  131. [[ZXDataMatrixVersion alloc] initWithVersionNumber:8
  132. symbolSizeRows:24
  133. symbolSizeColumns:24
  134. dataRegionSizeRows:22
  135. dataRegionSizeColumns:22
  136. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:24
  137. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:36]]],
  138. [[ZXDataMatrixVersion alloc] initWithVersionNumber:9
  139. symbolSizeRows:26
  140. symbolSizeColumns:26
  141. dataRegionSizeRows:24
  142. dataRegionSizeColumns:24
  143. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:28
  144. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:44]]],
  145. [[ZXDataMatrixVersion alloc] initWithVersionNumber:10
  146. symbolSizeRows:32
  147. symbolSizeColumns:32
  148. dataRegionSizeRows:14
  149. dataRegionSizeColumns:14
  150. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:36
  151. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:62]]],
  152. [[ZXDataMatrixVersion alloc] initWithVersionNumber:11
  153. symbolSizeRows:36
  154. symbolSizeColumns:36
  155. dataRegionSizeRows:16
  156. dataRegionSizeColumns:16
  157. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:42
  158. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:86]]],
  159. [[ZXDataMatrixVersion alloc] initWithVersionNumber:12
  160. symbolSizeRows:40
  161. symbolSizeColumns:40
  162. dataRegionSizeRows:18
  163. dataRegionSizeColumns:18
  164. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:48
  165. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:114]]],
  166. [[ZXDataMatrixVersion alloc] initWithVersionNumber:13
  167. symbolSizeRows:44
  168. symbolSizeColumns:44
  169. dataRegionSizeRows:20
  170. dataRegionSizeColumns:20
  171. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:56
  172. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:144]]],
  173. [[ZXDataMatrixVersion alloc] initWithVersionNumber:14
  174. symbolSizeRows:48
  175. symbolSizeColumns:48
  176. dataRegionSizeRows:22
  177. dataRegionSizeColumns:22
  178. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:68
  179. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:174]]],
  180. [[ZXDataMatrixVersion alloc] initWithVersionNumber:15
  181. symbolSizeRows:52
  182. symbolSizeColumns:52
  183. dataRegionSizeRows:24
  184. dataRegionSizeColumns:24
  185. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:42
  186. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:2 dataCodewords:102]]],
  187. [[ZXDataMatrixVersion alloc] initWithVersionNumber:16
  188. symbolSizeRows:64
  189. symbolSizeColumns:64
  190. dataRegionSizeRows:14
  191. dataRegionSizeColumns:14
  192. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:56
  193. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:2 dataCodewords:140]]],
  194. [[ZXDataMatrixVersion alloc] initWithVersionNumber:17
  195. symbolSizeRows:72
  196. symbolSizeColumns:72
  197. dataRegionSizeRows:16
  198. dataRegionSizeColumns:16
  199. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:36
  200. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:4 dataCodewords:92]]],
  201. [[ZXDataMatrixVersion alloc] initWithVersionNumber:18
  202. symbolSizeRows:80
  203. symbolSizeColumns:80
  204. dataRegionSizeRows:18
  205. dataRegionSizeColumns:18
  206. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:48
  207. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:4 dataCodewords:114]]],
  208. [[ZXDataMatrixVersion alloc] initWithVersionNumber:19
  209. symbolSizeRows:88
  210. symbolSizeColumns:88
  211. dataRegionSizeRows:20
  212. dataRegionSizeColumns:20
  213. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:56
  214. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:4 dataCodewords:144]]],
  215. [[ZXDataMatrixVersion alloc] initWithVersionNumber:20
  216. symbolSizeRows:96
  217. symbolSizeColumns:96
  218. dataRegionSizeRows:22
  219. dataRegionSizeColumns:22
  220. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:68
  221. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:4 dataCodewords:174]]],
  222. [[ZXDataMatrixVersion alloc] initWithVersionNumber:21
  223. symbolSizeRows:104
  224. symbolSizeColumns:104
  225. dataRegionSizeRows:24
  226. dataRegionSizeColumns:24
  227. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:56
  228. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:6 dataCodewords:136]]],
  229. [[ZXDataMatrixVersion alloc] initWithVersionNumber:22
  230. symbolSizeRows:120
  231. symbolSizeColumns:120
  232. dataRegionSizeRows:18
  233. dataRegionSizeColumns:18
  234. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:68
  235. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:6 dataCodewords:175]]],
  236. [[ZXDataMatrixVersion alloc] initWithVersionNumber:23
  237. symbolSizeRows:132
  238. symbolSizeColumns:132
  239. dataRegionSizeRows:20
  240. dataRegionSizeColumns:20
  241. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:62
  242. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:8 dataCodewords:163]]],
  243. [[ZXDataMatrixVersion alloc] initWithVersionNumber:24
  244. symbolSizeRows:144
  245. symbolSizeColumns:144
  246. dataRegionSizeRows:22
  247. dataRegionSizeColumns:22
  248. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:62
  249. ecBlocks1:[[ZXDataMatrixECB alloc] initWithCount:8 dataCodewords:156]
  250. ecBlocks2:[[ZXDataMatrixECB alloc] initWithCount:2 dataCodewords:155]]],
  251. [[ZXDataMatrixVersion alloc] initWithVersionNumber:25
  252. symbolSizeRows:8
  253. symbolSizeColumns:18
  254. dataRegionSizeRows:6
  255. dataRegionSizeColumns:16
  256. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:7
  257. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:5]]],
  258. [[ZXDataMatrixVersion alloc] initWithVersionNumber:26
  259. symbolSizeRows:8
  260. symbolSizeColumns:32
  261. dataRegionSizeRows:6
  262. dataRegionSizeColumns:14
  263. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:11
  264. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:10]]],
  265. [[ZXDataMatrixVersion alloc] initWithVersionNumber:27
  266. symbolSizeRows:12
  267. symbolSizeColumns:26
  268. dataRegionSizeRows:10
  269. dataRegionSizeColumns:24
  270. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:14
  271. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:16]]],
  272. [[ZXDataMatrixVersion alloc] initWithVersionNumber:28
  273. symbolSizeRows:12
  274. symbolSizeColumns:36
  275. dataRegionSizeRows:10
  276. dataRegionSizeColumns:16
  277. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:18
  278. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:22]]],
  279. [[ZXDataMatrixVersion alloc] initWithVersionNumber:29
  280. symbolSizeRows:16
  281. symbolSizeColumns:36
  282. dataRegionSizeRows:14
  283. dataRegionSizeColumns:16
  284. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:24
  285. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:32]]],
  286. [[ZXDataMatrixVersion alloc] initWithVersionNumber:30
  287. symbolSizeRows:16
  288. symbolSizeColumns:48
  289. dataRegionSizeRows:14
  290. dataRegionSizeColumns:22
  291. ecBlocks:[[ZXDataMatrixECBlocks alloc] initWithCodewords:28
  292. ecBlocks:[[ZXDataMatrixECB alloc] initWithCount:1 dataCodewords:49]]]];
  293. }
  294. @end