rqrencoder 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/Gemfile +0 -1
- data/Rakefile +8 -0
- data/ext/rqrencoder/RQREncoder.i +20 -19
- data/ext/rqrencoder/{RQREncoder_wrap.cxx → RQREncoder_wrap.c} +700 -900
- data/ext/rqrencoder/extconf.rb +7 -1
- data/ext/rqrencoder/qrencode.h +426 -0
- data/lib/rqrencoder/qr_encoder.rb +11 -16
- data/lib/rqrencoder/qrcode.rb +6 -6
- data/lib/rqrencoder/version.rb +1 -1
- data/test/test_rqrencoder.rb +9 -1
- metadata +5 -7
- data/ext/rqrencoder/QR_Encode.cpp +0 -1949
- data/ext/rqrencoder/QR_Encode.h +0 -152
- data/ext/rqrencoder/win2ansi.h +0 -20
data/ext/rqrencoder/extconf.rb
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
usage: ruby extconf.rb [options ...]
|
3
3
|
configure options:
|
4
4
|
--with-opt-dir=/path/to/libraries
|
5
|
+
--with-qrencode-include=dir
|
6
|
+
--with-qrencode-lib=dir
|
5
7
|
=end
|
6
8
|
require 'mkmf'
|
7
9
|
require 'rbconfig'
|
8
|
-
|
10
|
+
#$libs = append_library($libs, "supc++")
|
11
|
+
|
12
|
+
dir_config('qrencode')
|
13
|
+
|
14
|
+
$LDFLAGS = ENV["LDFLAGS"].to_s + " -lqrencode"
|
9
15
|
|
10
16
|
create_makefile('rqrencoder/RQREncoder')
|
@@ -0,0 +1,426 @@
|
|
1
|
+
/**
|
2
|
+
* qrencode - QR Code encoder
|
3
|
+
*
|
4
|
+
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
/** \mainpage
|
22
|
+
* Libqrencode is a library for encoding data in a QR Code symbol, a kind of 2D
|
23
|
+
* symbology.
|
24
|
+
*
|
25
|
+
* \section encoding Encoding
|
26
|
+
*
|
27
|
+
* There are two ways to encode data: <b>encoding a string</b> or
|
28
|
+
* <b>encoding a structured data</b>.
|
29
|
+
*
|
30
|
+
* \subsection encoding-string Encoding a string
|
31
|
+
* You can encode a string by calling QRcode_encodeString().
|
32
|
+
* The given string is parsed automatically and encoded. If you want to encode
|
33
|
+
* data that can be represented as a C string style (NUL terminated), you can
|
34
|
+
* simply use this way.
|
35
|
+
*
|
36
|
+
* If the input data contains Kanji (Shift-JIS) characters and you want to
|
37
|
+
* encode them as Kanji in QR Code, you should give QR_MODE_KANJI as a hint.
|
38
|
+
* Otherwise, all of non-alphanumeric characters are encoded as 8 bit data.
|
39
|
+
* If you want to encode a whole string in 8 bit mode, use
|
40
|
+
* QRcode_encodeString8bit() instead.
|
41
|
+
*
|
42
|
+
* Please note that a C string can not contain NUL character. If your data
|
43
|
+
* contains NUL, you should chose the second way.
|
44
|
+
*
|
45
|
+
* \subsection encoding-input Encoding a structured data
|
46
|
+
* You can construct a structured input data manually. If the structure of the
|
47
|
+
* input data is known, you can use this way.
|
48
|
+
* At first, create a ::QRinput object by QRinput_new(). Then add input data
|
49
|
+
* to the QRinput object by QRinput_append(). Finally call QRcode_encodeInput()
|
50
|
+
* to encode the QRinput data.
|
51
|
+
* You can reuse the QRinput data again to encode it in other symbols with
|
52
|
+
* different parameters.
|
53
|
+
*
|
54
|
+
* \section result Result
|
55
|
+
* The encoded symbol is resulted as a ::QRcode object. It will contain
|
56
|
+
* its version number, width of the symbol and an array represents the symbol.
|
57
|
+
* See ::QRcode for the details. You can free the object by QRcode_free().
|
58
|
+
*
|
59
|
+
* Please note that the version of the result may be larger than specified.
|
60
|
+
* In such cases, the input data would be too large to be encoded in a
|
61
|
+
* symbol of the specified version.
|
62
|
+
*
|
63
|
+
* \section structured Structured append
|
64
|
+
* Libqrencode can generate "Structured-appended" symbols that enables to split
|
65
|
+
* a large data set into mulitple QR codes. A QR code reader concatenates
|
66
|
+
* multiple QR code symbols into a string.
|
67
|
+
* Just like QRcode_encodeString(), you can use QRcode_encodeStringStructured()
|
68
|
+
* to generate structured-appended symbols. This functions returns an instance
|
69
|
+
* of ::QRcode_List. The returned list is a singly-linked list of QRcode: you
|
70
|
+
* can retrieve each QR code in this way:
|
71
|
+
*
|
72
|
+
* \code
|
73
|
+
* QRcode_List *qrcodes;
|
74
|
+
* QRcode_List *entry;
|
75
|
+
* QRcode *qrcode;
|
76
|
+
*
|
77
|
+
* qrcodes = QRcode_encodeStringStructured(...);
|
78
|
+
* entry = qrcodes;
|
79
|
+
* while(entry != NULL) {
|
80
|
+
* qrcode = entry->code;
|
81
|
+
* // do something
|
82
|
+
* entry = entry->next;
|
83
|
+
* }
|
84
|
+
* QRcode_List_free(entry);
|
85
|
+
* \endcode
|
86
|
+
*
|
87
|
+
* Instead of using auto-parsing functions, you can construct your own
|
88
|
+
* structured input. At first, instantiate an object of ::QRinput_Struct
|
89
|
+
* by calling QRinput_Struct_new(). This object can hold multiple ::QRinput,
|
90
|
+
* and one QR code is generated for a ::QRinput.
|
91
|
+
* QRinput_Struct_appendInput() appends a ::QRinput to a ::QRinput_Struct
|
92
|
+
* object. In order to generate structured-appended symbols, it is required to
|
93
|
+
* embed headers to each symbol. You can use
|
94
|
+
* QRinput_Struct_insertStructuredAppendHeaders() to insert appropriate
|
95
|
+
* headers to each symbol. You should call this function just once before
|
96
|
+
* encoding symbols.
|
97
|
+
*/
|
98
|
+
|
99
|
+
#ifndef __QRENCODE_H__
|
100
|
+
#define __QRENCODE_H__
|
101
|
+
|
102
|
+
#if defined(__cplusplus)
|
103
|
+
extern "C" {
|
104
|
+
#endif
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Encoding mode.
|
108
|
+
*/
|
109
|
+
typedef enum {
|
110
|
+
QR_MODE_NUL = -1, ///< Terminator (NUL character). Internal use only
|
111
|
+
QR_MODE_NUM = 0, ///< Numeric mode
|
112
|
+
QR_MODE_AN, ///< Alphabet-numeric mode
|
113
|
+
QR_MODE_8, ///< 8-bit data mode
|
114
|
+
QR_MODE_KANJI, ///< Kanji (shift-jis) mode
|
115
|
+
QR_MODE_STRUCTURE, ///< Internal use only
|
116
|
+
} QRencodeMode;
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Level of error correction.
|
120
|
+
*/
|
121
|
+
typedef enum {
|
122
|
+
QR_ECLEVEL_L = 0, ///< lowest
|
123
|
+
QR_ECLEVEL_M,
|
124
|
+
QR_ECLEVEL_Q,
|
125
|
+
QR_ECLEVEL_H ///< highest
|
126
|
+
} QRecLevel;
|
127
|
+
|
128
|
+
/******************************************************************************
|
129
|
+
* Input data (qrinput.c)
|
130
|
+
*****************************************************************************/
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Singly linked list to contain input strings. An instance of this class
|
134
|
+
* contains its version and error correction level too. It is required to
|
135
|
+
* set them by QRinput_setVersion() and QRinput_setErrorCorrectionLevel(),
|
136
|
+
* or use QRinput_new2() to instantiate an object.
|
137
|
+
*/
|
138
|
+
typedef struct _QRinput QRinput;
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Instantiate an input data object. The version is set to 0 (auto-select)
|
142
|
+
* and the error correction level is set to QR_ECLEVEL_L.
|
143
|
+
* @return an input object (initialized). On error, NULL is returned and errno
|
144
|
+
* is set to indicate the error.
|
145
|
+
* @throw ENOMEM unable to allocate memory.
|
146
|
+
*/
|
147
|
+
extern QRinput *QRinput_new(void);
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Instantiate an input data object.
|
151
|
+
* @param version version number.
|
152
|
+
* @param level Error correction level.
|
153
|
+
* @return an input object (initialized). On error, NULL is returned and errno
|
154
|
+
* is set to indicate the error.
|
155
|
+
* @throw ENOMEM unable to allocate memory for input objects.
|
156
|
+
* @throw EINVAL invalid arguments.
|
157
|
+
*/
|
158
|
+
extern QRinput *QRinput_new2(int version, QRecLevel level);
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Append data to an input object.
|
162
|
+
* The data is copied and appended to the input object.
|
163
|
+
* @param input input object.
|
164
|
+
* @param mode encoding mode.
|
165
|
+
* @param size size of data (byte).
|
166
|
+
* @param data a pointer to the memory area of the input data.
|
167
|
+
* @retval 0 success.
|
168
|
+
* @retval -1 an error occurred and errno is set to indeicate the error.
|
169
|
+
* See Execptions for the details.
|
170
|
+
* @throw ENOMEM unable to allocate memory.
|
171
|
+
* @throw EINVAL input data is invalid.
|
172
|
+
*
|
173
|
+
*/
|
174
|
+
extern int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data);
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Get current version.
|
178
|
+
* @param input input object.
|
179
|
+
* @return current version.
|
180
|
+
*/
|
181
|
+
extern int QRinput_getVersion(QRinput *input);
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Set version of the QR-code that is to be encoded.
|
185
|
+
* @param input input object.
|
186
|
+
* @param version version number (0 = auto)
|
187
|
+
* @retval 0 success.
|
188
|
+
* @retval -1 invalid argument.
|
189
|
+
*/
|
190
|
+
extern int QRinput_setVersion(QRinput *input, int version);
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Get current error correction level.
|
194
|
+
* @param input input object.
|
195
|
+
* @return Current error correcntion level.
|
196
|
+
*/
|
197
|
+
extern QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input);
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Set error correction level of the QR-code that is to be encoded.
|
201
|
+
* @param input input object.
|
202
|
+
* @param level Error correction level.
|
203
|
+
* @retval 0 success.
|
204
|
+
* @retval -1 invalid argument.
|
205
|
+
*/
|
206
|
+
extern int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level);
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Free the input object.
|
210
|
+
* All of data chunks in the input object are freed too.
|
211
|
+
* @param input input object.
|
212
|
+
*/
|
213
|
+
extern void QRinput_free(QRinput *input);
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Validate the input data.
|
217
|
+
* @param mode encoding mode.
|
218
|
+
* @param size size of data (byte).
|
219
|
+
* @param data a pointer to the memory area of the input data.
|
220
|
+
* @retval 0 success.
|
221
|
+
* @retval -1 invalid arguments.
|
222
|
+
*/
|
223
|
+
extern int QRinput_check(QRencodeMode mode, int size, const unsigned char *data);
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Set of QRinput for structured symbols.
|
227
|
+
*/
|
228
|
+
typedef struct _QRinput_Struct QRinput_Struct;
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Instantiate a set of input data object.
|
232
|
+
* @return an instance of QRinput_Struct. On error, NULL is returned and errno
|
233
|
+
* is set to indicate the error.
|
234
|
+
* @throw ENOMEM unable to allocate memory.
|
235
|
+
*/
|
236
|
+
extern QRinput_Struct *QRinput_Struct_new(void);
|
237
|
+
|
238
|
+
/**
|
239
|
+
* Set parity of structured symbols.
|
240
|
+
* @param s structured input object.
|
241
|
+
* @param parity parity of s.
|
242
|
+
*/
|
243
|
+
extern void QRinput_Struct_setParity(QRinput_Struct *s, unsigned char parity);
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Append a QRinput object to the set.
|
247
|
+
* @warning never append the same QRinput object twice or more.
|
248
|
+
* @param s structured input object.
|
249
|
+
* @param input an input object.
|
250
|
+
* @retval >0 number of input objects in the structure.
|
251
|
+
* @retval -1 an error occurred. See Exceptions for the details.
|
252
|
+
* @throw ENOMEM unable to allocate memory.
|
253
|
+
*/
|
254
|
+
extern int QRinput_Struct_appendInput(QRinput_Struct *s, QRinput *input);
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Free all of QRinput in the set.
|
258
|
+
* @param s a structured input object.
|
259
|
+
*/
|
260
|
+
extern void QRinput_Struct_free(QRinput_Struct *s);
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Split a QRinput to QRinput_Struct. It calculates a parity, set it, then
|
264
|
+
* insert structured-append headers.
|
265
|
+
* @param input input object. Version number and error correction level must be
|
266
|
+
* set.
|
267
|
+
* @return a set of input data. On error, NULL is returned, and errno is set
|
268
|
+
* to indicate the error. See Exceptions for the details.
|
269
|
+
* @throw ERANGE input data is too large.
|
270
|
+
* @throw EINVAL invalid input data.
|
271
|
+
* @throw ENOMEM unable to allocate memory.
|
272
|
+
*/
|
273
|
+
extern QRinput_Struct *QRinput_splitQRinputToStruct(QRinput *input);
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Insert structured-append headers to the input structure. It calculates
|
277
|
+
* a parity and set it if the parity is not set yet.
|
278
|
+
* @param s input structure
|
279
|
+
* @retval 0 success.
|
280
|
+
* @retval -1 an error occurred and errno is set to indeicate the error.
|
281
|
+
* See Execptions for the details.
|
282
|
+
* @throw EINVAL invalid input object.
|
283
|
+
* @throw ENOMEM unable to allocate memory.
|
284
|
+
*/
|
285
|
+
extern int QRinput_Struct_insertStructuredAppendHeaders(QRinput_Struct *s);
|
286
|
+
|
287
|
+
/******************************************************************************
|
288
|
+
* QRcode output (qrencode.c)
|
289
|
+
*****************************************************************************/
|
290
|
+
|
291
|
+
/**
|
292
|
+
* QRcode class.
|
293
|
+
* Symbol data is represented as an array contains width*width uchars.
|
294
|
+
* Each uchar represents a module (dot). If the less significant bit of
|
295
|
+
* the uchar is 1, the corresponding module is black. The other bits are
|
296
|
+
* meaningless for usual applications, but here its specification is described.
|
297
|
+
*
|
298
|
+
* <pre>
|
299
|
+
* MSB 76543210 LSB
|
300
|
+
* |||||||`- 1=black/0=white
|
301
|
+
* ||||||`-- data and ecc code area
|
302
|
+
* |||||`--- format information
|
303
|
+
* ||||`---- version information
|
304
|
+
* |||`----- timing pattern
|
305
|
+
* ||`------ alignment pattern
|
306
|
+
* |`------- finder pattern and separator
|
307
|
+
* `-------- non-data modules (format, timing, etc.)
|
308
|
+
* </pre>
|
309
|
+
*/
|
310
|
+
typedef struct {
|
311
|
+
int version; ///< version of the symbol
|
312
|
+
int width; ///< width of the symbol
|
313
|
+
unsigned char *data; ///< symbol data
|
314
|
+
} QRcode;
|
315
|
+
|
316
|
+
/**
|
317
|
+
* Singly-linked list of QRcode. Used to represent a structured symbols.
|
318
|
+
* A list is terminated with NULL.
|
319
|
+
*/
|
320
|
+
typedef struct _QRcode_List QRcode_List;
|
321
|
+
|
322
|
+
struct _QRcode_List {
|
323
|
+
QRcode *code;
|
324
|
+
QRcode_List *next;
|
325
|
+
};
|
326
|
+
|
327
|
+
/**
|
328
|
+
* Create a symbol from the input data.
|
329
|
+
* @warning This function is THREAD UNSAFE.
|
330
|
+
* @param input input data.
|
331
|
+
* @return an instance of QRcode class. The version of the result QRcode may
|
332
|
+
* be larger than the designated version. On error, NULL is returned,
|
333
|
+
* and errno is set to indicate the error. See Exceptions for the
|
334
|
+
* details.
|
335
|
+
* @throw EINVAL invalid input object.
|
336
|
+
* @throw ENOMEM unable to allocate memory for input objects.
|
337
|
+
*/
|
338
|
+
extern QRcode *QRcode_encodeInput(QRinput *input);
|
339
|
+
|
340
|
+
/**
|
341
|
+
* Create a symbol from the string. The library automatically parses the input
|
342
|
+
* string and encodes in a QR Code symbol.
|
343
|
+
* @warning This function is THREAD UNSAFE.
|
344
|
+
* @param string input string. It must be NULL terminated.
|
345
|
+
* @param version version of the symbol. If 0, the library chooses the minimum
|
346
|
+
* version for the given input data.
|
347
|
+
* @param level error correction level.
|
348
|
+
* @param hint tell the library how non-alphanumerical characters should be
|
349
|
+
* encoded. If QR_MODE_KANJI is given, kanji characters will be
|
350
|
+
* encoded as Shif-JIS characters. If QR_MODE_8 is given, all of
|
351
|
+
* non-alphanumerical characters will be encoded as is. If you want
|
352
|
+
* to embed UTF-8 string, choose this.
|
353
|
+
* @param casesensitive case-sensitive(1) or not(0).
|
354
|
+
* @return an instance of QRcode class. The version of the result QRcode may
|
355
|
+
* be larger than the designated version. On error, NULL is returned,
|
356
|
+
* and errno is set to indicate the error. See Exceptions for the
|
357
|
+
* details.
|
358
|
+
* @throw EINVAL invalid input object.
|
359
|
+
* @throw ENOMEM unable to allocate memory for input objects.
|
360
|
+
*/
|
361
|
+
extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
|
362
|
+
|
363
|
+
/**
|
364
|
+
* Same to QRcode_encodeString(), but encode whole data in 8-bit mode.
|
365
|
+
* @warning This function is THREAD UNSAFE.
|
366
|
+
*/
|
367
|
+
extern QRcode *QRcode_encodeString8bit(const char *string, int version, QRecLevel level);
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Free the instance of QRcode class.
|
371
|
+
* @param qrcode an instance of QRcode class.
|
372
|
+
*/
|
373
|
+
extern void QRcode_free(QRcode *qrcode);
|
374
|
+
|
375
|
+
/**
|
376
|
+
* Create structured symbols from the input data.
|
377
|
+
* @warning This function is THREAD UNSAFE.
|
378
|
+
* @param s
|
379
|
+
* @return a singly-linked list of QRcode.
|
380
|
+
*/
|
381
|
+
extern QRcode_List *QRcode_encodeInputStructured(QRinput_Struct *s);
|
382
|
+
|
383
|
+
/**
|
384
|
+
* Create structured symbols from the string. The library automatically parses
|
385
|
+
* the input string and encodes in a QR Code symbol.
|
386
|
+
* @warning This function is THREAD UNSAFE.
|
387
|
+
* @param string input string. It should be NULL terminated.
|
388
|
+
* @param version version of the symbol.
|
389
|
+
* @param level error correction level.
|
390
|
+
* @param hint tell the library how non-alphanumerical characters should be
|
391
|
+
* encoded. If QR_MODE_KANJI is given, kanji characters will be
|
392
|
+
* encoded as Shif-JIS characters. If QR_MODE_8 is given, all of
|
393
|
+
* non-alphanumerical characters will be encoded as is. If you want
|
394
|
+
* to embed UTF-8 string, choose this.
|
395
|
+
* @param casesensitive case-sensitive(1) or not(0).
|
396
|
+
* @return a singly-linked list of QRcode. On error, NULL is returned, and
|
397
|
+
* errno is set to indicate the error. See Exceptions for the details.
|
398
|
+
* @throw EINVAL invalid input object.
|
399
|
+
* @throw ENOMEM unable to allocate memory for input objects.
|
400
|
+
*/
|
401
|
+
extern QRcode_List *QRcode_encodeStringStructured(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
|
402
|
+
|
403
|
+
/**
|
404
|
+
* Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode.
|
405
|
+
* @warning This function is THREAD UNSAFE.
|
406
|
+
*/
|
407
|
+
extern QRcode_List *QRcode_encodeString8bitStructured(const char *string, int version, QRecLevel level);
|
408
|
+
|
409
|
+
/**
|
410
|
+
* Return the number of symbols included in a QRcode_List.
|
411
|
+
* @param qrlist a head entry of a QRcode_List.
|
412
|
+
* @return number of symbols in the list.
|
413
|
+
*/
|
414
|
+
extern int QRcode_List_size(QRcode_List *qrlist);
|
415
|
+
|
416
|
+
/**
|
417
|
+
* Free the QRcode_List.
|
418
|
+
* @param qrlist a head entry of a QRcode_List.
|
419
|
+
*/
|
420
|
+
extern void QRcode_List_free(QRcode_List *qrlist);
|
421
|
+
|
422
|
+
#if defined(__cplusplus)
|
423
|
+
}
|
424
|
+
#endif
|
425
|
+
|
426
|
+
#endif /* __QRENCODE_H__ */
|
@@ -2,16 +2,13 @@ require 'rqrencoder/RQREncoder'
|
|
2
2
|
|
3
3
|
module RQREncoder
|
4
4
|
class QREncoder
|
5
|
-
|
5
|
+
# options
|
6
|
+
# :version will auto-extend if too low (default)
|
6
7
|
# :level L:0, M:1(default), Q:2, H:3
|
7
|
-
# :
|
8
|
-
# :
|
9
|
-
# :masking masking pattern 0-7, -1(default auto)
|
10
|
-
# :length data length
|
11
|
-
# :module_size module pixel size
|
12
|
-
# :eps_preview true|false(default)
|
8
|
+
# :mode hint for mode NUM:0, A/N:1 (default), 8Bit: 2, KANJI: 3
|
9
|
+
# :case_sensitive true(default) / false
|
13
10
|
def initialize(options = {})
|
14
|
-
@options = { :level => 1, :version => 0, :
|
11
|
+
@options = { :level => 1, :version => 0, :mode => 2, :case_sensitive => true }
|
15
12
|
@options.merge!(options)
|
16
13
|
end
|
17
14
|
|
@@ -27,18 +24,16 @@ module RQREncoder
|
|
27
24
|
|
28
25
|
def method_missing(sym, *args, &block)
|
29
26
|
if (sym[-1] == '=')
|
30
|
-
|
27
|
+
key = sym[0..-2].to_sym
|
28
|
+
super(sym, *args, &block) unless (@options.has_key? key)
|
29
|
+
@options[key] = args[0]
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
33
|
def encode(data)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
result = QRCode.new(cencoder.m_nLevel, cencoder.m_nVersion, cencoder.m_nMaskingNo, cencoder.m_nSymbleSize, cencoder.results)
|
40
|
-
cencoder = nil
|
41
|
-
result
|
34
|
+
c_code_result = RQREncoder.QRcode_encodeString(data, @options[:version], @options[:level], @options[:mode], @options[:case_sensitive] ? 1 : 0)
|
35
|
+
puts c_code_result.inspect
|
36
|
+
QRCode.new(data, @options[:level], c_code_result.version, c_code_result.width, c_code_result.modules)
|
42
37
|
end
|
43
38
|
|
44
39
|
end
|
data/lib/rqrencoder/qrcode.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module RQREncoder
|
2
2
|
class QRCode
|
3
3
|
|
4
|
-
def initialize(level, version,
|
4
|
+
def initialize(content, level, version, size, modules)
|
5
|
+
@content = content
|
5
6
|
@level = level
|
6
7
|
@version = version
|
7
|
-
@masking = masking
|
8
8
|
@size = size
|
9
9
|
@modules = modules
|
10
10
|
end
|
11
11
|
|
12
|
+
def content
|
13
|
+
@content
|
14
|
+
end
|
15
|
+
|
12
16
|
def level
|
13
17
|
@level
|
14
18
|
end
|
@@ -17,10 +21,6 @@ module RQREncoder
|
|
17
21
|
@version
|
18
22
|
end
|
19
23
|
|
20
|
-
def masking
|
21
|
-
@masking
|
22
|
-
end
|
23
|
-
|
24
24
|
def size
|
25
25
|
@size
|
26
26
|
end
|
data/lib/rqrencoder/version.rb
CHANGED
data/test/test_rqrencoder.rb
CHANGED
@@ -10,12 +10,20 @@ class TestRQREncoder < Test::Unit::TestCase
|
|
10
10
|
assert_equal(2, encoder.options[:level])
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_block_form_missing_option
|
14
|
+
assert_raise NoMethodError do
|
15
|
+
encoder = RQREncoder::QREncoder.create do |enc|
|
16
|
+
enc.not_an_option_or_method = "Fail"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
def test_encoding
|
14
22
|
encoder = RQREncoder::QREncoder.new
|
15
23
|
result = encoder.encode("FOO BAR")
|
24
|
+
assert_equal("FOO BAR", result.content)
|
16
25
|
assert_equal(1, result.level)
|
17
26
|
assert_equal(1, result.version)
|
18
|
-
assert_equal(0, result.masking)
|
19
27
|
assert_equal(21, result.size)
|
20
28
|
assert_equal(21, result.modules.length)
|
21
29
|
assert_equal(21, result.modules[0].length)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matt Robinson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-30 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -32,12 +32,10 @@ files:
|
|
32
32
|
- Gemfile
|
33
33
|
- README.markdown
|
34
34
|
- Rakefile
|
35
|
-
- ext/rqrencoder/QR_Encode.cpp
|
36
|
-
- ext/rqrencoder/QR_Encode.h
|
37
35
|
- ext/rqrencoder/RQREncoder.i
|
38
|
-
- ext/rqrencoder/RQREncoder_wrap.
|
36
|
+
- ext/rqrencoder/RQREncoder_wrap.c
|
39
37
|
- ext/rqrencoder/extconf.rb
|
40
|
-
- ext/rqrencoder/
|
38
|
+
- ext/rqrencoder/qrencode.h
|
41
39
|
- lib/rqrencoder.rb
|
42
40
|
- lib/rqrencoder/qr_encoder.rb
|
43
41
|
- lib/rqrencoder/qrcode.rb
|