Skip to content

Commit

Permalink
added pod
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshiki committed Feb 24, 2007
1 parent ff8b415 commit f09a007
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 79 deletions.
45 changes: 23 additions & 22 deletions lib/Imager/QRCode.pm
Expand Up @@ -63,7 +63,6 @@ Imager::QRCode - Generate QR Code with Imager
margin => 2,
version => 1,
level => 'M',
kanji => 1,
casesensitive => 1,
lightcolor => Imager::Color->new(255, 255, 255),
darkcolor => Imager::Color->new(0, 0, 0),
Expand All @@ -85,55 +84,57 @@ This module allows you to generate QR Code with Imager. This module use libqrenc
=over 4
=item new()
=item new
The new() constructor method instantiates a new Imager::QRCode object. new() accepts the following parameters.
$qrcode = Imager::QRCode->new(%params);
=over 4
The C<new()> constructor method instantiates a new Imager::QRCode object. C<new()> accepts the following parameters.
=item text
=over 4
Input text. If you specify Japanese characters, you must encode it to Shift_JIS.
=item *
=item size
C<size> - Horizontal and vertical size of module(dot). Default is 4.
Horizontal and vertical size of module(dot). Default is 4.
=item *
=item margin
C<margin> - Margin size of QR Code. Default is 3.
Margin size of QR Code. Default is 3.
=item *
=item level
C<level> - Error collectin level. Valid values are 'M', 'L', 'Q' or 'H'. Default is 'L'.
Error collectin level. You can specify 'M', 'L', 'H' or 'Q'. Default is 'L'.
=item *
=item version
C<version> - Version of the symbol. If specify '0', this module chooses the minimum version for the input data. Default is '0'.
Version of the symbol. If you specify '0', this module chooses the minimum version for the input data. Default is '0'.
=item *
=item kanji
C<mode> - Encoding mode. Valid values are 'numerical', 'alpha-numerical', '8-bit' or 'kanji'. Default is '8-bit'.
If you specify Japanese characters to 'string' argument, You must set '1'.
If not give C<casesensitive> then should be given C<mode>. If 'kanji' is given, characters will be encoded as Shif-JIS characters. If '8-bit' is given, all of non-alpha-numerical characters will be encoded as is. If you want to embed UTF-8 string, choose '8-bit'.
=item casesensitive
=item *
If your application is case-sensitive using 8-bit characters, set to '1'. Default is '0'.
C<casesensitive> - If your application is case-sensitive using 8-bit characters, set to '1'. Default is '0'.
=back
=item plot(%params)
=item plot($text)
$img = $qrcode->plot("blah blah");
Create a new QR Code image. It returns Imager object.
Create a new QR Code image. This method returns Imager object ploted QR Code with the given text.
=back
=head1 INSTANCE METHODS
=head1 INSTANT METHODS
=over 4
=item plot_qrcode($text, \%params)
This method is instance method. $text is input text for plot. %params is same paramater as new().
Instant method. C<$text> is input text. C<%params> is same paramater as C<new()>.
=back
Expand Down
107 changes: 50 additions & 57 deletions lib/Imager/QRCode.xs
Expand Up @@ -16,24 +16,17 @@ extern "C" {
DEFINE_IMAGER_CALLBACKS;

QRcode *encode(const char *text,
QRecLevel level,
int version,
int kanji,
QRecLevel level,
QRencodeMode mode,
int casesensitive)
{
QRencodeMode hint;
QRcode *code;

if(kanji) {
hint = QR_MODE_KANJI;
} else {
hint = QR_MODE_8;
}

if(casesensitive) {
code = QRcode_encodeStringCase(text, version, level);
} else {
code = QRcode_encodeString(text, version, level, hint);
code = QRcode_encodeString(text, version, level, mode);
}

return code;
Expand Down Expand Up @@ -90,7 +83,6 @@ void generate(i_img *im,
i_box_filled(im, x*size, y*size, x*size + size, y*size + size - 1, lightcolor);
}
}
QRcode_free(qrcode);
}

i_img *_plot(char* text, HV *hv)
Expand All @@ -102,66 +94,67 @@ i_img *_plot(char* text, HV *hv)
int size = 3;
int margin = 4;
int version = 0;
int kanji = 0;
int casesensitive = 0;
QRencodeMode mode = QR_MODE_8;
QRecLevel level = QR_ECLEVEL_L;
i_color lightcolor, darkcolor;

if ((svp = hv_fetch(hv, "size", 4, 0)) && *svp) {
ptr = SvPV(*svp, len);
if (SvOK(*svp)) {
if ((svp = hv_fetch(hv, "size", 4, 0)) && *svp && SvOK(*svp)) {
ptr = SvPV(*svp, len);
if (ptr >= 0)
size = atoi(ptr);
}
}
if ((svp = hv_fetch(hv, "margin", 6, 0)) && *svp) {
if (SvOK(*svp)) {
ptr = SvPV(*svp, len);
if ((svp = hv_fetch(hv, "margin", 6, 0)) && *svp && SvOK(*svp)) {
ptr = SvPV(*svp, len);
if (ptr >= 0)
margin = atoi(ptr);
}
}
if ((svp = hv_fetch(hv, "level", 5, 0)) && *svp) {
if (!SvOK(*svp)) {
if ((svp = hv_fetch(hv, "level", 5, 0)) && *svp && SvOK(*svp)) {
ptr = SvPV(*svp, len);
switch (*ptr) {
case 'l':
case 'L':
level = QR_ECLEVEL_L;
break;
case 'm':
case 'M':
level = QR_ECLEVEL_M;
break;
case 'q':
case 'Q':
level = QR_ECLEVEL_Q;
break;
case 'h':
case 'H':
level = QR_ECLEVEL_H;
break;
default:
level = QR_ECLEVEL_L;
}
else {
ptr = SvPV(*svp, len);
switch (*ptr) {
case 'l':
case 'L':
level = QR_ECLEVEL_L;
break;
case 'm':
case 'M':
level = QR_ECLEVEL_M;
break;
case 'q':
case 'Q':
level = QR_ECLEVEL_Q;
break;
case 'h':
case 'H':
level = QR_ECLEVEL_H;
break;
default:
level = QR_ECLEVEL_L;
}
}
}
if ((svp = hv_fetch(hv, "version", 7, 0)) && *svp) {
if (!SvOK(*svp)) {
version = 0;
if ((svp = hv_fetch(hv, "version", 7, 0)) && *svp && SvOK(*svp)) {
ptr = SvPV(*svp, len);
if (ptr >= 0)
version = atoi(ptr);
}
if ((svp = hv_fetch(hv, "mode", 4, 0)) && *svp && SvOK(*svp)) {
ptr = SvPV(*svp, len);
if (strcmp(ptr, "numerical") == 0) {
mode = QR_MODE_NUM;
}
else if (strcmp(ptr, "alpha-numerical") == 0) {
mode = QR_MODE_AN;
}
else if (strcmp(ptr, "8-bit") == 0) {
mode = QR_MODE_8;
}
else if (strcmp(ptr, "kanji") == 0) {
mode = QR_MODE_KANJI;
}
else {
ptr = SvPV(*svp, len);
if (ptr < 0)
version = 0;
else
version = atoi(ptr);
mode = QR_MODE_8;
}
}
if ((svp = hv_fetch(hv, "kanji", 5, 0)) && *svp) {
kanji = SvTRUE(*svp);
}
if ((svp = hv_fetch(hv, "casesensitive", 13, 0)) && *svp) {
casesensitive = SvTRUE(*svp);
}
Expand All @@ -186,7 +179,7 @@ i_img *_plot(char* text, HV *hv)
darkcolor.rgba.a = 255;
}

QRcode *qrcode = encode(text, level, version, kanji, casesensitive);
QRcode *qrcode = encode(text, version, level, mode, casesensitive);
if(qrcode == NULL) {
croak("Failed to encode the input data: XS error");
}
Expand Down

0 comments on commit f09a007

Please sign in to comment.