選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ZXMultiFormatWriter.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "ZXBitMatrix.h"
  17. #import "ZXErrors.h"
  18. #import "ZXMultiFormatWriter.h"
  19. #if defined(ZXINGOBJC_AZTEC) || !defined(ZXINGOBJC_USE_SUBSPECS)
  20. #import "ZXAztecWriter.h"
  21. #endif
  22. #if defined(ZXINGOBJC_ONED) || !defined(ZXINGOBJC_USE_SUBSPECS)
  23. #import "ZXCodaBarWriter.h"
  24. #import "ZXCode39Writer.h"
  25. #import "ZXCode128Writer.h"
  26. #import "ZXEAN8Writer.h"
  27. #import "ZXEAN13Writer.h"
  28. #import "ZXITFWriter.h"
  29. #import "ZXUPCAWriter.h"
  30. #import "ZXUPCEWriter.h"
  31. #endif
  32. #if defined(ZXINGOBJC_DATAMATRIX) || !defined(ZXINGOBJC_USE_SUBSPECS)
  33. #import "ZXDataMatrixWriter.h"
  34. #endif
  35. #if defined(ZXINGOBJC_PDF417) || !defined(ZXINGOBJC_USE_SUBSPECS)
  36. #import "ZXPDF417Writer.h"
  37. #endif
  38. #if defined(ZXINGOBJC_QRCODE) || !defined(ZXINGOBJC_USE_SUBSPECS)
  39. #import "ZXQRCodeWriter.h"
  40. #endif
  41. @implementation ZXMultiFormatWriter
  42. + (id)writer {
  43. return [[ZXMultiFormatWriter alloc] init];
  44. }
  45. - (ZXBitMatrix *)encode:(NSString *)contents format:(ZXBarcodeFormat)format width:(int)width height:(int)height error:(NSError **)error {
  46. return [self encode:contents format:format width:width height:height hints:nil error:error];
  47. }
  48. - (ZXBitMatrix *)encode:(NSString *)contents format:(ZXBarcodeFormat)format width:(int)width height:(int)height hints:(ZXEncodeHints *)hints error:(NSError **)error {
  49. id<ZXWriter> writer;
  50. switch (format) {
  51. #if defined(ZXINGOBJC_ONED) || !defined(ZXINGOBJC_USE_SUBSPECS)
  52. case kBarcodeFormatEan8:
  53. writer = [[ZXEAN8Writer alloc] init];
  54. break;
  55. case kBarcodeFormatEan13:
  56. writer = [[ZXEAN13Writer alloc] init];
  57. break;
  58. case kBarcodeFormatUPCA:
  59. writer = [[ZXUPCAWriter alloc] init];
  60. break;
  61. case kBarcodeFormatUPCE:
  62. writer = [[ZXUPCEWriter alloc] init];
  63. break;
  64. case kBarcodeFormatCode39:
  65. writer = [[ZXCode39Writer alloc] init];
  66. break;
  67. case kBarcodeFormatCode128:
  68. writer = [[ZXCode128Writer alloc] init];
  69. break;
  70. case kBarcodeFormatITF:
  71. writer = [[ZXITFWriter alloc] init];
  72. break;
  73. case kBarcodeFormatCodabar:
  74. writer = [[ZXCodaBarWriter alloc] init];
  75. break;
  76. #endif
  77. #if defined(ZXINGOBJC_QRCODE) || !defined(ZXINGOBJC_USE_SUBSPECS)
  78. case kBarcodeFormatQRCode:
  79. writer = [[ZXQRCodeWriter alloc] init];
  80. break;
  81. #endif
  82. #if defined(ZXINGOBJC_PDF417) || !defined(ZXINGOBJC_USE_SUBSPECS)
  83. case kBarcodeFormatPDF417:
  84. writer = [[ZXPDF417Writer alloc] init];
  85. break;
  86. #endif
  87. #if defined(ZXINGOBJC_DATAMATRIX) || !defined(ZXINGOBJC_USE_SUBSPECS)
  88. case kBarcodeFormatDataMatrix:
  89. writer = [[ZXDataMatrixWriter alloc] init];
  90. break;
  91. #endif
  92. #if defined(ZXINGOBJC_AZTEC) || !defined(ZXINGOBJC_USE_SUBSPECS)
  93. case kBarcodeFormatAztec:
  94. writer = [[ZXAztecWriter alloc] init];
  95. break;
  96. #endif
  97. default:
  98. if (error) *error = [NSError errorWithDomain:ZXErrorDomain code:ZXWriterError userInfo:@{NSLocalizedDescriptionKey: @"No encoder available for format"}];
  99. return nil;
  100. }
  101. return [writer encode:contents format:format width:width height:height hints:hints error:error];
  102. }
  103. @end