Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ZXMultiFormatOneDReader.m 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "ZXCodaBarReader.h"
  17. #import "ZXCode128Reader.h"
  18. #import "ZXCode39Reader.h"
  19. #import "ZXCode93Reader.h"
  20. #import "ZXDecodeHints.h"
  21. #import "ZXErrors.h"
  22. #import "ZXITFReader.h"
  23. #import "ZXMultiFormatOneDReader.h"
  24. #import "ZXMultiFormatUPCEANReader.h"
  25. #import "ZXRSS14Reader.h"
  26. #import "ZXRSSExpandedReader.h"
  27. @interface ZXMultiFormatOneDReader ()
  28. @property (nonatomic, strong, readonly) NSMutableArray *readers;
  29. @end
  30. @implementation ZXMultiFormatOneDReader
  31. - (id)initWithHints:(ZXDecodeHints *)hints {
  32. if (self = [super init]) {
  33. BOOL useCode39CheckDigit = hints != nil && hints.assumeCode39CheckDigit;
  34. _readers = [NSMutableArray array];
  35. if (hints != nil) {
  36. if ([hints containsFormat:kBarcodeFormatEan13] ||
  37. [hints containsFormat:kBarcodeFormatUPCA] ||
  38. [hints containsFormat:kBarcodeFormatEan8] ||
  39. [hints containsFormat:kBarcodeFormatUPCE]) {
  40. [_readers addObject:[[ZXMultiFormatUPCEANReader alloc] initWithHints:hints]];
  41. }
  42. if ([hints containsFormat:kBarcodeFormatCode39]) {
  43. [_readers addObject:[[ZXCode39Reader alloc] initUsingCheckDigit:useCode39CheckDigit]];
  44. }
  45. if ([hints containsFormat:kBarcodeFormatCode93]) {
  46. [_readers addObject:[[ZXCode93Reader alloc] init]];
  47. }
  48. if ([hints containsFormat:kBarcodeFormatCode128]) {
  49. [_readers addObject:[[ZXCode128Reader alloc] init]];
  50. }
  51. if ([hints containsFormat:kBarcodeFormatITF]) {
  52. [_readers addObject:[[ZXITFReader alloc] init]];
  53. }
  54. if ([hints containsFormat:kBarcodeFormatCodabar]) {
  55. [_readers addObject:[[ZXCodaBarReader alloc] init]];
  56. }
  57. if ([hints containsFormat:kBarcodeFormatRSS14]) {
  58. [_readers addObject:[[ZXRSS14Reader alloc] init]];
  59. }
  60. if ([hints containsFormat:kBarcodeFormatRSSExpanded]) {
  61. [_readers addObject:[[ZXRSSExpandedReader alloc] init]];
  62. }
  63. }
  64. if ([_readers count] == 0) {
  65. [_readers addObject:[[ZXMultiFormatUPCEANReader alloc] initWithHints:hints]];
  66. [_readers addObject:[[ZXCode39Reader alloc] init]];
  67. [_readers addObject:[[ZXCodaBarReader alloc] init]];
  68. [_readers addObject:[[ZXCode93Reader alloc] init]];
  69. [_readers addObject:[[ZXCode128Reader alloc] init]];
  70. [_readers addObject:[[ZXITFReader alloc] init]];
  71. [_readers addObject:[[ZXRSS14Reader alloc] init]];
  72. [_readers addObject:[[ZXRSSExpandedReader alloc] init]];
  73. }
  74. }
  75. return self;
  76. }
  77. - (ZXResult *)decodeRow:(int)rowNumber row:(ZXBitArray *)row hints:(ZXDecodeHints *)hints error:(NSError **)error {
  78. for (ZXOneDReader *reader in self.readers) {
  79. ZXResult *result = [reader decodeRow:rowNumber row:row hints:hints error:error];
  80. if (result) {
  81. return result;
  82. }
  83. }
  84. if (error) *error = ZXNotFoundErrorInstance();
  85. return nil;
  86. }
  87. - (void)reset {
  88. for (id<ZXReader> reader in self.readers) {
  89. [reader reset];
  90. }
  91. }
  92. @end