5 use Data::Dump qw(dump);
7 # convert Zebra label printer ZPL to pbm image
12 my ( $cmd, $desc ) = split(/\s/,$_,2);
13 $command->{$cmd} = $desc;
16 my $file = shift @ARGV || die "usage: $0 dump.zpl > dump.pbm\n";
18 open(my $in, '<', $file);
22 $line .= <$in> unless length $line > 3;
27 $line =~ s/[\r\n]+$// && warn "## removed CR/LF\n";
28 warn "# line ",dump($line),$/ if length($line) < 80 or $ENV{DEBUG};
29 if ( $line =~ s/~DG(\w+:)?(.+)// ) {
30 my ( $name, $total_bytes, $row_bytes ) = split(/,/,$2,4);
32 warn "# ~DG$1 => [$name] $total_bytes bytes $row_bytes in row\n";
36 my $w = $row_bytes * 2; # hex digits
41 foreach my $p ( 0 .. length($data) - 1 ) {
43 if ( length($out) == $total_bytes * 2 ) {
44 warn "END of bitmap\n";
45 $line = substr($data,$p);
50 my $c = substr($data,$p,1);
53 my $l = $w - ( length($out) % $w );
55 warn "# $p ZERO-to-EOL $c [$l]\n";
57 } elsif ( $c eq '!' ) {
58 my $l = $w - ( length($out) % $w );
60 warn "# $p ONE-to-EOL $c [$l]\n";
62 } elsif ( $c eq ':' ) {
63 # $out .= length($out) > $w ? substr($out,-$w) : "0" x $w;
64 $out .= substr($out,-$w);
65 warn "# $p repeat last line\n";
66 } elsif ( $c eq 'z' ) {
68 } elsif ( $c ge 'g' && $c le 'y' ) {
69 $repeat += 20 * ( ord($c) - ord('f') );
70 } elsif ( $c ge 'G' && $c le 'Y' ) {
71 $repeat += ord($c) - ord('F');
72 } elsif ( $c =~ m/[0-9A-F]/i ) {
74 warn "# $p $repeat $c\n";
82 die "ABORT: offset $p data [$c]";
85 warn "## $repeat [$c] out = ",length($out),$/;
88 my $bitmap = pack('H*', $out);
89 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
90 my $pw = $row_bytes * 8;
91 my $ph = int(length($bitmap) / $row_bytes);
92 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$row_bytes);
94 } elsif ( $line =~ s/^([~\^][^~\^\r\n]*)// ) {
95 my $cmd = substr($1,0,3);
96 if ( my $desc = $command->{$cmd} ) {
97 warn "ZPL: $1\t$desc\n";
99 warn "UNKNOWN: ",dump($1),$/;
101 $line =~ s/^[\r\n]+// && warn "## removed CR/LF\n";
103 my $unknown = $1 if $line =~ s/^(.)//; # printer seems to ignore invalid chars
104 warn "IGNORE: ",dump($unknown);
111 ^A Scalable/Bitmapped Font
112 ^A@ Use Font Name to Call Font
114 ^B2 Interleaved 2 of 5 Bar Code
117 ^B5 Planet Code bar code
122 ^BB CODABLOCK Bar Code
123 ^BC Code 128 Bar Code (Subsets A, B, and C)
124 ^BD UPS MaxiCode Bar Code
126 ^BF Micro-PDF417 Bar Code
127 ^BI Industrial 2 of 5 Bar Codes
128 ^BJ Standard 2 of 5 Bar Code
129 ^BK ANSI Codabar Bar Code
132 ^BO Aztec Bar Code Parameters
135 ^BR RSS (Reduced Space Symbology) Bar Code
136 ^BS UPC/EAN Extensions
139 ^BX Data Matrix Bar Code
140 ^BY Bar Code Field Default
146 ^CF Change Alphanumeric Default Font
147 ^CI Change International Font
148 ^CM Change Memory Letter Designation
154 ~DB Download Bitmap Font
155 ~DE Download Encoding
157 ~DG Download Graphics
158 ~DN Abort Download Graphic
159 ~DS Download Scalable Font
160 ~DT Download TrueType Font
161 ~DU Download Unbounded TrueType Font
162 ~DY Download Graphics
163 ~EG Erase Download Graphics
165 ^FC Field Clock (for Real-Time Clock)
167 ^FH Field Hexadecimal Indicator
168 ^FM Multiple Field Origin Locations
172 ^FR Field Reverse Print
176 ^FW Field Orientation
180 ^GD Graphic Diagonal Line
185 ~HD Head Temperature Information
188 ^HH Configuration Label Return
189 ~HI Host Identification
191 ~HS Host Status Return
192 ~HU Return ZebraNet Alert Configuration
193 ^HV Host Verification
194 ^HW Host Directory List
196 ^HZ Display Description Information
202 ^JB Initialize Flash Memory
203 ~JB Reset Optional Memory
204 ~JC Set Media Sensor Calibration
205 ~JD Enable Communications Diagnostics
206 ~JE Disable Diagnostics
207 ~JF Set Battery Condition
208 ~JG Graphing Sensor Calibration
209 ^JJ Set Auxiliary Port
211 ^JM Set Dots per Millimeter
213 ~JO Head Test Non fatal
214 ~JP Pause and Cancel Format
217 ~JS Change Backfeed Sequence
218 ^JT Head Test Interval
219 ^JU Configuration Update
220 ^JW Set Ribbon Tension
221 ~JX Cancel Current Partially Input Format
222 ^JZ Reprint After Error
223 ~KB Kill Battery (Battery Discharge Mode)
224 ^KD Select Date and Time Format (for Real Time Clock)
226 ^KN Define Printer Name
230 ^LR Label Reverse Print
236 ^ML Maximum Label Length
241 ^MU Set Units of Measurement
242 ^MW Modify Head Cold Warning
244 ^NI Network ID Number
245 ~NR Set All Network Printers Transparent
246 ^NS Change Networking Settings
247 ~NT Set Currently Connected Printer Transparent
248 ^PF Slew Given Number of Dot Rows
249 ^PH Slew to Home Position
250 ~PH Slew to Home Position
251 ^PM Printing Mirror Image of Label
252 ^PO Print Orientation
253 ^PP Programmable Pause
254 ~PP Programmable Pause
257 ~PR Applicator Reprint
260 ~RO Reset Advanced Counter
261 ^SC Set Serial Communications
264 ^SF Serialization Field (with a Standard ^FD String)
265 ^SL Set Mode and Language (for Real-Time Clock)
266 ^SN Serialization Data
267 ^SO Set Offset (for Real-Time Clock)
269 ^SQ Halt ZebraNet Alert
270 ^SR Set Printhead Resistance
271 ^SS Set Media Sensors
272 ^ST Set Date and Time (for Real-Time Clock)
273 ^SX Set ZebraNet Alert
275 ~TA Tear-off Adjust Position
277 ~WC Print Configuration Label
278 ^WD Print Directory Label
280 ^XB Suppress Backfeed