z-rqr 0.2.3

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.
@@ -0,0 +1,20 @@
1
+ #ifndef __WIN32_TO_ANSI__
2
+ #define __WIN32_TO_ANSI__
3
+
4
+ #include <string.h>
5
+ #include <stdlib.h>
6
+
7
+ typedef bool BOOL;
8
+ typedef unsigned char BYTE;
9
+ typedef unsigned short WORD;
10
+ typedef char* LPCSTR;
11
+ typedef unsigned char * LPBYTE;
12
+
13
+ #define TRUE true
14
+ #define FALSE false
15
+
16
+ #define lstrlen strlen
17
+ #define ZeroMemory(x, y) memset(x, 0, y)
18
+ #define min(x, y) x < y ? x : y
19
+
20
+ #endif
data/lib/rqr/errors.rb ADDED
@@ -0,0 +1,11 @@
1
+ module RQR
2
+
3
+ class EncodeException < Exception; end
4
+
5
+ class FormatNotFoundException < Exception; end
6
+
7
+ class BlockNotFoundException < Exception; end
8
+
9
+ class ImageException < Exception; end
10
+
11
+ end
data/lib/rqr/qrcode.rb ADDED
@@ -0,0 +1,95 @@
1
+
2
+ module RQR
3
+ class QRCode
4
+ # options
5
+ # :level L:0, M:1(default), Q:2, H:3
6
+ # :version S:0(default), M:1, L:2
7
+ # :auto_extend true(default)|false auto extent if over version size
8
+ # :masking masking pattern 0-7, -1(default auto)
9
+ # :length data length
10
+ # :module_size module pixel size
11
+ # :eps_preview true|false(default)
12
+ def initialize(options = {})
13
+ @options = { :level => 1, :version => 0, :auto_extend => true,
14
+ :masking => -1, :eps_preview => false, :module_size => 4 }
15
+ @options.merge!(options)
16
+ @imager = nil
17
+ end
18
+
19
+ def self.create(options = {})
20
+ raise BlockNotFoundException.new("Block not found!") unless block_given?
21
+ qrcode = RQR::QRCode.new(options)
22
+ yield qrcode
23
+ qrcode.close
24
+ end
25
+
26
+ # data:: data for qrcode
27
+ # path:: path for qrcode image file
28
+ # format:: image format. :jpg|:png|:tiff|:eps
29
+ def save(data, path, format=nil)
30
+ format ||= get_format(path)
31
+
32
+ init_encoder(data)
33
+
34
+ case format.to_sym
35
+ when :jpg, :jpeg
36
+ res = save_as_jpeg(path)
37
+ when :png
38
+ res = save_as_png(path)
39
+ when :tiff, :tif
40
+ res = save_as_tiff(path)
41
+ when :eps
42
+ res = save_as_eps(path)
43
+ else
44
+ close; raise RQR::FormatNotFoundException.new("invalid format! #{format}")
45
+ end
46
+
47
+ close
48
+
49
+ if res != 0
50
+ raise RQR::ImageException.new("qrcode image error! #{path} wasn't created.")
51
+ end
52
+ end
53
+
54
+ def close()
55
+ @encoder = nil if @encoder
56
+ (@imager.close; @imager = nil) if @imager
57
+ end
58
+
59
+ private
60
+ def get_format(path)
61
+ File.extname(path).gsub(/^\./,"").to_sym
62
+ end
63
+
64
+ def init_encoder(data)
65
+ @encoder = QR::CQR_Encode.new
66
+ unless @encoder.EncodeData(@options[:level], @options[:version], @options[:auto_extend], @options[:masking], data)
67
+ close; raise EncodeException.new("qrcode encord error!")
68
+ end
69
+ end
70
+
71
+ def save_as_jpeg(path)
72
+ @imager=QR::QRDrawJPEG.new
73
+ @imager.draw(path, @options[:module_size], @encoder.m_nSymbleSize, @encoder.m_byModuleData, nil)
74
+ end
75
+
76
+ def save_as_png(path)
77
+ @imager=QR::QRDrawPNG.new
78
+ @imager.draw(path, @options[:module_size], @encoder.m_nSymbleSize, @encoder.m_byModuleData, nil)
79
+ end
80
+
81
+ def save_as_tiff(path)
82
+ @imager=QR::QRDrawTIFF.new
83
+ @imager.draw(path, @options[:module_size], @encoder.m_nSymbleSize, @encoder.m_byModuleData, nil)
84
+ end
85
+
86
+ def save_as_eps(path)
87
+ opt= @options[:eps_preview] ? DL::PtrData.allocate : nil
88
+ @imager=QR::QRDrawPS.new
89
+ ret = @imager.draw(path, @options[:module_size], @encoder.m_nSymbleSize, @encoder.m_byModuleData, opt)
90
+ opt.free if opt
91
+ ret
92
+ end
93
+ end
94
+ end
95
+
@@ -0,0 +1,9 @@
1
+ module RQR #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ TINY = 3
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/rqr.rb ADDED
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module RQR
5
+ require 'dl'
6
+ require "rqr/QR"
7
+ require "rqr/errors"
8
+ require "rqr/qrcode"
9
+ end