gbarcode-plus 0.98
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/barcode.h +119 -0
- data/ext/barcode_wrap.c +3192 -0
- data/ext/codabar.c +182 -0
- data/ext/code128.c +607 -0
- data/ext/code39.c +173 -0
- data/ext/code93.c +213 -0
- data/ext/ean.c +774 -0
- data/ext/extconf.rb +10 -0
- data/ext/i25.c +164 -0
- data/ext/library.c +244 -0
- data/ext/msi.c +155 -0
- data/ext/pcl.c +200 -0
- data/ext/plessey.c +164 -0
- data/ext/ps.c +272 -0
- data/ext/svg.c +174 -0
- data/test/assets/gb-code128b.eps +44 -0
- data/test/gbarcode_test.rb +54 -0
- data/test/test_helper.rb +2 -0
- metadata +96 -0
data/ext/svg.c
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
/*
|
2
|
+
* svg.c -- print out the barcode SVG-style
|
3
|
+
*
|
4
|
+
* Copyright (c) 2001 David J. Humphreys (humphrd@tcd.ie)
|
5
|
+
*
|
6
|
+
* This program is free software; you can redistribute it and/or modify
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
8
|
+
* the Free Software Foundation; either version 2 of the License, or
|
9
|
+
* (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This program 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
|
14
|
+
* GNU General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public License
|
17
|
+
* along with this program; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*
|
20
|
+
*
|
21
|
+
* http://www.onefour.net/barcode/
|
22
|
+
*
|
23
|
+
* Made with a mac! (Tested under os X, 10.1)
|
24
|
+
*
|
25
|
+
* I wanted to output barcodes as SVG for some art work.
|
26
|
+
* This will output everything as an SVG file. This file can
|
27
|
+
* then be inserted into another SVG file.
|
28
|
+
*
|
29
|
+
* I don't want to get into the specifics of SVG files here. I
|
30
|
+
* suppose there will be a few specifics on my website (above) along
|
31
|
+
* with a few examples.
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include <stdio.h>
|
35
|
+
#include <stdlib.h>
|
36
|
+
#include <string.h>
|
37
|
+
#include <ctype.h>
|
38
|
+
#include <errno.h>
|
39
|
+
|
40
|
+
#include "barcode.h"
|
41
|
+
|
42
|
+
/* If there is any need to print out a comment,
|
43
|
+
* then this is the method */
|
44
|
+
int svg_comment(char *Message, FILE *f){
|
45
|
+
fprintf(f, "<!-- %s -->\n",Message);
|
46
|
+
return 0;
|
47
|
+
}
|
48
|
+
|
49
|
+
/* Prints the title (bc->ascii) and the
|
50
|
+
* desc(ription) */
|
51
|
+
int svg_desc(struct Barcode_Item *bc, FILE *f){
|
52
|
+
fprintf(f, "<title>%s</title>\n",bc->ascii);
|
53
|
+
fprintf(f, "<desc>\n");
|
54
|
+
fprintf(f, "\t%s:\t%s\n",bc->encoding,bc->ascii);
|
55
|
+
fprintf(f, "\tGNU-barcode:\t%s\n",BARCODE_VERSION);
|
56
|
+
fprintf(f, "\tbarcode:\thttp://www.gnu.org/\n");
|
57
|
+
fprintf(f, "\tsvg-code:\thttp://www.onefour.net/barcode\n");
|
58
|
+
fprintf(f, "</desc>\n");
|
59
|
+
return 0;
|
60
|
+
}
|
61
|
+
|
62
|
+
/* print out the start of the svg file,
|
63
|
+
* with some xml voodoo. There are a
|
64
|
+
* lot of \"s in this code.
|
65
|
+
* It bounds the svg file by
|
66
|
+
* bc->width or 104 and
|
67
|
+
* bc->height or 100
|
68
|
+
* The title of the file is bc->ascii
|
69
|
+
* NOTE: margins and scale are ignored
|
70
|
+
* the user can simply insert the
|
71
|
+
* svg file into another and then
|
72
|
+
* specify scale and margin.*/
|
73
|
+
int svg_start( struct Barcode_Item *bc, FILE *f){
|
74
|
+
if(bc->height == 0) bc->height = 100;
|
75
|
+
if(bc->width == 0) bc->width = 104;
|
76
|
+
fprintf(f, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
|
77
|
+
fprintf(f, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
|
78
|
+
fprintf(f, "<svg width=\"%i\" height=\"%i\">\n",bc->width ,bc->height);
|
79
|
+
svg_desc(bc,f);
|
80
|
+
return 0;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* just close the svg file */
|
84
|
+
int svg_end(FILE *f){
|
85
|
+
fprintf(f, "</svg>\n");
|
86
|
+
return 0;
|
87
|
+
}
|
88
|
+
|
89
|
+
/* prints out the code for the bars.
|
90
|
+
* the bars are drawn with rect(angles)
|
91
|
+
* rather than lines. The mathematics
|
92
|
+
* for placing a line then setting the
|
93
|
+
* stroke width gets messy. */
|
94
|
+
int svg_bars(struct Barcode_Item *bc, FILE *f){
|
95
|
+
int
|
96
|
+
i = 0, /* Loop counter */
|
97
|
+
height = 70, /* Each box is 70 pixels in hieght */
|
98
|
+
xpos = 0; /* Where the current box is drawn */
|
99
|
+
int current; /* The current character in partial */
|
100
|
+
int is_bar = 0;
|
101
|
+
|
102
|
+
fprintf(f, "<g fill=\"black\">\n");
|
103
|
+
|
104
|
+
for(i = 0; i < strlen(bc->partial); i++){
|
105
|
+
current = (int)bc->partial[i] - 48;
|
106
|
+
if(current > 9){
|
107
|
+
height = 75; /* Guide bar */
|
108
|
+
current = (int)bc->partial[++i] - 48;
|
109
|
+
i++; /* Skip the following 'a' */
|
110
|
+
}
|
111
|
+
else
|
112
|
+
height = 70;
|
113
|
+
if(is_bar == 1){
|
114
|
+
fprintf(f, "\t<rect x=\"%i\" y=\"0\" ",xpos); /* all bars start at y=0 */
|
115
|
+
fprintf(f, "height=\"%i\" width=\"%i\" stroke-width=\"0\"/>\n",height,current);
|
116
|
+
is_bar = 0;
|
117
|
+
}
|
118
|
+
else
|
119
|
+
is_bar = 1;
|
120
|
+
xpos += current;
|
121
|
+
}
|
122
|
+
fprintf(f, "</g>\n");
|
123
|
+
return 0;
|
124
|
+
}
|
125
|
+
|
126
|
+
/* positions the characters that will
|
127
|
+
* be printed. This assumes they will
|
128
|
+
* be under the barcode.*/
|
129
|
+
int svg_text(struct Barcode_Item *bc, FILE *f){
|
130
|
+
unsigned
|
131
|
+
i = 0,
|
132
|
+
j = 0,
|
133
|
+
infosz = strlen(bc->textinfo),
|
134
|
+
xpos = 0,
|
135
|
+
prev_x = 0,
|
136
|
+
correction = 0; /* This correction seems to be needed to align text properly */
|
137
|
+
double dub1, dub2;
|
138
|
+
char printer;
|
139
|
+
char *temp_info = malloc(infosz);
|
140
|
+
if(!temp_info)
|
141
|
+
return -1;
|
142
|
+
fprintf(f, "<g font-family=\"Helvitica\" font-size=\"12\">\n");
|
143
|
+
|
144
|
+
while(i < infosz){
|
145
|
+
for(j = 0; bc->textinfo[i + j + 1] != ' ' &&
|
146
|
+
bc->textinfo[i + j + 1] != '\0';j++); /* Empty loop, just increment j */
|
147
|
+
|
148
|
+
j ++;
|
149
|
+
strncpy(temp_info, (bc->textinfo + i),j);
|
150
|
+
sscanf(temp_info, "%lf:%lf:%c", &dub1, &dub2, &printer);
|
151
|
+
i += j;
|
152
|
+
|
153
|
+
xpos = (int)dub1;
|
154
|
+
if((xpos - prev_x) >= 10)
|
155
|
+
correction += 2;
|
156
|
+
|
157
|
+
prev_x = xpos;
|
158
|
+
fprintf(f, "\t<text x=\"%i\" y=\"%i\">%c</text>\n",(xpos - correction),80,printer);
|
159
|
+
}
|
160
|
+
fprintf(f, "</g>\n");
|
161
|
+
free(temp_info);
|
162
|
+
return 0;
|
163
|
+
}
|
164
|
+
|
165
|
+
/* This is the function to call. It calls the
|
166
|
+
* functions above in order. Thers is no real
|
167
|
+
* error detection in this code. */
|
168
|
+
int Barcode_svg_print(struct Barcode_Item *bc, FILE *f){
|
169
|
+
svg_start(bc,f);
|
170
|
+
svg_bars(bc,f);
|
171
|
+
svg_text(bc,f); /* Should test for text output bit in flags */
|
172
|
+
svg_end(f);
|
173
|
+
return 0;
|
174
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
%!PS-Adobe-2.0 EPSF-1.2
|
2
|
+
%%Creator: libbarcode
|
3
|
+
%%BoundingBox: 0 0 143 100
|
4
|
+
%%EndComments
|
5
|
+
% Printing barcode for "Gbarcode", scaled 1.00, encoded using "code 128-B"
|
6
|
+
% The space/bar succession is represented by the following widths (space first):
|
7
|
+
% 02112142113131214211211241212411411221341111412211122143141112331112
|
8
|
+
[
|
9
|
+
% height xpos ypos width height xpos ypos width
|
10
|
+
[75.00 11.00 15.00 1.85] [75.00 13.50 15.00 0.85]
|
11
|
+
[75.00 16.50 15.00 0.85] [70.00 22.00 20.00 1.85]
|
12
|
+
[70.00 24.50 20.00 0.85] [70.00 28.50 20.00 0.85]
|
13
|
+
[70.00 32.50 20.00 0.85] [70.00 35.50 20.00 0.85]
|
14
|
+
[70.00 41.00 20.00 1.85] [70.00 43.50 20.00 0.85]
|
15
|
+
[70.00 46.50 20.00 0.85] [70.00 49.00 20.00 1.85]
|
16
|
+
[70.00 54.50 20.00 0.85] [70.00 57.50 20.00 0.85]
|
17
|
+
[70.00 62.00 20.00 3.85] [70.00 65.50 20.00 0.85]
|
18
|
+
[70.00 70.50 20.00 0.85] [70.00 73.00 20.00 1.85]
|
19
|
+
[70.00 76.50 20.00 0.85] [70.00 82.00 20.00 3.85]
|
20
|
+
[70.00 85.50 20.00 0.85] [70.00 87.50 20.00 0.85]
|
21
|
+
[70.00 92.50 20.00 0.85] [70.00 96.00 20.00 1.85]
|
22
|
+
[70.00 98.50 20.00 0.85] [70.00 101.00 20.00 1.85]
|
23
|
+
[70.00 104.50 20.00 0.85] [70.00 110.50 20.00 2.85]
|
24
|
+
[70.00 115.00 20.00 3.85] [70.00 118.50 20.00 0.85]
|
25
|
+
[75.00 121.00 15.00 1.85] [75.00 126.50 15.00 2.85]
|
26
|
+
[75.00 129.50 15.00 0.85] [75.00 132.00 15.00 1.85]
|
27
|
+
|
28
|
+
] { {} forall setlinewidth moveto 0 exch rlineto stroke} bind forall
|
29
|
+
[
|
30
|
+
% char xpos ypos fontsize
|
31
|
+
[(G) 21.00 10.00 12.00]
|
32
|
+
[(b) 32.00 10.00 0.00]
|
33
|
+
[(a) 43.00 10.00 0.00]
|
34
|
+
[(r) 54.00 10.00 0.00]
|
35
|
+
[(c) 65.00 10.00 0.00]
|
36
|
+
[(o) 76.00 10.00 0.00]
|
37
|
+
[(d) 87.00 10.00 0.00]
|
38
|
+
[(e) 98.00 10.00 0.00]
|
39
|
+
] { {} forall dup 0.00 ne {
|
40
|
+
/Helvetica findfont exch scalefont setfont
|
41
|
+
} {pop} ifelse
|
42
|
+
moveto show} bind forall
|
43
|
+
% End barcode for "Gbarcode"
|
44
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class GbarcodeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@@BC_TEXT = "Gbarcode"
|
7
|
+
@@BC = Gbarcode.barcode_create(@@BC_TEXT)
|
8
|
+
Gbarcode.barcode_encode(@@BC, Gbarcode::BARCODE_128B)
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
Gbarcode.barcode_delete(@@BC)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_barcode_create
|
16
|
+
assert(@@BC != nil, "BC not created")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_barcode_delete
|
20
|
+
r = Gbarcode.barcode_delete(Gbarcode.barcode_create(@@BC_TEXT))
|
21
|
+
assert(r == 0, "barcode_delete failed")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_ascii
|
25
|
+
assert_equal(@@BC.ascii, "Gbarcode")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_barcode_encode
|
29
|
+
b = Gbarcode.barcode_create("1234")
|
30
|
+
r = Gbarcode.barcode_encode(b, Gbarcode::BARCODE_39)
|
31
|
+
assert(r == 0, "encoding unsuccessful")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_encoding
|
35
|
+
assert_equal(@@BC.encoding, "code 128-B")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_barcode_print
|
39
|
+
r,w = File.pipe
|
40
|
+
Gbarcode.barcode_print(@@BC,w,0)
|
41
|
+
w.close()
|
42
|
+
b = lines_without_comments r
|
43
|
+
r.close()
|
44
|
+
f = lines_without_comments File.open(File.dirname(__FILE__) + "/assets/gb-code128b.eps")
|
45
|
+
assert_equal(b, f)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def lines_without_comments(eps_file)
|
52
|
+
eps_file.readlines.reject!{|l| l =~ /^%/ }
|
53
|
+
end
|
54
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gbarcode-plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.98'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Angel Pizarro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A C extension that wraps the GNU Barcode project. For more Ruby-ish syntax,
|
42
|
+
you should use the Rbarcode gem.
|
43
|
+
email: angel@delagoya.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ext/barcode.h
|
50
|
+
- ext/barcode_wrap.c
|
51
|
+
- ext/codabar.c
|
52
|
+
- ext/code128.c
|
53
|
+
- ext/code39.c
|
54
|
+
- ext/code93.c
|
55
|
+
- ext/ean.c
|
56
|
+
- ext/extconf.rb
|
57
|
+
- ext/i25.c
|
58
|
+
- ext/library.c
|
59
|
+
- ext/msi.c
|
60
|
+
- ext/pcl.c
|
61
|
+
- ext/plessey.c
|
62
|
+
- ext/ps.c
|
63
|
+
- ext/svg.c
|
64
|
+
- test/assets/gb-code128b.eps
|
65
|
+
- test/gbarcode_test.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
homepage: http://gbarcode.rubyforge.org
|
68
|
+
licenses: []
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- "--exclude"
|
73
|
+
- ".c$"
|
74
|
+
require_paths:
|
75
|
+
- "."
|
76
|
+
- ext
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.8.4
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project: gbarcode
|
89
|
+
rubygems_version: 2.2.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A C extension that wraps the GNU Barcode project.
|
93
|
+
test_files:
|
94
|
+
- test/assets/gb-code128b.eps
|
95
|
+
- test/gbarcode_test.rb
|
96
|
+
- test/test_helper.rb
|