4 $SIG{__WARN__} = sub { die @_; };
6 # xxx much of the comment below is TODO
8 # We generate a physical indication of which commit was used.
10 # We provide for scaling factors with dynamic variables:
11 # $Commitid_pixelsz if not set, we use 0.8 } multiplied
12 # $Commitid_scale if not set, we use 1.0 } together
13 # $Commitid_depth if not set, we use xy pixel size from above / 2
14 # $Commitid_depth_scale if not set, we use 1.0 (multiplies depth above)
16 # For each form we have
18 # module Commitid_Form_2D() { ... }
19 # module Commitid_Form() { ... }
20 # function Commitid_Form_sz() => [ x, y ]
22 # These have their origin in the bottom left corner. The 3D model
23 # is a positive, has its origin halfway through, and is twice the
24 # depth in height, so it can be added or subtracted.
28 # function Commitid_pixelsz() // $Commitid_pixelsz * $Commitid_scale
29 # function Commitid_depth() // see above
31 # We can generate these forms:
39 # git rev-list --first-parent --count HEAD
40 # typically 3-4 characters but we allow for up to 6
41 # padded with zeroes; if too long we reduce mod 10^n
48 # same but in two lines eg
55 # git-rev-parse HEAD (prefix of requested length)
62 # git-rev-list --first-parent --count HEAD
68 sub p { print @_ or die $!; }
71 // *** AUTOGENERATED - DO NOT EDIT *** //
72 function Commitid_pixelsz() =
73 ($Commitid_pixelsz ? $Commitid_pixelsz : 0.8) *
74 ($Commitid_scale ? $Commitid_scale : 1.0);
75 function Commitid_depth() =
76 ($Commitid_depth ? $Commitid_depth : Commitid_pixelsz()/2) *
77 ($Commitid_depth_scale ? $Commitid_depth_scale : 1.0);
78 function Commitid__scale() =
79 Commitid_pixelsz() / 0.2;
84 my $chrx = sprintf '%#x', ord $chr;
85 return "Commitid__chr_$chrx";
88 sub gentextmodule ($@) {
89 my ($form, @lines) = @_;
90 my $modb = "Commitid_$form";
91 p "module ${modb}_2D(){\n";
92 p " // |$_|\n" foreach @lines;
93 p " scale(Commitid__scale()){\n";
96 foreach my $line (@lines) {
99 foreach my $chr (split //, $line) {
100 next if $chr !~ m/\S/;
101 p sprintf " translate([%d * 0.8, %d * 1.2]) %s();\n",
102 $x, $y, chrmodname $chr;
105 $cols = $x if $x > $cols;
109 p "module ${modb}(){\n";
110 p " d=Commitid_depth();\n";
111 p " translate([0,0,-d]) linear_extrude(height=d*2) ${modb}_2D();\n";
113 p sprintf "function %s_sz() = Commitid__scale() * 0.1 * [ %d, %d ];\n",
114 $modb, 2 * ($cols * 4 - 1), 2 * (@lines * 6 - 1);
123 last if %cellmap && !m/\S/;
133 my @chrs = split / /, $_;
134 <DATA> !~ m/\S/ or die;
135 foreach my $row (reverse 0..4) {
146 foreach my $chr (@chrs) {
147 s{^ }{} or die "$chr $_ ?";
148 foreach my $col (0..2) {
152 my $f = $cellmap{$&};
154 $f =~ s/\b\d/ sprintf '%05d', $col*2000 + $&*1025 /ge;
155 $f =~ s/\d\b/ sprintf '%05d', $row*2000 + $&*1025 /ge;
156 push @{ $chrpolys{$chr} }, [ split / /, $f ];
168 foreach my $chr (sort keys %chrpolys) {
169 my $mod = chrmodname $chr;
170 p "module $mod () {\n";
171 foreach my $poly (@{ $chrpolys{$chr} }) {
174 foreach my $pt (@$poly) {
176 $pt =~ s{\d{5}}{$&,};
177 $pt =~ s{\b\d}{$&.}g;
186 @demo = reverse $demo =~ m{.{1,$democols}}go;
191 gentextmodule('FontDemo', @demo);
193 flush STDOUT or die $!;
194 close STDOUT or die $!;
208 /#\ r /#\ ##\ # # ### // ### /#\ /#\
209 # # /# # # # # # # # # # # #
210 # # # /#/ ##< \## ##\ ##\ // >#< \##
211 # # # # # # # # # # # # #
212 \#/ /#\ ### ##/ # ##/ \#/ # \#/ ##/
218 /## ##\ # /## #r# ###
220 \## ##/ \## \## \#/ #