Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / makepsheader.pl
1 #!/usr/bin/perl
2 #############################################################################
3 ##
4 ## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
7 ##
8 ## This file is part of the QtGui module of the Qt Toolkit.
9 ##
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ##
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ##
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
30 ##
31 ## Other Usage
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## conditions contained in a signed written agreement between you and Nokia.
34 ##
35 ##
36 ##
37 ##
38 ##
39 ## $QT_END_LICENSE$
40 ##
41 #############################################################################
42
43 open(INPUT, 'qpsprinter.ps')
44   or die "Can't open qpsprinter.ps";
45
46 $dontcompress = 1;
47 while(<INPUT>) {
48   $line = $_;
49   chomp $line;
50   if ( /ENDUNCOMPRESS/ ) {
51     $dontcompress = 0;
52   }
53   $line =~ s/%.*$//;
54   $line = $line;
55   if ( $dontcompress eq 1 ) {
56     push(@uncompressed, $line);
57   } else {
58     push(@lines, $line);
59   }
60 #  print "$line\n";
61 }
62
63 $uc = join(" ", @uncompressed);
64 $uc =~ s,\t+, ,g;
65 $uc=~ s, +, ,g;
66
67 $h = join(" ", @lines);
68 $h =~ s,\t+, ,g;
69 $h =~ s, +, ,g;
70 $h = $h.' ';
71
72 # now compress as much as possible
73 $h =~ s/ bind def / BD /g;
74 $h =~ s/ dup dup / d2 /g;
75 $h =~ s/ exch def / ED /g;
76 $h =~ s/ setfont / F /g;
77 $h =~ s/ rlineto / RL /g;
78 $h =~ s/ newpath / n /g;
79 $h =~ s/ currentmatrix / CM /g;
80 $h =~ s/ setmatrix / SM /g;
81 $h =~ s/ translate / TR /g;
82 $h =~ s/ setdash / SD /g;
83 $h =~ s/ aload pop setrgbcolor / SC /g;
84 $h =~ s/ currentfile read pop / CR /g;
85 $h =~ s/ index / i /g;
86 $h =~ s/ bitshift / bs /g;
87 $h =~ s/ setcolorspace / scs /g;
88 $h =~ s/ dict dup begin / DB /g;
89 $h =~ s/ end def / DE /g;
90 $h =~ s/ ifelse / ie /g;
91
92 # PDF compatible naming
93 $h =~ s/ setlinewidth / w /g;
94 $h =~ s/ setdash / d /g;
95
96 $h =~ s/ lineto / l /g;
97 $h =~ s/ moveto / m /g;
98 $h =~ s/ curveto / c /g;
99 $h =~ s/ closepath / h /g;
100 $h =~ s/ clip / W /g;
101 $h =~ s/ eoclip / W* /g;
102
103 $h =~ s/ gsave / gs /g;
104 $h =~ s/ grestore / gr /g;
105
106 # add the uncompressed part of the header before
107 $h = $uc.' '.$h;
108
109
110
111 #print $h;
112
113 # wordwrap at col 76
114 @head = split(' ', $h);
115 $line = shift @head;
116 while( @head ) {
117   $token = shift @head;
118   chomp $token;
119 #  print "\nl=$l, len=$len, token=$token.";
120   $newline = $line.' '.$token;
121   $newline =~ s, /,/,g;
122   $newline =~ s, \{,\{,g;
123   $newline =~ s, \},\},g;
124   $newline =~ s, \[,\[,g;
125   $newline =~ s, \],\],g;
126   $newline =~ s,\{ ,\{,g;
127   $newline =~ s,\} ,\},g;
128   $newline =~ s,\[ ,\[,g;
129   $newline =~ s,\] ,\],g;
130   if ( length( $newline ) > 76 ) {
131 #    print "\nline=$line\n";
132     $header = $header."\n\"".$line."\\n\"";
133     $newline = $token;
134   }
135   $line = $newline;
136 }
137 $header = $header."\n\"".$line."\\n\"";
138
139
140 print "static const char *const ps_header =";
141 print $header.";\n\n";
142
143 close(INPUT);
144 exit;
145
146 open(INPUT, 'qpsprinter.agl')
147   or die "Can't open qpsprinter.ps";
148
149 print "static const char * const agl =\n";
150
151 $str = "\"";
152 $string ="";
153 $i = 0;
154 while(<INPUT>) {
155   $line = $_;
156   chomp $line;
157   $line =~ s/#.*//;
158   if(length($line) ne 0) {
159     $num = $line;
160     $name = $line;
161     $num =~ s/,.*//;
162     $name =~ s/.*, \"//;
163     $name =~ s/\".*//;
164     push(@qchar, $num);
165     push(@index, $i);
166     if(length($str.$name) > 76) {
167       $str = $str."\"\n";
168       $string = $string.$str;
169       $str = "\"";
170     }
171     $str = $str.$name."\\0";
172     $i += length($name)+1;
173   }
174 }
175
176 print $string.";\n\n";
177
178 print "static const struct { quint16 u; quint16 index; } unicodetoglyph[] = {\n    ";
179
180 $loop = 0;
181 while( @qchar ) {
182   $loop = $loop + 1;
183   $ch = shift @qchar;
184   $i = shift @index;
185   print "{".$ch.", ".$i."}";
186   if($ch ne "0xFFFF") {
187     print ", ";
188   }
189   if(!($loop % 4)) {
190     print "\n    ";
191   }
192 };
193
194 print "\n};\n\n";
195