summaryrefslogtreecommitdiffstats
path: root/libcairobarcode
diff options
context:
space:
mode:
Diffstat (limited to 'libcairobarcode')
-rw-r--r--libcairobarcode/.gitignore3
-rw-r--r--libcairobarcode/Makefile11
-rw-r--r--libcairobarcode/code39.vala128
-rw-r--r--libcairobarcode/ean.vala142
-rw-r--r--libcairobarcode/error.vala19
5 files changed, 0 insertions, 303 deletions
diff --git a/libcairobarcode/.gitignore b/libcairobarcode/.gitignore
deleted file mode 100644
index 8721023..0000000
--- a/libcairobarcode/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-libcairobarcode.h
-libcairobarcode.so
-libcairobarcode.vapi
diff --git a/libcairobarcode/Makefile b/libcairobarcode/Makefile
deleted file mode 100644
index b51cf30..0000000
--- a/libcairobarcode/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include ../config.mk
-
-all: libcairobarcode.so
-
-libcairobarcode.so: ean.vala code39.vala error.vala
- ${VALAC} -o $@ -H libcairobarcode.h --library libcairobarcode -X -fPIC -X -shared --pkg cairo $^
-
-clean:
- rm -f libcairobarcode.h libcairobarcode.so libcairobarcode.vapi
-
-.PHONY: all clean
diff --git a/libcairobarcode/code39.vala b/libcairobarcode/code39.vala
deleted file mode 100644
index dd3d8c5..0000000
--- a/libcairobarcode/code39.vala
+++ /dev/null
@@ -1,128 +0,0 @@
-/* Copyright 2014, Sebastian Reichel <sre@ring0.de>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-public class Code39 {
- Cairo.Context ctx;
- double width;
- double height;
-
- /* 0 = wide black, 1 = narrow black, 2 = wide white, 3 = narrow white */
- static const uint32[] lookup_table = {
- 0x1d8cd, 0xd9dc, 0x1c9dc, 0xc9dd, 0x1d8dc, 0xd8dd, 0x1c8dd, 0x1d9cc,
- 0xd9cd, 0x1c9cd, 0xdd9c, 0x1cd9c, 0xcd9d, 0x1dc9c, 0xdc9d, 0x1cc9d,
- 0x1dd8c, 0xdd8d, 0x1cd8d, 0x1dc8d, 0xddd8, 0x1cdd8, 0xcdd9, 0x1dcd8,
- 0xdcd9, 0x1ccd9, 0x1ddc8, 0xddc9, 0x1cdc9, 0x1dcc9, 0x9ddc, 0x18ddc,
- 0x8ddd, 0x19cdc, 0x9cdd, 0x18cdd, 0x19dcc, 0x9dcd, 0x18dcd, 0x1999d,
- 0x199d9, 0x19d99, 0x1d999, 0x19ccd
- };
-
- public Code39(Cairo.Context ctx, double width, double height) {
- this.ctx = ctx;
- this.width = width;
- this.height = height;
- }
-
- private int lookup_index(char c) throws BarcodeError {
- if(c >= '0' && c <= '9')
- return c - '0';
- if(c >= 'A' && c <= 'Z')
- return c - 'A' + 10;
- switch (c) {
- case '-':
- return 36;
- case '.':
- return 37;
- case ' ':
- return 38;
- case '$':
- return 39;
- case '/':
- return 40;
- case '+':
- return 41;
- case '%':
- return 42;
- case '*':
- return 43;
- default:
- throw new BarcodeError.UNEXPECTED_CHARACTER("Character '%c' is not allowed in Code 39".printf(c));
- }
- }
-
- private uint32 lookup(char c) throws BarcodeError {
- return lookup_table[lookup_index(c)];
- }
-
- private void draw_line(bool black, double linewidth) {
- double x,y;
-
- if(black)
- ctx.set_source_rgb(0, 0, 0);
- else
- ctx.set_source_rgb(1, 1, 1);
-
- ctx.rel_line_to(0,height);
- ctx.rel_move_to(linewidth,-height);
-
- ctx.get_current_point(out x, out y);
- ctx.stroke();
- ctx.move_to(x,y);
- }
-
- public void draw(string code) throws BarcodeError {
- string mycode = code;
-
- if(!mycode.has_prefix("*"))
- mycode = "*" + mycode;
- if(!mycode.has_suffix("*"))
- mycode = mycode + "*";
-
- double linewidth = width / (mycode.length * 13.0);
-
- ctx.save();
- ctx.set_line_width(linewidth);
- ctx.move_to(0,0);
- ctx.rel_move_to(0.5*linewidth,0);
-
- for(int i=0; i<mycode.length; i++) {
- var format = lookup(mycode[i]);
-
- for(int j=8; j>=0; j--) {
- var line = (format >> (2*j)) & 0x3;
-
- switch(line) {
- case 0:
- draw_line(true, linewidth);
- draw_line(true, linewidth);
- break;
- case 1:
- draw_line(true, linewidth);
- break;
- case 2:
- draw_line(false, linewidth);
- draw_line(false, linewidth);
- break;
- default:
- draw_line(false, linewidth);
- break;
- }
- }
-
- draw_line(false, linewidth);
- }
-
- ctx.restore();
- }
-}
diff --git a/libcairobarcode/ean.vala b/libcairobarcode/ean.vala
deleted file mode 100644
index 9709987..0000000
--- a/libcairobarcode/ean.vala
+++ /dev/null
@@ -1,142 +0,0 @@
-/* Copyright 2014, Sebastian Reichel <sre@ring0.de>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-public class EAN {
- Cairo.Context ctx;
- double width;
- double height;
- const double marker_length_diff = 10.0;
- double basex;
- double basey;
-
- static const uint8[] C = { 0x00, 0x0b, 0x0d, 0x0e, 0x13, 0x19, 0x1c, 0x15, 0x16, 0x1a };
-
- static uint8[,] lookup = {
- { 0x0d, 0x19, 0x13, 0x3d, 0x23, 0x31, 0x2f, 0x3b, 0x37, 0x0b }, /* L */
- { 0x27, 0x33, 0x1b, 0x21, 0x1d, 0x39, 0x05, 0x11, 0x09, 0x17 }, /* G */
- { 0x72, 0x66, 0x6c, 0x42, 0x5c, 0x4e, 0x50, 0x44, 0x48, 0x74 } /* R */
- };
-
- public EAN(Cairo.Context ctx, double width, double height) {
- this.ctx = ctx;
- this.width = width / 95.0;
- this.height = height;
- }
-
- private void draw_line(bool black) {
- double x,y;
-
- if(black)
- ctx.set_source_rgb(0, 0, 0);
- else
- ctx.set_source_rgb(1, 1, 1);
-
- ctx.rel_line_to(0,height);
- ctx.rel_move_to(width,-height);
-
- ctx.get_current_point(out x, out y);
- ctx.stroke();
- ctx.move_to(x,y);
- }
-
- private void draw_startstop() {
- draw_line(true);
- draw_line(false);
- draw_line(true);
- }
-
- private void draw_middle() {
- draw_line(false);
- draw_line(true);
- draw_line(false);
- draw_line(true);
- draw_line(false);
- }
-
- private void draw_number_text(uint8 number) {
- double x, y;
- ctx.get_current_point(out x, out y);
- ctx.set_source_rgb(0, 0, 0);
-
- ctx.stroke();
- ctx.move_to(x,y);
- }
-
- private void draw_number(uint8 number, uint8 type) {
- draw_number_text(number);
-
- for(int i=6; i>=0; i--) {
- var bit = (lookup[type,number] >> i) & 1;
- draw_line(bit == 1);
- }
- }
-
- private uint8 get_number(string ean, int pos) {
- return (uint8) int.parse("%c".printf(ean[pos]));
- }
-
- private void draw13(string ean) {
- /* need some extra space for the checksum */
- width = (width * 95.0) / 102.0;
-
- uint8 LG = C[get_number(ean, 0)];
-
- draw_startstop();
- for(int i=1, x = 5; i<7; i++, x--) {
- uint8 type = (uint8) (LG >> x) & 1;
- draw_number(get_number(ean,i), type);
- }
- draw_middle();
- for(int i=7; i<13; i++)
- draw_number(get_number(ean,i), 2);
- draw_startstop();
-
- /* remove extra space for the checksum */
- width = (width * 102.0) / 95.0;
-
- }
-
- private void draw8(string ean) {
- draw_startstop();
- for(int i=0; i<4; i++)
- draw_number(get_number(ean,i), 0);
- draw_middle();
- for(int i=4; i<8; i++)
- draw_number(get_number(ean,i), 2);
- draw_startstop();
- }
-
- public void draw(string ean) throws BarcodeError {
- ctx.save();
- ctx.set_line_width(width);
- ctx.get_current_point(out basex, out basey);
- ctx.rel_move_to(0.5*width,0);
-
- for(int i=0; i<ean.length; i++) {
- if(ean[i] < '0' || ean[i] > '9') {
- throw new BarcodeError.UNEXPECTED_CHARACTER("Character '%c' is not allowed in EAN".printf(ean[i]));
- }
- }
-
- if(ean.length == 13)
- draw13(ean);
- else if(ean.length == 8)
- draw8(ean);
- else
- throw new BarcodeError.UNEXPECTED_LENGTH("length of EAN is incorrect (must be 8 or 13)");
-
- ctx.restore();
- }
-}
diff --git a/libcairobarcode/error.vala b/libcairobarcode/error.vala
deleted file mode 100644
index f81df91..0000000
--- a/libcairobarcode/error.vala
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright 2014, Sebastian Reichel <sre@ring0.de>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-public errordomain BarcodeError {
- UNEXPECTED_CHARACTER,
- UNEXPECTED_LENGTH
-}