latin: code 128 as svg images
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 2 Apr 2017 17:00:33 +0000 (19:00 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 24 Apr 2017 18:44:10 +0000 (20:44 +0200)
Unicode characters do not have any reliable form or width, so will only be
similar at best.  Replace by SVG drawing to ensure exact multiples of module
size as specified.

writing-latn.inc.pl

index 93b5edcfc3bfbcd56b109da0b5ba742098986a99..7fabb6ed1520eb3407706358d894a5cca93565cb 100644 (file)
@@ -10,6 +10,7 @@ sub disptap {
 }
 
 my %C = qw(red #EC1C24  blue #3953A3  yellow #F9EC31  black #231F20);
+my $U = 0;  # optional unicode alternatives
 
 (
 '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 }],
@@ -242,7 +243,16 @@ my %C = qw(red #EC1C24  blue #3953A3  yellow #F9EC31  black #231F20);
        )
 ],
 'Code 128' => [
-       map { tr/1-3-/❘❙❚ /r }
+       map { $U ? tr/1-3-/❘❙❚ /r : sprintf
+               '<svg width="20" height="14" viewBox="-.5 0 10 7"><path d="M0,0 %s"/></svg>',
+               join ' ',
+               map {
+                       $_ eq '' ? 'm2,-7' :
+                       $_ eq '-' ? 'm4,-7' :
+                       join 'm1,-7', ('v7') x $_
+               }
+               split /(-)?/, $_  # each bar [123] and space [ -]
+       }
        # bar widths (1-3) followed by space of width 1 (implied) or 3 (-)
        qw(
                11-2 1-12 1-1-2 12-1 1-21 1-2-1 21-1 2-11 2-1-1 123  12-3 1-23 132