From 47ac775c8ddf3573a066b5d417c9c785ff23d534 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 5 Feb 2016 03:16:03 +0000 Subject: [PATCH] commitid.scad.pl: Introduce gentextmodule and use it for Commitid_FontDemo (nfc) --- commitid.scad.pl | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/commitid.scad.pl b/commitid.scad.pl index dcebd26..d2e5eca 100755 --- a/commitid.scad.pl +++ b/commitid.scad.pl @@ -78,6 +78,27 @@ sub chrmodname ($) { return "Commitid__chr_$chrx"; } +sub gentextmodule ($@) { + my ($modulename, @lines) = @_; + p "module $modulename(){\n"; + p " scale(Commitid__scale()){\n"; + my $y = @lines; + foreach my $line (@lines) { + $y--; + my $x = 0; + foreach my $chr (split //, $line) { + next if $chr !~ m/\S/; + p sprintf " translate([%d * 0.8, %d * 1.2]) %s();\n", + $x, $y, chrmodname $chr; + $x++; + } + } + p " }\n"; + p "}\n"; +} + +our @demo; + sub parsefont () { my %cellmap; for (;;) { @@ -125,7 +146,7 @@ sub parsefont () { } } - my @demo; + my $demo = ''; my $democols = 6; foreach my $chr (sort keys %chrpolys) { my $mod = chrmodname $chr; @@ -143,22 +164,14 @@ sub parsefont () { p "]);\n"; } p "}\n"; - my $px = @demo % $democols; - my $py = int(@demo / $democols); - push @demo, " scale( Commitid__scale() ) translate([$px * 0.800, $py * 1.200]) - $mod ();\n"; + $demo .= $chr; } - p "module Commitid_FontDemo(){\n"; - p $_ foreach @demo; - p "}\n"; - -# use Data::Dumper; -# print Dumper(\%chrpolys); + @demo = reverse $demo =~ m{.{1,$democols}}go; } parsefont(); -#p "Commitid_FontDemo();\n"; +gentextmodule('Commitid_FontDemo', @demo); __DATA__ -- 2.30.2