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

Last change on this file since 18723 was 18115, checked in by stoecker, 4 years ago

add font-checks to geticons.pl, see #21143

  • 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 {
[13277]33 if($l =~ /private static final String ([A-Z_]+) = ("[^"]+")/)
34 {
35 push(@defs, [$1, $2]);
36 }
[7668]37 next if $l =~ /NO-ICON/;
[13277]38 for my $d (@defs)
39 {
40 $l =~ s/$d->[0]/$d->[1]/g;
41 }
[10069]42 if($l =~ /icon\s*[:=]\s*["']([^"'+]+?)["']/)
[2808]43 {
[18115]44 my $i = $1;
45 ++$icons{$i};
[2808]46 }
47
[7670]48 if(($l =~ /(?:icon-image|repeat-image|fill-image)\s*:\s*(\"?(.*?)\"?)\s*;/) && ($1 ne "none"))
[4172]49 {
[18115]50 my $i = $2;
51 ++$icons{$i};
[4172]52 }
[13857]53 if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"(?:, (?:ImageProvider\.)?ImageSizes\.[A-Z]+)?\)/)
[2808]54 {
55 my $i = $1;
56 ++$icons{$i};
57 }
[4172]58 while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
59 {
60 my $i = $1;
61 ++$icons{$i};
62 }
63 while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
64 {
65 my $i = "$1$2";
66 ++$icons{$i};
67 }
[2808]68 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
69 {
70 my $i = "statusline/$1";
71 ++$icons{$i};
72 }
[10069]73 if($l =~ /setIcon\(\"(.*?)\"/)
[2808]74 {
[10069]75 my $i = "statusline/$1";
76 ++$icons{$i};
77 }
[13857]78 if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"(?:, (?:ImageProvider\.)?ImageSizes\.[A-Z]+)?\s*\)/)
[10069]79 {
[2808]80 my $i = "$1/$2";
81 ++$icons{$i};
82 }
[10069]83 if($l =~ /new ImageProvider\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
84 {
85 my $i = "$1/$2";
86 ++$icons{$i};
87 }
[2811]88 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
89 {
[2808]90 my $i = "cursor/modifier/$2";
91 ++$icons{$i};
92 $i = "cursor/$1";
93 ++$icons{$i};
94 }
[2811]95 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
96 {
97 my $i = "cursor/$1";
98 ++$icons{$i};
99 }
[2808]100 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
101 {
102 my $i = "$extends$1";
103 ++$icons{$i};
104 }
[2981]105 if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
106 {
107 my $i = "$extends$1";
108 ++$icons{$i};
109 }
[13277]110 if($l =~ /setButtonIcons.*\{(.*)\}/ || $l =~ /setButtonIcons\((.*)\)/ )
[2808]111 {
112 my $t = $1;
113 while($t =~ /\"(.*?)\"/g)
114 {
115 my $i = $1;
116 ++$icons{$i};
117 }
118 }
119 if($l =~ /extends MapMode/)
120 {
121 $extends = "mapmode/";
122 }
[7668]123 elsif($l =~ /extends ToggleDialog/)
[2808]124 {
125 $extends = "dialogs/";
126 }
[10069]127 elsif($l =~ /extends JosmAction/)
128 {
129 $extends = "";
130 }
[2808]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.