-
Notifications
You must be signed in to change notification settings - Fork 23
/
README
149 lines (91 loc) · 4.07 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
= Ruby Semacode Encoder
== Introduction
This Ruby extension implements a DataMatrix encoder for Ruby. It is typically
used to create semacodes, which are barcodes, that contain URLs. This encoder
does not create image files or visual representations of the semacode. This is
because it can be used for more than creating images, such as rendering
semacodes to HTML, SVG, PDF or even stored in a database or file for later
use.
See test.rb for an example of how to create a visual symbol for a semacode, it
presents a semacode in HTML and plain text formats, and this can give you an
idea of how to start.
Once you have a visual representation of the semacode, you can use a reader,
such as those from http://semacode.org on your camera phone, to capture the
URL embedded in the semacode and proceed directly to that web site.
=== License
This software is released under the terms of the GNU Public License version 2,
available from <http://www.gnu.org>
=== Contact Information
You can contact me via <[email protected]> if you have patches, bug fixes or
improvements.
Copyright (C) 2007, Guido Sohne
Website: http://sohne.net/projects/semafox
=== Credits
Based on the iec16022ecc200.c encoder by Adrian Kennard, Andrews & Arnold Ltd
== Quick Start
Configure the extension to your local system and ruby
<tt>ruby extconf.rb</tt>
Build the extension
<tt>make</tt>
Test that it works
<tt>ruby test.rb</tt>
Install the extension (you may need to become root)
<tt>make install</tt>
You should take a look at tests/test.rb to understand how to use this. It
includes some code to generate a semacode using HTML and CSS, so that could
end up being useful.
== USAGE
Here's some basic ways in which you can make use of this extension. It tries
to show by example, how the semacodes can be created and what can be done with
or to a semacode object.
Include this library
<tt>require 'rubygems'</tt>
<tt>require 'semacode'</tt>
Create a semacode
<tt>semacode = Barcode::Semacode.new "http://sohne.net/projects/semafox/"</tt>
Return the semacode as an array of arrays of boolean
The first element of the array is the top row, the last element is the
bottom row. the array length is the semacode height, and each element is
an array as wide as the semacode width
<tt>grid = semacode.data</tt> or
<tt>grid = semacode.to_a</tt> or
Return the encoding list used to create the semacode
This encoding list is composed of the 'character set', complete with
shifts from one encoding type to another, that is used for the DataMatrix
algorithm.
<tt>encoding = semacode.encoding</tt>
Return the semacode as a string
The string is a comma separated list of character vectors. Each vector is a row
in the semacode symbol, the top row is first, and the bottom row is last. Inside
each row, the vector reads from left to right.
<tt>semacode.to_s</tt> or
<tt>semacode.to_str</tt>
Encode another string
<tt>semacode.encode "http://sohne.net"</tt>
Get the width of the semacode
<tt>semacode.width</tt>
Get the height of the semacode
<tt>semacode.height</tt>
How long is the semacode? (width * height)
<tt>semacode.length</tt> or
<tt>semacode.size</tt>
Get the raw encoded length (before padding and before ECC)
<tt>semacode.raw_encoded_length</tt>
Get the symbol size
The max number of characters this semacode type
(specific width x height) can hold is called the
symbol size.
<tt>semacode.symbol_size</tt>
Count the ECC bytes
How many bytes were used for error correction?
<tt>semacode.ecc_bytes</tt>
== NOTES
The C code can throw runtime exceptions. Be sure to include
a catch block if you want to use this in production. Mostly
the exceptions are not recoverable, except for when the data
is too long, in which case you can shorten it and try again.
There are two type of exceptions that it will throw. The first
is a RangeError exception, which happens when the input is too
long or when it just can't find a fit for the data. The second
is a ArgumentError (ArgError?) exception that gets thrown when
the input contains data it cannot handle.