source: josm/trunk/scripts/geticons.pl@ 19069

Last change on this file since 19069 was 18743, checked in by stoecker, 19 months ago

fix icon script and warning in SVG image

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.4 KB
RevLine 
[2808]1#! /usr/bin/perl -w
2# short tool to find out all used icons and allows deleting unused icons
3# when building release files
4
5my @default = (
[16006]6 "resources/styles/standard/*.xml",
7 "resources/styles/standard/*.mapcss",
8 "resources/data/*.xml",
[2808]9 "src/org/openstreetmap/josm/*.java",
10 "src/org/openstreetmap/josm/*/*.java",
11 "src/org/openstreetmap/josm/*/*/*.java",
12 "src/org/openstreetmap/josm/*/*/*/*.java",
13 "src/org/openstreetmap/josm/*/*/*/*/*.java",
[18115]14 "src/org/openstreetmap/josm/*/*/*/*/*/*.java",
15 "src/org/openstreetmap/josm/*/*/*/*/*/*/*.java"
[2808]16);
17
18my %icons;
19
20my $o = $/;
21
22for my $arg (@ARGV ? @ARGV : @default)
23{
24 for my $file (glob($arg))
25 {
[13277]26 my @defs;
[2808]27 open(FILE,"<",$file) or die "Could not open $file\n";
28 #print "Read file $file\n";
29 $/ = $file =~ /\.java$/ ? ";" : $o;
30 my $extends = "";
31 while(my $l = <FILE>)
32 {
[18743]33 if($l =~ /extends MapMode/)
34 {
35 $extends = "mapmode/";
36 }
37 elsif($l =~ /extends ToggleDialog/)
38 {
39 $extends = "dialogs/";
40 }
41 elsif($l =~ /extends JosmAction/)
42 {
43 $extends = "";
44 }
[13277]45 if($l =~ /private static final String ([A-Z_]+) = ("[^"]+")/)
46 {
47 push(@defs, [$1, $2]);
48 }
[7668]49 next if $l =~ /NO-ICON/;
[13277]50 for my $d (@defs)
51 {
52 $l =~ s/$d->[0]/$d->[1]/g;
53 }
[10069]54 if($l =~ /icon\s*[:=]\s*["']([^"'+]+?)["']/)
[2808]55 {
[18115]56 my $i = $1;
57 ++$icons{$i};
[2808]58 }
59
[7670]60 if(($l =~ /(?:icon-image|repeat-image|fill-image)\s*:\s*(\"?(.*?)\"?)\s*;/) && ($1 ne "none"))
[4172]61 {
[18115]62 my $i = $2;
63 ++$icons{$i};
[4172]64 }
[13857]65 if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"(?:, (?:ImageProvider\.)?ImageSizes\.[A-Z]+)?\)/)
[2808]66 {
67 my $i = $1;
68 ++$icons{$i};
69 }
[4172]70 while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
71 {
72 my $i = $1;
73 ++$icons{$i};
74 }
75 while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
76 {
77 my $i = "$1$2";
78 ++$icons{$i};
79 }
[2808]80 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
81 {
82 my $i = "statusline/$1";
83 ++$icons{$i};
84 }
[10069]85 if($l =~ /setIcon\(\"(.*?)\"/)
[2808]86 {
[10069]87 my $i = "statusline/$1";
88 ++$icons{$i};
89 }
[13857]90 if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"(?:, (?:ImageProvider\.)?ImageSizes\.[A-Z]+)?\s*\)/)
[10069]91 {
[2808]92 my $i = "$1/$2";
93 ++$icons{$i};
94 }
[10069]95 if($l =~ /new ImageProvider\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
96 {
97 my $i = "$1/$2";
98 ++$icons{$i};
99 }
[2811]100 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
101 {
[2808]102 my $i = "cursor/modifier/$2";
103 ++$icons{$i};
104 $i = "cursor/$1";
105 ++$icons{$i};
106 }
[2811]107 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
108 {
109 my $i = "cursor/$1";
110 ++$icons{$i};
111 }
[2808]112 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
113 {
114 my $i = "$extends$1";
115 ++$icons{$i};
116 }
[2981]117 if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
118 {
119 my $i = "$extends$1";
120 ++$icons{$i};
121 }
[13277]122 if($l =~ /setButtonIcons.*\{(.*)\}/ || $l =~ /setButtonIcons\((.*)\)/ )
[2808]123 {
124 my $t = $1;
125 while($t =~ /\"(.*?)\"/g)
126 {
127 my $i = $1;
128 ++$icons{$i};
129 }
130 }
131 }
132 close FILE;
133 }
134}
135
136my %haveicons;
137
[16006]138for($i = 1; my @ifiles = (glob("resources/images".("/*" x $i).".png"), glob("resources/images".("/*" x $i).".svg")); ++$i)
[2808]139{
140 for my $ifile (sort @ifiles)
141 {
[16006]142 $ifile =~ s/^resources\/images\///;
[10561]143 # svg comes after png due to the glob, so only check for svg's
144 if($ifile =~ /^(.*)\.svg$/)
145 {
146 if($haveicons{"$1.png"})
147 {
[13279]148 print STDERR "$1: File exists twice as .svg and .png.\n";
[10561]149 }
150 # check for unwanted svg effects
[16006]151 if(open FILE, "<","resources/images/$ifile")
[10561]152 {
[18115]153 my $hadfont = 0;
[10561]154 undef $/;
155 my $f = <FILE>;
156 close FILE;
[13384]157 for my $sep ("'", '"')
[10561]158 {
[13384]159 while($f =~ /style\s*=\s*$sep([^$sep]+)$sep/g)
[10561]160 {
[13384]161 for my $x (split(/\s*;\s*/, $1))
162 {
163 print STDERR "$ifile: Style starts with minus: $x\n" if $x =~ /^-/;
[18115]164 ++$hadfont if($x =~ /^font-/);
165 if($x =~ /^font-family:(.*)$/ && $x !~ /^font-family:'Droid Sans'/)
166 {
167 print STDERR "$ifile: Unwanted font-family: $1\n"
168 }
[13384]169 }
[10561]170 }
171 }
[16876]172 if($f =~ /<style[^>]+type=['"]text\/css['"][^>]*>/m)
173 {
174 print STDERR "$ifile: CSS-Style in SVG icon not supported\n";
175 }
[10561]176 if($f =~ /viewBox\s*=\s*["']([^"']+)["']/)
177 {
178 my $x = $1;
[13279]179 print STDERR "$ifile: ViewBox has float values: $x\n" if $x =~ /\./;
[10561]180 }
[18115]181 if($f !~ /<text/ && $hadfont)
182 {
183 print STDERR "$ifile: Font-style without <text>\n";
184 }
[10561]185 }
186 else
187 {
[13279]188 print STDERR "$ifile: Could not open file: $1";
[10561]189 }
190 }
[2808]191 $haveicons{$ifile} = 1;
192 }
193}
194
195for my $img (sort keys %icons)
196{
[7668]197 if($img =~ /\.(png|svg)/)
198 {
[16006]199 print STDERR "$img: File does not exist!\n" if(!-f "resources/images/$img");
[7668]200 delete $haveicons{$img};
201 }
202 else
203 {
[16006]204 print STDERR "$img(.svg|.png): File does not exist!\n" if(!-f "resources/images/$img.png" && !-f "resources/images/$img.svg");
[7668]205 delete $haveicons{"$img.svg"};
206 delete $haveicons{"$img.png"};
207 }
[2808]208}
209
210for my $img (sort keys %haveicons)
211{
[13279]212 print "$img: Unused image.\n";
[2808]213}
Note: See TracBrowser for help on using the repository browser.