Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "ZXBarcodeFormat.h"
  17. #import "ZXBoolArray.h"
  18. #import "ZXEAN8Writer.h"
  19. #import "ZXUPCEANReader.h"
  20. const int ZX_EAN8_CODE_WIDTH = 3 + (7 * 4) + 5 + (7 * 4) + 3;
  21. @implementation ZXEAN8Writer
  22. - (ZXBitMatrix *)encode:(NSString *)contents format:(ZXBarcodeFormat)format width:(int)width height:(int)height hints:(ZXEncodeHints *)hints error:(NSError **)error {
  23. if (format != kBarcodeFormatEan8) {
  24. [NSException raise:NSInvalidArgumentException format:@"Can only encode EAN_8"];
  25. }
  26. return [super encode:contents format:format width:width height:height hints:hints error:error];
  27. }
  28. /**
  29. * Returns a byte array of horizontal pixels (FALSE = white, TRUE = black)
  30. */
  31. - (ZXBoolArray *)encode:(NSString *)contents {
  32. if ([contents length] != 8) {
  33. [NSException raise:NSInvalidArgumentException format:@"Requested contents should be 8 digits long, but got %d", (int)[contents length]];
  34. }
  35. ZXBoolArray *result = [[ZXBoolArray alloc] initWithLength:ZX_EAN8_CODE_WIDTH];
  36. int pos = 0;
  37. pos += [self appendPattern:result pos:pos pattern:ZX_UPC_EAN_START_END_PATTERN patternLen:ZX_UPC_EAN_START_END_PATTERN_LEN startColor:YES];
  38. for (int i = 0; i <= 3; i++) {
  39. int digit = [[contents substringWithRange:NSMakeRange(i, 1)] intValue];
  40. pos += [self appendPattern:result pos:pos pattern:ZX_UPC_EAN_L_PATTERNS[digit] patternLen:ZX_UPC_EAN_L_PATTERNS_SUB_LEN startColor:FALSE];
  41. }
  42. pos += [self appendPattern:result pos:pos pattern:ZX_UPC_EAN_MIDDLE_PATTERN patternLen:ZX_UPC_EAN_MIDDLE_PATTERN_LEN startColor:FALSE];
  43. for (int i = 4; i <= 7; i++) {
  44. int digit = [[contents substringWithRange:NSMakeRange(i, 1)] intValue];
  45. pos += [super appendPattern:result pos:pos pattern:ZX_UPC_EAN_L_PATTERNS[digit] patternLen:ZX_UPC_EAN_L_PATTERNS_SUB_LEN startColor:YES];
  46. }
  47. [self appendPattern:result pos:pos pattern:ZX_UPC_EAN_START_END_PATTERN patternLen:ZX_UPC_EAN_START_END_PATTERN_LEN startColor:YES];
  48. return result;
  49. }
  50. @end