summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Renaud <arenaud@designa-electronics.com>2018-08-01 11:11:56 +1200
committerAndre Renaud <arenaud@designa-electronics.com>2018-08-01 11:11:56 +1200
commit57160d276280e078aca3418a30d5256ffa145cc2 (patch)
treeb1baa4149e391535bd0c5466581163d4fefb1380
parentc4fb5030287eb4ea19421604fb47933b88e8638f (diff)
barcode: Scale via the PDF rather than the barcode library
This allows arbitrary barcode scaling, rather than whole multiple as required by github.com/boombuler/barcode
-rw-r--r--contrib/barcode/barcode.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go
index 26f99c3..ad84fe5 100644
--- a/contrib/barcode/barcode.go
+++ b/contrib/barcode/barcode.go
@@ -71,16 +71,10 @@ func printBarcode(pdf barcodePdf, code string, x, y float64, w, h *float64, flow
bname := uniqueBarcodeName(code, x, y)
info := pdf.GetImageInfo(bname)
+ scaleToWidth := unscaled.Bounds().Dx()
+ scaleToHeight := unscaled.Bounds().Dy()
if info == nil {
- scaleToWidth := unscaled.Bounds().Dx()
- scaleToHeight := unscaled.Bounds().Dy()
- if w != nil {
- scaleToWidth = int(convertTo96Dpi(pdf, *w))
- }
- if h != nil {
- scaleToHeight = int(convertTo96Dpi(pdf, *h))
- }
bcode, err := barcode.Scale(
unscaled,
scaleToWidth,
@@ -99,7 +93,13 @@ func printBarcode(pdf barcodePdf, code string, x, y float64, w, h *float64, flow
}
}
- pdf.Image(bname, x, y, 0, 0, flow, "jpg", 0, "")
+ if w != nil {
+ scaleToWidth = int(*w)
+ }
+ if h != nil {
+ scaleToHeight = int(*h)
+ }
+ pdf.Image(bname, x, y, float64(scaleToWidth), float64(scaleToHeight), flow, "jpg", 0, "")
}