/usr/share/perl5/Barcode/DataMatrix/CharDataFiller.pm is in libbarcode-datamatrix-perl 0.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | package Barcode::DataMatrix::CharDataFiller;
use strict;
use warnings;
=head1 NAME
Barcode::DataMatrix::CharDataFiller - Handle filling character data within the
data matrix array.
=head1 DESCRIPTION
The documentation for the methods in this class has been adapted from the
comments in
L<https://github.com/itext/itextpdf/blob/master/itext/src/main/java/com/itextpdf/text/pdf/BarcodeDatamatrix.java>.
=head2 new
Construct a C<Barcode::DataMatrix::CharDataFiller> object.
=cut
sub new {
my $self = bless {}, shift;
@$self{qw( ncol nrow array )} = @_;
$self->fill();
return $self;
}
=head2 module (i, j, k, l)
Places "chr+bit" with the appropriate wrapping within the array.
=cut
sub module {
my ($self,$i,$j,$k,$l) = @_;
if($i < 0) {
$i += $self->{nrow};
$j += 4 - ($self->{nrow} + 4) % 8;
}
if($j < 0) {
$j += $self->{ncol};
$i += 4 - ($self->{ncol} + 4) % 8;
}
$self->{array}->[$i * $self->{ncol} + $j] = 10 * $k + $l;
return;
}
=head2 utah (i, j, k)
Places the 8 bits of a utah-shaped symbol character.
=cut
sub utah {
my ($self,$i,$j,$k) = @_;
$self->module($i - 2, $j - 2, $k, 1);
$self->module($i - 2, $j - 1, $k, 2);
$self->module($i - 1, $j - 2, $k, 3);
$self->module($i - 1, $j - 1, $k, 4);
$self->module($i - 1, $j, $k, 5);
$self->module($i, $j - 2, $k, 6);
$self->module($i, $j - 1, $k, 7);
$self->module($i, $j, $k, 8);
return;
}
=head2 corner1 (i)
Places 8 bits of the first of the four special corner cases.
=cut
sub corner1 {
my ($self,$i) = @_;
my ($ncol,$nrow) = @$self{qw( ncol nrow )};
$self->module($nrow - 1, 0, $i, 1);
$self->module($nrow - 1, 1, $i, 2);
$self->module($nrow - 1, 2, $i, 3);
$self->module(0, $ncol - 2, $i, 4);
$self->module(0, $ncol - 1, $i, 5);
$self->module(1, $ncol - 1, $i, 6);
$self->module(2, $ncol - 1, $i, 7);
$self->module(3, $ncol - 1, $i, 8);
return;
}
=head2 corner2 (i)
Places 8 bits of the second of the four special corner cases.
=cut
sub corner2 { #(int i)
my ($self,$i) = @_;
my ($ncol,$nrow) = @$self{qw( ncol nrow )};
$self->module($nrow - 3, 0, $i, 1);
$self->module($nrow - 2, 0, $i, 2);
$self->module($nrow - 1, 0, $i, 3);
$self->module(0, $ncol - 4, $i, 4);
$self->module(0, $ncol - 3, $i, 5);
$self->module(0, $ncol - 2, $i, 6);
$self->module(0, $ncol - 1, $i, 7);
$self->module(1, $ncol - 1, $i, 8);
return;
}
=head2 corner3 (i)
Places 8 bits of the third of the four special corner cases.
=cut
sub corner3 { #(int i)
my ($self,$i) = @_;
my ($ncol,$nrow) = @$self{qw( ncol nrow )};
$self->module($nrow - 3, 0, $i, 1);
$self->module($nrow - 2, 0, $i, 2);
$self->module($nrow - 1, 0, $i, 3);
$self->module(0, $ncol - 2, $i, 4);
$self->module(0, $ncol - 1, $i, 5);
$self->module(1, $ncol - 1, $i, 6);
$self->module(2, $ncol - 1, $i, 7);
$self->module(3, $ncol - 1, $i, 8);
return;
}
=head2 corner4 (i)
Places 8 bits of the fourth of the four special corner cases.
=cut
sub corner4 { #(int i)
my ($self,$i) = @_;
my ($ncol,$nrow) = @$self{qw( ncol nrow )};
$self->module($nrow - 1, 0, $i, 1);
$self->module($nrow - 1, $ncol - 1, $i, 2);
$self->module(0, $ncol - 3, $i, 3);
$self->module(0, $ncol - 2, $i, 4);
$self->module(0, $ncol - 1, $i, 5);
$self->module(1, $ncol - 3, $i, 6);
$self->module(1, $ncol - 2, $i, 7);
$self->module(1, $ncol - 1, $i, 8);
return;
}
=head2 fill
Fills an nrow x ncol array with appropriate values.
=cut
sub fill { # (int ncol; int nrow; int array;) : void
my $self = shift;
my ($ncol,$nrow,$array) = @$self{qw( ncol nrow array )};
my $i = 1;
my $j = 4;
my $k = 0;
for(my $l = 0; $l < $nrow; $l++) {
for(my $i1 = 0; $i1 < $ncol; $i1++) {
$array->[$l * $ncol + $i1] = 0;
}
}
do {
$self->corner1($i++) if $j == $nrow && $k == 0;
$self->corner2($i++) if $j == $nrow - 2 && $k == 0 && $ncol % 4 != 0;
$self->corner3($i++) if $j == $nrow - 2 && $k == 0 && $ncol % 8 == 4;
$self->corner4($i++) if $j == $nrow + 4 && $k == 2 && $ncol % 8 == 0;
do {
$self->utah($j, $k, $i++) if $j < $nrow && $k >= 0 && $array->[$j * $ncol + $k] == 0;
$j -= 2;
$k += 2;
} while($j >= 0 && $k < $ncol);
$j++;
$k += 3;
do {
$self->utah($j, $k, $i++) if $j >= 0 && $k < $ncol && $array->[$j * $ncol + $k] == 0;
$j += 2;
$k -= 2;
} while($j < $nrow && $k >= 0);
$j += 3;
$k++;
} while($j < $nrow || $k < $ncol);
$array->[$nrow * $ncol - 1] = $array->[($nrow - 1) * $ncol - 2] = 1
if($array->[$nrow * $ncol - 1] == 0);
return;
}
1;
|