summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-01-18 12:35:53 +0100
committercos <cos>2015-01-18 12:36:36 +0100
commit927d4675325c119aa3f8f2eef5f65fb6b1127408 (patch)
tree25dbe7c86ce730931f6d9902d671ff6be0cc3f91
parent43efa58e6cc52d27ad879b4953a37b08b214f05a (diff)
downloadmat-927d4675325c119aa3f8f2eef5f65fb6b1127408.zip
First attempt at cleaning up label printing mess.
-rwxr-xr-xmat84
-rwxr-xr-xpapersize.sh16
2 files changed, 69 insertions, 31 deletions
diff --git a/mat b/mat
index c480a6d..509c269 100755
--- a/mat
+++ b/mat
@@ -269,25 +269,48 @@ sub print_label {
my $fontname = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
my $fontsize = 15;
- my $x_border = 40;
- my $y_border = 15;
+ my $x_border = 35; # Obtained with papersize.sh
+ my $y_border = 18;
+ my $x_limit = 307;
+ my $y_limit = 324;
+ my $x_max = 307-35;
+ my $y_max = 324-18;
+ my $y_offset = 75;
+
+ my $qr_border = 4;
my $iconv = Text::Iconv->new("UTF-8", "ISO8859-1");
+ my $latin1_dish = $iconv->convert($dish_name);
my $row0 = $Config{'label_name'};
- my $row1 = $iconv->convert($dish_name);
- my $row2 = `date +%Y%m%d|tr -d '\n'`.' ('.$amount.'g)';
+ my $row1;
+ my $row2;
+ if( length($latin1_dish) < 15) {
+ $row1 = $latin1_dish;
+ $row2 = "";
+ } else {
+ $row1 = $latin1_dish;
+ $row1 =~ s/(.{15,23}) .*/$1/;
+ $row2 = substr($latin1_dish, (length $row1) + 1);
+ }
+ my $row3 = `date +%Y%m%d|tr -d '\n'`.' ('.$amount.'g)';
my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", $Config{'label_id_prefix'}, $id), { Version=>3 });
my $idbarcode_image=$idbarcode->plot();
+ my $qr_cropped = new GD::Image($idbarcode_image->width() - 2 * $qr_border, $idbarcode_image->height() - 2 * $qr_border);
+ my $white = $qr_cropped->colorAllocate(255,255,255);
+ my $black = $qr_cropped->colorAllocate(0,0,0);
+ $qr_cropped->fill(0, 0, $white);
+ $qr_cropped->copy($idbarcode_image, 0, 0, $qr_border, $qr_border, $idbarcode_image->width() - $qr_border, $idbarcode_image->height() - $qr_border);
+
my $logo;
if ($ENV{'PRINT_WITH_LOGO'}) {
$logo = GD::Image->newFromPng("layer1.png");
}
my $idtext = new GD::Image(500, $fontsize * 2);
- my $white = $idtext->colorAllocate(255,255,255);
- my $black = $idtext->colorAllocate(0,0,0);
+ $white = $idtext->colorAllocate(255,255,255);
+ $black = $idtext->colorAllocate(0,0,0);
$idtext->fill(1, 1, $white);
$idtext->string(gdGiantFont, 0, 0, $id, $black);
@@ -297,7 +320,6 @@ sub print_label {
$text0->fill(1, 1, $white);
my @bounds0 = $text0->stringFT(-1 * $black, $fontname, $fontsize, 0, 0, 2 * $fontsize, $row0);
my $text0_image=$text0->copyRotate90();
- $text0_image->line(0, 0, 100, 100, $white);
my $text1 = new GD::Image(500, $fontsize * 3);
$white = $text1->colorAllocate(255,255,255);
@@ -315,41 +337,41 @@ sub print_label {
my @bounds2 = $text2->stringFT(-1 * $black, $fontname, $fontsize, 0, 0, 2 * $fontsize, $row2);
my $text2_image=$text2->copyRotate90();
- my $labelwidth = $idbarcode_image->width() * 5 + $idtext->height() * 2 + 2 * $y_border;
- if($bounds0[2] + 2 * $y_border > $labelwidth) {
- $labelwidth = $bounds0[2] + 2 * $y_border;
- }
- if($bounds1[2] + 2 * $y_border > $labelwidth) {
- $labelwidth = $bounds1[2] + 2 * $y_border;
- }
- if($bounds2[2] + 2 * $y_border > $labelwidth) {
- $labelwidth = $bounds2[2] + 2 * $y_border;
- }
- if($labelwidth > 1063)
- {
- $labelwidth = 1063;
- }
-
- # 300 dpi & 29 x 90 mm ger: 300*2.9/2.54 = 343, 300*9.0/2.54 = 1063
- my $label = new GD::Image(343, $labelwidth);
+ my $text3 = new GD::Image(500, $fontsize * 3);
+ $white = $text3->colorAllocate(255,255,255);
+ $black = $text3->colorAllocate(0,0,0);
+ $text3->fill(1, 1, $white);
+ $text3->filledRectangle(0, 0, $text3->width(), $text3->height(), $white);
+ my @bounds3 = $text3->stringFT(-1 * $black, $fontname, $fontsize, 0, 0, 2 * $fontsize, $row3);
+ my $text3_image=$text3->copyRotate90();
+ my $label = new GD::Image($x_max, $y_max);
$white = $label->colorAllocate(255,255,255);
$black = $label->colorAllocate(0,0,0);
$label->fill(0, 0, $white);
- $label->copyResized($idbarcode_image, $x_border, $y_border, 0, 0, $idbarcode_image->width() * 5, $idbarcode_image->height() * 5, $idbarcode_image->width(), $idbarcode_image->height());
- $label->copyResized($idtext, $x_border * 3, $y_border + $idbarcode_image->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height());
- $label->copyResized($text0_image, $label->width() - $x_border - 2 * $fontsize, $y_border * 2, 0, 0, $bounds0[1] * 1, $bounds0[2], $bounds0[1], $bounds0[2]);
- $label->copyResized($text1_image, $label->width() - $x_border - 4 * $fontsize, $y_border, 0, 0, $bounds1[1] * 1, $bounds1[2], $bounds1[1], $bounds1[2]);
- $label->copyResized($text2_image, $label->width() - $x_border - 6 * $fontsize, $y_border, 0, 0, $bounds2[1] * 1, $bounds2[2], $bounds2[1], $bounds2[2]);
+ $label->copyResized($qr_cropped, 0, 0, 0, 0, $qr_cropped->width() * 5, $qr_cropped->height() * 5, $qr_cropped->width(), $qr_cropped->height());
+ $label->copyResized($idtext, 0, 0 + $qr_cropped->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height());
+ $label->copyResized($text0_image, $x_max - 2 * $fontsize, 0, 0, 0, $bounds0[1] * 1, $bounds0[2], $bounds0[1], $bounds0[2]);
+ $label->copyResized($text1_image, $x_max - 4 * $fontsize, 0, 0, 0, $bounds1[1] * 1, $bounds1[2], $bounds1[1], $bounds1[2]);
+ $label->copyResized($text2_image, $x_max - 6 * $fontsize, 0, 0, 0, $bounds2[1] * 1, $bounds2[2], $bounds2[1], $bounds2[2]);
+ $label->copyResized($text3_image, $x_max - 8 * $fontsize, 0, 0, 0, $bounds3[1] * 1, $bounds3[2], $bounds3[1], $bounds3[2]);
+
if ($ENV{'PRINT_WITH_LOGO'}) {
my ($logo_w, $logo_h ) = $logo->getBounds();
my $vl = $logo->copyRotate90();
- $label->copy($vl, $x_border - 20, $label->height - $y_border + 20 - $logo_w, 0, 0, $logo_h, $logo_w);
+# $label->copy($vl, 0, $y_max - $logo_w, 0, 0, $logo_h, $logo_w);
+ $label->copy($vl, 0, 267 - $logo_w, 0, 0, $logo_h, $logo_w);
}
+ my $offset = new GD::Image($x_max, 267);
+ $white = $offset->colorAllocate(255,255,255);
+ $black = $offset->colorAllocate(0,0,0);
+ $offset->fill(0, 0, $white);
+ $offset->copy($label, 0, 0, 0, 0, $label->width(), $label->height());
+
open(PNGFILE, ">label.png");
- print PNGFILE $label->png;
+ print PNGFILE $offset->png;
system($Config{'print_command'});
}
diff --git a/papersize.sh b/papersize.sh
new file mode 100755
index 0000000..475bf4d
--- /dev/null
+++ b/papersize.sh
@@ -0,0 +1,16 @@
+#!/bin/zsh -e
+
+PAPERSIZE=`lpoptions -p lbla -l|sed --silent 's/^PageSize.*\*//p'`
+DIMENSIONS=`rgrep "$PAPERSIZE" /etc/cups 2>/dev/null|
+ sed --silent 's/.*PaperDimension.*["]\([0-9.[:blank:]]*\)"/\1/p'`
+MARGINS=`rgrep "$PAPERSIZE" /etc/cups 2>/dev/null|
+ sed --silent 's/.*ImageableArea.*["]\([0-9.[:blank:]]*\)"/\1/p'`
+
+
+echo "Dimensions in postscript points: $DIMENSIONS"
+echo "Margins in postscript points: $MARGINS"
+
+for value in `echo $DIMENSIONS $MARGINS`
+do
+ echo "$value pt = $value pt * 300 dpi/72 pt/inch = $(( $value * 300 / 72 )) dots"
+done