latin: common function to format code93 bar codes
[sheet.git] / writing-latn.inc.pl
index babdb40f74f4f7b877a20d0231dc2ca69b197ad8..3aab17a9630c0930d0029b572c32ea39dd6f6af8 100644 (file)
@@ -1,6 +1,9 @@
 use 5.014;
 use utf8;
-use List::Util qw( pairs );
+use List::Util qw( pairs sum );
+
+my %C = qw(red #EC1C24  blue #3953A3  yellow #F9EC31  black #231F20);
+my $U = 0;  # optional unicode alternatives
 
 sub disptap {
        return map {
@@ -11,8 +14,21 @@ sub disptap {
        } @_;
 }
 
-my %C = qw(red #EC1C24  blue #3953A3  yellow #F9EC31  black #231F20);
-my $U = 0;  # optional unicode alternatives
+sub dispbar {
+       my @cols = split //, shift;  # bar and space widths
+       my $width = sum(@cols);
+       return sprintf(
+               '<svg width="%d" height="%d" viewBox="-.5 0 %d %d"><path d="%s"/></svg>',
+               $width * 2, 14, $width, 7, join(' ',
+                       'M0,0',
+                       map {
+                               join('m1,-7', ('v7') x $_->[0]),  # line per bar width
+                               (map { sprintf 'm%d,-7', $_ + 1 } $_->[1] || ()),  # space forward
+                       }
+                       pairs @cols
+               )
+       );
+}
 
 (
 'Uppercase' => [qw{ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }],
@@ -265,24 +281,11 @@ my $U = 0;  # optional unicode alternatives
                201112 102112 202111 101212 201211 102211        102121 0 101221
        )
 ],
-'Code 93' => [
-       map {
-               sprintf
-               '<svg width="18" height="14" viewBox="-.5 0 9 7"><path d="M0,0 %s"/></svg>',
-               join ' ',
-               map {
-                       join('m1,-7', ('v7') x $_->[0]),  # line per bar width
-                       (map { sprintf 'm%d,-7', $_ + 1 } $_->[1] || ()),  # space forward
-               }
-               pairs split //
-       }
-       # bar and space widths (1-3)
-       qw(
-               21111 21121 21131 22111 22121 23111 11211 11221 11231
-               12211 13211 11112 11122 11132 12112 13112 21211 21221
-               21112 21122 22112 22211 11212 11222 12212 12311 31121
-       )
-],
+'Code 93' => [map { dispbar($_) } qw(
+       211113 211212 211311 221112 221211 231111 112113 112212 112311 122112
+       132111 111123 111222 111321 121122 131121 212112 212211 211122 211221
+       221121 222111 112122 112221 122121 123111        311211
+)],
 'Code 128' => [
        map { $U ? tr/1-3-/❘❙❚ /r : sprintf
                '<svg width="22" height="14" viewBox="-.5 0 11 7"><path d="M0,0 %s"/></svg>',
@@ -328,24 +331,24 @@ my $U = 0;  # optional unicode alternatives
 ],
 "D'ni" => [
        map {
-               state $window = 'M-.5,-.5H12.5V12.5H-.5Z';
+               state $window = 'M-.5,-.5H8.5V8.5H-.5Z';
                state $v = [
                        '',
-                       'M0,6 12,6',
-                       'M0,12 Q6,6 12,12',
-                       'M0,6 6,12 12,6',
-                       'M3,0 3,6 12,6',
-                       'M0,0 12,12 M0,12 12,0', # cross
-                       'M5.5,6 h1', # dot
+                       'M0,4 8,4',
+                       'M0,8 Q4,4 8,8',
+                       'M0,4 4,8 8,4',
+                       'M2,0 2,4 8,4',
+                       'M0,0 8,8 M0,8 8,0', # cross
+                       'M3.5,4 h1', # dot
                ];
                state $h = [
                        '',
-                       'M6,0 6,12',
-                       'M0,0 Q6,6 0,12',
-                       'M6,-.5 0,6 6,12.5',
-                       'M6,12 6,3 12,3',
+                       'M4,0 4,8',
+                       'M0,0 Q4,4 0,8',
+                       'M4,-.5 0,4 4,8.5',
+                       'M4,8 4,2 8,2',
                ];
-               sprintf '<svg width="20" height="20" viewBox="-.5 -.5 13 13"><path d="%s"/></svg>',
+               sprintf '<svg width="16" height="16" viewBox="-.5 -.5 9 9"><path d="%s"/></svg>',
                        $window . ($h->[$_ % 5] . $v->[$_ / 5] || $v->[6]);
        } 0 .. 5*5
 ],