]> git.sur5r.net Git - glabels/blob - barcode-0.98/sample.c
Imported Upstream version 2.2.8
[glabels] / barcode-0.98 / sample.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "barcode.h"
5
6 int main(int argc, char **argv)
7 {
8     int ps = 1, pcl = 0, oflags;
9     if (argc == 2 && !strcmp(argv[1],"-P")) {
10         ps = 0; pcl = 1; argc=1;
11     }
12     if (argc>2) {
13         fprintf(stderr, "%s: use \"%s\" for postscript or \"%s -P\" for PCL\n",
14                 argv[0], argv[0], argv[0]);
15         exit(1);
16     }
17     if (pcl) {
18         oflags = BARCODE_OUT_PCL;
19     } else {
20         oflags = BARCODE_OUT_PS | BARCODE_OUT_NOHEADERS;
21         printf("%%!PS-Adobe-2.0\n");
22         printf("%%%%Creator: barcode sample program\n");
23         printf("%%%%EndComments\n");
24         printf("%%%%EndProlog\n\n");
25         printf("%%%%Page: 1 1\n\n");
26     }
27     /* Print a few barcodes in several places in the page */
28
29     /* default size, bottom left */
30     Barcode_Encode_and_Print("800894002700",stdout, 0, 0, 40, 40, 
31                       BARCODE_EAN | oflags);
32
33     /* smaller */
34     Barcode_Encode_and_Print("800894002700",stdout, 70, 50, 160, 55, 
35                       BARCODE_EAN | oflags);
36
37     /* smallest */
38     Barcode_Encode_and_Print("800894002700",stdout, 40, 30, 270, 70, 
39                       BARCODE_EAN | oflags);
40
41     /* A bigger all-0 */
42     Barcode_Encode_and_Print("000000000000",stdout, 170, 0, 40, 160, 
43                       BARCODE_EAN | oflags);
44
45     /* Still bigger all-0 (but UPC, this time) */
46     Barcode_Encode_and_Print("00000000000",stdout, 250, 0, 270, 160, 
47                       BARCODE_UPC | oflags);
48
49     /* A few code-39 ones */
50     Barcode_Encode_and_Print("silly code",stdout, 0, 0, 40, 320, 
51                       BARCODE_39 | oflags);
52     Barcode_Encode_and_Print("SAMPLE CODES",stdout, 100, 30, 400, 80, 
53                       BARCODE_39 | oflags);
54
55     /* ISBN with add-5 */
56     Barcode_Encode_and_Print("1-56592-292-1 90000",stdout, 0, 0, 40, 430, 
57                       BARCODE_ISBN | oflags);
58
59     /* UPC with add-2 */
60     Barcode_Encode_and_Print("07447084452 07",stdout, 0, 0, 300, 410, 
61                       BARCODE_UPC | oflags);
62
63     /* code 128-C */
64     Barcode_Encode_and_Print("12345678900123456789",stdout, 0, 0, 40, 530, 
65                       BARCODE_128C | oflags);
66
67     /* and my data as code-128B autodetected */
68     Barcode_Encode_and_Print("RBNLSN68T11E897W",stdout, 0, 60, 240, 510, 
69                 oflags);
70     /* same as code-39, forced */
71     Barcode_Encode_and_Print("RBNLSN68T11E897W",stdout, 0, 60, 240, 590, 
72                 BARCODE_NO_CHECKSUM | BARCODE_39 | oflags);
73
74     /* one interleaved 2 of 5 */
75     Barcode_Encode_and_Print("0123456789",stdout, 0, 0, 40, 620, 
76                 BARCODE_I25 | oflags);
77
78     /* upc-e and ean-8 (autotected based on code size) */
79     Barcode_Encode_and_Print("012345",stdout, 0, 0, 50, 720, oflags);
80     Barcode_Encode_and_Print("0123456",stdout, 0, 0, 160, 720, oflags);
81
82
83     
84     if (pcl) {
85         printf("\f");
86     } else {
87         printf("\nshowpage\n");
88         printf("%%%%Trailer\n\n");
89     }
90     return 0;
91 }
92
93
94
95
96
97
98