+my $x = 30.00; # mm
+my $y = 30.00; # mm
+
+if ( $opt_svg ) {
+ print qq{<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ id="svg8"
+ version="1.1"
+ viewBox="0 0 210 297"
+ height="297mm"
+ width="210mm">
+
+
+<g id="layer1">
+
+ }; # svg, insert rest of rect
+
+ print qq{<rect x="0" y="0" width="210" height="297" style="fill:#000000" id="high-contrast"/>} if $opt_invert;
+}
+
+my @later;
+
+my $cols = { # foreground background
+ txt => [ '#000000', '#ffffff' ],
+ pins => [ '#ffffff', '#ff00ff' ],
+ vcc => [ '#ff0000', '#ffff00' ],
+ gnd => [ '#000000', '#00ffff' ],
+ i2c => [ '#008888', '#ffcccc' ],
+ uart => [ '#880088', '#ccffcc' ],
+ spi => [ '#888800', '#ccccff' ],
+};
+
+sub svg_style {
+ my ($name,$x,$y,$col) = @_;
+ $y -= 2.10; # shift box overlay to right vertical position based on font baseline
+
+ sub rect {
+ my ($x,$y,$col,$fill) = @_;
+ print qq{<rect x="$x" y="$y" height="2.54" width="}, $max_len[$col] * $font_w, qq{" style="opacity:1;fill:$fill;fill-opacity:1;stroke:#ffffff;stroke-width:0.10;stroke-opacity:1" />};
+
+ }
+
+ if ( $name =~ m/^(\d+)$/ ) { # pins
+ my $pin = $1;
+ my ( $fg, $bg ) = @{ $cols->{pins} };
+ if ( $pin == 1 ) {
+ my $w = $max_len[$col]*$font_w - 0.1;
+ my $cx = $x + $w;
+ my $cy = $y + 2.54;
+ #print qq{<polygon points="$x,$y $cx,$y $x,$cy $x,$y" stroke="$fg" stroke-width="0.25" fill="$bg" />};
+ #print qq{<polygon points="$x,$cy $cx,$cy $cx,$y $x,$cy" stroke="$bg" stroke-width="0.25" fill="$fg" />};
+ print qq{<rect x="$x" y="$y" width="$w" height="2.54" stroke="$fg" stroke-width="0.3" fill="$bg" />};
+ my ( $fg, $bg ) = @{ $cols->{txt} };
+ print qq{<rect x="$x" y="$y" width="$w" height="2.54" rx="1" ry="1" stroke="$fg" stroke-width="0.3" fill="$bg" />};
+ } else {
+ rect $x,$y,$col,$fg;
+ }
+ return qq{ style="fill:$bg"};
+ }
+
+ if ( $name =~ m/(VCC|3V3|3.3V)/i ) {
+ my ($fg,$bg) = @{ $cols->{vcc} };
+ rect $x,$y,$col,$bg;
+ return qq{ style="fill:$fg"};
+ } elsif ( $name =~ m/(G(ND|Round)|VSS)/i ) {
+ my ($fg,$bg) = @{ $cols->{gnd} };
+ rect $x,$y,$col,$bg;
+ return qq{ style="fill:$fg"};
+ } elsif ( $name =~ m/\[(\w+)\d\]/ ) { # kernel
+ my $dev = $1;
+ if ( my ($fg,$bg) = @{ $cols->{$dev} } ) {
+ rect $x,$y,$col,$bg;
+ return qq{ style="fill:$fg"};
+ }
+ } else {
+ my ( $fg, $bg ) = @{ $cols->{txt} };
+ rect $x,$y,$col,$bg;
+ #return qq{ style="fill:$fg"};
+ return '';
+ }
+}
+
+my $alt_col = 0;
+
+my @cols_order = ( 0,1,2,3 );
+my @cols_align = ( '','-','','-' ); # sprintf prefix
+
+@cols_order = ( 0,1,3,2 ); # pins outside on the right
+@cols_align = ( '','-','-','' );
+
+foreach my $i ( 0 .. $#line_parts ) {
+ $i = $#line_parts - $i if $opt_vertical;
+ my $line = $line_parts[$i];
+
+ my $pin_color = $alt_col ? '#cccccc' : '#444444';
+ $alt_col = ! $alt_col;
+
+ if ( $opt_svg ) {
+
+ my ($fg,$bg) = @{ $cols->{txt} };
+ my $tspan = qq{<tspan x="$x" y="$y" style="line-height:2.54;fill-opacity:1;fill:$fg;stroke:none;">};
+
+ my $x_pos = $x;
+ foreach my $i ( @cols_order ) {
+ next unless $line->[$i];
+ $tspan .= qq{<tspan x="$x_pos"}.svg_style($line->[$i],$x_pos,$y,$i).sprintf( '>%' . $cols_align[$i] . $max_len[$i] . 's</tspan>', $line->[$i]);
+ $x_pos += $max_len[$i] * $font_w;
+ }
+
+ $tspan .= qq{</tspan>};
+ push @later,sprintf $tspan, @$line;
+ $y += 2.54;
+
+ # swap pin colors for line stripes
+ foreach my $swap (qw( pins txt )) {
+ my ( $c1, $c2 ) = @{ $cols->{$swap} };
+ $cols->{$swap} = [ $c2, $c1 ];
+ };
+