Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ZXUPCAReader.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "ZXEAN13Reader.h"
  17. #import "ZXErrors.h"
  18. #import "ZXResult.h"
  19. #import "ZXUPCAReader.h"
  20. @interface ZXUPCAReader ()
  21. @property (nonatomic, strong, readonly) ZXUPCEANReader *ean13Reader;
  22. @end
  23. @implementation ZXUPCAReader
  24. - (id)init {
  25. if (self = [super init]) {
  26. _ean13Reader = [[ZXEAN13Reader alloc] init];
  27. }
  28. return self;
  29. }
  30. - (ZXResult *)decodeRow:(int)rowNumber row:(ZXBitArray *)row startGuardRange:(NSRange)startGuardRange hints:(ZXDecodeHints *)hints error:(NSError **)error {
  31. ZXResult *result = [self.ean13Reader decodeRow:rowNumber row:row startGuardRange:startGuardRange hints:hints error:error];
  32. if (result) {
  33. result = [self maybeReturnResult:result];
  34. if (!result) {
  35. if (error) *error = ZXFormatErrorInstance();
  36. return nil;
  37. }
  38. return result;
  39. } else {
  40. return nil;
  41. }
  42. }
  43. - (ZXResult *)decodeRow:(int)rowNumber row:(ZXBitArray *)row hints:(ZXDecodeHints *)hints error:(NSError **)error {
  44. ZXResult *result = [self.ean13Reader decodeRow:rowNumber row:row hints:hints error:error];
  45. if (result) {
  46. result = [self maybeReturnResult:result];
  47. if (!result) {
  48. if (error) *error = ZXFormatErrorInstance();
  49. return nil;
  50. }
  51. return result;
  52. } else {
  53. return nil;
  54. }
  55. }
  56. - (ZXResult *)decode:(ZXBinaryBitmap *)image error:(NSError **)error {
  57. ZXResult *result = [self.ean13Reader decode:image error:error];
  58. if (result) {
  59. result = [self maybeReturnResult:result];
  60. if (!result) {
  61. if (error) *error = ZXFormatErrorInstance();
  62. return nil;
  63. }
  64. return result;
  65. } else {
  66. return nil;
  67. }
  68. }
  69. - (ZXResult *)decode:(ZXBinaryBitmap *)image hints:(ZXDecodeHints *)hints error:(NSError **)error {
  70. ZXResult *result = [self.ean13Reader decode:image hints:hints error:error];
  71. if (result) {
  72. result = [self maybeReturnResult:result];
  73. if (!result) {
  74. if (error) *error = ZXFormatErrorInstance();
  75. return nil;
  76. }
  77. return result;
  78. } else {
  79. return nil;
  80. }
  81. }
  82. - (ZXBarcodeFormat)barcodeFormat {
  83. return kBarcodeFormatUPCA;
  84. }
  85. - (int)decodeMiddle:(ZXBitArray *)row startRange:(NSRange)startRange result:(NSMutableString *)result error:(NSError **)error {
  86. return [self.ean13Reader decodeMiddle:row startRange:startRange result:result error:error];
  87. }
  88. - (ZXResult *)maybeReturnResult:(ZXResult *)result {
  89. NSString *text = result.text;
  90. if ([text characterAtIndex:0] == '0') {
  91. return [ZXResult resultWithText:[text substringFromIndex:1]
  92. rawBytes:nil
  93. resultPoints:result.resultPoints
  94. format:kBarcodeFormatUPCA];
  95. } else {
  96. return nil;
  97. }
  98. }
  99. @end