[PATCH 2/2] Add optional border around barcodes in table mode

Markus Berg markus@kelvin.nu
Mon Apr 11 23:12:09 CEST 2011


Signed-off-by: Markus Berg <markus@kelvin.nu>
---
 barcode.h |    1 +
 library.c |    1 +
 main.c    |    6 +++++-
 ps.c      |   12 ++++++++++++
 4 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/barcode.h b/barcode.h
index 19be940..9093a08 100644
--- a/barcode.h
+++ b/barcode.h
@@ -40,6 +40,7 @@ struct Barcode_Item {
     int xoff, yoff;    /* output units */
     int margin;        /* output units */
     int xpadding, ypadding; /* output units */
+    int border;        /* print a border around the barcode */
     double scalef;     /* requested scaling for barcode */
     int error;         /* an errno-like value, in case of failure */
 };
diff --git a/library.c b/library.c
index 96070c4..a77f7de 100644
--- a/library.c
+++ b/library.c
@@ -46,6 +46,7 @@ struct Barcode_Item *Barcode_Create(char *text)
     bc->margin = BARCODE_DEFAULT_MARGIN; /* default margin */
     bc->xpadding = 0;
     bc->ypadding = 0;
+    bc->border = 0;
     return bc;
 }
 
diff --git a/main.c b/main.c
index cf94b55..cdef930 100644
--- a/main.c
+++ b/main.c
@@ -127,7 +127,7 @@ int xpadding, ypadding;               /* internal padding for "-g" */
 int xmargin0, ymargin0;               /* left bottom page margins */
 int xmargin1, ymargin1;               /* same, but right and top */
 int ximargin, yimargin;               /* "-m": internal margins of table */
-int eps, pcl, ps, noascii, nochecksum; /* boolean flags */
+int eps, pcl, ps, noascii, nochecksum, border; /* boolean flags */
 int page_wid, page_hei;               /* page size in points */
 char *page_name;                      /* name of the media */
 double unit = 1.0;                    /* unit specification */
@@ -389,6 +389,8 @@ struct commandline option_table[] = {
                     "geometry on the page: [<wid>x<hei>][+<padding>+<padding>]"},
     {'t', CMDLINE_S, NULL, get_table, "BARCODE_TABLE", NULL,
                     "table geometry: <cols>x<lines>[+<margin>+<margin>]"},
+    {'B', CMDLINE_NONE, &border, NULL, NULL, NULL,
+                    "print a thin border around barcodes in table mode"},
     {'m', CMDLINE_S, NULL, get_margin, "BARCODE_MARGIN", "10",
                     "internal margin for each item in a table: <xm>[,<ym>]"},
     {'n', CMDLINE_NONE, &noascii, NULL, NULL, NULL,
@@ -599,6 +601,8 @@ int main(int argc, char **argv)
 	    bc->margin = 0;
 	    bc->xpadding = xpadding;
 	    bc->ypadding = ypadding;
+	    bc->border = border;
+
 	    if ( (Barcode_Position(bc, code_width, code_height,
 				   xbl, ybl, 0.0) < 0)
 		 || (Barcode_Encode(bc, flags) < 0)
diff --git a/ps.c b/ps.c
index 3bfda46..12c2e4b 100644
--- a/ps.c
+++ b/ps.c
@@ -255,6 +255,18 @@ int Barcode_ps_print(struct Barcode_Item *bc, FILE *f)
 
     }
 
+    if (bc->border) {
+	fprintf(f, "0.1 setlinewidth\n");
+	fprintf(f, "0.4 setgray\n");
+	fprintf(f, "newpath %d %d %d %d rectstroke\n",
+		bc->xoff - bc->xpadding,
+		bc->yoff - bc->ypadding,
+		bc->width + 2 * bc->xpadding,
+		bc->height + 2 * bc->ypadding);
+	fprintf(f, "0 setgray\n");
+    }
+
+
     fprintf(f,"%% End barcode for \"%s\"\n\n",
 	    printable ? bc->ascii : "<unprintable string>");
 
-- 
1.7.4


--=-dyM6JsBZRutZe/oegFtt--



More information about the barcode mailing list