From a1764391c7954b6bf5f49d09d4a5a32924e74dc9 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Tue, 27 Dec 2016 13:46:03 +0100 Subject: Add support for Aztec barcodes (#101) * Add RegisterAztec * Add test for RegisterAztec --- contrib/barcode/barcode.go | 10 ++++++++++ contrib/barcode/barcode_test.go | 13 +++++++++++++ 2 files changed, 23 insertions(+) (limited to 'contrib') diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go index 0649564..63a4908 100644 --- a/contrib/barcode/barcode.go +++ b/contrib/barcode/barcode.go @@ -21,6 +21,7 @@ import ( "bytes" "errors" "github.com/boombuler/barcode" + "github.com/boombuler/barcode/aztec" "github.com/boombuler/barcode/codabar" "github.com/boombuler/barcode/code128" "github.com/boombuler/barcode/code39" @@ -110,6 +111,15 @@ func Register(bcode barcode.Barcode) string { return key } +// RegisterAztec registers a barcode of type Aztec to the PDF, but not to +// the page. Use Barcode() with the return value to put the barcode on the page. +// code is the string to be encoded. minECCPercent is the error correction percentage. 33 is the default. +// userSpecifiedLayers can be a value between -4 and 32 inclusive. +func RegisterAztec(pdf barcodePdf, code string, minECCPercent int, userSpecifiedLayers int) string { + bcode, err := aztec.Encode([]byte(code), minECCPercent, userSpecifiedLayers) + return registerBarcode(pdf, bcode, err) +} + // RegisterCodabar registers a barcode of type Codabar to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. func RegisterCodabar(pdf barcodePdf, code string) string { diff --git a/contrib/barcode/barcode_test.go b/contrib/barcode/barcode_test.go index f2c57f1..c3c648c 100644 --- a/contrib/barcode/barcode_test.go +++ b/contrib/barcode/barcode_test.go @@ -47,6 +47,19 @@ func ExampleRegisterCodabar() { // Successfully generated ../../pdf/contrib_barcode_RegisterCodabar.pdf } +func ExampleRegisterAztec() { + pdf := createPdf() + + key := barcode.RegisterAztec(pdf, "aztec", 33, 0) + barcode.Barcode(pdf, key, 15, 15, 100, 100, false) + + fileStr := example.Filename("contrib_barcode_RegisterAztec") + err := pdf.OutputFileAndClose(fileStr) + example.Summary(err, fileStr) + // Output: + // Successfully generated ../../pdf/contrib_barcode_RegisterAztec.pdf +} + func ExampleRegisterCode128() { pdf := createPdf() -- cgit v1.2.1-24-ge1ad