Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / gfx / thebes / test / process-textruns.pl
blobd1805b8dceb1dbbcbfc478a1084bdf5057dd48ea
1 #!/usr/bin/perl -w
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is Mozilla Corportation code.
18 # The Initial Developer of the Original Code is Mozilla Corporation.
19 # Portions created by the Initial Developer are Copyright (C) 2007
20 # the Initial Developer. All Rights Reserved.
22 # Contributor(s):
23 # Robert O'Callahan <robert@ocallahan.org>
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 # This script is a bunch of utilities for computing statistics about the textruns
40 # created during a Gecko run.
42 # Usage:
43 # 1) Uncomment #define DUMP_TEXT_RUNS in gfxAtsuiFonts.cpp
44 # 2) Build
45 # 3) Run over some test set, redirecting stdout to a file
46 # 4) Pipe that file through this script
48 # --exclude-spaces-only: ignore all textruns that consistent of zero or more
49 # spaces
50 my $exclude_spaces = grep(/^--exclude-spaces-only$/, @ARGV);
52 # --dump-runs: process textruns into a format that can be used by
53 # gfxTextRunPerfTest, print that on standard output, and do nothing else
54 my $dump_runs = grep(/^--dump-runs$/, @ARGV);
56 # --obfuscate: ROTL13 the textrun text
57 my $obfuscate = grep(/^--obfuscate$/, @ARGV);
59 my @textruns = ();
61 while (<STDIN>) {
62 if (/^0x(\w+)\((.*)\) TEXTRUN "(.*)" ENDTEXTRUN$/) {
63 my %tr = ( fontgroup => $1,
64 families => $2,
65 text => $3 );
66 push(@textruns, \%tr);
67 } elsif (/^0x(\w+)\((.*)\) TEXTRUN "(.*)$/) {
68 my %tr = ( fontgroup => $1,
69 families => $2 );
70 my $text = $3."\n";
71 while (<STDIN>) {
72 if (/^(.*)" ENDTEXTRUN$/) {
73 $text .= $1;
74 last;
76 $text .= $_;
78 $tr{text} = $text;
79 push(@textruns, \%tr);
83 my %quote = ( "\\" => 1, "\"" => 1 );
85 sub quote_str {
86 my ($text) = @_;
87 my @chars = split(//, $text);
88 my @strs = ();
89 foreach my $c (@chars) {
90 if (ord($c) >= 0x80) {
91 $c = "\\x".sprintf("%x",ord($c)).'""';
92 } elsif ($quote{$c}) {
93 $c = "\\$c";
94 } elsif ($c eq "\n") {
95 $c = " ";
97 push(@strs, $c);
99 return '"'.join("", @strs).'"';
102 if ($dump_runs) {
103 foreach my $tr (@textruns) {
104 print "{ ", &quote_str($tr->{families}), ",\n";
105 my $text = $tr->{text};
106 if ($obfuscate) {
107 $text =~ tr/a-mA-Mn-zN-Z/n-zN-Za-mA-M/;
109 print " ", &quote_str($text), " },\n";
111 exit(0);
114 my %trs_by_text = ();
115 my %trs_by_text_and_fontgroup = ();
116 my %trs_by_trimmed_text_and_fontgroup = ();
117 my @tr_lengths = ();
119 $trs_by_text{" "} = [];
120 $trs_by_text{""} = [];
122 sub trim {
123 my ($s) = @_;
124 $s =~ s/^ *//g;
125 $s =~ s/ *$//g;
126 return $s;
129 my $total_textruns = 0;
131 foreach my $tr (@textruns) {
132 if ($exclude_spaces && $tr->{text} =~ /^ *$/) {
133 next;
135 ++$total_textruns;
136 push(@{$trs_by_text{$tr->{text}}}, $tr);
137 push(@{$trs_by_text_and_fontgroup{$tr->{fontgroup}.$tr->{text}}}, $tr);
138 push(@{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup}.&trim($tr->{text})}}, $tr);
139 if (1 < scalar(@{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup}.&trim($tr->{text})}})) {
140 $tr_lengths[length($tr->{text})]++;
144 print "Number of textruns:\t$total_textruns\n";
145 print "Number of textruns which are one space:\t", scalar(@{$trs_by_text{" "}}), "\n";
146 print "Number of textruns which are empty:\t", scalar(@{$trs_by_text{""}}), "\n";
148 my $count = 0;
149 foreach my $k (keys(%trs_by_text)) {
150 if ($k =~ /^ *$/) {
151 $count += @{$trs_by_text{$k}};
154 print "Number of textruns which are zero or more spaces:\t$count\n";
156 print "Number of unique textruns by text and fontgroup:\t", scalar(keys(%trs_by_text_and_fontgroup)), "\n";
157 print "Number of unique textruns by trimmed text and fontgroup:\t", scalar(keys(%trs_by_trimmed_text_and_fontgroup)), "\n";
159 my $sum = 0;
160 my $weighted_sum = 0;
161 if (1) {
162 print "Textrun length distribution:\n";
163 for my $i (0..(scalar(@tr_lengths)-1)) {
164 my $amount = defined($tr_lengths[$i])?$tr_lengths[$i]:0;
165 $sum += $amount;
166 $weighted_sum += $i*$amount;
167 print "$i\t$sum\t$weighted_sum\n";