rhodes 2.4.1 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (395) hide show
  1. data/CHANGELOG +7 -0
  2. data/Rakefile +7 -36
  3. data/doc/build.txt +48 -22
  4. data/doc/device-caps.txt +130 -1
  5. data/doc/rhom.txt +9 -3
  6. data/doc/test-log-debug.txt +5 -2
  7. data/lib/extensions/barcode/ext/barcode/platform/android/Rakefile +40 -20
  8. data/lib/extensions/barcode/ext/barcode/platform/android/ZXing_Info/AUTHORS +58 -0
  9. data/lib/extensions/barcode/ext/barcode/platform/android/ZXing_Info/CHANGES +266 -0
  10. data/lib/extensions/barcode/ext/barcode/platform/android/ZXing_Info/COPYING +201 -0
  11. data/lib/extensions/barcode/ext/barcode/platform/android/ZXing_Info/README +11 -0
  12. data/lib/extensions/barcode/ext/barcode/platform/android/ext_build.files +173 -0
  13. data/lib/extensions/barcode/ext/barcode/platform/android/jni/src/barcode.cpp +34 -0
  14. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/BarcodeFormat.java +103 -0
  15. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/Binarizer.java +80 -0
  16. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/BinaryBitmap.java +128 -0
  17. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/ChecksumException.java +37 -0
  18. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/DecodeHintType.java +79 -0
  19. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/EncodeHintType.java +39 -0
  20. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/FormatException.java +38 -0
  21. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/LuminanceSource.java +113 -0
  22. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/MultiFormatReader.java +166 -0
  23. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/MultiFormatWriter.java +65 -0
  24. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/NotFoundException.java +37 -0
  25. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/Reader.java +64 -0
  26. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/ReaderException.java +98 -0
  27. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/Result.java +143 -0
  28. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/ResultMetadataType.java +109 -0
  29. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/ResultPoint.java +127 -0
  30. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/ResultPointCallback.java +29 -0
  31. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/Writer.java +54 -0
  32. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/WriterException.java +35 -0
  33. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/AbstractDoCoMoResultParser.java +39 -0
  34. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/AddressBookAUResultParser.java +73 -0
  35. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/AddressBookDoCoMoResultParser.java +85 -0
  36. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/AddressBookParsedResult.java +122 -0
  37. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/BizcardResultParser.java +94 -0
  38. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/BookmarkDoCoMoResultParser.java +46 -0
  39. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/CalendarParsedResult.java +134 -0
  40. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/EmailAddressParsedResult.java +61 -0
  41. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/EmailAddressResultParser.java +64 -0
  42. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/EmailDoCoMoResultParser.java +87 -0
  43. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ExpandedProductParsedResult.java +195 -0
  44. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ExpandedProductResultParser.java +199 -0
  45. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/GeoParsedResult.java +132 -0
  46. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/GeoResultParser.java +77 -0
  47. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ISBNParsedResult.java +39 -0
  48. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ISBNResultParser.java +54 -0
  49. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ParsedResult.java +73 -0
  50. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ParsedResultType.java +53 -0
  51. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ProductParsedResult.java +49 -0
  52. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ProductResultParser.java +66 -0
  53. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/ResultParser.java +319 -0
  54. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/SMSMMSResultParser.java +107 -0
  55. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/SMSParsedResult.java +104 -0
  56. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/SMSTOMMSTOResultParser.java +57 -0
  57. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/TelParsedResult.java +54 -0
  58. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/TelResultParser.java +44 -0
  59. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/TextParsedResult.java +48 -0
  60. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/URIParsedResult.java +113 -0
  61. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/URIResultParser.java +87 -0
  62. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/URLTOResultParser.java +47 -0
  63. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/VCardResultParser.java +346 -0
  64. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/VEventResultParser.java +54 -0
  65. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/WifiParsedResult.java +53 -0
  66. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/WifiResultParser.java +50 -0
  67. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/optional/AbstractNDEFResultParser.java +45 -0
  68. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/optional/NDEFRecord.java +87 -0
  69. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/optional/NDEFSmartPosterParsedResult.java +63 -0
  70. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/optional/NDEFSmartPosterResultParser.java +81 -0
  71. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/optional/NDEFTextResultParser.java +57 -0
  72. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/client/result/optional/NDEFURIResultParser.java +95 -0
  73. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/BitArray.java +247 -0
  74. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/BitMatrix.java +226 -0
  75. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/BitSource.java +97 -0
  76. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/CharacterSetECI.java +110 -0
  77. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/Collections.java +53 -0
  78. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/Comparator.java +27 -0
  79. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/DecoderResult.java +63 -0
  80. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/DefaultGridSampler.java +81 -0
  81. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/DetectorResult.java +46 -0
  82. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/ECI.java +52 -0
  83. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/GlobalHistogramBinarizer.java +196 -0
  84. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/GridSampler.java +171 -0
  85. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/HybridBinarizer.java +185 -0
  86. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/PerspectiveTransform.java +148 -0
  87. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/StringUtils.java +191 -0
  88. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java +209 -0
  89. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/detector/WhiteRectangleDetector.java +316 -0
  90. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/reedsolomon/GF256.java +139 -0
  91. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/reedsolomon/GF256Poly.java +263 -0
  92. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoder.java +194 -0
  93. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/reedsolomon/ReedSolomonEncoder.java +75 -0
  94. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/common/reedsolomon/ReedSolomonException.java +31 -0
  95. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/DataMatrixReader.java +161 -0
  96. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java +446 -0
  97. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/decoder/DataBlock.java +118 -0
  98. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java +462 -0
  99. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/decoder/Decoder.java +134 -0
  100. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/decoder/Version.java +242 -0
  101. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/datamatrix/detector/Detector.java +348 -0
  102. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/multi/ByQuadrantReader.java +96 -0
  103. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/multi/GenericMultipleBarcodeReader.java +156 -0
  104. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/multi/MultipleBarcodeReader.java +37 -0
  105. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java +80 -0
  106. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/multi/qrcode/detector/MultiDetector.java +72 -0
  107. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java +324 -0
  108. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/CodaBarReader.java +263 -0
  109. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/Code128Reader.java +473 -0
  110. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/Code128Writer.java +73 -0
  111. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/Code39Reader.java +333 -0
  112. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/Code39Writer.java +82 -0
  113. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/Code93Reader.java +273 -0
  114. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/EAN13Reader.java +135 -0
  115. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/EAN13Writer.java +81 -0
  116. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/EAN8Reader.java +72 -0
  117. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/EAN8Writer.java +76 -0
  118. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/EANManufacturerOrgSupport.java +170 -0
  119. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/ITFReader.java +348 -0
  120. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/ITFWriter.java +68 -0
  121. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/MultiFormatOneDReader.java +109 -0
  122. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/MultiFormatUPCEANReader.java +113 -0
  123. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/OneDReader.java +297 -0
  124. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/UPCAReader.java +75 -0
  125. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/UPCEANExtensionSupport.java +186 -0
  126. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/UPCEANReader.java +355 -0
  127. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/UPCEANWriter.java +104 -0
  128. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/UPCEReader.java +153 -0
  129. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/AbstractRSSReader.java +110 -0
  130. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/DataCharacter.java +37 -0
  131. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/FinderPattern.java +48 -0
  132. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/Pair.java +41 -0
  133. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/RSS14Reader.java +494 -0
  134. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/RSSUtils.java +155 -0
  135. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/BitArrayBuilder.java +85 -0
  136. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/ExpandedPair.java +68 -0
  137. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java +578 -0
  138. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI013103decoder.java +47 -0
  139. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI01320xDecoder.java +55 -0
  140. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI01392xDecoder.java +66 -0
  141. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI01393xDecoder.java +76 -0
  142. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI013x0x1xDecoder.java +106 -0
  143. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI013x0xDecoder.java +56 -0
  144. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI01AndOtherAIs.java +56 -0
  145. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI01decoder.java +81 -0
  146. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AI01weightDecoder.java +58 -0
  147. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AbstractExpandedDecoder.java +85 -0
  148. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/AnyAIDecoder.java +48 -0
  149. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/BlockParsedResult.java +60 -0
  150. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/CurrentParsingState.java +69 -0
  151. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/DecodedChar.java +52 -0
  152. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/DecodedInformation.java +63 -0
  153. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/DecodedNumeric.java +79 -0
  154. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/DecodedObject.java +44 -0
  155. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/FieldParser.java +285 -0
  156. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/oned/rss/expanded/decoders/GeneralAppIdDecoder.java +414 -0
  157. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/pdf417/PDF417Reader.java +79 -0
  158. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java +1163 -0
  159. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java +629 -0
  160. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/pdf417/decoder/Decoder.java +150 -0
  161. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/pdf417/detector/Detector.java +498 -0
  162. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/QRCodeReader.java +166 -0
  163. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/QRCodeWriter.java +108 -0
  164. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/BitMatrixParser.java +203 -0
  165. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/DataBlock.java +123 -0
  166. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/DataMask.java +155 -0
  167. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +261 -0
  168. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/Decoder.java +148 -0
  169. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/ErrorCorrectionLevel.java +86 -0
  170. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/FormatInformation.java +171 -0
  171. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/Mode.java +112 -0
  172. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/decoder/Version.java +586 -0
  173. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/detector/AlignmentPattern.java +48 -0
  174. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java +279 -0
  175. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/detector/Detector.java +400 -0
  176. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/detector/FinderPattern.java +63 -0
  177. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java +585 -0
  178. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/detector/FinderPatternInfo.java +49 -0
  179. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/encoder/BlockPair.java +37 -0
  180. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/encoder/ByteMatrix.java +97 -0
  181. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/encoder/Encoder.java +557 -0
  182. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/encoder/MaskUtil.java +217 -0
  183. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/encoder/MatrixUtil.java +524 -0
  184. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/google/zxing/qrcode/encoder/QRCode.java +239 -0
  185. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/rhomobile/barcode/Barcode.java +63 -0
  186. data/lib/extensions/barcode/ext/barcode/platform/android/src/com/rhomobile/barcode/RhoLuminanceSource.java +75 -0
  187. data/lib/extensions/barcode/ext/barcode/platform/iphone/Barcode.xcodeproj/project.pbxproj +74 -318
  188. data/lib/extensions/barcode/ext/barcode/platform/iphone/Classes/barcode.m +70 -0
  189. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/COPYING +27 -0
  190. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarCaptureReader.h +105 -0
  191. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarHelpController.h +60 -0
  192. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarImage.h +69 -0
  193. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarImageScanner.h +51 -0
  194. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarReaderController.h +142 -0
  195. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarReaderView.h +118 -0
  196. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarReaderViewController.h +100 -0
  197. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarSDK.h +33 -0
  198. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/ZBarSymbol.h +71 -0
  199. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar.h +1476 -0
  200. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Decoder.h +201 -0
  201. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Exception.h +187 -0
  202. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Image.h +321 -0
  203. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/ImageScanner.h +130 -0
  204. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Processor.h +223 -0
  205. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Scanner.h +162 -0
  206. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Symbol.h +529 -0
  207. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Video.h +170 -0
  208. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Headers/ZBarSDK/zbar/Window.h +136 -0
  209. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/LICENSE +504 -0
  210. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/README +59 -0
  211. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Resources/zbar-back.png +0 -0
  212. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Resources/zbar-help.html +88 -0
  213. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Resources/zbar-helpicons.png +0 -0
  214. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/Resources/zbar-samples.png +0 -0
  215. data/lib/extensions/barcode/ext/barcode/platform/iphone/ZBarSDK/libzbar.a +0 -0
  216. data/lib/extensions/debugger/debugger.rb +215 -67
  217. data/lib/extensions/nfc/ext/nfc/platform/android/AndroidManifest.xml +1 -1
  218. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/nfc/Nfc.java +14 -2
  219. data/lib/extensions/timeout/timeout.rb +114 -0
  220. data/lib/framework/rho/render.rb +14 -16
  221. data/lib/framework/rho/rho.rb +38 -14
  222. data/lib/framework/rho/rhoapplication.rb +1 -1
  223. data/lib/framework/rho/rhocontroller.rb +3 -3
  224. data/lib/framework/rho/rhofsconnector.rb +18 -6
  225. data/lib/framework/rho/rhoviewhelpers.rb +1 -1
  226. data/lib/framework/rhoappmanifest.rb +44 -0
  227. data/lib/framework/rhodes.rb +1 -1
  228. data/lib/framework/rhoframework.rb +31 -11
  229. data/lib/framework/rholang/localization_simplified.rb +10 -6
  230. data/lib/framework/rhom/rhom_object_factory.rb +3 -3
  231. data/lib/framework/version.rb +1 -1
  232. data/lib/rhodes.rb +1 -1
  233. data/platform/android/Rhodes/AndroidManifest.xml +2 -2
  234. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_RhodesApplication.h +32 -8
  235. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_RhodesService.h +21 -21
  236. data/platform/android/Rhodes/jni/src/rhocryptimpl.cpp +1 -0
  237. data/platform/android/Rhodes/jni/src/rhodes.cpp +21 -9
  238. data/platform/android/Rhodes/jni/src/sslimpl.cpp +1 -0
  239. data/platform/android/Rhodes/src/com/rhomobile/rhodes/BaseActivity.java +7 -6
  240. data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushReceiver.java +19 -1
  241. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhoCryptImpl.java +2 -2
  242. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesActivity.java +24 -15
  243. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesApplication.java +39 -47
  244. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +113 -106
  245. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/Alert.java +11 -0
  246. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/StatusNotification.java +49 -0
  247. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +1 -1
  248. data/platform/android/Rhodes/src/com/rhomobile/rhodes/socket/SSLImpl.java +5 -1
  249. data/platform/android/build/RhodesSRC_build.files +1 -0
  250. data/platform/android/build/android.rake +93 -6
  251. data/platform/bb/RubyVM/src/com/rho/RhodesApp.java +5 -4
  252. data/platform/bb/RubyVM/src/com/rho/file/RhoFile.java +10 -0
  253. data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +16 -15
  254. data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +2 -2
  255. data/platform/bb/RubyVM/src/com/rho/sync/SyncSource.java +21 -19
  256. data/platform/bb/rhodes/src/com/rho/BrowserAdapter5.java +2 -2
  257. data/platform/bb/rhodes/src/com/rho/rubyext/System.java +6 -1
  258. data/platform/bb/rhodes/src/com/rho/rubyext/WebView.java +10 -3
  259. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +21 -1
  260. data/platform/iphone/Classes/SimpleMainView.m +5 -5
  261. data/platform/iphone/Info.plist +1 -1
  262. data/platform/iphone/rbuild/iphone.rake +30 -1
  263. data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +12 -0
  264. data/platform/shared/SyncClient/SyncClient.cpp +136 -20
  265. data/platform/shared/SyncClient/SyncClient.h +17 -0
  266. data/platform/shared/common/AppMenu.cpp +6 -1
  267. data/platform/shared/common/RhoConf.cpp +13 -1
  268. data/platform/shared/common/RhoConf.h +3 -1
  269. data/platform/shared/common/RhoDefs.h +10 -0
  270. data/platform/shared/common/RhoFile.cpp +15 -0
  271. data/platform/shared/common/RhoFile.h +1 -0
  272. data/platform/shared/common/RhodesApp.cpp +16 -3
  273. data/platform/shared/common/RhodesApp.h +1 -0
  274. data/platform/shared/common/RhodesAppBase.cpp +102 -62
  275. data/platform/shared/common/RhodesAppBase.h +7 -1
  276. data/platform/shared/curl/lib/rhossl.c +1 -0
  277. data/platform/shared/db/DBAdapter.cpp +14 -2
  278. data/platform/shared/logging/RhoLogConf.cpp +21 -0
  279. data/platform/shared/logging/RhoLogConf.h +11 -0
  280. data/platform/shared/logging/RhoLogSink.cpp +24 -0
  281. data/platform/shared/logging/RhoLogSink.h +20 -1
  282. data/platform/shared/net/HttpServer.cpp +8 -6
  283. data/platform/shared/net/RawSocket.cpp +130 -0
  284. data/platform/shared/net/RawSocket.h +74 -0
  285. data/platform/shared/ruby/ext/rho/rhoruby.c +37 -1
  286. data/platform/shared/ruby/ext/rho/rhosupport.c +74 -21
  287. data/platform/shared/ruby/ext/sqlite3_api/sqlite3_api_wrap.c +9 -1
  288. data/platform/shared/ruby/vm_eval.c +4 -3
  289. data/platform/shared/sync/SyncEngine.cpp +11 -12
  290. data/platform/shared/sync/SyncEngine.h +2 -2
  291. data/platform/shared/sync/SyncNotify.cpp +41 -13
  292. data/platform/shared/sync/SyncNotify.h +20 -3
  293. data/platform/shared/sync/SyncSource.cpp +21 -19
  294. data/platform/shared/sync/SyncThread.cpp +11 -1
  295. data/platform/shared/sync/SyncThread.h +3 -0
  296. data/platform/shared/test/test_helper.cpp +7 -0
  297. data/platform/win32/RhoSimulator/QtCore4.dll +0 -0
  298. data/platform/win32/RhoSimulator/QtGui4.dll +0 -0
  299. data/platform/win32/RhoSimulator/QtNetwork4.dll +0 -0
  300. data/platform/win32/RhoSimulator/QtWebKit4.dll +0 -0
  301. data/platform/win32/RhoSimulator/imageformats/qgif4.dll +0 -0
  302. data/platform/win32/RhoSimulator/imageformats/qjpeg4.dll +0 -0
  303. data/platform/win32/RhoSimulator/rhosimulator.exe +0 -0
  304. data/platform/wm/RhoLib/RhoLib.vcproj +762 -14
  305. data/platform/wm/build/wm.rake +87 -10
  306. data/platform/wm/rhodes.sln +155 -72
  307. data/platform/wm/rhodes/MainWindow.cpp +5 -2
  308. data/platform/wm/rhodes/MainWindow.h +9 -1
  309. data/platform/wm/rhodes/RhoNativeViewManager.cpp +4 -0
  310. data/platform/wm/rhodes/Rhodes.cpp +60 -6
  311. data/platform/wm/rhodes/emulator/ExternalWebView.cpp +20 -0
  312. data/platform/wm/rhodes/emulator/ExternalWebView.h +23 -0
  313. data/platform/wm/rhodes/emulator/ExternalWebView.ui +46 -0
  314. data/platform/wm/rhodes/emulator/MainWindowCallback.h +18 -0
  315. data/platform/wm/rhodes/emulator/MainWindowProxy.cpp +268 -0
  316. data/platform/wm/rhodes/emulator/MainWindowProxy.h +34 -0
  317. data/platform/wm/rhodes/emulator/MainWindowQt.cpp +345 -0
  318. data/platform/wm/rhodes/emulator/MainWindowQt.h +118 -0
  319. data/platform/wm/rhodes/emulator/NativeToolbarQt.cpp +57 -0
  320. data/platform/wm/rhodes/emulator/NativeToolbarQt.h +52 -0
  321. data/platform/wm/rhodes/emulator/QtMainWindow.cpp +219 -0
  322. data/platform/wm/rhodes/emulator/QtMainWindow.h +62 -0
  323. data/platform/wm/rhodes/emulator/QtMainWindow.ui +122 -0
  324. data/platform/wm/rhodes/{RhoCryptImpl.cpp → rho/common/RhoCryptImpl.cpp} +0 -0
  325. data/platform/wm/rhodes/{RhoCryptImpl.h → rho/common/RhoCryptImpl.h} +0 -0
  326. data/platform/wm/rhodes/rho/rubyext/NativeToolbar.cpp +2 -86
  327. data/platform/wm/rhodes/rho/rubyext/NativeToolbarExt.cpp +87 -0
  328. data/platform/wm/rhodes/rho/rubyext/NativeToolbarExt.h +6 -0
  329. data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +60 -0
  330. data/platform/wm/rhodes/rhodes.vcproj +4025 -365
  331. data/platform/wm/rhodes/signature/Signature.cpp +29 -13
  332. data/platform/wm/rubylib/rubylib.vcproj +1167 -195
  333. data/platform/wm/shttpd/shttpd.vcproj +4 -4
  334. data/platform/wm/sqlite3/sqlite3.vcproj +441 -13
  335. data/platform/wm/syncengine/syncengine.vcproj +443 -15
  336. data/platform/wm/tcmalloc/tcmalloc.vcproj +0 -154
  337. data/platform/wm/tools/detool/LogServer.cpp +150 -0
  338. data/platform/wm/tools/detool/LogServer.h +23 -0
  339. data/platform/wm/tools/detool/detool.cpp +42 -4
  340. data/platform/wm/tools/detool/detool.vcproj +10 -1
  341. data/platform/wp7/IronRuby/Bin/Silverlight3Release/IronRuby.Libraries.dll +0 -0
  342. data/platform/wp7/IronRuby/Bin/Silverlight3Release/IronRuby.dll +0 -0
  343. data/platform/wp7/IronRuby/Bin/Silverlight3Release/Microsoft.Dynamic.dll +0 -0
  344. data/platform/wp7/IronRuby/Bin/Silverlight3Release/Microsoft.Scripting.Core.dll +0 -0
  345. data/platform/wp7/IronRuby/Bin/Silverlight3Release/Microsoft.Scripting.dll +0 -0
  346. data/platform/wp7/RhoAppRunner/Program.cs +20 -3
  347. data/platform/wp7/RhoLogServer/Program.cs +22 -0
  348. data/platform/wp7/RhoLogServer/Properties/AssemblyInfo.cs +36 -0
  349. data/platform/wp7/RhoLogServer/RhoLogServer.csproj +65 -0
  350. data/platform/wp7/RhoLogServer/SocketServer.cs +210 -0
  351. data/platform/wp7/RhoRubyExtGen/RhoAsyncHttp.cs +6 -0
  352. data/platform/wp7/RhoRubyLib/Initializers.Generated.cs +3 -2
  353. data/platform/wp7/RhoRubyLib/RhoRuby.cs +82 -0
  354. data/platform/wp7/RhoRubyLib/RhoRubyLib.csproj +7 -5
  355. data/platform/wp7/RhoRubyLib/WP_PlatformAdaptationLayer.cs +1 -1
  356. data/platform/wp7/RhoRubyLib/common/RhoParams.cs +1 -1
  357. data/platform/wp7/RhoRubyLib/common/ThreadQueue.cs +4 -1
  358. data/platform/wp7/RhoRubyLib/db/DBAdapter.cs +2 -2
  359. data/platform/wp7/RhoRubyLib/logging/IRhoLogSink.cs +1 -1
  360. data/platform/wp7/RhoRubyLib/logging/RhoEmptyLogger.cs +30 -0
  361. data/platform/wp7/RhoRubyLib/logging/RhoLogConf.cs +10 -0
  362. data/platform/wp7/RhoRubyLib/logging/RhoLogFileSink.cs +6 -1
  363. data/platform/wp7/RhoRubyLib/logging/RhoLogServerSink.cs +56 -0
  364. data/platform/wp7/RhoRubyLib/logging/RhoLogger.cs +24 -11
  365. data/platform/wp7/RhoRubyLib/net/AsyncHttp.cs +57 -14
  366. data/platform/wp7/RhoRubyLib/net/NetRequest.cs +32 -9
  367. data/platform/wp7/RhoRubyLib/rubyext/RhoAsyncHttp.cs +7 -0
  368. data/platform/wp7/RhoRubyLib/rubyext/RhoKernelOps.cs +6 -0
  369. data/platform/wp7/RhoRubyLib/sync/SyncEngine.cs +20 -16
  370. data/platform/wp7/RhoRubyLib/sync/SyncNotify.cs +2 -2
  371. data/platform/wp7/RhoRubyLib/sync/SyncSource.cs +138 -40
  372. data/platform/wp7/WPApplication/rho/apps/app/layout.erb +3 -1
  373. data/platform/wp7/build/wp.rake +151 -12
  374. data/platform/wp7/rhodes.sln +10 -0
  375. data/platform/wp7/rhodes/App.xaml.cs +6 -0
  376. data/platform/wp7/rhodes/MainPage.xaml +3 -0
  377. data/platform/wp7/rhodes/MainPage.xaml.cs +19 -0
  378. data/platform/wp7/rhodes/Rhodes.csproj +4 -2
  379. data/rakefile.rb +7 -36
  380. data/res/build-tools/RhoAppRunner.exe +0 -0
  381. data/res/build-tools/RhoLogServer.exe +0 -0
  382. data/res/build-tools/detool.exe +0 -0
  383. data/res/build-tools/wp7explorer.exe +0 -0
  384. data/res/generators/templates/application/app/layout.erb +3 -1
  385. data/res/generators/templates/application/public/jqtouch/jqtouch.js +1 -1
  386. data/rhodes.gemspec +1 -1
  387. data/spec/framework_spec/app/layout.erb +1 -1
  388. data/spec/framework_spec/build.yml +1 -0
  389. data/spec/perfomance_spec/app/layout.erb +3 -0
  390. data/spec/phone_spec/app/Account_s/account_s.rb +4 -1
  391. data/spec/phone_spec/app/spec/rhom_object_spec.rb +30 -1
  392. data/spec/phone_spec/app/spec_runner.rb +1 -1
  393. data/spec/phone_spec/build.yml +4 -1
  394. metadata +262 -10
  395. data/platform/wp7/IronRuby/Languages/Ruby/Ruby/Builtins/ConsoleStream.cs +0 -107
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Copyright 2007 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
+
17
+ package com.google.zxing.qrcode.detector;
18
+
19
+ /**
20
+ * <p>Encapsulates information about finder patterns in an image, including the location of
21
+ * the three finder patterns, and their estimated module size.</p>
22
+ *
23
+ * @author Sean Owen
24
+ */
25
+ public final class FinderPatternInfo {
26
+
27
+ private final FinderPattern bottomLeft;
28
+ private final FinderPattern topLeft;
29
+ private final FinderPattern topRight;
30
+
31
+ public FinderPatternInfo(FinderPattern[] patternCenters) {
32
+ this.bottomLeft = patternCenters[0];
33
+ this.topLeft = patternCenters[1];
34
+ this.topRight = patternCenters[2];
35
+ }
36
+
37
+ public FinderPattern getBottomLeft() {
38
+ return bottomLeft;
39
+ }
40
+
41
+ public FinderPattern getTopLeft() {
42
+ return topLeft;
43
+ }
44
+
45
+ public FinderPattern getTopRight() {
46
+ return topRight;
47
+ }
48
+
49
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2008 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
+
17
+ package com.google.zxing.qrcode.encoder;
18
+
19
+ final class BlockPair {
20
+
21
+ private final byte[] dataBytes;
22
+ private final byte[] errorCorrectionBytes;
23
+
24
+ BlockPair(byte[] data, byte[] errorCorrection) {
25
+ dataBytes = data;
26
+ errorCorrectionBytes = errorCorrection;
27
+ }
28
+
29
+ public byte[] getDataBytes() {
30
+ return dataBytes;
31
+ }
32
+
33
+ public byte[] getErrorCorrectionBytes() {
34
+ return errorCorrectionBytes;
35
+ }
36
+
37
+ }
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Copyright 2008 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
+
17
+ package com.google.zxing.qrcode.encoder;
18
+
19
+ /**
20
+ * A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a
21
+ * unsigned container, it's up to you to do byteValue & 0xff at each location.
22
+ *
23
+ * JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
24
+ * -1, 0, and 1, I'm going to use less memory and go with bytes.
25
+ *
26
+ * @author dswitkin@google.com (Daniel Switkin)
27
+ */
28
+ public final class ByteMatrix {
29
+
30
+ private final byte[][] bytes;
31
+ private final int width;
32
+ private final int height;
33
+
34
+ public ByteMatrix(int width, int height) {
35
+ bytes = new byte[height][width];
36
+ this.width = width;
37
+ this.height = height;
38
+ }
39
+
40
+ public int getHeight() {
41
+ return height;
42
+ }
43
+
44
+ public int getWidth() {
45
+ return width;
46
+ }
47
+
48
+ public byte get(int x, int y) {
49
+ return bytes[y][x];
50
+ }
51
+
52
+ public byte[][] getArray() {
53
+ return bytes;
54
+ }
55
+
56
+ public void set(int x, int y, byte value) {
57
+ bytes[y][x] = value;
58
+ }
59
+
60
+ public void set(int x, int y, int value) {
61
+ bytes[y][x] = (byte) value;
62
+ }
63
+
64
+ public void set(int x, int y, boolean value) {
65
+ bytes[y][x] = (byte) (value ? 1 : 0);
66
+ }
67
+
68
+ public void clear(byte value) {
69
+ for (int y = 0; y < height; ++y) {
70
+ for (int x = 0; x < width; ++x) {
71
+ bytes[y][x] = value;
72
+ }
73
+ }
74
+ }
75
+
76
+ public String toString() {
77
+ StringBuffer result = new StringBuffer(2 * width * height + 2);
78
+ for (int y = 0; y < height; ++y) {
79
+ for (int x = 0; x < width; ++x) {
80
+ switch (bytes[y][x]) {
81
+ case 0:
82
+ result.append(" 0");
83
+ break;
84
+ case 1:
85
+ result.append(" 1");
86
+ break;
87
+ default:
88
+ result.append(" ");
89
+ break;
90
+ }
91
+ }
92
+ result.append('\n');
93
+ }
94
+ return result.toString();
95
+ }
96
+
97
+ }
@@ -0,0 +1,557 @@
1
+ /*
2
+ * Copyright 2008 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
+
17
+ package com.google.zxing.qrcode.encoder;
18
+
19
+ import com.google.zxing.EncodeHintType;
20
+ import com.google.zxing.WriterException;
21
+ import com.google.zxing.common.BitArray;
22
+ import com.google.zxing.common.CharacterSetECI;
23
+ import com.google.zxing.common.ECI;
24
+ import com.google.zxing.common.reedsolomon.GF256;
25
+ import com.google.zxing.common.reedsolomon.ReedSolomonEncoder;
26
+ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
27
+ import com.google.zxing.qrcode.decoder.Mode;
28
+ import com.google.zxing.qrcode.decoder.Version;
29
+
30
+ import java.io.UnsupportedEncodingException;
31
+ import java.util.Hashtable;
32
+ import java.util.Vector;
33
+
34
+ /**
35
+ * @author satorux@google.com (Satoru Takabayashi) - creator
36
+ * @author dswitkin@google.com (Daniel Switkin) - ported from C++
37
+ */
38
+ public final class Encoder {
39
+
40
+ // The original table is defined in the table 5 of JISX0510:2004 (p.19).
41
+ private static final int[] ALPHANUMERIC_TABLE = {
42
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00-0x0f
43
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10-0x1f
44
+ 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // 0x20-0x2f
45
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // 0x30-0x3f
46
+ -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x40-0x4f
47
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // 0x50-0x5f
48
+ };
49
+
50
+ static final String DEFAULT_BYTE_MODE_ENCODING = "ISO-8859-1";
51
+
52
+ private Encoder() {
53
+ }
54
+
55
+ // The mask penalty calculation is complicated. See Table 21 of JISX0510:2004 (p.45) for details.
56
+ // Basically it applies four rules and summate all penalties.
57
+ private static int calculateMaskPenalty(ByteMatrix matrix) {
58
+ int penalty = 0;
59
+ penalty += MaskUtil.applyMaskPenaltyRule1(matrix);
60
+ penalty += MaskUtil.applyMaskPenaltyRule2(matrix);
61
+ penalty += MaskUtil.applyMaskPenaltyRule3(matrix);
62
+ penalty += MaskUtil.applyMaskPenaltyRule4(matrix);
63
+ return penalty;
64
+ }
65
+
66
+ /**
67
+ * Encode "bytes" with the error correction level "ecLevel". The encoding mode will be chosen
68
+ * internally by chooseMode(). On success, store the result in "qrCode".
69
+ *
70
+ * We recommend you to use QRCode.EC_LEVEL_L (the lowest level) for
71
+ * "getECLevel" since our primary use is to show QR code on desktop screens. We don't need very
72
+ * strong error correction for this purpose.
73
+ *
74
+ * Note that there is no way to encode bytes in MODE_KANJI. We might want to add EncodeWithMode()
75
+ * with which clients can specify the encoding mode. For now, we don't need the functionality.
76
+ */
77
+ public static void encode(String content, ErrorCorrectionLevel ecLevel, QRCode qrCode)
78
+ throws WriterException {
79
+ encode(content, ecLevel, null, qrCode);
80
+ }
81
+
82
+ public static void encode(String content, ErrorCorrectionLevel ecLevel, Hashtable hints,
83
+ QRCode qrCode) throws WriterException {
84
+
85
+ String encoding = hints == null ? null : (String) hints.get(EncodeHintType.CHARACTER_SET);
86
+ if (encoding == null) {
87
+ encoding = DEFAULT_BYTE_MODE_ENCODING;
88
+ }
89
+
90
+ // Step 1: Choose the mode (encoding).
91
+ Mode mode = chooseMode(content, encoding);
92
+
93
+ // Step 2: Append "bytes" into "dataBits" in appropriate encoding.
94
+ BitArray dataBits = new BitArray();
95
+ appendBytes(content, mode, dataBits, encoding);
96
+ // Step 3: Initialize QR code that can contain "dataBits".
97
+ int numInputBytes = dataBits.getSizeInBytes();
98
+ initQRCode(numInputBytes, ecLevel, mode, qrCode);
99
+
100
+ // Step 4: Build another bit vector that contains header and data.
101
+ BitArray headerAndDataBits = new BitArray();
102
+
103
+ // Step 4.5: Append ECI message if applicable
104
+ if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) {
105
+ CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding);
106
+ if (eci != null) {
107
+ appendECI(eci, headerAndDataBits);
108
+ }
109
+ }
110
+
111
+ appendModeInfo(mode, headerAndDataBits);
112
+
113
+ int numLetters = mode.equals(Mode.BYTE) ? dataBits.getSizeInBytes() : content.length();
114
+ appendLengthInfo(numLetters, qrCode.getVersion(), mode, headerAndDataBits);
115
+ headerAndDataBits.appendBitArray(dataBits);
116
+
117
+ // Step 5: Terminate the bits properly.
118
+ terminateBits(qrCode.getNumDataBytes(), headerAndDataBits);
119
+
120
+ // Step 6: Interleave data bits with error correction code.
121
+ BitArray finalBits = new BitArray();
122
+ interleaveWithECBytes(headerAndDataBits, qrCode.getNumTotalBytes(), qrCode.getNumDataBytes(),
123
+ qrCode.getNumRSBlocks(), finalBits);
124
+
125
+ // Step 7: Choose the mask pattern and set to "qrCode".
126
+ ByteMatrix matrix = new ByteMatrix(qrCode.getMatrixWidth(), qrCode.getMatrixWidth());
127
+ qrCode.setMaskPattern(chooseMaskPattern(finalBits, qrCode.getECLevel(), qrCode.getVersion(),
128
+ matrix));
129
+
130
+ // Step 8. Build the matrix and set it to "qrCode".
131
+ MatrixUtil.buildMatrix(finalBits, qrCode.getECLevel(), qrCode.getVersion(),
132
+ qrCode.getMaskPattern(), matrix);
133
+ qrCode.setMatrix(matrix);
134
+ // Step 9. Make sure we have a valid QR Code.
135
+ if (!qrCode.isValid()) {
136
+ throw new WriterException("Invalid QR code: " + qrCode.toString());
137
+ }
138
+ }
139
+
140
+ /**
141
+ * @return the code point of the table used in alphanumeric mode or
142
+ * -1 if there is no corresponding code in the table.
143
+ */
144
+ static int getAlphanumericCode(int code) {
145
+ if (code < ALPHANUMERIC_TABLE.length) {
146
+ return ALPHANUMERIC_TABLE[code];
147
+ }
148
+ return -1;
149
+ }
150
+
151
+ public static Mode chooseMode(String content) {
152
+ return chooseMode(content, null);
153
+ }
154
+
155
+ /**
156
+ * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
157
+ * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
158
+ */
159
+ public static Mode chooseMode(String content, String encoding) {
160
+ if ("Shift_JIS".equals(encoding)) {
161
+ // Choose Kanji mode if all input are double-byte characters
162
+ return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE;
163
+ }
164
+ boolean hasNumeric = false;
165
+ boolean hasAlphanumeric = false;
166
+ for (int i = 0; i < content.length(); ++i) {
167
+ char c = content.charAt(i);
168
+ if (c >= '0' && c <= '9') {
169
+ hasNumeric = true;
170
+ } else if (getAlphanumericCode(c) != -1) {
171
+ hasAlphanumeric = true;
172
+ } else {
173
+ return Mode.BYTE;
174
+ }
175
+ }
176
+ if (hasAlphanumeric) {
177
+ return Mode.ALPHANUMERIC;
178
+ } else if (hasNumeric) {
179
+ return Mode.NUMERIC;
180
+ }
181
+ return Mode.BYTE;
182
+ }
183
+
184
+ private static boolean isOnlyDoubleByteKanji(String content) {
185
+ byte[] bytes;
186
+ try {
187
+ bytes = content.getBytes("Shift_JIS");
188
+ } catch (UnsupportedEncodingException uee) {
189
+ return false;
190
+ }
191
+ int length = bytes.length;
192
+ if (length % 2 != 0) {
193
+ return false;
194
+ }
195
+ for (int i = 0; i < length; i += 2) {
196
+ int byte1 = bytes[i] & 0xFF;
197
+ if ((byte1 < 0x81 || byte1 > 0x9F) && (byte1 < 0xE0 || byte1 > 0xEB)) {
198
+ return false;
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+
204
+ private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, int version,
205
+ ByteMatrix matrix) throws WriterException {
206
+
207
+ int minPenalty = Integer.MAX_VALUE; // Lower penalty is better.
208
+ int bestMaskPattern = -1;
209
+ // We try all mask patterns to choose the best one.
210
+ for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++) {
211
+ MatrixUtil.buildMatrix(bits, ecLevel, version, maskPattern, matrix);
212
+ int penalty = calculateMaskPenalty(matrix);
213
+ if (penalty < minPenalty) {
214
+ minPenalty = penalty;
215
+ bestMaskPattern = maskPattern;
216
+ }
217
+ }
218
+ return bestMaskPattern;
219
+ }
220
+
221
+ /**
222
+ * Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success,
223
+ * modify "qrCode".
224
+ */
225
+ private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode,
226
+ QRCode qrCode) throws WriterException {
227
+ qrCode.setECLevel(ecLevel);
228
+ qrCode.setMode(mode);
229
+
230
+ // In the following comments, we use numbers of Version 7-H.
231
+ for (int versionNum = 1; versionNum <= 40; versionNum++) {
232
+ Version version = Version.getVersionForNumber(versionNum);
233
+ // numBytes = 196
234
+ int numBytes = version.getTotalCodewords();
235
+ // getNumECBytes = 130
236
+ Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
237
+ int numEcBytes = ecBlocks.getTotalECCodewords();
238
+ // getNumRSBlocks = 5
239
+ int numRSBlocks = ecBlocks.getNumBlocks();
240
+ // getNumDataBytes = 196 - 130 = 66
241
+ int numDataBytes = numBytes - numEcBytes;
242
+ // We want to choose the smallest version which can contain data of "numInputBytes" + some
243
+ // extra bits for the header (mode info and length info). The header can be three bytes
244
+ // (precisely 4 + 16 bits) at most. Hence we do +3 here.
245
+ if (numDataBytes >= numInputBytes + 3) {
246
+ // Yay, we found the proper rs block info!
247
+ qrCode.setVersion(versionNum);
248
+ qrCode.setNumTotalBytes(numBytes);
249
+ qrCode.setNumDataBytes(numDataBytes);
250
+ qrCode.setNumRSBlocks(numRSBlocks);
251
+ // getNumECBytes = 196 - 66 = 130
252
+ qrCode.setNumECBytes(numEcBytes);
253
+ // matrix width = 21 + 6 * 4 = 45
254
+ qrCode.setMatrixWidth(version.getDimensionForVersion());
255
+ return;
256
+ }
257
+ }
258
+ throw new WriterException("Cannot find proper rs block info (input data too big?)");
259
+ }
260
+
261
+ /**
262
+ * Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
263
+ */
264
+ static void terminateBits(int numDataBytes, BitArray bits) throws WriterException {
265
+ int capacity = numDataBytes << 3;
266
+ if (bits.getSize() > capacity) {
267
+ throw new WriterException("data bits cannot fit in the QR Code" + bits.getSize() + " > " +
268
+ capacity);
269
+ }
270
+ for (int i = 0; i < 4 && bits.getSize() < capacity; ++i) {
271
+ bits.appendBit(false);
272
+ }
273
+ // Append termination bits. See 8.4.8 of JISX0510:2004 (p.24) for details.
274
+ // If the last byte isn't 8-bit aligned, we'll add padding bits.
275
+ int numBitsInLastByte = bits.getSize() & 0x07;
276
+ if (numBitsInLastByte > 0) {
277
+ for (int i = numBitsInLastByte; i < 8; i++) {
278
+ bits.appendBit(false);
279
+ }
280
+ }
281
+ // If we have more space, we'll fill the space with padding patterns defined in 8.4.9 (p.24).
282
+ int numPaddingBytes = numDataBytes - bits.getSizeInBytes();
283
+ for (int i = 0; i < numPaddingBytes; ++i) {
284
+ bits.appendBits(((i & 0x01) == 0) ? 0xEC : 0x11, 8);
285
+ }
286
+ if (bits.getSize() != capacity) {
287
+ throw new WriterException("Bits size does not equal capacity");
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Get number of data bytes and number of error correction bytes for block id "blockID". Store
293
+ * the result in "numDataBytesInBlock", and "numECBytesInBlock". See table 12 in 8.5.1 of
294
+ * JISX0510:2004 (p.30)
295
+ */
296
+ static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes, int numDataBytes,
297
+ int numRSBlocks, int blockID, int[] numDataBytesInBlock,
298
+ int[] numECBytesInBlock) throws WriterException {
299
+ if (blockID >= numRSBlocks) {
300
+ throw new WriterException("Block ID too large");
301
+ }
302
+ // numRsBlocksInGroup2 = 196 % 5 = 1
303
+ int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
304
+ // numRsBlocksInGroup1 = 5 - 1 = 4
305
+ int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
306
+ // numTotalBytesInGroup1 = 196 / 5 = 39
307
+ int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks;
308
+ // numTotalBytesInGroup2 = 39 + 1 = 40
309
+ int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1;
310
+ // numDataBytesInGroup1 = 66 / 5 = 13
311
+ int numDataBytesInGroup1 = numDataBytes / numRSBlocks;
312
+ // numDataBytesInGroup2 = 13 + 1 = 14
313
+ int numDataBytesInGroup2 = numDataBytesInGroup1 + 1;
314
+ // numEcBytesInGroup1 = 39 - 13 = 26
315
+ int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1;
316
+ // numEcBytesInGroup2 = 40 - 14 = 26
317
+ int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2;
318
+ // Sanity checks.
319
+ // 26 = 26
320
+ if (numEcBytesInGroup1 != numEcBytesInGroup2) {
321
+ throw new WriterException("EC bytes mismatch");
322
+ }
323
+ // 5 = 4 + 1.
324
+ if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2) {
325
+ throw new WriterException("RS blocks mismatch");
326
+ }
327
+ // 196 = (13 + 26) * 4 + (14 + 26) * 1
328
+ if (numTotalBytes !=
329
+ ((numDataBytesInGroup1 + numEcBytesInGroup1) *
330
+ numRsBlocksInGroup1) +
331
+ ((numDataBytesInGroup2 + numEcBytesInGroup2) *
332
+ numRsBlocksInGroup2)) {
333
+ throw new WriterException("Total bytes mismatch");
334
+ }
335
+
336
+ if (blockID < numRsBlocksInGroup1) {
337
+ numDataBytesInBlock[0] = numDataBytesInGroup1;
338
+ numECBytesInBlock[0] = numEcBytesInGroup1;
339
+ } else {
340
+ numDataBytesInBlock[0] = numDataBytesInGroup2;
341
+ numECBytesInBlock[0] = numEcBytesInGroup2;
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Interleave "bits" with corresponding error correction bytes. On success, store the result in
347
+ * "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
348
+ */
349
+ static void interleaveWithECBytes(BitArray bits, int numTotalBytes,
350
+ int numDataBytes, int numRSBlocks, BitArray result) throws WriterException {
351
+
352
+ // "bits" must have "getNumDataBytes" bytes of data.
353
+ if (bits.getSizeInBytes() != numDataBytes) {
354
+ throw new WriterException("Number of bits and data bytes does not match");
355
+ }
356
+
357
+ // Step 1. Divide data bytes into blocks and generate error correction bytes for them. We'll
358
+ // store the divided data bytes blocks and error correction bytes blocks into "blocks".
359
+ int dataBytesOffset = 0;
360
+ int maxNumDataBytes = 0;
361
+ int maxNumEcBytes = 0;
362
+
363
+ // Since, we know the number of reedsolmon blocks, we can initialize the vector with the number.
364
+ Vector blocks = new Vector(numRSBlocks);
365
+
366
+ for (int i = 0; i < numRSBlocks; ++i) {
367
+ int[] numDataBytesInBlock = new int[1];
368
+ int[] numEcBytesInBlock = new int[1];
369
+ getNumDataBytesAndNumECBytesForBlockID(
370
+ numTotalBytes, numDataBytes, numRSBlocks, i,
371
+ numDataBytesInBlock, numEcBytesInBlock);
372
+
373
+ int size = numDataBytesInBlock[0];
374
+ byte[] dataBytes = new byte[size];
375
+ bits.toBytes(8*dataBytesOffset, dataBytes, 0, size);
376
+ byte[] ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]);
377
+ blocks.addElement(new BlockPair(dataBytes, ecBytes));
378
+
379
+ maxNumDataBytes = Math.max(maxNumDataBytes, size);
380
+ maxNumEcBytes = Math.max(maxNumEcBytes, ecBytes.length);
381
+ dataBytesOffset += numDataBytesInBlock[0];
382
+ }
383
+ if (numDataBytes != dataBytesOffset) {
384
+ throw new WriterException("Data bytes does not match offset");
385
+ }
386
+
387
+ // First, place data blocks.
388
+ for (int i = 0; i < maxNumDataBytes; ++i) {
389
+ for (int j = 0; j < blocks.size(); ++j) {
390
+ byte[] dataBytes = ((BlockPair) blocks.elementAt(j)).getDataBytes();
391
+ if (i < dataBytes.length) {
392
+ result.appendBits(dataBytes[i], 8);
393
+ }
394
+ }
395
+ }
396
+ // Then, place error correction blocks.
397
+ for (int i = 0; i < maxNumEcBytes; ++i) {
398
+ for (int j = 0; j < blocks.size(); ++j) {
399
+ byte[] ecBytes = ((BlockPair) blocks.elementAt(j)).getErrorCorrectionBytes();
400
+ if (i < ecBytes.length) {
401
+ result.appendBits(ecBytes[i], 8);
402
+ }
403
+ }
404
+ }
405
+ if (numTotalBytes != result.getSizeInBytes()) { // Should be same.
406
+ throw new WriterException("Interleaving error: " + numTotalBytes + " and " +
407
+ result.getSizeInBytes() + " differ.");
408
+ }
409
+ }
410
+
411
+ static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
412
+ int numDataBytes = dataBytes.length;
413
+ int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
414
+ for (int i = 0; i < numDataBytes; i++) {
415
+ toEncode[i] = dataBytes[i] & 0xFF;
416
+ }
417
+ new ReedSolomonEncoder(GF256.QR_CODE_FIELD).encode(toEncode, numEcBytesInBlock);
418
+
419
+ byte[] ecBytes = new byte[numEcBytesInBlock];
420
+ for (int i = 0; i < numEcBytesInBlock; i++) {
421
+ ecBytes[i] = (byte) toEncode[numDataBytes + i];
422
+ }
423
+ return ecBytes;
424
+ }
425
+
426
+ /**
427
+ * Append mode info. On success, store the result in "bits".
428
+ */
429
+ static void appendModeInfo(Mode mode, BitArray bits) {
430
+ bits.appendBits(mode.getBits(), 4);
431
+ }
432
+
433
+
434
+ /**
435
+ * Append length info. On success, store the result in "bits".
436
+ */
437
+ static void appendLengthInfo(int numLetters, int version, Mode mode, BitArray bits)
438
+ throws WriterException {
439
+ int numBits = mode.getCharacterCountBits(Version.getVersionForNumber(version));
440
+ if (numLetters > ((1 << numBits) - 1)) {
441
+ throw new WriterException(numLetters + "is bigger than" + ((1 << numBits) - 1));
442
+ }
443
+ bits.appendBits(numLetters, numBits);
444
+ }
445
+
446
+ /**
447
+ * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
448
+ */
449
+ static void appendBytes(String content, Mode mode, BitArray bits, String encoding)
450
+ throws WriterException {
451
+ if (mode.equals(Mode.NUMERIC)) {
452
+ appendNumericBytes(content, bits);
453
+ } else if (mode.equals(Mode.ALPHANUMERIC)) {
454
+ appendAlphanumericBytes(content, bits);
455
+ } else if (mode.equals(Mode.BYTE)) {
456
+ append8BitBytes(content, bits, encoding);
457
+ } else if (mode.equals(Mode.KANJI)) {
458
+ appendKanjiBytes(content, bits);
459
+ } else {
460
+ throw new WriterException("Invalid mode: " + mode);
461
+ }
462
+ }
463
+
464
+ static void appendNumericBytes(String content, BitArray bits) {
465
+ int length = content.length();
466
+ int i = 0;
467
+ while (i < length) {
468
+ int num1 = content.charAt(i) - '0';
469
+ if (i + 2 < length) {
470
+ // Encode three numeric letters in ten bits.
471
+ int num2 = content.charAt(i + 1) - '0';
472
+ int num3 = content.charAt(i + 2) - '0';
473
+ bits.appendBits(num1 * 100 + num2 * 10 + num3, 10);
474
+ i += 3;
475
+ } else if (i + 1 < length) {
476
+ // Encode two numeric letters in seven bits.
477
+ int num2 = content.charAt(i + 1) - '0';
478
+ bits.appendBits(num1 * 10 + num2, 7);
479
+ i += 2;
480
+ } else {
481
+ // Encode one numeric letter in four bits.
482
+ bits.appendBits(num1, 4);
483
+ i++;
484
+ }
485
+ }
486
+ }
487
+
488
+ static void appendAlphanumericBytes(String content, BitArray bits) throws WriterException {
489
+ int length = content.length();
490
+ int i = 0;
491
+ while (i < length) {
492
+ int code1 = getAlphanumericCode(content.charAt(i));
493
+ if (code1 == -1) {
494
+ throw new WriterException();
495
+ }
496
+ if (i + 1 < length) {
497
+ int code2 = getAlphanumericCode(content.charAt(i + 1));
498
+ if (code2 == -1) {
499
+ throw new WriterException();
500
+ }
501
+ // Encode two alphanumeric letters in 11 bits.
502
+ bits.appendBits(code1 * 45 + code2, 11);
503
+ i += 2;
504
+ } else {
505
+ // Encode one alphanumeric letter in six bits.
506
+ bits.appendBits(code1, 6);
507
+ i++;
508
+ }
509
+ }
510
+ }
511
+
512
+ static void append8BitBytes(String content, BitArray bits, String encoding)
513
+ throws WriterException {
514
+ byte[] bytes;
515
+ try {
516
+ bytes = content.getBytes(encoding);
517
+ } catch (UnsupportedEncodingException uee) {
518
+ throw new WriterException(uee.toString());
519
+ }
520
+ for (int i = 0; i < bytes.length; ++i) {
521
+ bits.appendBits(bytes[i], 8);
522
+ }
523
+ }
524
+
525
+ static void appendKanjiBytes(String content, BitArray bits) throws WriterException {
526
+ byte[] bytes;
527
+ try {
528
+ bytes = content.getBytes("Shift_JIS");
529
+ } catch (UnsupportedEncodingException uee) {
530
+ throw new WriterException(uee.toString());
531
+ }
532
+ int length = bytes.length;
533
+ for (int i = 0; i < length; i += 2) {
534
+ int byte1 = bytes[i] & 0xFF;
535
+ int byte2 = bytes[i + 1] & 0xFF;
536
+ int code = (byte1 << 8) | byte2;
537
+ int subtracted = -1;
538
+ if (code >= 0x8140 && code <= 0x9ffc) {
539
+ subtracted = code - 0x8140;
540
+ } else if (code >= 0xe040 && code <= 0xebbf) {
541
+ subtracted = code - 0xc140;
542
+ }
543
+ if (subtracted == -1) {
544
+ throw new WriterException("Invalid byte sequence");
545
+ }
546
+ int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
547
+ bits.appendBits(encoded, 13);
548
+ }
549
+ }
550
+
551
+ private static void appendECI(ECI eci, BitArray bits) {
552
+ bits.appendBits(Mode.ECI.getBits(), 4);
553
+ // This is correct for values up to 127, which is all we need now.
554
+ bits.appendBits(eci.getValue(), 8);
555
+ }
556
+
557
+ }