]> git.pld-linux.org Git - packages/libreoffice.git/blob - openoffice-scale-icons
- DON'T hardcode java paths!
[packages/libreoffice.git] / openoffice-scale-icons
1 #!/usr/bin/perl -w
2
3 # Newer ImageMagick's don't like some of the
4 # broken icons OO.o contains.
5 $lc_good = 'res/lc00000.bmp';
6 $sc_good = 'res/sc00000.bmp';
7
8 # beautiful hard-coding action.
9 @scale_dirs = (
10         'res',
11         'sc/res/imglst/apptbx',
12         'sc/res/imglst/navipi',
13         'sd/res/imagelst',
14         'sd/res/imagelst/korean',
15         'sw/win/imglst', 
16         'sw/win/imglst/korean',
17         'sch/res',
18         'offmgr/res',
19         'res/enus',
20         'dbaccess/res',
21         'sc/res',
22         'sd/res',
23         'sw/win/res',
24         'starmath/res',
25         'res/arab',
26         'res/catalan',
27         'res/chinsim',
28         'res/chintrad',
29         'res/czech',
30         'res/dtch',
31         'res/fren',
32         'res/hung',
33         'res/ital',
34         'res/japn',
35         'res/korean',
36         'res/pol',
37         'res/poln',
38         'res/port',
39         'res/portbr',
40         'res/russ',
41         'res/slovak',
42         'res/slovenian',
43         'res/span',
44         'res/turk'
45                );
46
47 %scale_exceptions = (
48         'sw/win/imglst' => '[sn][cr][0-9]*\.bmp',
49         'sc/res/imglst/navipi' => 'na0.*\.bmp',
50         'res' => '[si][cm][0-9]*\.bmp'
51 );
52
53 sub usage {
54     printf "Usage: scale-icons </path/to/ooo_checkout> [--quiet] [--backupdir=</path/for/original_bmps>\n";
55 }
56
57 if (@ARGV < 1) {
58     usage ();
59     exit (1);
60 }
61
62 $OOO_PATH = shift (@ARGV);
63
64 if ($OOO_PATH =~ m/--.*/) {
65     usage ();
66     exit (1);
67 }
68
69 $lc_good = "$OOO_PATH/$lc_good";
70 $sc_good = "$OOO_PATH/$sc_good";
71
72 $quiet = 0;
73 $remove = 0;
74 $backupdir = "";
75
76 foreach $a (@ARGV) {
77     if ($a eq '--quiet') {
78         $quiet = 1;
79     } elsif ($a eq '--remove') {
80         $remove = 1;
81     } elsif ($a =~ m/--backupdir=(.*)/) {
82         $backupdir = $1;
83     }
84 }
85
86 sub handle_scaled {
87     my $relinstdir = shift;
88     my $small_regex = shift;
89     my $large_regex = shift;
90     my ($dirhandle, $file);
91     my $instdir = "$OOO_PATH/$relinstdir";
92     my $STAMPNAME = "$instdir/ooo-convert-stamp";
93
94     if (! -d $instdir) {
95         print "skipping $instdir\n";
96         next;
97     }
98
99     if ($remove) {
100         -f $STAMPNAME || return;
101     } else {
102         -f $STAMPNAME && return;
103     }
104
105     print "Scaling: '$instdir'\n";
106     
107     opendir ($dirhandle, $instdir) || die "can't opendir $instdir: $!";
108     
109     while ($file = readdir ($dirhandle)) {
110         if ($file =~ m/^$small_regex$|^$large_regex$/) {
111             my $src = "$instdir/$file";
112             my $dest = "$src.cnvt";
113
114             if ($remove) {
115                 $quiet || print "Remove '$src'\n";
116                 unlink ($src);
117                 next;
118             }
119             $quiet || print "Convert '$src'\n";
120
121             -f $src || die "Internal error";
122
123             if ($src =~ /$small_regex/) {
124                 if (system ("convert -mattecolor '#c0c0c0' -frame 2x2 -crop 16x16+2+2 $src $dest") != 0) {
125                     print "*** Warning: convert failed; trying copy\n";
126                     system ("cp -f $sc_good $dest");
127                 }
128             } elsif ($src =~ /$large_regex/) {
129                 if (system ("convert -mattecolor '#c0c0c0' -frame 2x2 -crop 24x24+3+2 $src $dest") != 0) {
130                     print "*** Warning: convert failed; trying copy\n";
131                     system ("cp -f $lc_good $dest");
132                 }
133             }
134             if (-f $dest) {
135                 print $backupdir ? "$backupdir/$relinstdir/$file" : "$src.orig", "\n";
136                 rename ($src,
137                         $backupdir ? "$backupdir/$relinstdir/$file" : "$src.orig");
138                 rename ($dest, $src);
139             }
140         }
141     }
142    
143     closedir ($dirhandle);
144
145     if ($remove) {
146         unlink ("$STAMPNAME");
147     } else {
148         my $stamphandle;
149         open ($stamphandle, ">$STAMPNAME") || die "Error stamping $STAMPNAME $!";
150         print $stamphandle "Stamp\n";
151         close ($stamphandle);
152     }
153 }
154
155 for $a (@scale_dirs) {
156     my $small_regex;
157     if (defined ($scale_exceptions{$a})) {
158         $small_regex = $scale_exceptions{$a};
159         print "Exception on '$a' => '$small_regex'\n";
160     } else {
161         $small_regex = 'sc[0-9]*\.bmp';
162     }
163     if ($backupdir) {
164         if (system ("mkdir -p $backupdir/$a\n") != 0) {
165             print "*** Warning: could not create $backupdir/$a\n" ;
166             $backupdir = "";
167         }
168     }
169     handle_scaled ("$a", $small_regex, 'lc[0-9]*\.bmp');
170 }
171
172 print "Binning dupped icons\n";
173 -f "$OOO_PATH/extras/source/symbols/makefile.mk" || die "No dupped icon directory";
174 if ($backupdir) {
175     system ("mkdir -p $backupdir/extras/source/symbols");
176     system ("cp -a $OOO_PATH/extras/source/symbols/*.bmp $backupdir/extras/source/symbols");
177 }
178 system ("rm -f $OOO_PATH/extras/source/symbols/*.bmp");
179
180 print "Completed cleanly.\n";
181 exit (0);
This page took 0.04705 seconds and 3 git commands to generate.