root/yapcasia2008/misc/nameplate-svg.pl

Revision 2666 (checked in by miyagawa, 12 years ago)

Add userid

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Encode;
5 use SVG;
6 use SVG::Parser;
7 use Text::CSV_XS;
8 use Locale::Country;
9
10 Locale::Country::rename_country('tw' => 'Taiwan');
11
12 my $base_file = "namecard_2x5.svg";
13 my $csv_file  = shift @ARGV || "sample.csv";
14
15 open my $fh, $csv_file or die $!;
16
17 my $csv = Text::CSV_XS->new({ binary => 1 });
18 my $header = $csv->getline($fh);
19 $csv->column_names(@$header);
20
21 my $out_dir = "$ENV{HOME}/Sites/yapc-nameplates";
22
23 my $font = '"M+ 1c"';
24
25 my @users;
26 while (!$csv->eof) {
27     my $ref = $csv->getline_hr($fh);
28     next unless $ref->{user_id};
29     push @users, $ref;
30 }
31
32 while (my @chunk = splice(@users, 0, 10)) {
33     my $first_id = $chunk[0]->{user_id};
34     my $ox = 0;
35     my $oy = 0;
36
37     my $parser = SVG::Parser->new;
38     my $svg = $parser->parse_file($base_file);
39
40     for my $ref (@chunk) {
41         $svg->text(x => $ox + 50, y => $oy + 60, style => { 'font-family' => $font, 'font-weight' => 'bold', 'color' => 'black', 'font-size' => 24 })->cdata(get_name($ref));
42         $svg->text(x => $ox + 50, y => $oy + 80, style => { 'font-family' => $font, 'color' => 'black', 'font-size' => 12 })->cdata(($ref->{pm_group} ? "$ref->{pm_group} / " : "") . code2country($ref->{country}));
43
44         my $role = $ref->{has_talk} ? 'SPEAKER' :
45             ($ref->{is_orga} || $ref->{is_staff}) ? 'STAFF' : '';
46
47         if ($role) {
48             $svg->text(x => $ox + 50, y => $oy + 120, style => { 'font-family' => $font, 'font-weight' => 'bold', color => 'black', 'font-size' => 16 })->cdata($role);
49         }
50
51         $svg->text(x => $ox + 50, y => $oy + 140, style => { 'font-family' => $font, color => 'black', 'font-size' => 10 })->cdata($ref->{user_id});
52
53         $ox = $ox == 0 ? 296 : 0;
54         $oy+= 168 if $ox == 0;
55     }
56
57     my $outfile = "$out_dir/$first_id.svg";
58     open my $out, ">:utf8", $outfile or die "$outfile: $!";
59     print $out $svg->xmlify;
60 }
61
62 sub get_name {
63     my $ref = shift;
64
65     ## xxx nickname
66     if (is_cjk($ref)) {
67         return decode_utf8( $ref->{last_name} . $ref->{first_name} );
68     } else {
69         return decode_utf8( join " ", $ref->{first_name}, $ref->{last_name} );
70     }
71 }
72
73 sub is_cjk {
74     my $ref = shift;
75     my $name = decode_utf8($ref->{first_name} . $ref->{last_name});
76     $name =~ /\p{Han}/;
77 }
Note: See TracBrowser for help on using the browser.