X-Git-Url: http://git.rot13.org/?p=Printer-Zebra.git;a=blobdiff_plain;f=ZPL2pbm.pl;h=692fb66344499c05126ce8524fc96c998728e403;hp=818198d0d6815c5378f090d8330a1f4ae159230c;hb=e3d07b7bcee9e98f7600a9cea357a3a58397f745;hpb=b840570849c70a476c643bfa7d21150535944ae8 diff --git a/ZPL2pbm.pl b/ZPL2pbm.pl index 818198d..692fb66 100755 --- a/ZPL2pbm.pl +++ b/ZPL2pbm.pl @@ -25,35 +25,39 @@ slurp_line; while( $line ) { $line =~ s/[\r\n]+$// && warn "## removed CR/LF\n"; - warn "# line ",dump($line),$/; + warn "# line ",dump($line),$/ if length($line) < 80 or $ENV{DEBUG}; if ( $line =~ s/~DG(\w+:)?(.+)// ) { my ( $name, $t,$w ) = split(/,/,$2,4); warn "# ~DG$1 => [$name] t=$t w=$w\n"; - my $data; - read $in, $data, $t; + my $data = <$in>; my $out; # ZPL decompress - my $repeat = 1; - foreach my $p ( 0 .. length($data) ) { + my $repeat = 0; + foreach my $p ( 0 .. length($data) - 1 ) { my $c = substr($data,$p,1); if ( $c eq ',' ) { my $l = ( $w * 2 ) - length($out) % ( $w * 2 ); $l = $w * 2 if $l == 0; warn "# $p ZERO-to-EOL $c [$l]\n"; $out .= "0" x $l; + } elsif ( $c eq '!' ) { + my $l = ( $w * 2 ) - length($out) % ( $w * 2 ); + $l = $w * 2 if $l == 0; + warn "# $p ONE-to-EOL $c [$l]\n"; + $out .= "F" x $l; } elsif ( $c eq ':' ) { $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w; - warn "# $p :\n"; + warn "# $p repeat last line\n"; } elsif ( $c eq 'z' ) { $repeat += 400; } elsif ( $c ge 'g' && $c le 'y' ) { $repeat += 20 * ( ord($c) - ord('f') ); } elsif ( $c ge 'G' && $c le 'Y' ) { $repeat += ord($c) - ord('F'); - } elsif ( $c =~ m/[0-9A-F]/ ) { + } elsif ( $c =~ m/[0-9A-F]/i ) { if ( $repeat ) { warn "# $p $repeat $c\n"; $out .= $c x $repeat; @@ -86,6 +90,9 @@ while( $line ) { warn "UNKNOWN: ",dump($1),$/; } $line =~ s/^[\r\n]+// && warn "## removed CR/LF\n"; + } else { + my $unknown = $1 if $line =~ s/^(.)//; # printer seems to ignore invalid chars + warn "IGNORE: ",dump($unknown); } slurp_line;