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.

ZXDataMatrixTextEncoder.m 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2013 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 "ZXDataMatrixHighLevelEncoder.h"
  17. #import "ZXDataMatrixTextEncoder.h"
  18. @implementation ZXDataMatrixTextEncoder
  19. - (int)encodingMode {
  20. return [ZXDataMatrixHighLevelEncoder textEncodation];
  21. }
  22. - (int)encodeChar:(unichar)c buffer:(NSMutableString *)sb {
  23. if (c == ' ') {
  24. [sb appendString:@"\3"];
  25. return 1;
  26. }
  27. if (c >= '0' && c <= '9') {
  28. [sb appendFormat:@"%C", (unichar) (c - 48 + 4)];
  29. return 1;
  30. }
  31. if (c >= 'a' && c <= 'z') {
  32. [sb appendFormat:@"%C", (unichar) (c - 97 + 14)];
  33. return 1;
  34. }
  35. if (c >= '\0' && c <= (unichar)0x001f) {
  36. [sb appendString:@"\0"]; //Shift 1 Set
  37. [sb appendFormat:@"%C", c];
  38. return 2;
  39. }
  40. if (c >= '!' && c <= '/') {
  41. [sb appendString:@"\1"]; //Shift 2 Set
  42. [sb appendFormat:@"%C", (unichar) (c - 33)];
  43. return 2;
  44. }
  45. if (c >= ':' && c <= '@') {
  46. [sb appendString:@"\1"]; //Shift 2 Set
  47. [sb appendFormat:@"%C", (unichar) (c - 58 + 15)];
  48. return 2;
  49. }
  50. if (c >= '[' && c <= '_') {
  51. [sb appendString:@"\1"]; //Shift 2 Set
  52. [sb appendFormat:@"%C", (unichar) (c - 91 + 22)];
  53. return 2;
  54. }
  55. if (c == '\u0060') {
  56. [sb appendString:@"\2"]; //Shift 3 Set
  57. [sb appendFormat:@"%C", (unichar) (c - 96)];
  58. return 2;
  59. }
  60. if (c >= 'A' && c <= 'Z') {
  61. [sb appendString:@"\2"]; //Shift 3 Set
  62. [sb appendFormat:@"%C", (unichar) (c - 65 + 1)];
  63. return 2;
  64. }
  65. if (c >= '{' && c <= (unichar)0x007f) {
  66. [sb appendString:@"\2"]; //Shift 3 Set
  67. [sb appendFormat:@"%C", (unichar) (c - 123 + 27)];
  68. return 2;
  69. }
  70. if (c >= (unichar)0x0080) {
  71. [sb appendFormat:@"\1%C", (unichar)0x001e]; //Shift 2, Upper Shift
  72. int len = 2;
  73. len += [self encodeChar:(unichar) (c - 128) buffer:sb];
  74. return len;
  75. }
  76. [ZXDataMatrixHighLevelEncoder illegalCharacter:c];
  77. return -1;
  78. }
  79. @end