summaryrefslogtreecommitdiff
path: root/contrib/barcode/barcode_test.go
diff options
context:
space:
mode:
authorDan Meyers <danmeyers00@gmail.com>2017-08-07 23:54:14 -0400
committerDan Meyers <danmeyers00@gmail.com>2017-12-20 20:06:58 -0500
commit9b87a30f0671d13b9d4f76780b41eb9e87883935 (patch)
treeaa4b32cf789fa0ae8f296ee991db4f0bcf5b0452 /contrib/barcode/barcode_test.go
parente79bdb537c4e4e719b91d5f35afa9f54976e0d4d (diff)
make barcode scaling optional, provide a method to get unscaled barcode dimensions
Diffstat (limited to 'contrib/barcode/barcode_test.go')
-rw-r--r--contrib/barcode/barcode_test.go51
1 files changed, 46 insertions, 5 deletions
diff --git a/contrib/barcode/barcode_test.go b/contrib/barcode/barcode_test.go
index 5b6c8cf..0a40a09 100644
--- a/contrib/barcode/barcode_test.go
+++ b/contrib/barcode/barcode_test.go
@@ -27,7 +27,9 @@ func ExampleRegister() {
if err == nil {
key := barcode.Register(bcode)
- barcode.Barcode(pdf, key, 15, 15, 100, 10, false)
+ var width float64 = 100
+ var height float64 = 10.0
+ barcode.BarcodeUnscalable(pdf, key, 15, 15, &width, &height, false)
}
err = pdf.OutputFileAndClose(fileStr)
@@ -40,7 +42,9 @@ func ExampleRegisterCodabar() {
pdf := createPdf()
key := barcode.RegisterCode128(pdf, "codabar")
- barcode.Barcode(pdf, key, 15, 15, 100, 10, false)
+ var width float64 = 100
+ var height float64 = 10
+ barcode.BarcodeUnscalable(pdf, key, 15, 15, &width, &height, false)
fileStr := example.Filename("contrib_barcode_RegisterCodabar")
err := pdf.OutputFileAndClose(fileStr)
@@ -118,7 +122,7 @@ func ExampleRegisterQR() {
pdf := createPdf()
key := barcode.RegisterQR(pdf, "qrcode", qr.H, qr.Unicode)
- barcode.Barcode(pdf, key, 15, 15, 20, 20, false)
+ barcode.Barcode(pdf, key, 15, 15, 100, 10, false)
fileStr := example.Filename("contrib_barcode_RegisterQR")
err := pdf.OutputFileAndClose(fileStr)
@@ -131,7 +135,7 @@ func ExampleRegisterTwoOfFive() {
pdf := createPdf()
key := barcode.RegisterTwoOfFive(pdf, "1234567895", true)
- barcode.Barcode(pdf, key, 15, 15, 100, 20, false)
+ barcode.Barcode(pdf, key, 15, 15, 100, 10, false)
fileStr := example.Filename("contrib_barcode_RegisterTwoOfFive")
err := pdf.OutputFileAndClose(fileStr)
@@ -144,7 +148,7 @@ func ExampleRegisterPdf417() {
pdf := createPdf()
key := barcode.RegisterPdf417(pdf, "1234567895", 10, 5)
- barcode.Barcode(pdf, key, 15, 15, 100, 20, false)
+ barcode.Barcode(pdf, key, 15, 15, 100, 10, false)
fileStr := example.Filename("contrib_barcode_RegisterPdf417")
err := pdf.OutputFileAndClose(fileStr)
@@ -158,3 +162,40 @@ func TestRegisterCode128(t *testing.T) {
pdf := createPdf()
barcode.RegisterCode128(pdf, "Invalid character: é")
}
+
+// Shows that the barcode may be scaled or not by providing optional heights and widths.
+func TestBarcodeUnscalable(t *testing.T) {
+ pdf := createPdf()
+
+ key := barcode.RegisterCode128(pdf, "code128")
+ var width float64 = 100
+ var height float64 = 10
+ barcode.BarcodeUnscalable(pdf, key, 15, 15, &width, &height, false)
+ barcode.BarcodeUnscalable(pdf, key, 15, 35, nil, &height, false)
+ barcode.BarcodeUnscalable(pdf, key, 15, 55, &width, nil, false)
+ barcode.BarcodeUnscalable(pdf, key, 15, 75, nil, nil, false)
+
+ fileStr := example.Filename("contrib_barcode_Barcode")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated ../../pdf/contrib_barcode_Barcode.pdf
+}
+
+// Shows that the width and height returned by the function match that of the barcode
+func TestGetUnscaledBarcodeDimensions(t *testing.T) {
+ pdf := createPdf()
+
+ key := barcode.RegisterQR(pdf, "qrcode", qr.H, qr.Unicode)
+ barcode.BarcodeUnscalable(pdf, key, 15, 15, nil, nil, false)
+ w, h := barcode.GetUnscaledBarcodeDimensions(pdf, key)
+
+ pdf.SetDrawColor(255, 0, 0)
+ pdf.Line(15, 15, 15+w, 15+h)
+
+ fileStr := example.Filename("contrib_barcode_GetBarcodeDimensions")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated ../../pdf/contrib_barcode_GetBarcodeDimensions.pdf
+}